Skip to content

Conversation

zhengbli
Copy link
Contributor

This PR provides completion list for the following cases:

  • List all the JsDoc tag names right after the @ sign or in the tagname, e.g.:
/** @^ */
var foo = ...

and

/** @pa^ */
var foo = ...
  • Full intellisense in certain JsDoc tag braces, e.g.:
/** @type { numbe^ } */
var foo = ...
/** @param { numbe^ } bar */
var foo = ...

The initial implementation only applies to js files, as currently the parser stores the JSDocComment nodes in the tree for js files but not ts files. Support for ts files may need some discussion.

@zhengbli
Copy link
Contributor Author

@billti @CyrusNajmabadi could you take a look

@zhengbli zhengbli changed the title Add Intellisense for JsDoc Add Intellisense to JsDoc Aug 12, 2015
if (paramTag.typeExpression) {
insideJsDocTagExpression = position > paramTag.typeExpression.pos && position < paramTag.typeExpression.end;
};
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These branches are identical, just let each fall through and use a variable typeTagOrParamTag of type JSDocTypeTag | JSDocParamTag.

}

function getAllJsDocCompletionEntries(): CompletionEntry[] {
return ts.map(JsDocTagNames, tagName => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider caching the result. these are not going to change between invocations. saves you the allocations.

see keywordCompletions for an example.

@@ -131,6 +131,46 @@ namespace ts {
let scanner: Scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ true);

let emptyArray: any[] = [];

const jsDocTagNames: string[] = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the type annotation.

@billti
Copy link
Member

billti commented Aug 21, 2015

Playing around with this, and it returns no completions if I don't have the param name yet, for example, if the cursor is where the | is below, I get no completions. I have to have @param {|} a to get intellisense at the bar. As these are written left-to-right, this is a pain. It means I have to write the rest of the tag, then come back and complete the type. Is this fixable?

/**
 @param {|}
 */
function foo(a){
  // TODO
}

@zhengbli
Copy link
Contributor Author

The problem is that if there is no param name, in the parser the JsDoc comment won't be parsed as a valid jstag node right now, so the compiler can't tell me if I'm inside the braces.

@billti
Copy link
Member

billti commented Aug 21, 2015

Seems like we'll need to fix that then. Having to skip over the type and then backtrack to it to get intellisense if not very intuitive or usable. It should be easy to still parse the tag as an @param tag with an empty name until it is provided.

Also, @returns {|} doesn't give type intellisense at the |, is this not implemented yet?

@zhengbli
Copy link
Contributor Author

I thought the reason we stopped parsing param tag without any param names is to be conservative about the type checking process; however, after I talked to Cyrus it turns out to be fine to keep the parsing going. Therefore now the fix for parsing param tag is added, and the @return tag type expression is considered as well.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 21, 2015

👍

zhengbli added a commit that referenced this pull request Aug 21, 2015
@zhengbli zhengbli merged commit ecaf16d into microsoft:master Aug 21, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants