2020-04-29 18:08:22 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2020-04-29 18:08:22 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as ts from 'typescript/lib/tsserverlibrary';
|
|
|
|
import {LanguageService} from './language_service';
|
|
|
|
|
|
|
|
export function create(info: ts.server.PluginCreateInfo): ts.LanguageService {
|
2020-04-29 18:52:17 -04:00
|
|
|
const {project, languageService: tsLS, config} = info;
|
2020-04-29 18:08:22 -04:00
|
|
|
const angularOnly = config?.angularOnly === true;
|
|
|
|
|
2020-04-29 18:52:17 -04:00
|
|
|
const ngLS = new LanguageService(project, tsLS);
|
2020-04-29 18:08:22 -04:00
|
|
|
|
|
|
|
function getSemanticDiagnostics(fileName: string): ts.Diagnostic[] {
|
|
|
|
const diagnostics: ts.Diagnostic[] = [];
|
|
|
|
if (!angularOnly) {
|
|
|
|
diagnostics.push(...tsLS.getSemanticDiagnostics(fileName));
|
|
|
|
}
|
|
|
|
diagnostics.push(...ngLS.getSemanticDiagnostics(fileName));
|
|
|
|
return diagnostics;
|
|
|
|
}
|
|
|
|
|
2020-09-28 14:26:07 -04:00
|
|
|
function getQuickInfoAtPosition(fileName: string, position: number): ts.QuickInfo|undefined {
|
|
|
|
if (angularOnly) {
|
|
|
|
return ngLS.getQuickInfoAtPosition(fileName, position);
|
|
|
|
} else {
|
|
|
|
// If TS could answer the query, then return that result. Otherwise, return from Angular LS.
|
|
|
|
return tsLS.getQuickInfoAtPosition(fileName, position) ??
|
|
|
|
ngLS.getQuickInfoAtPosition(fileName, position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 16:54:18 -04:00
|
|
|
function getTypeDefinitionAtPosition(
|
|
|
|
fileName: string, position: number): readonly ts.DefinitionInfo[]|undefined {
|
|
|
|
if (angularOnly) {
|
|
|
|
return ngLS.getTypeDefinitionAtPosition(fileName, position);
|
|
|
|
} else {
|
|
|
|
// If TS could answer the query, then return that result. Otherwise, return from Angular LS.
|
|
|
|
return tsLS.getTypeDefinitionAtPosition(fileName, position) ??
|
|
|
|
ngLS.getTypeDefinitionAtPosition(fileName, position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-30 11:47:36 -04:00
|
|
|
function getDefinitionAndBoundSpan(
|
|
|
|
fileName: string, position: number): ts.DefinitionInfoAndBoundSpan|undefined {
|
|
|
|
if (angularOnly) {
|
|
|
|
return ngLS.getDefinitionAndBoundSpan(fileName, position);
|
|
|
|
} else {
|
|
|
|
// If TS could answer the query, then return that result. Otherwise, return from Angular LS.
|
|
|
|
return tsLS.getDefinitionAndBoundSpan(fileName, position) ??
|
|
|
|
ngLS.getDefinitionAndBoundSpan(fileName, position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-24 14:57:34 -05:00
|
|
|
function getReferencesAtPosition(fileName: string, position: number) {
|
|
|
|
// TODO(atscott): implement references
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2020-04-29 18:08:22 -04:00
|
|
|
return {
|
|
|
|
...tsLS,
|
|
|
|
getSemanticDiagnostics,
|
2020-09-29 17:25:28 -04:00
|
|
|
getTypeDefinitionAtPosition,
|
2020-09-28 14:26:07 -04:00
|
|
|
getQuickInfoAtPosition,
|
2020-09-30 11:47:36 -04:00
|
|
|
getDefinitionAndBoundSpan,
|
2020-11-24 14:57:34 -05:00
|
|
|
getReferencesAtPosition,
|
2020-04-29 18:08:22 -04:00
|
|
|
};
|
|
|
|
}
|