Skip to content

Commit 7b67ad2

Browse files
ivanwonderthePunderWoman
authored andcommitted
refactor(language-service): support showing tags info in the completion (#51140)
The Angular VSCode extension will support showing the tags info in this [PR][1], so the language service can return the tags info now. [1]: angular/vscode-ng-language-service#1904 PR Close #51140
1 parent 129c973 commit 7b67ad2

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

packages/language-service/src/completions.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,15 @@ export class CompletionBuilder<N extends TmplAstNode|AST> {
470470
return undefined;
471471
}
472472

473-
const {kind, displayParts, documentation} =
473+
const {kind, displayParts, documentation, tags} =
474474
getSymbolDisplayInfo(this.tsLS, this.typeChecker, symbol);
475475
return {
476476
kind: unsafeCastDisplayInfoKindToScriptElementKind(kind),
477477
name: entryName,
478478
kindModifiers: ts.ScriptElementKindModifier.none,
479479
displayParts,
480480
documentation,
481+
tags,
481482
};
482483
} else {
483484
return this.tsLS.getCompletionEntryDetails(
@@ -579,12 +580,14 @@ export class CompletionBuilder<N extends TmplAstNode|AST> {
579580
const directive = tagMap.get(entryName)!;
580581
let displayParts: ts.SymbolDisplayPart[];
581582
let documentation: ts.SymbolDisplayPart[]|undefined = undefined;
583+
let tags: ts.JSDocTagInfo[]|undefined = undefined;
582584
if (directive === null) {
583585
displayParts = [];
584586
} else {
585587
const displayInfo = getDirectiveDisplayInfo(this.tsLS, directive);
586588
displayParts = displayInfo.displayParts;
587589
documentation = displayInfo.documentation;
590+
tags = displayInfo.tags;
588591
}
589592

590593
return {
@@ -593,6 +596,7 @@ export class CompletionBuilder<N extends TmplAstNode|AST> {
593596
kindModifiers: ts.ScriptElementKindModifier.none,
594597
displayParts,
595598
documentation,
599+
tags,
596600
};
597601
}
598602

@@ -832,6 +836,7 @@ export class CompletionBuilder<N extends TmplAstNode|AST> {
832836
const completion = attrTable.get(name)!;
833837
let displayParts: ts.SymbolDisplayPart[];
834838
let documentation: ts.SymbolDisplayPart[]|undefined = undefined;
839+
let tags: ts.JSDocTagInfo[]|undefined = undefined;
835840
let info: DisplayInfo|null;
836841
switch (completion.kind) {
837842
case AttributeCompletionKind.DomEvent:
@@ -846,6 +851,7 @@ export class CompletionBuilder<N extends TmplAstNode|AST> {
846851
info = getDirectiveDisplayInfo(this.tsLS, completion.directive);
847852
displayParts = info.displayParts;
848853
documentation = info.documentation;
854+
tags = info.tags;
849855
break;
850856
case AttributeCompletionKind.StructuralDirectiveAttribute:
851857
case AttributeCompletionKind.DirectiveInput:
@@ -871,6 +877,7 @@ export class CompletionBuilder<N extends TmplAstNode|AST> {
871877
}
872878
displayParts = info.displayParts;
873879
documentation = info.documentation;
880+
tags = info.tags;
874881
}
875882

876883
return {
@@ -879,6 +886,7 @@ export class CompletionBuilder<N extends TmplAstNode|AST> {
879886
kindModifiers: ts.ScriptElementKindModifier.none,
880887
displayParts,
881888
documentation,
889+
tags,
882890
};
883891
}
884892

packages/language-service/src/display_parts.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface DisplayInfo {
4343
kind: DisplayInfoKind;
4444
displayParts: ts.SymbolDisplayPart[];
4545
documentation: ts.SymbolDisplayPart[]|undefined;
46+
tags: ts.JSDocTagInfo[]|undefined;
4647
}
4748

4849
export function getSymbolDisplayInfo(
@@ -61,13 +62,14 @@ export function getSymbolDisplayInfo(
6162
const displayParts = createDisplayParts(
6263
symbol.declaration.name, kind, /* containerName */ undefined,
6364
typeChecker.typeToString(symbol.tsType));
64-
const documentation = symbol.kind === SymbolKind.Reference ?
65-
getDocumentationFromTypeDefAtLocation(tsLS, symbol.targetLocation) :
66-
getDocumentationFromTypeDefAtLocation(tsLS, symbol.initializerLocation);
65+
const quickInfo = symbol.kind === SymbolKind.Reference ?
66+
getQuickInfoFromTypeDefAtLocation(tsLS, symbol.targetLocation) :
67+
getQuickInfoFromTypeDefAtLocation(tsLS, symbol.initializerLocation);
6768
return {
6869
kind,
6970
displayParts,
70-
documentation,
71+
documentation: quickInfo?.documentation,
72+
tags: quickInfo?.tags,
7173
};
7274
}
7375

@@ -121,28 +123,37 @@ export function unsafeCastDisplayInfoKindToScriptElementKind(kind: DisplayInfoKi
121123
return kind as string as ts.ScriptElementKind;
122124
}
123125

124-
function getDocumentationFromTypeDefAtLocation(
125-
tsLS: ts.LanguageService, tcbLocation: TcbLocation): ts.SymbolDisplayPart[]|undefined {
126+
function getQuickInfoFromTypeDefAtLocation(
127+
tsLS: ts.LanguageService, tcbLocation: TcbLocation): ts.QuickInfo|undefined {
126128
const typeDefs =
127129
tsLS.getTypeDefinitionAtPosition(tcbLocation.tcbPath, tcbLocation.positionInFile);
128130
if (typeDefs === undefined || typeDefs.length === 0) {
129131
return undefined;
130132
}
131-
return tsLS.getQuickInfoAtPosition(typeDefs[0].fileName, typeDefs[0].textSpan.start)
132-
?.documentation;
133+
return tsLS.getQuickInfoAtPosition(typeDefs[0].fileName, typeDefs[0].textSpan.start);
133134
}
134135

135136
export function getDirectiveDisplayInfo(
136137
tsLS: ts.LanguageService, dir: PotentialDirective): DisplayInfo {
137138
const kind = dir.isComponent ? DisplayInfoKind.COMPONENT : DisplayInfoKind.DIRECTIVE;
138139
const decl = dir.tsSymbol.declarations.find(ts.isClassDeclaration);
139140
if (decl === undefined || decl.name === undefined) {
140-
return {kind, displayParts: [], documentation: []};
141+
return {
142+
kind,
143+
displayParts: [],
144+
documentation: [],
145+
tags: undefined,
146+
};
141147
}
142148

143149
const res = tsLS.getQuickInfoAtPosition(decl.getSourceFile().fileName, decl.name.getStart());
144150
if (res === undefined) {
145-
return {kind, displayParts: [], documentation: []};
151+
return {
152+
kind,
153+
displayParts: [],
154+
documentation: [],
155+
tags: undefined,
156+
};
146157
}
147158

148159
const displayParts =
@@ -152,6 +163,7 @@ export function getDirectiveDisplayInfo(
152163
kind,
153164
displayParts,
154165
documentation: res.documentation,
166+
tags: res.tags,
155167
};
156168
}
157169

@@ -167,7 +179,12 @@ export function getTsSymbolDisplayInfo(
167179
}
168180
const res = tsLS.getQuickInfoAtPosition(decl.getSourceFile().fileName, decl.name.getStart());
169181
if (res === undefined) {
170-
return {kind, displayParts: [], documentation: []};
182+
return {
183+
kind,
184+
displayParts: [],
185+
documentation: [],
186+
tags: undefined,
187+
};
171188
}
172189

173190
const type = checker.getDeclaredTypeOfSymbol(symbol);
@@ -179,5 +196,6 @@ export function getTsSymbolDisplayInfo(
179196
kind,
180197
displayParts,
181198
documentation: res.documentation,
199+
tags: res.tags,
182200
};
183201
}

0 commit comments

Comments
 (0)