Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 479814 - Relate JSDoc and the nodes it references (was: [refs] Consider function and param names in their doc as exact matches)
Summary: Relate JSDoc and the nodes it references (was: [refs] Consider function and p...
Status: CLOSED WONTFIX
Alias: None
Product: Orion
Classification: ECD
Component: JS Tools (show other bugs)
Version: 10.0   Edit
Hardware: PC Windows 7
: P4 normal (vote)
Target Milestone: ---   Edit
Assignee: Michael Rennie CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 471947
  Show dependency tree
 
Reported: 2015-10-15 01:21 EDT by Michael Rennie CLA
Modified: 2018-04-09 09:40 EDT (History)
3 users (show)

See Also:


Attachments
Trying to add other jsdoc directives like params but failed to show the result in the final panel. (3.09 KB, patch)
2016-04-12 16:57 EDT, Troy Tao CLA
no flags Details | Diff
screen shot (134.45 KB, image/png)
2016-04-18 16:27 EDT, Michael Rennie CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Rennie CLA 2015-10-15 01:21:02 EDT
Consider the following snippet:

/**
 * @name myfunc
 */
function myfunc() {}

If you select the function name and run Rferences > Project, the match in the comment is placed in the 'unrelated matches' group. We should improve the type-checking for a block comment to see if it is talking about the function type we are searching for.

We should also be checking @see, @param, @return(s), @memberOf and @type.
Comment 1 Eclipse Genie CLA 2016-04-11 09:30:11 EDT
New Gerrit change created: https://git.eclipse.org/r/70360
Comment 2 Michael Rennie CLA 2016-04-11 11:23:23 EDT
The change looks good in the refsCommand code, but I would prefer if you could move the change out of doc_comment - the reason being, doc_comment is a Tern core plugin, and we are trying to avoid making any changes in the Tern code unless absolutely necessary.
Comment 3 Troy Tao CLA 2016-04-11 11:39:25 EDT
Yes, "trying to not hurt any Tern-related stuff" is the main issue I faced in last two weeks. Since the mechanism behind Tern still remained obscure to me, I hardly can find a way to ensure my change will not influence Tern's functionalities. This issue also caused a hard-time with https://bugs.eclipse.org/bugs/show_bug.cgi?id=481271 because sometimes there are just strong signs showing we have no other way rather than changing tern.js or infer.js or its plugins directly. Mike, could you elaborate Tern's mechanism (like how Tern populates its types in the fileMap)?
Comment 4 Michael Rennie CLA 2016-04-11 17:01:44 EDT
(In reply to Troy Tao from comment #3)
> Yes, "trying to not hurt any Tern-related stuff" is the main issue I faced
> in last two weeks. Since the mechanism behind Tern still remained obscure to
> me, I hardly can find a way to ensure my change will not influence Tern's
> functionalities. This issue also caused a hard-time with
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=481271 because sometimes there
> are just strong signs showing we have no other way rather than changing
> tern.js or infer.js or its plugins directly. Mike, could you elaborate
> Tern's mechanism (like how Tern populates its types in the fileMap)?

In the case of your changes, it will actually break Terns' ability to process type infos from comments, since you change what used to be a string to an object.

It might make more sense to add the processing in the refs plugin (web/javascript/ternPlugins/refs.js) when we make the request to Tern. You can ask for the AST and leading / trailing comments for a given node (or node parent).

There is already a section in there specifically for block comments, which might be useful.
Comment 5 Eclipse Genie CLA 2016-04-12 10:56:57 EDT
New Gerrit change created: https://git.eclipse.org/r/70483
Comment 6 Troy Tao CLA 2016-04-12 11:02:03 EDT
I have uploaded a new git commit where the Tern plugin keeps unchanged.
Comment 7 Troy Tao CLA 2016-04-12 16:57:22 EDT
Created attachment 260903 [details]
Trying to add other jsdoc directives like params but failed to show the result in the final panel.

I tried to add other jsdoc directives like params to refs but failed because I can only see a blank clause in the final panel after adding directives to "expected.result" variable. It seems there are other steps happening outside refsCommand.js
Comment 8 Michael Rennie CLA 2016-04-18 16:25:21 EDT
testing the last gerrit, and I found that if you have the same name in doc in other files it is incorrectly tagged as an exact match.

For example I have more than one file with an '@name myfunc' JSDoc tag in it, and they are all marked as matching - when only the doc attached to the function in-context should be a match.

I'll attach a screen shot showing what I mean.
Comment 9 Michael Rennie CLA 2016-04-18 16:27:10 EDT
Created attachment 261051 [details]
screen shot

Notice also there is a 'perfect match' being reported against a name match in a globals directive...
Comment 10 Troy Tao CLA 2016-04-19 15:55:07 EDT
I have uploaded a new change. The previous one failed because of a wrong understanding of several methods like Finder.findComment. It seems that in current Orion, we dont have a strict connection between a AST node (function declaration) and its doc. The interpretComments is doc_comments.js is the only place where we connect doc to a node and it is a very loose one because as long as there is more than two new lines between a function and its jsdoc, tern refuse to think them as together. 

Besides, for the jsdoc checking step (check things like format), my original thought is to change the jsdocInterpretComments in doc_comments.js but since tern's plugin code is better keeping unchanged, I put that step in refsCommand.js
Comment 11 Michael Rennie CLA 2017-01-05 13:02:30 EST
I think we need to go for a more general approach here.

We should attach the doc comment infos directly to the node they reference as well as tag the comment object with the node infos it talks about. This would allow us to very quickly find the relationship between doc and nodes without forward lookups, and could also be used for:

1. occurrences in doc
2. param hovers - show only the params doc instead of the entire function doc
3. content assist - show only param / name doc instead of root node doc
Comment 12 Michael Rennie CLA 2018-04-09 09:40:56 EDT
Closing as part of a mass clean up of inactive bugs. Please reopen if this problem still occurs or is relevant to you. 

For more details see: https://dev.eclipse.org/mhonarc/lists/orion-dev/msg04114.html