fix(language-service): Use proper types instead of any (#29942)
PR Close #29942
This commit is contained in:
parent
60e9d2da4f
commit
1a56cd5c0b
|
@ -7,6 +7,7 @@ ls_rollup_bundle(
|
||||||
"fs": "fs",
|
"fs": "fs",
|
||||||
"path": "path",
|
"path": "path",
|
||||||
"typescript": "ts",
|
"typescript": "ts",
|
||||||
|
"typescript/lib/tsserverlibrary": "tsserverlibrary",
|
||||||
},
|
},
|
||||||
license_banner = "banner.js.txt",
|
license_banner = "banner.js.txt",
|
||||||
visibility = ["//packages/language-service:__pkg__"],
|
visibility = ["//packages/language-service:__pkg__"],
|
||||||
|
|
|
@ -6,18 +6,19 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript/lib/tsserverlibrary';
|
||||||
|
|
||||||
import {createLanguageService} from './language_service';
|
import {createLanguageService} from './language_service';
|
||||||
import {Completion, Diagnostic, DiagnosticMessageChain} from './types';
|
import {Completion, Diagnostic, DiagnosticMessageChain} from './types';
|
||||||
import {TypeScriptServiceHost} from './typescript_host';
|
import {TypeScriptServiceHost} from './typescript_host';
|
||||||
|
|
||||||
const projectHostMap = new WeakMap<any, TypeScriptServiceHost>();
|
const projectHostMap = new WeakMap<ts.server.Project, TypeScriptServiceHost>();
|
||||||
|
|
||||||
export function getExternalFiles(project: any): string[]|undefined {
|
export function getExternalFiles(project: ts.server.Project): string[]|undefined {
|
||||||
const host = projectHostMap.get(project);
|
const host = projectHostMap.get(project);
|
||||||
if (host) {
|
if (host) {
|
||||||
return host.getTemplateReferences();
|
const externalFiles = host.getTemplateReferences();
|
||||||
|
return externalFiles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ function diagnosticToDiagnostic(d: Diagnostic, file: ts.SourceFile): ts.Diagnost
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageService {
|
export function create(info: ts.server.PluginCreateInfo): ts.LanguageService {
|
||||||
const oldLS: ts.LanguageService = info.languageService;
|
const oldLS: ts.LanguageService = info.languageService;
|
||||||
const proxy: ts.LanguageService = Object.assign({}, oldLS);
|
const proxy: ts.LanguageService = Object.assign({}, oldLS);
|
||||||
const logger = info.project.projectService.logger;
|
const logger = info.project.projectService.logger;
|
||||||
|
@ -78,7 +79,7 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
|
||||||
}
|
}
|
||||||
|
|
||||||
const serviceHost = new TypeScriptServiceHost(info.languageServiceHost, oldLS);
|
const serviceHost = new TypeScriptServiceHost(info.languageServiceHost, oldLS);
|
||||||
const ls = createLanguageService(serviceHost as any);
|
const ls = createLanguageService(serviceHost);
|
||||||
serviceHost.setSite(ls);
|
serviceHost.setSite(ls);
|
||||||
projectHostMap.set(info.project, serviceHost);
|
projectHostMap.set(info.project, serviceHost);
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,13 @@ describe('plugin', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
let plugin = create(
|
let plugin = create({
|
||||||
{ts: ts, languageService: service, project: mockProject, languageServiceHost: mockHost});
|
languageService: service,
|
||||||
|
project: mockProject as any,
|
||||||
|
languageServiceHost: mockHost,
|
||||||
|
serverHost: {} as any,
|
||||||
|
config: {},
|
||||||
|
});
|
||||||
|
|
||||||
it('should not report template errors on tour of heroes', () => {
|
it('should not report template errors on tour of heroes', () => {
|
||||||
for (let source of program !.getSourceFiles()) {
|
for (let source of program !.getSourceFiles()) {
|
||||||
|
|
Loading…
Reference in New Issue