Skip to content

Commit 220e3c1

Browse files
committed
Move LSIF to TS 4.4.0 Beta
1 parent 3c30b74 commit 220e3c1

File tree

9 files changed

+10656
-54
lines changed

9 files changed

+10656
-54
lines changed

package-lock.json

Lines changed: 10558 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"name": "typescript",
2+
"name": "lsif-typescript",
33
"author": "Microsoft Corp.",
44
"homepage": "https://www.typescriptlang.org/",
55
"version": "4.4.0-beta",
66
"license": "Apache-2.0",
7-
"description": "TypeScript is a language for application scale JavaScript development",
7+
"description": "A special version of the Typescript libraries to support LSIF (https://microsoft.github.io/language-server-protocol/specifications/lsif/0.5.0/specification/)",
88
"keywords": [
99
"TypeScript",
1010
"Microsoft",

src/compiler/checker.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ namespace ts {
375375
// extra cost of calling `getParseTreeNode` when calling these functions from inside the
376376
// checker.
377377
const checker: TypeChecker = {
378+
setSymbolChainCache: (cache: SymbolChainCache | undefined): void => {
379+
nodeBuilder.setSymbolChainCache(cache);
380+
},
378381
getNodeCount: () => sum(host.getSourceFiles(), "nodeCount"),
379382
getIdentifierCount: () => sum(host.getSourceFiles(), "identifierCount"),
380383
getSymbolCount: () => sum(host.getSourceFiles(), "symbolCount") + symbolCount,
@@ -4472,7 +4475,9 @@ namespace ts {
44724475
}
44734476

44744477
function createNodeBuilder() {
4478+
let symbolChainCache: SymbolChainCache | undefined;
44754479
return {
4480+
setSymbolChainCache: (cache: SymbolChainCache | undefined): void => { symbolChainCache = cache },
44764481
typeToTypeNode: (type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) =>
44774482
withContext(enclosingDeclaration, flags, tracker, context => typeToTypeNodeHelper(type, context)),
44784483
indexInfoToIndexSignatureDeclaration: (indexInfo: IndexInfo, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) =>
@@ -4510,6 +4515,7 @@ namespace ts {
45104515
fileExists: fileName => host.fileExists(fileName),
45114516
getFileIncludeReasons: () => host.getFileIncludeReasons(),
45124517
} : undefined },
4518+
cache: symbolChainCache,
45134519
encounteredError: false,
45144520
reportedDiagnostic: false,
45154521
visitedTypes: undefined,
@@ -5587,6 +5593,30 @@ namespace ts {
55875593

55885594
/** @param endOfChain Set to false for recursive calls; non-recursive calls should always output something. */
55895595
function getSymbolChain(symbol: Symbol, meaning: SymbolFlags, endOfChain: boolean): Symbol[] | undefined {
5596+
let key: SymbolChainCacheKey | undefined;
5597+
let result: Symbol[] | undefined;
5598+
if (context.cache) {
5599+
key = {
5600+
symbol,
5601+
enclosingDeclaration: context.enclosingDeclaration,
5602+
flags: context.flags,
5603+
meaning: meaning,
5604+
yieldModuleSymbol: yieldModuleSymbol,
5605+
endOfChain: endOfChain
5606+
}
5607+
result = context.cache.lookup(key);
5608+
if (result) {
5609+
return result;
5610+
}
5611+
}
5612+
result = doGetSymbolChain(symbol, meaning, endOfChain);
5613+
if (result && key && context.cache) {
5614+
context.cache.cache(key, result);
5615+
}
5616+
return result;
5617+
}
5618+
5619+
function doGetSymbolChain(symbol: Symbol, meaning: SymbolFlags, endOfChain: boolean): Symbol[] | undefined {
55905620
let accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, !!(context.flags & NodeBuilderFlags.UseOnlyExternalAliasing));
55915621
let parentSpecifiers: (string | undefined)[];
55925622
if (!accessibleSymbolChain ||
@@ -7800,6 +7830,7 @@ namespace ts {
78007830
enclosingDeclaration: Node | undefined;
78017831
flags: NodeBuilderFlags;
78027832
tracker: SymbolTracker;
7833+
cache: SymbolChainCache | undefined;
78037834

78047835
// State
78057836
encounteredError: boolean;

src/compiler/types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4092,7 +4092,22 @@ namespace ts {
40924092
readonly redirectTargetsMap: RedirectTargetsMap;
40934093
}
40944094

4095+
export interface SymbolChainCacheKey {
4096+
symbol: Symbol;
4097+
enclosingDeclaration?: Node;
4098+
flags: NodeBuilderFlags;
4099+
meaning: SymbolFlags;
4100+
yieldModuleSymbol?: boolean;
4101+
endOfChain: boolean;
4102+
}
4103+
4104+
export interface SymbolChainCache {
4105+
lookup(key: SymbolChainCacheKey): Symbol[] | undefined;
4106+
cache(key: SymbolChainCacheKey, value: Symbol[]): void;
4107+
}
4108+
40954109
export interface TypeChecker {
4110+
setSymbolChainCache(cache: SymbolChainCache | undefined): void;
40964111
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
40974112
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
40984113
getPropertiesOfType(type: Type): Symbol[];

src/harness/client.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ namespace ts.server {
163163
return { line, character: offset };
164164
}
165165

166-
getQuickInfoAtPosition(fileName: string, position: number): QuickInfo {
166+
getQuickInfoAtPosition(fileName: string, position: number): QuickInfo;
167+
getQuickInfoAtPosition(node: ts.Node, sourceFile?: ts.SourceFile): QuickInfo;
168+
getQuickInfoAtPosition(arg0: string | ts.Node, arg1: number | ts.SourceFile | undefined): QuickInfo {
169+
const fileName = typeof arg0 === "string" ? arg0 : arg1 !== undefined ? (arg1 as ts.SourceFile).fileName : arg0.getSourceFile().fileName;
170+
const position = typeof arg0 === "string" ? arg1 as number : arg0.getStart(arg1 as ts.SourceFile);
167171
const args = this.createFileLocationRequestArgs(fileName, position);
168172

169173
const request = this.processRequest<protocol.QuickInfoRequest>(CommandNames.Quickinfo, args);
@@ -597,7 +601,10 @@ namespace ts.server {
597601
}));
598602
}
599603

600-
getOutliningSpans(file: string): OutliningSpan[] {
604+
getOutliningSpans(file: string): OutliningSpan[];
605+
getOutliningSpans(sourceFile: ts.SourceFile): OutliningSpan[];
606+
getOutliningSpans(arg0: string | ts.SourceFile): OutliningSpan[] {
607+
const file = typeof arg0 === "string" ? arg0 : arg0.fileName;
601608
const request = this.processRequest<protocol.OutliningSpansRequest>(CommandNames.GetOutliningSpans, { file });
602609
const response = this.processResponse<protocol.OutliningSpansResponse>(request);
603610

src/harness/harnessLanguageService.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,10 @@ namespace Harness.LanguageService {
480480
getCompletionEntrySymbol(): ts.Symbol {
481481
throw new Error("getCompletionEntrySymbol not implemented across the shim layer.");
482482
}
483-
getQuickInfoAtPosition(fileName: string, position: number): ts.QuickInfo {
484-
return unwrapJSONCallResult(this.shim.getQuickInfoAtPosition(fileName, position));
483+
getQuickInfoAtPosition(filename: string, position: number): ts.QuickInfo | undefined;
484+
getQuickInfoAtPosition(node: ts.Node, sourceFile: ts.SourceFile | undefined): ts.QuickInfo | undefined;
485+
getQuickInfoAtPosition(arg0: string | ts.Node, arg1: number | ts.SourceFile | undefined): ts.QuickInfo | undefined {
486+
return unwrapJSONCallResult(this.shim.getQuickInfoAtPosition(arg0 as any, arg1 as any));
485487
}
486488
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): ts.TextSpan {
487489
return unwrapJSONCallResult(this.shim.getNameOrDottedNameSpan(fileName, startPos, endPos));
@@ -537,8 +539,8 @@ namespace Harness.LanguageService {
537539
getNavigationTree(fileName: string): ts.NavigationTree {
538540
return unwrapJSONCallResult(this.shim.getNavigationTree(fileName));
539541
}
540-
getOutliningSpans(fileName: string): ts.OutliningSpan[] {
541-
return unwrapJSONCallResult(this.shim.getOutliningSpans(fileName));
542+
getOutliningSpans(arg0: string | ts.SourceFile): ts.OutliningSpan[] {
543+
return unwrapJSONCallResult(this.shim.getOutliningSpans(arg0 as any));
542544
}
543545
getTodoComments(fileName: string, descriptors: ts.TodoCommentDescriptor[]): ts.TodoComment[] {
544546
return unwrapJSONCallResult(this.shim.getTodoComments(fileName, JSON.stringify(descriptors)));

src/services/services.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,11 +1624,15 @@ namespace ts {
16241624
return Completions.getCompletionEntrySymbol(program, log, getValidSourceFile(fileName), position, { name, source }, host, preferences);
16251625
}
16261626

1627-
function getQuickInfoAtPosition(fileName: string, position: number): QuickInfo | undefined {
1628-
synchronizeHostData();
1627+
function getQuickInfoAtPosition(fileName: string, position: number): QuickInfo | undefined;
1628+
function getQuickInfoAtPosition(node: ts.Node, sourceFile?: ts.SourceFile): QuickInfo | undefined;
1629+
function getQuickInfoAtPosition(arg0: string | ts.Node, arg1: number | ts.SourceFile | undefined): QuickInfo | undefined {
1630+
synchronizeHostData();
1631+
1632+
const sourceFile: ts.SourceFile = typeof arg0 === 'string' ? getValidSourceFile(arg0) : (arg1 !== undefined) ? arg1 as ts.SourceFile : arg0.getSourceFile();
1633+
const node: ts.Node = typeof arg0 === 'string' ? getTouchingPropertyName(sourceFile, arg1 as number) : arg0;
1634+
const position: number = typeof arg1 === 'number' ? arg1 : node.getStart(sourceFile, false);
16291635

1630-
const sourceFile = getValidSourceFile(fileName);
1631-
const node = getTouchingPropertyName(sourceFile, position);
16321636
if (node === sourceFile) {
16331637
// Avoid giving quickInfo for the sourceFile as a whole.
16341638
return undefined;
@@ -1923,11 +1927,13 @@ namespace ts {
19231927
return ts.getEncodedSyntacticClassifications(cancellationToken, syntaxTreeCache.getCurrentSourceFile(fileName), span);
19241928
}
19251929

1926-
function getOutliningSpans(fileName: string): OutliningSpan[] {
1927-
// doesn't use compiler - no need to synchronize with host
1928-
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
1930+
function getOutliningSpans(fileName: string): OutliningSpan[];
1931+
function getOutliningSpans(sourceFile: ts.SourceFile): OutliningSpan[];
1932+
function getOutliningSpans(arg0: string | ts.SourceFile): OutliningSpan[] {
1933+
// doesn't use compiler - no need to synchronize with host
1934+
const sourceFile = typeof arg0 === 'string' ? syntaxTreeCache.getCurrentSourceFile(arg0) : arg0;
19291935
return OutliningElementsCollector.collectElements(sourceFile, cancellationToken);
1930-
}
1936+
}
19311937

19321938
const braceMatching = new Map(getEntries({
19331939
[SyntaxKind.OpenBraceToken]: SyntaxKind.CloseBraceToken,

src/services/shims.ts

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

772776

773777
/// NAMEORDOTTEDNAMESPAN
@@ -1030,12 +1034,15 @@ namespace ts {
10301034
);
10311035
}
10321036

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

10401047
public getTodoComments(fileName: string, descriptors: string): string {
10411048
return this.forwardJSONCall(

src/services/types.ts

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

452453
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan | undefined;
453454

@@ -484,6 +485,7 @@ namespace ts {
484485
provideInlayHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlayHint[]
485486

486487
getOutliningSpans(fileName: string): OutliningSpan[];
488+
getOutliningSpans(sourceFile: ts.SourceFile): OutliningSpan[];
487489
getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[];
488490
getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[];
489491
getIndentationAtPosition(fileName: string, position: number, options: EditorOptions | EditorSettings): number;

0 commit comments

Comments
 (0)