-
Notifications
You must be signed in to change notification settings - Fork 720
JSDoc completions #1561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSDoc completions #1561
Changes from 8 commits
6f4c926
d0fe474
1c139db
5681cd2
586cc88
7195326
735e964
dbb019c
9f591cd
d9fdf3b
29a2e97
f2d246d
ec2c9bb
cb9e480
ec55a18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2104,6 +2104,9 @@ | |
} | ||
|
||
// True if node is of a JSDoc kind that may contain comment text. | ||
// NOTE: while this is a faithful port of Strada's implementation, | ||
|
||
// it is unsafe to call `.Comments()` on a node that returns true from this function, | ||
// becuase JSDoc type literal and JSDoc signature nodes do not have comments. | ||
func IsJSDocCommentContainingNode(node *Node) bool { | ||
return node.Kind == KindJSDoc || | ||
node.Kind == KindJSDocText || | ||
|
@@ -3017,13 +3020,27 @@ | |
return node.Kind == KindTypeKeyword | ||
} | ||
|
||
// If node is a single comment JSDoc, we do not visit the comment node list. | ||
func IsJSDocSingleCommentNodeList(parent *Node, nodeList *NodeList) bool { | ||
return IsJSDocSingleCommentNode(parent) && nodeList == parent.AsJSDoc().Comment | ||
// See `IsJSDocSingleCommentNode`. | ||
func IsJSDocSingleCommentNodeList(nodeList *NodeList) bool { | ||
if nodeList == nil || len(nodeList.Nodes) == 0 { | ||
return false | ||
} | ||
parent := nodeList.Nodes[0].Parent | ||
return IsJSDocSingleCommentNode(parent) && nodeList == parent.CommentList() | ||
} | ||
|
||
// See `IsJSDocSingleCommentNode`. | ||
func IsJSDocSingleCommentNodeComment(node *Node) bool { | ||
if node == nil || node.Parent == nil { | ||
return false | ||
} | ||
return IsJSDocSingleCommentNode(node.Parent) && node == node.Parent.CommentList().Nodes[0] | ||
} | ||
|
||
// In Strada, if a JSDoc node has a single comment, that comment is represented as a string property | ||
// as a simplification, and therefore that comment is not visited by `forEachChild`. | ||
func IsJSDocSingleCommentNode(node *Node) bool { | ||
return node.Kind == KindJSDoc && node.AsJSDoc().Comment != nil && len(node.AsJSDoc().Comment.Nodes) == 1 | ||
return hasComment(node.Kind) && node.CommentList() != nil && len(node.CommentList().Nodes) == 1 | ||
} | ||
|
||
func IsValidTypeOnlyAliasUseSite(useSite *Node) bool { | ||
|
@@ -3635,3 +3652,18 @@ | |
} | ||
}) | ||
} | ||
|
||
// Returns true if the node kind has a comment property. | ||
func hasComment(kind Kind) bool { | ||
switch kind { | ||
case KindJSDoc, KindJSDocTag, KindJSDocAugmentsTag, KindJSDocImplementsTag, | ||
KindJSDocDeprecatedTag, KindJSDocPublicTag, KindJSDocPrivateTag, KindJSDocProtectedTag, | ||
KindJSDocReadonlyTag, KindJSDocOverrideTag, KindJSDocCallbackTag, KindJSDocOverloadTag, | ||
KindJSDocParameterTag, KindJSDocPropertyTag, KindJSDocReturnTag, KindJSDocThisTag, | ||
KindJSDocTypeTag, KindJSDocTemplateTag, KindJSDocTypedefTag, KindJSDocSeeTag, | ||
KindJSDocSatisfiesTag, KindJSDocImportTag: | ||
return true | ||
default: | ||
return false | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.