Skip to content

Commit cd5f836

Browse files
atscottKeen Yee Liau
authored andcommitted
feat: Add typeDefinitionProvider to capabilities
The Angular Language Service for Ivy will have a distinction between "go to definition" and "go to type definition". We need to add `typeDefinitionProvider` to the capabilities and call `getTypeDefinitionAtPosition` when type definitions are requested.
1 parent 623d3b3 commit cd5f836

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

integration/lsp/smoke_spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ describe('Angular Language Service', () => {
108108
'completionProvider':
109109
{'resolveProvider': false, 'triggerCharacters': ['<', '.', '*', '[', '(', '$', '|']},
110110
'definitionProvider': true,
111+
'typeDefinitionProvider': true,
111112
'hoverProvider': true,
112113
'workspace': {'workspaceFolders': {'supported': true}}
113114
}
@@ -137,6 +138,7 @@ describe('Angular Language Service', () => {
137138
'completionProvider':
138139
{'resolveProvider': false, 'triggerCharacters': ['<', '.', '*', '[', '(', '$', '|']},
139140
'definitionProvider': true,
141+
'typeDefinitionProvider': true,
140142
'hoverProvider': true,
141143
'workspace': {'workspaceFolders': {'supported': true}}
142144
}

server/src/session.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export class Session {
9696
conn.onDidChangeTextDocument(p => this.onDidChangeTextDocument(p));
9797
conn.onDidSaveTextDocument(p => this.onDidSaveTextDocument(p));
9898
conn.onDefinition(p => this.onDefinition(p));
99+
conn.onTypeDefinition(p => this.onTypeDefinition(p));
99100
conn.onHover(p => this.onHover(p));
100101
conn.onCompletion(p => this.onCompletion(p));
101102
}
@@ -240,6 +241,7 @@ export class Session {
240241
triggerCharacters: ['<', '.', '*', '[', '(', '$', '|']
241242
},
242243
definitionProvider: true,
244+
typeDefinitionProvider: true,
243245
hoverProvider: true,
244246
workspace: {
245247
workspaceFolders: {supported: true},
@@ -362,6 +364,20 @@ export class Session {
362364
return this.tsDefinitionsToLspLocationLinks(definition.definitions, originSelectionRange);
363365
}
364366

367+
private onTypeDefinition(params: lsp.TextDocumentPositionParams): lsp.LocationLink[]|undefined {
368+
const lsInfo = this.getLSAndScriptInfo(params.textDocument);
369+
if (lsInfo === undefined) {
370+
return;
371+
}
372+
const {languageService, scriptInfo} = lsInfo;
373+
const offset = lspPositionToTsPosition(scriptInfo, params.position);
374+
const definitions = languageService.getTypeDefinitionAtPosition(scriptInfo.fileName, offset);
375+
if (!definitions) {
376+
return;
377+
}
378+
return this.tsDefinitionsToLspLocationLinks(definitions);
379+
}
380+
365381
private tsDefinitionsToLspLocationLinks(
366382
definitions: readonly ts.DefinitionInfo[],
367383
originSelectionRange?: lsp.Range): lsp.LocationLink[] {

0 commit comments

Comments
 (0)