Skip to content

Commit

Permalink
Add more support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingwl committed May 13, 2020
1 parent 726b933 commit a587d53
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace ts {
export interface ReusableDiagnostic extends ReusableDiagnosticRelatedInformation {
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
reportsUnnecessary?: {};
reportDeprecated?: {}
source?: string;
relatedInformation?: ReusableDiagnosticRelatedInformation[];
}
Expand Down
9 changes: 9 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31170,6 +31170,13 @@ namespace ts {
error(classLike, Diagnostics.JSDoc_0_is_not_attached_to_a_class, idText(node.tagName));
}
}

function checkJSDocDeprecatedTag(node: JSDocDeprecatedTag): void {
const diag = Diagnostics._0_is_deprecated;
diag.reportsDeprecated = true;
errorOrSuggestion(/* isError */ false, node.parent, diag, "test")
}

function checkJSDocAugmentsTag(node: JSDocAugmentsTag): void {
const classLike = getEffectiveJSDocHost(node);
if (!classLike || !isClassDeclaration(classLike) && !isClassExpression(classLike)) {
Expand Down Expand Up @@ -34736,6 +34743,8 @@ namespace ts {
return checkJSDocAugmentsTag(node as JSDocAugmentsTag);
case SyntaxKind.JSDocImplementsTag:
return checkJSDocImplementsTag(node as JSDocImplementsTag);
case SyntaxKind.JSDocDeprecatedTag:
return checkJSDocDeprecatedTag(node as JSDocDeprecatedTag);
case SyntaxKind.JSDocTypedefTag:
case SyntaxKind.JSDocCallbackTag:
case SyntaxKind.JSDocEnumTag:
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4574,6 +4574,10 @@
"category": "Message",
"code": 6384
},
"'{0}' is deprecated": {
"category": "Suggestion",
"code": 6385
},

"The expected type comes from property '{0}' which is declared here on type '{1}'": {
"category": "Message",
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5046,6 +5046,7 @@ namespace ts {
code: number;
message: string;
reportsUnnecessary?: {};
reportsDeprecated?: {};
/* @internal */
elidedInCompatabilityPyramid?: boolean;
}
Expand All @@ -5066,6 +5067,8 @@ namespace ts {
export interface Diagnostic extends DiagnosticRelatedInformation {
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
reportsUnnecessary?: {};

reportsDeprecated?: {}
source?: string;
relatedInformation?: DiagnosticRelatedInformation[];
}
Expand Down
11 changes: 6 additions & 5 deletions src/harness/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ namespace ts.server {
isNewIdentifierLocation: false,
entries: response.body!.map<CompletionEntry>(entry => { // TODO: GH#18217
if (entry.replacementSpan !== undefined) {
const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, source, isRecommended } = entry;
const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, source, isRecommended, tags } = entry;
// TODO: GH#241
const res: CompletionEntry = { name, kind, kindModifiers, sortText, replacementSpan: this.decodeSpan(replacementSpan, fileName), hasAction, source, isRecommended };
const res: CompletionEntry = { name, kind, kindModifiers, sortText, replacementSpan: this.decodeSpan(replacementSpan, fileName), hasAction, source, isRecommended, isDeprecated: tags?.includes(protocol.SymbolTag.Deprecated) };
return res;
}

return entry as { name: string, kind: ScriptElementKind, kindModifiers: string, sortText: string }; // TODO: GH#18217
})
const { name, kind, kindModifiers, sortText, tags } = entry;
return { name, kind, kindModifiers, sortText, isDeprecated: tags?.includes(protocol.SymbolTag.Deprecated) } })
};
}

Expand Down Expand Up @@ -750,7 +750,8 @@ namespace ts.server {
name: item.name,
kind: item.kind,
span: this.decodeSpan(item.span, item.file),
selectionSpan: this.decodeSpan(item.selectionSpan, item.file)
selectionSpan: this.decodeSpan(item.selectionSpan, item.file),
isDeprecated: item.tags?.includes(protocol.SymbolTag.Deprecated)
};
}

Expand Down
6 changes: 6 additions & 0 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,11 @@ namespace ts.server.protocol {
* and therefore may not be accurate.
*/
isFromUncheckedFile?: true;

/**
* Exist if the item has some symbol Tag.
*/
tags?: SymbolTag[]
}

/**
Expand Down Expand Up @@ -3074,6 +3079,7 @@ namespace ts.server.protocol {
file: string;
span: TextSpan;
selectionSpan: TextSpan;
tags?: SymbolTag[]
}

export interface CallHierarchyIncomingCall {
Expand Down
7 changes: 4 additions & 3 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1661,10 +1661,10 @@ namespace ts.server {
const prefix = args.prefix || "";
const entries = mapDefined<CompletionEntry, protocol.CompletionEntry>(completions.entries, entry => {
if (completions.isMemberCompletion || startsWith(entry.name.toLowerCase(), prefix.toLowerCase())) {
const { name, kind, kindModifiers, sortText, insertText, replacementSpan, hasAction, source, isRecommended } = entry;
const { name, kind, kindModifiers, sortText, insertText, replacementSpan, hasAction, source, isRecommended, isDeprecated } = entry;
const convertedSpan = replacementSpan ? toProtocolTextSpan(replacementSpan, scriptInfo) : undefined;
// Use `hasAction || undefined` to avoid serializing `false`.
return { name, kind, kindModifiers, sortText, insertText, replacementSpan: convertedSpan, hasAction: hasAction || undefined, source, isRecommended };
return { name, kind, kindModifiers, sortText, insertText, replacementSpan: convertedSpan, hasAction: hasAction || undefined, source, isRecommended, tags: isDeprecated ? [protocol.SymbolTag.Deprecated] : undefined };
}
}).sort((a, b) => compareStringsCaseSensitiveUI(a.name, b.name));

Expand Down Expand Up @@ -2224,7 +2224,8 @@ namespace ts.server {
kind: item.kind,
file: item.file,
span: toProtocolTextSpan(item.span, scriptInfo),
selectionSpan: toProtocolTextSpan(item.selectionSpan, scriptInfo)
selectionSpan: toProtocolTextSpan(item.selectionSpan, scriptInfo),
tags: item.isDeprecated ? [protocol.SymbolTag.Deprecated] : undefined
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/callHierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ namespace ts.CallHierarchy {
const kind = getNodeKind(node);
const span = createTextSpanFromBounds(skipTrivia(sourceFile.text, node.getFullStart(), /*stopAfterLineBreak*/ false, /*stopAtComments*/ true), node.getEnd());
const selectionSpan = createTextSpanFromBounds(name.pos, name.end);
return { file: sourceFile.fileName, kind, name: name.text, span, selectionSpan };
return { file: sourceFile.fileName, kind, name: name.text, span, selectionSpan, isDeprecated: !!getJSDocDeprecatedTag(node) };
}

function isDefined<T>(x: T): x is NonNullable<T> {
Expand Down
13 changes: 9 additions & 4 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ namespace ts.Completions {
kind: ScriptElementKind.classElement,
kindModifiers: undefined,
sortText: SortText.LocationPriority,
isDeprecated: undefined
};
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: false, entries: [entry] };
}
Expand Down Expand Up @@ -337,7 +338,8 @@ namespace ts.Completions {
kind: ScriptElementKind.warning,
kindModifiers: "",
sortText: SortText.JavascriptIdentifiers,
isFromUncheckedFile: true
isFromUncheckedFile: true,
isDeprecated: undefined
});
}
});
Expand All @@ -349,7 +351,7 @@ namespace ts.Completions {
}

function createCompletionEntryForLiteral(literal: string | number | PseudoBigInt, preferences: UserPreferences): CompletionEntry {
return { name: completionNameForLiteral(literal, preferences), kind: ScriptElementKind.string, kindModifiers: ScriptElementKindModifier.none, sortText: SortText.LocationPriority };
return { name: completionNameForLiteral(literal, preferences), kind: ScriptElementKind.string, kindModifiers: ScriptElementKindModifier.none, sortText: SortText.LocationPriority, isDeprecated: undefined };
}

function createCompletionEntry(
Expand Down Expand Up @@ -437,6 +439,7 @@ namespace ts.Completions {
isRecommended: isRecommendedCompletionMatch(symbol, recommendedCompletion, typeChecker) || undefined,
insertText,
replacementSpan,
isDeprecated: symbol.declarations.some(decl => getJSDocDeprecatedTag(decl))
};
}

Expand Down Expand Up @@ -558,7 +561,8 @@ namespace ts.Completions {
name,
kindModifiers: ScriptElementKindModifier.none,
kind: ScriptElementKind.label,
sortText: SortText.LocationPriority
sortText: SortText.LocationPriority,
isDeprecated: undefined
});
}
}
Expand Down Expand Up @@ -2517,7 +2521,8 @@ namespace ts.Completions {
name: tokenToString(i)!,
kind: ScriptElementKind.keyword,
kindModifiers: ScriptElementKindModifier.none,
sortText: SortText.GlobalsOrKeywords
sortText: SortText.GlobalsOrKeywords,
isDeprecated: undefined
});
}
return res;
Expand Down
3 changes: 2 additions & 1 deletion src/services/jsDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ namespace ts.JsDoc {
kind: ScriptElementKind.keyword,
kindModifiers: "",
sortText: "0",
isDeprecated: undefined
};
}));
}
Expand Down Expand Up @@ -211,7 +212,7 @@ namespace ts.JsDoc {
return undefined;
}

return { name, kind: ScriptElementKind.parameterElement, kindModifiers: "", sortText: "0" };
return { name, kind: ScriptElementKind.parameterElement, kindModifiers: "", sortText: "0", isDeprecated: undefined };
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ namespace ts {
file: string;
span: TextSpan;
selectionSpan: TextSpan;
isDeprecated?: boolean
}

export interface CallHierarchyIncomingCall {
Expand Down Expand Up @@ -1067,6 +1068,7 @@ namespace ts {
source?: string;
isRecommended?: true;
isFromUncheckedFile?: true;
isDeprecated?: boolean
}

export interface CompletionEntryDetails {
Expand Down

0 comments on commit a587d53

Please sign in to comment.