Skip to content

Commit 33ad591

Browse files
committed
Move LSIF to TS 4.8.4
1 parent a614119 commit 33ad591

File tree

7 files changed

+95
-26
lines changed

7 files changed

+95
-26
lines changed

src/compiler/checker.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ namespace ts {
395395
// extra cost of calling `getParseTreeNode` when calling these functions from inside the
396396
// checker.
397397
const checker: TypeChecker = {
398+
setSymbolChainCache: (cache: SymbolChainCache | undefined): void => {
399+
nodeBuilder.setSymbolChainCache(cache);
400+
},
398401
getNodeCount: () => sum(host.getSourceFiles(), "nodeCount"),
399402
getIdentifierCount: () => sum(host.getSourceFiles(), "identifierCount"),
400403
getSymbolCount: () => sum(host.getSourceFiles(), "symbolCount") + symbolCount,
@@ -4901,7 +4904,9 @@ namespace ts {
49014904
}
49024905

49034906
function createNodeBuilder() {
4907+
let symbolChainCache: SymbolChainCache | undefined;
49044908
return {
4909+
setSymbolChainCache: (cache: SymbolChainCache | undefined): void => { symbolChainCache = cache },
49054910
typeToTypeNode: (type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) =>
49064911
withContext(enclosingDeclaration, flags, tracker, context => typeToTypeNodeHelper(type, context)),
49074912
indexInfoToIndexSignatureDeclaration: (indexInfo: IndexInfo, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) =>
@@ -4942,6 +4947,7 @@ namespace ts {
49424947
readFile: host.readFile ? (fileName => host.readFile!(fileName)) : undefined,
49434948
} : undefined },
49444949
encounteredError: false,
4950+
cache: symbolChainCache,
49454951
reportedDiagnostic: false,
49464952
visitedTypes: undefined,
49474953
symbolDepth: undefined,
@@ -6146,6 +6152,30 @@ namespace ts {
61466152

61476153
/** @param endOfChain Set to false for recursive calls; non-recursive calls should always output something. */
61486154
function getSymbolChain(symbol: Symbol, meaning: SymbolFlags, endOfChain: boolean): Symbol[] | undefined {
6155+
let key: SymbolChainCacheKey | undefined;
6156+
let result: Symbol[] | undefined;
6157+
if (context.cache) {
6158+
key = {
6159+
symbol,
6160+
enclosingDeclaration: context.enclosingDeclaration,
6161+
flags: context.flags,
6162+
meaning: meaning,
6163+
yieldModuleSymbol: yieldModuleSymbol,
6164+
endOfChain: endOfChain
6165+
}
6166+
result = context.cache.lookup(key);
6167+
if (result) {
6168+
return result;
6169+
}
6170+
}
6171+
result = doGetSymbolChain(symbol, meaning, endOfChain);
6172+
if (result && key && context.cache) {
6173+
context.cache.cache(key, result);
6174+
}
6175+
return result;
6176+
}
6177+
6178+
function doGetSymbolChain(symbol: Symbol, meaning: SymbolFlags, endOfChain: boolean): Symbol[] | undefined {
61496179
let accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, !!(context.flags & NodeBuilderFlags.UseOnlyExternalAliasing));
61506180
let parentSpecifiers: (string | undefined)[];
61516181
if (!accessibleSymbolChain ||
@@ -8423,6 +8453,7 @@ namespace ts {
84238453
enclosingDeclaration: Node | undefined;
84248454
flags: NodeBuilderFlags;
84258455
tracker: SymbolTracker;
8456+
cache: SymbolChainCache | undefined;
84268457

84278458
// State
84288459
encounteredError: boolean;

src/compiler/types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4359,7 +4359,22 @@ namespace ts {
43594359
readonly redirectTargetsMap: RedirectTargetsMap;
43604360
}
43614361

4362+
export interface SymbolChainCacheKey {
4363+
symbol: Symbol;
4364+
enclosingDeclaration?: Node;
4365+
flags: NodeBuilderFlags;
4366+
meaning: SymbolFlags;
4367+
yieldModuleSymbol?: boolean;
4368+
endOfChain: boolean;
4369+
}
4370+
4371+
export interface SymbolChainCache {
4372+
lookup(key: SymbolChainCacheKey): Symbol[] | undefined;
4373+
cache(key: SymbolChainCacheKey, value: Symbol[]): void;
4374+
}
4375+
43624376
export interface TypeChecker {
4377+
setSymbolChainCache(cache: SymbolChainCache | undefined): void;
43634378
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
43644379
/* @internal */ getTypeOfSymbol(symbol: Symbol): Type;
43654380
getDeclaredTypeOfSymbol(symbol: Symbol): Type;

src/harness/client.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ namespace ts.server {
170170
return { line, character: offset };
171171
}
172172

173-
getQuickInfoAtPosition(fileName: string, position: number): QuickInfo {
173+
getQuickInfoAtPosition(fileName: string, position: number): QuickInfo;
174+
getQuickInfoAtPosition(node: ts.Node, sourceFile?: ts.SourceFile): QuickInfo;
175+
getQuickInfoAtPosition(arg0: string | ts.Node, arg1: number | ts.SourceFile | undefined): QuickInfo {
176+
const fileName = typeof arg0 === "string" ? arg0 : arg1 !== undefined ? (arg1 as ts.SourceFile).fileName : arg0.getSourceFile().fileName;
177+
const position = typeof arg0 === "string" ? arg1 as number : arg0.getStart(arg1 as ts.SourceFile);
174178
const args = this.createFileLocationRequestArgs(fileName, position);
175179

176180
const request = this.processRequest<protocol.QuickInfoRequest>(CommandNames.Quickinfo, args);
@@ -632,7 +636,10 @@ namespace ts.server {
632636
}));
633637
}
634638

635-
getOutliningSpans(file: string): OutliningSpan[] {
639+
getOutliningSpans(file: string): OutliningSpan[];
640+
getOutliningSpans(sourceFile: ts.SourceFile): OutliningSpan[];
641+
getOutliningSpans(arg0: string | ts.SourceFile): OutliningSpan[] {
642+
const file = typeof arg0 === "string" ? arg0 : arg0.fileName;
636643
const request = this.processRequest<protocol.OutliningSpansRequest>(CommandNames.GetOutliningSpans, { file });
637644
const response = this.processResponse<protocol.OutliningSpansResponse>(request);
638645

src/harness/harnessLanguageService.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,10 @@ namespace Harness.LanguageService {
499499
getCompletionEntrySymbol(): ts.Symbol {
500500
throw new Error("getCompletionEntrySymbol not implemented across the shim layer.");
501501
}
502-
getQuickInfoAtPosition(fileName: string, position: number): ts.QuickInfo {
503-
return unwrapJSONCallResult(this.shim.getQuickInfoAtPosition(fileName, position));
502+
getQuickInfoAtPosition(filename: string, position: number): ts.QuickInfo | undefined;
503+
getQuickInfoAtPosition(node: ts.Node, sourceFile: ts.SourceFile | undefined): ts.QuickInfo | undefined;
504+
getQuickInfoAtPosition(arg0: string | ts.Node, arg1: number | ts.SourceFile | undefined): ts.QuickInfo | undefined {
505+
return unwrapJSONCallResult(this.shim.getQuickInfoAtPosition(arg0 as any, arg1 as any));
504506
}
505507
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): ts.TextSpan {
506508
return unwrapJSONCallResult(this.shim.getNameOrDottedNameSpan(fileName, startPos, endPos));
@@ -556,8 +558,8 @@ namespace Harness.LanguageService {
556558
getNavigationTree(fileName: string): ts.NavigationTree {
557559
return unwrapJSONCallResult(this.shim.getNavigationTree(fileName));
558560
}
559-
getOutliningSpans(fileName: string): ts.OutliningSpan[] {
560-
return unwrapJSONCallResult(this.shim.getOutliningSpans(fileName));
561+
getOutliningSpans(arg0: string | ts.SourceFile): ts.OutliningSpan[] {
562+
return unwrapJSONCallResult(this.shim.getOutliningSpans(arg0 as any));
561563
}
562564
getTodoComments(fileName: string, descriptors: ts.TodoCommentDescriptor[]): ts.TodoComment[] {
563565
return unwrapJSONCallResult(this.shim.getTodoComments(fileName, JSON.stringify(descriptors)));

src/services/services.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,11 +1675,14 @@ namespace ts {
16751675
return Completions.getCompletionEntrySymbol(program, log, getValidSourceFile(fileName), position, { name, source }, host, preferences);
16761676
}
16771677

1678-
function getQuickInfoAtPosition(fileName: string, position: number): QuickInfo | undefined {
1679-
synchronizeHostData();
1680-
1681-
const sourceFile = getValidSourceFile(fileName);
1682-
const node = getTouchingPropertyName(sourceFile, position);
1678+
function getQuickInfoAtPosition(fileName: string, position: number): QuickInfo | undefined;
1679+
function getQuickInfoAtPosition(node: ts.Node, sourceFile?: ts.SourceFile): QuickInfo | undefined;
1680+
function getQuickInfoAtPosition(arg0: string | ts.Node, arg1: number | ts.SourceFile | undefined): QuickInfo | undefined {
1681+
synchronizeHostData();
1682+
1683+
const sourceFile: ts.SourceFile = typeof arg0 === 'string' ? getValidSourceFile(arg0) : (arg1 !== undefined) ? arg1 as ts.SourceFile : arg0.getSourceFile();
1684+
const node: ts.Node = typeof arg0 === 'string' ? getTouchingPropertyName(sourceFile, arg1 as number) : arg0;
1685+
const position: number = typeof arg1 === 'number' ? arg1 : node.getStart(sourceFile, false);
16831686
if (node === sourceFile) {
16841687
// Avoid giving quickInfo for the sourceFile as a whole.
16851688
return undefined;
@@ -1979,9 +1982,11 @@ namespace ts {
19791982
return ts.getEncodedSyntacticClassifications(cancellationToken, syntaxTreeCache.getCurrentSourceFile(fileName), span);
19801983
}
19811984

1982-
function getOutliningSpans(fileName: string): OutliningSpan[] {
1983-
// doesn't use compiler - no need to synchronize with host
1984-
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
1985+
function getOutliningSpans(fileName: string): OutliningSpan[];
1986+
function getOutliningSpans(sourceFile: ts.SourceFile): OutliningSpan[];
1987+
function getOutliningSpans(arg0: string | ts.SourceFile): OutliningSpan[] {
1988+
// doesn't use compiler - no need to synchronize with host
1989+
const sourceFile = typeof arg0 === 'string' ? syntaxTreeCache.getCurrentSourceFile(arg0) : arg0;
19851990
return OutliningElementsCollector.collectElements(sourceFile, cancellationToken);
19861991
}
19871992

src/services/shims.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,16 @@ namespace ts {
764764
* Computes a string representation of the type at the requested position
765765
* in the active file.
766766
*/
767-
public getQuickInfoAtPosition(fileName: string, position: number): string {
768-
return this.forwardJSONCall(
769-
`getQuickInfoAtPosition('${fileName}', ${position})`,
770-
() => this.languageService.getQuickInfoAtPosition(fileName, position)
771-
);
772-
}
767+
public getQuickInfoAtPosition(fileName: string, position: number): string;
768+
public getQuickInfoAtPosition(node: ts.Node, sourceFile: ts.SourceFile | undefined): string;
769+
public getQuickInfoAtPosition(arg0: string | ts.Node, arg1: number | ts.SourceFile | undefined): string {
770+
const fileName = typeof arg0 === "string" ? arg0 : arg1 !== undefined ? (arg1 as ts.SourceFile).fileName : arg0.getSourceFile().fileName;
771+
const position = typeof arg0 === "string" ? arg1 as number : arg0.getStart(arg1 as ts.SourceFile);
772+
return this.forwardJSONCall(
773+
`getQuickInfoAtPosition('${fileName}', ${position})`,
774+
() => this.languageService.getQuickInfoAtPosition(arg0 as any, arg1 as any)
775+
);
776+
}
773777

774778

775779
/// NAMEORDOTTEDNAMESPAN
@@ -1032,12 +1036,15 @@ namespace ts {
10321036
);
10331037
}
10341038

1035-
public getOutliningSpans(fileName: string): string {
1036-
return this.forwardJSONCall(
1037-
`getOutliningSpans('${fileName}')`,
1038-
() => this.languageService.getOutliningSpans(fileName)
1039-
);
1040-
}
1039+
public getOutliningSpans(fileName: string): string;
1040+
public getOutliningSpans(sourceFile: ts.SourceFile): string;
1041+
public getOutliningSpans(arg0: string | ts.SourceFile): string {
1042+
let fileName = typeof arg0 === "string" ? arg0 : arg0.fileName;
1043+
return this.forwardJSONCall(
1044+
`getOutliningSpans('${fileName}')`,
1045+
() => this.languageService.getOutliningSpans(arg0 as any)
1046+
);
1047+
}
10411048

10421049
public getTodoComments(fileName: string, descriptors: string): string {
10431050
return this.forwardJSONCall(

src/services/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ namespace ts {
460460
* @param position A zero-based index of the character where you want the quick info
461461
*/
462462
getQuickInfoAtPosition(fileName: string, position: number): QuickInfo | undefined;
463+
getQuickInfoAtPosition(node: ts.Node, sourceFile?: ts.SourceFile): QuickInfo | undefined;
463464

464465
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan | undefined;
465466

@@ -505,6 +506,7 @@ namespace ts {
505506
provideInlayHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlayHint[]
506507

507508
getOutliningSpans(fileName: string): OutliningSpan[];
509+
getOutliningSpans(sourceFile: ts.SourceFile): OutliningSpan[];
508510
getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[];
509511
getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[];
510512
getIndentationAtPosition(fileName: string, position: number, options: EditorOptions | EditorSettings): number;

0 commit comments

Comments
 (0)