Skip to content

Commit 2426eb4

Browse files
Add '(approximate)' to the beginning of quick info requests in PartialSemantic mode (#40061)
* Add '(approximate)' to the beginning of quick info requests. * Use 'approximation' instead of 'approximate'.
1 parent c95cffe commit 2426eb4

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/services/services.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,9 @@ namespace ts {
15871587
kind: ScriptElementKind.unknown,
15881588
kindModifiers: ScriptElementKindModifier.none,
15891589
textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
1590-
displayParts: typeChecker.runWithCancellationToken(cancellationToken, typeChecker => typeToDisplayParts(typeChecker, type, getContainerNode(nodeForQuickInfo))),
1590+
displayParts: prefixWithApproximation(
1591+
typeChecker.runWithCancellationToken(cancellationToken, typeChecker => typeToDisplayParts(typeChecker, type, getContainerNode(nodeForQuickInfo)))
1592+
),
15911593
documentation: type.symbol ? type.symbol.getDocumentationComment(typeChecker) : undefined,
15921594
tags: type.symbol ? type.symbol.getJsDocTags() : undefined
15931595
};
@@ -1600,7 +1602,7 @@ namespace ts {
16001602
kind: symbolKind,
16011603
kindModifiers: SymbolDisplay.getSymbolModifiers(symbol),
16021604
textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
1603-
displayParts,
1605+
displayParts: prefixWithApproximation(displayParts),
16041606
documentation,
16051607
tags,
16061608
};
@@ -1630,6 +1632,13 @@ namespace ts {
16301632
}
16311633
}
16321634

1635+
function prefixWithApproximation(displayParts: SymbolDisplayPart[]): SymbolDisplayPart[] {
1636+
if (languageServiceMode === LanguageServiceMode.Semantic) {
1637+
return displayParts;
1638+
}
1639+
return [textPart("(approximation)"), spacePart(), ...displayParts];
1640+
}
1641+
16331642
/// Goto definition
16341643
function getDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined {
16351644
synchronizeHostData();

src/testRunner/unittests/tsserver/partialSemanticServer.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ import { something } from "something";
3030
return { host, session, file1, file2, file3, something, configFile };
3131
}
3232

33+
it("adds '(approximation)' to the description of quick info", () => {
34+
const file: File = {
35+
path: `${tscWatch.projectRoot}/foo.ts`,
36+
content: "export const foo = 100;"
37+
};
38+
const host = createServerHost([file]);
39+
const session = createSession(host, { serverMode: LanguageServiceMode.PartialSemantic, useSingleInferredProject: true });
40+
openFilesForSession([file], session);
41+
const response = session.executeCommandSeq<protocol.QuickInfoRequest>({
42+
command: protocol.CommandTypes.Quickinfo,
43+
arguments: protocolFileLocationFromSubstring(file, "foo"),
44+
}).response as protocol.QuickInfoResponseBody;
45+
46+
assert(stringContainsAt(response.displayString, "(approximation)", 0));
47+
});
48+
3349
it("open files are added to inferred project even if config file is present and semantic operations succeed", () => {
3450
const { host, session, file1, file2 } = setup();
3551
const service = session.getProjectService();

0 commit comments

Comments
 (0)