mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 07:29:16 -05:00
Add JsDoc intellisense for JavaScript files
This commit is contained in:
@@ -3653,6 +3653,10 @@ namespace ts {
|
||||
|
||||
let completionData = getCompletionData(fileName, position);
|
||||
if (!completionData) {
|
||||
let entries = getJsDocCompletionEntries(fileName, position);
|
||||
if (entries) {
|
||||
return { isMemberCompletion: false, isNewIdentifierLocation: false, entries };
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -3705,6 +3709,56 @@ namespace ts {
|
||||
return entries;
|
||||
}
|
||||
|
||||
function getJsDocCompletionEntries(fileName: string, position: number): CompletionEntry[] {
|
||||
let sourceFile = getValidSourceFile(fileName);
|
||||
let hasJsDocComment = ts.hasDocComment(sourceFile, position);
|
||||
if (!hasJsDocComment) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// If the current position is right after an At sign
|
||||
if (sourceFile.text.charCodeAt(position - 1) === CharacterCodes.at) {
|
||||
return getAllJsDocCompletionEntries();
|
||||
}
|
||||
|
||||
// Or if the current position is in a tag name
|
||||
let jsDocCommentNode: JSDocComment;
|
||||
let node = ts.getTokenAtPosition(sourceFile, position);
|
||||
while (true) {
|
||||
if (node === sourceFile ||
|
||||
node.kind === SyntaxKind.VariableStatement ||
|
||||
node.kind === SyntaxKind.FunctionDeclaration ||
|
||||
node.kind === SyntaxKind.Parameter ||
|
||||
node.jsDocComment) {
|
||||
jsDocCommentNode = node.jsDocComment;
|
||||
break;
|
||||
}
|
||||
node = node.parent;
|
||||
}
|
||||
if (jsDocCommentNode) {
|
||||
for (let tag of jsDocCommentNode.tags) {
|
||||
if (position >= tag.atToken.pos && position <= tag.tagName.end) {
|
||||
return getAllJsDocCompletionEntries();
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function getAllJsDocCompletionEntries(): CompletionEntry[] {
|
||||
let tagNames = ["augments", "author", "argument", "borrows", "class", "constant", "constructor", "constructs", "default", "deprecated", "description", "event", "example", "extends", "field", "fileOverview", "function", "ignore", "inner", "lends", "link", "memberOf", "name", "namespace", "param", "private", "property", "public", "requires", "returns", "see", "since", "static", "throws", "type", "version"];
|
||||
let entries: CompletionEntry[] = [];
|
||||
for (let tagName of tagNames) {
|
||||
entries.push({
|
||||
name: tagName,
|
||||
kind: ScriptElementKind.keyword,
|
||||
kindModifiers: "",
|
||||
sortText: "0",
|
||||
});
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
function createCompletionEntry(symbol: Symbol, location: Node): CompletionEntry {
|
||||
// Try to get a valid display name for this symbol, if we could not find one, then ignore it.
|
||||
// We would like to only show things that can be added after a dot, so for instance numeric properties can
|
||||
|
||||
Reference in New Issue
Block a user