refactor: clean up language service from unused code and imports (#30534)
PR Close #30534
This commit is contained in:
parent
01919fbaae
commit
fd7dd4d9fc
|
@ -13,7 +13,7 @@ import {getTemplateCompletions} from './completions';
|
||||||
import {getDefinition} from './definitions';
|
import {getDefinition} from './definitions';
|
||||||
import {getDeclarationDiagnostics, getTemplateDiagnostics} from './diagnostics';
|
import {getDeclarationDiagnostics, getTemplateDiagnostics} from './diagnostics';
|
||||||
import {getHover} from './hover';
|
import {getHover} from './hover';
|
||||||
import {Completions, Definition, Diagnostic, DiagnosticKind, Diagnostics, Hover, LanguageService, LanguageServiceHost, Pipes, Span, TemplateSource} from './types';
|
import {Completions, Definition, Diagnostic, DiagnosticKind, Diagnostics, Hover, LanguageService, LanguageServiceHost, Span, TemplateSource} from './types';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -48,7 +48,6 @@ class ReflectorModuleModuleResolutionHost implements ts.ModuleResolutionHost, Me
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ReflectorHost implements StaticSymbolResolverHost {
|
export class ReflectorHost implements StaticSymbolResolverHost {
|
||||||
private moduleResolutionCache: ts.ModuleResolutionCache;
|
|
||||||
private hostAdapter: ReflectorModuleModuleResolutionHost;
|
private hostAdapter: ReflectorModuleModuleResolutionHost;
|
||||||
private metadataReaderCache = createMetadataReaderCache();
|
private metadataReaderCache = createMetadataReaderCache();
|
||||||
|
|
||||||
|
@ -56,8 +55,6 @@ export class ReflectorHost implements StaticSymbolResolverHost {
|
||||||
getProgram: () => ts.Program, serviceHost: ts.LanguageServiceHost,
|
getProgram: () => ts.Program, serviceHost: ts.LanguageServiceHost,
|
||||||
private options: CompilerOptions) {
|
private options: CompilerOptions) {
|
||||||
this.hostAdapter = new ReflectorModuleModuleResolutionHost(serviceHost, getProgram);
|
this.hostAdapter = new ReflectorModuleModuleResolutionHost(serviceHost, getProgram);
|
||||||
this.moduleResolutionCache =
|
|
||||||
ts.createModuleResolutionCache(serviceHost.getCurrentDirectory(), (s) => s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getMetadataFor(modulePath: string): {[key: string]: any}[]|undefined {
|
getMetadataFor(modulePath: string): {[key: string]: any}[]|undefined {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AotSummaryResolver, CompileMetadataResolver, CompilerConfig, DEFAULT_INTERPOLATION_CONFIG, DirectiveNormalizer, DirectiveResolver, DomElementSchemaRegistry, FormattedError, FormattedMessageChain, HtmlParser, InterpolationConfig, JitSummaryResolver, NgAnalyzedModules, NgModuleResolver, ParseTreeResult, PipeResolver, ResourceLoader, StaticReflector, StaticSymbol, StaticSymbolCache, StaticSymbolResolver, analyzeNgModules, createOfflineCompileUrlResolver, isFormattedError} from '@angular/compiler';
|
import {AotSummaryResolver, CompileMetadataResolver, CompilerConfig, DirectiveNormalizer, DirectiveResolver, DomElementSchemaRegistry, FormattedError, FormattedMessageChain, HtmlParser, JitSummaryResolver, NgAnalyzedModules, NgModuleResolver, ParseTreeResult, PipeResolver, ResourceLoader, StaticReflector, StaticSymbol, StaticSymbolCache, StaticSymbolResolver, analyzeNgModules, createOfflineCompileUrlResolver, isFormattedError} from '@angular/compiler';
|
||||||
import {CompilerOptions, getClassMembersFromDeclaration, getPipesTable, getSymbolQuery} from '@angular/compiler-cli/src/language_services';
|
import {CompilerOptions, getClassMembersFromDeclaration, getPipesTable, getSymbolQuery} from '@angular/compiler-cli/src/language_services';
|
||||||
import {ViewEncapsulation, ɵConsole as Console} from '@angular/core';
|
import {ViewEncapsulation, ɵConsole as Console} from '@angular/core';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
|
|
@ -86,12 +86,10 @@ describe('completions', () => {
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
let chance = 0.05;
|
let chance = 0.05;
|
||||||
let requests = 0;
|
|
||||||
function tryCompletionsAt(position: number) {
|
function tryCompletionsAt(position: number) {
|
||||||
try {
|
try {
|
||||||
if (Math.random() < chance) {
|
if (Math.random() < chance) {
|
||||||
ngService.getCompletionsAt(fileName, position);
|
ngService.getCompletionsAt(fileName, position);
|
||||||
requests++;
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Emit enough diagnostic information to reproduce the error.
|
// Emit enough diagnostic information to reproduce the error.
|
||||||
|
|
|
@ -103,7 +103,7 @@ describe('diagnostics', () => {
|
||||||
|
|
||||||
it('should not report an error for a form\'s host directives', () => {
|
it('should not report an error for a form\'s host directives', () => {
|
||||||
const code = '\n@Component({template: \'<form></form>\'}) export class MyComponent {}';
|
const code = '\n@Component({template: \'<form></form>\'}) export class MyComponent {}';
|
||||||
addCode(code, (fileName, content) => {
|
addCode(code, fileName => {
|
||||||
const diagnostics = ngService.getDiagnostics(fileName);
|
const diagnostics = ngService.getDiagnostics(fileName);
|
||||||
expectOnlyModuleDiagnostics(diagnostics);
|
expectOnlyModuleDiagnostics(diagnostics);
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
import {createLanguageService} from '../src/language_service';
|
import {createLanguageService} from '../src/language_service';
|
||||||
import {Completions, LanguageService} from '../src/types';
|
|
||||||
import {TypeScriptServiceHost} from '../src/typescript_host';
|
import {TypeScriptServiceHost} from '../src/typescript_host';
|
||||||
|
|
||||||
import {toh} from './test_data';
|
import {toh} from './test_data';
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
import {createLanguageService} from '../src/language_service';
|
import {createLanguageService} from '../src/language_service';
|
||||||
import {Completions, Diagnostic, Diagnostics, LanguageService} from '../src/types';
|
import {LanguageService} from '../src/types';
|
||||||
import {TypeScriptServiceHost} from '../src/typescript_host';
|
import {TypeScriptServiceHost} from '../src/typescript_host';
|
||||||
|
|
||||||
import {toh} from './test_data';
|
import {toh} from './test_data';
|
||||||
|
@ -19,14 +19,12 @@ describe('references', () => {
|
||||||
let documentRegistry = ts.createDocumentRegistry();
|
let documentRegistry = ts.createDocumentRegistry();
|
||||||
let mockHost: MockTypescriptHost;
|
let mockHost: MockTypescriptHost;
|
||||||
let service: ts.LanguageService;
|
let service: ts.LanguageService;
|
||||||
let program: ts.Program;
|
|
||||||
let ngHost: TypeScriptServiceHost;
|
let ngHost: TypeScriptServiceHost;
|
||||||
let ngService: LanguageService = createLanguageService(undefined !);
|
let ngService: LanguageService = createLanguageService(undefined !);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts'], toh);
|
mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts'], toh);
|
||||||
service = ts.createLanguageService(mockHost, documentRegistry);
|
service = ts.createLanguageService(mockHost, documentRegistry);
|
||||||
program = service.getProgram() !;
|
|
||||||
ngHost = new TypeScriptServiceHost(mockHost, service);
|
ngHost = new TypeScriptServiceHost(mockHost, service);
|
||||||
ngService = createLanguageService(ngHost);
|
ngService = createLanguageService(ngHost);
|
||||||
ngHost.setSite(ngService);
|
ngHost.setSite(ngService);
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {MockData} from './test_utils';
|
|
||||||
|
|
||||||
export const toh = {
|
export const toh = {
|
||||||
'foo.ts': `export * from './app/app.component.ts';`,
|
'foo.ts': `export * from './app/app.component.ts';`,
|
||||||
app: {
|
app: {
|
||||||
|
|
|
@ -212,12 +212,6 @@ describe('plugin', () => {
|
||||||
locationMarker, plugin.getCompletionsAtPosition(fileName, location, undefined) !, ...names);
|
locationMarker, plugin.getCompletionsAtPosition(fileName, location, undefined) !, ...names);
|
||||||
}
|
}
|
||||||
|
|
||||||
function expectEmpty(fileName: string, locationMarker: string) {
|
|
||||||
const location = getMarkerLocation(fileName, locationMarker);
|
|
||||||
expect(plugin.getCompletionsAtPosition(fileName, location, undefined) !.entries || []).toEqual([
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function expectSemanticError(fileName: string, locationMarker: string, message: string) {
|
function expectSemanticError(fileName: string, locationMarker: string, message: string) {
|
||||||
const start = getMarkerLocation(fileName, locationMarker);
|
const start = getMarkerLocation(fileName, locationMarker);
|
||||||
const end = getMarkerLocation(fileName, locationMarker + '-end');
|
const end = getMarkerLocation(fileName, locationMarker + '-end');
|
||||||
|
|
Loading…
Reference in New Issue