Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-service): remove incompletely used parameter from `creat… #13278

Merged
merged 1 commit into from
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions modules/@angular/language-service/src/ts_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@ import {TypeScriptServiceHost} from './typescript_host';
* @experimental
*/
export class LanguageServicePlugin {
private ts: typeof ts;
private serviceHost: TypeScriptServiceHost;
private service: LanguageService;
private host: ts.LanguageServiceHost;

static 'extension-kind' = 'language-service';

constructor(config: {
ts: typeof ts; host: ts.LanguageServiceHost; service: ts.LanguageService;
host: ts.LanguageServiceHost; service: ts.LanguageService;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be "," instead of ";" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typescript accepts both here but I prefer using ; as it is more consistent.

registry?: ts.DocumentRegistry, args?: any
}) {
this.ts = config.ts;
this.host = config.host;
this.serviceHost = new TypeScriptServiceHost(this.ts, config.host, config.service);
this.serviceHost = new TypeScriptServiceHost(config.host, config.service);
this.service = createLanguageService(this.serviceHost);
this.serviceHost.setSite(this.service);
}
Expand All @@ -51,7 +49,7 @@ export class LanguageServicePlugin {
start: error.span.start,
length: error.span.end - error.span.start,
messageText: error.message,
category: this.ts.DiagnosticCategory.Error,
category: ts.DiagnosticCategory.Error,
code: 0
});
}
Expand Down
77 changes: 34 additions & 43 deletions modules/@angular/language-service/src/typescript_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ import {BuiltinType, CompletionKind, Declaration, DeclarationError, Declarations
* Create a `LanguageServiceHost`
*/
export function createLanguageServiceFromTypescript(
typescript: typeof ts, host: ts.LanguageServiceHost,
service: ts.LanguageService): LanguageService {
const ngHost = new TypeScriptServiceHost(typescript, host, service);
host: ts.LanguageServiceHost, service: ts.LanguageService): LanguageService {
const ngHost = new TypeScriptServiceHost(host, service);
const ngServer = createLanguageService(ngHost);
ngHost.setSite(ngServer);
return ngServer;
Expand Down Expand Up @@ -74,7 +73,6 @@ export class DummyResourceLoader extends ResourceLoader {
* @expermental
*/
export class TypeScriptServiceHost implements LanguageServiceHost {
private ts: typeof ts;
private _resolver: CompileMetadataResolver;
private _staticSymbolCache = new StaticSymbolCache();
private _reflector: StaticReflector;
Expand All @@ -90,11 +88,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
private templateReferences: string[];
private collectedErrors: Map<string, any[]>;

constructor(
typescript: typeof ts, private host: ts.LanguageServiceHost,
private tsService: ts.LanguageService) {
this.ts = typescript;
}
constructor(private host: ts.LanguageServiceHost, private tsService: ts.LanguageService) {}

setSite(service: LanguageService) { this.service = service; }

Expand Down Expand Up @@ -190,14 +184,14 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
if (templateSource) {
result.push(templateSource);
} else {
this.ts.forEachChild(child, visit);
ts.forEachChild(child, visit);
}
};

let sourceFile = this.getSourceFile(fileName);
if (sourceFile) {
this.context = sourceFile.path;
this.ts.forEachChild(sourceFile, visit);
ts.forEachChild(sourceFile, visit);
}
return result.length ? result : undefined;
}
Expand Down Expand Up @@ -304,7 +298,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
return new TypeWrapper(type, {node, program, checker}).members();},
get query(): SymbolQuery{
if (!queryCache) {
queryCache = new TypeScriptSymbolQuery(t.ts, t.program, t.checker, sourceFile, () => {
queryCache = new TypeScriptSymbolQuery(t.program, t.checker, sourceFile, () => {
const pipes = t.service.getPipesAt(fileName, node.getStart());
const checker = t.checker;
const program = t.program;
Expand All @@ -321,8 +315,8 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
let result: TemplateSource|undefined = undefined;
const t = this;
switch (node.kind) {
case this.ts.SyntaxKind.NoSubstitutionTemplateLiteral:
case this.ts.SyntaxKind.StringLiteral:
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
case ts.SyntaxKind.StringLiteral:
let [declaration, decorator] = this.getTemplateClassDeclFromNode(node);
let queryCache: SymbolQuery|undefined = undefined;
if (declaration) {
Expand Down Expand Up @@ -403,7 +397,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
private getTemplateClassFromStaticSymbol(type: StaticSymbol): ts.ClassDeclaration|undefined {
const source = this.getSourceFile(type.filePath);
if (source) {
const declarationNode = this.ts.forEachChild(source, child => {
const declarationNode = ts.forEachChild(source, child => {
if (child.kind === ts.SyntaxKind.ClassDeclaration) {
const classDeclaration = child as ts.ClassDeclaration;
if (classDeclaration.name.text === type.name) {
Expand Down Expand Up @@ -431,7 +425,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
if (!parentNode) {
return TypeScriptServiceHost.missingTemplate;
}
if (parentNode.kind !== this.ts.SyntaxKind.PropertyAssignment) {
if (parentNode.kind !== ts.SyntaxKind.PropertyAssignment) {
return TypeScriptServiceHost.missingTemplate;
} else {
// TODO: Is this different for a literal, i.e. a quoted property name like "template"?
Expand All @@ -440,23 +434,23 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
}
}
parentNode = parentNode.parent; // ObjectLiteralExpression
if (!parentNode || parentNode.kind !== this.ts.SyntaxKind.ObjectLiteralExpression) {
if (!parentNode || parentNode.kind !== ts.SyntaxKind.ObjectLiteralExpression) {
return TypeScriptServiceHost.missingTemplate;
}

parentNode = parentNode.parent; // CallExpression
if (!parentNode || parentNode.kind !== this.ts.SyntaxKind.CallExpression) {
if (!parentNode || parentNode.kind !== ts.SyntaxKind.CallExpression) {
return TypeScriptServiceHost.missingTemplate;
}
const callTarget = (<ts.CallExpression>parentNode).expression;

let decorator = parentNode.parent; // Decorator
if (!decorator || decorator.kind !== this.ts.SyntaxKind.Decorator) {
if (!decorator || decorator.kind !== ts.SyntaxKind.Decorator) {
return TypeScriptServiceHost.missingTemplate;
}

let declaration = <ts.ClassDeclaration>decorator.parent; // ClassDeclaration
if (!declaration || declaration.kind !== this.ts.SyntaxKind.ClassDeclaration) {
if (!declaration || declaration.kind !== ts.SyntaxKind.ClassDeclaration) {
return TypeScriptServiceHost.missingTemplate;
}
return [declaration, callTarget];
Expand Down Expand Up @@ -515,9 +509,9 @@ export class TypeScriptServiceHost implements LanguageServiceHost {

private stringOf(node: ts.Node): string|undefined {
switch (node.kind) {
case this.ts.SyntaxKind.NoSubstitutionTemplateLiteral:
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
return (<ts.LiteralExpression>node).text;
case this.ts.SyntaxKind.StringLiteral:
case ts.SyntaxKind.StringLiteral:
return (<ts.StringLiteral>node).text;
}
}
Expand All @@ -527,7 +521,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {

function find(node: ts.Node): ts.Node|undefined {
if (position >= node.getStart() && position < node.getEnd()) {
return _this.ts.forEachChild(node, find) || node;
return ts.forEachChild(node, find) || node;
}
}

Expand All @@ -540,26 +534,26 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
switch (kind) {
case BuiltinType.Any:
type = checker.getTypeAtLocation(<ts.Node><any>{
kind: this.ts.SyntaxKind.AsExpression,
expression: <ts.Node>{kind: this.ts.SyntaxKind.TrueKeyword},
type: <ts.Node>{kind: this.ts.SyntaxKind.AnyKeyword}
kind: ts.SyntaxKind.AsExpression,
expression: <ts.Node>{kind: ts.SyntaxKind.TrueKeyword},
type: <ts.Node>{kind: ts.SyntaxKind.AnyKeyword}
});
break;
case BuiltinType.Boolean:
type = checker.getTypeAtLocation(<ts.Node>{kind: this.ts.SyntaxKind.TrueKeyword});
type = checker.getTypeAtLocation(<ts.Node>{kind: ts.SyntaxKind.TrueKeyword});
break;
case BuiltinType.Null:
type = checker.getTypeAtLocation(<ts.Node>{kind: this.ts.SyntaxKind.NullKeyword});
type = checker.getTypeAtLocation(<ts.Node>{kind: ts.SyntaxKind.NullKeyword});
break;
case BuiltinType.Number:
type = checker.getTypeAtLocation(<ts.Node>{kind: this.ts.SyntaxKind.NumericLiteral});
type = checker.getTypeAtLocation(<ts.Node>{kind: ts.SyntaxKind.NumericLiteral});
break;
case BuiltinType.String:
type = checker.getTypeAtLocation(
<ts.Node>{kind: this.ts.SyntaxKind.NoSubstitutionTemplateLiteral});
type =
checker.getTypeAtLocation(<ts.Node>{kind: ts.SyntaxKind.NoSubstitutionTemplateLiteral});
break;
case BuiltinType.Undefined:
type = checker.getTypeAtLocation(<ts.Node>{kind: this.ts.SyntaxKind.VoidExpression});
type = checker.getTypeAtLocation(<ts.Node>{kind: ts.SyntaxKind.VoidExpression});
break;
default:
throw new Error(`Internal error, unhandled literal kind ${kind}:${BuiltinType[kind]}`);
Expand All @@ -569,30 +563,27 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
}

class TypeScriptSymbolQuery implements SymbolQuery {
private ts: typeof ts;
private typeCache = new Map<BuiltinType, Symbol>();
private pipesCache: SymbolTable;

constructor(
typescript: typeof ts, private program: ts.Program, private checker: ts.TypeChecker,
private source: ts.SourceFile, private fetchPipes: () => SymbolTable) {
this.ts = typescript;
}
private program: ts.Program, private checker: ts.TypeChecker, private source: ts.SourceFile,
private fetchPipes: () => SymbolTable) {}

getTypeKind(symbol: Symbol): BuiltinType {
const type = this.getTsTypeOf(symbol);
if (type) {
if (type.flags & this.ts.TypeFlags.Any) {
if (type.flags & ts.TypeFlags.Any) {
return BuiltinType.Any;
} else if (
type.flags & (this.ts.TypeFlags.String | this.ts.TypeFlags.StringLike |
this.ts.TypeFlags.StringLiteral)) {
type.flags &
(ts.TypeFlags.String | ts.TypeFlags.StringLike | ts.TypeFlags.StringLiteral)) {
return BuiltinType.String;
} else if (type.flags & (this.ts.TypeFlags.Number | this.ts.TypeFlags.NumberLike)) {
} else if (type.flags & (ts.TypeFlags.Number | ts.TypeFlags.NumberLike)) {
return BuiltinType.Number;
} else if (type.flags & (this.ts.TypeFlags.Undefined)) {
} else if (type.flags & (ts.TypeFlags.Undefined)) {
return BuiltinType.Undefined;
} else if (type.flags & (this.ts.TypeFlags.Null)) {
} else if (type.flags & (ts.TypeFlags.Null)) {
return BuiltinType.Null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/@angular/language-service/test/completions_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('completions', () => {
let mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts'], toh);
let service = ts.createLanguageService(mockHost, documentRegistry);
let program = service.getProgram();
let ngHost = new TypeScriptServiceHost(ts, mockHost, service);
let ngHost = new TypeScriptServiceHost(mockHost, service);
let ngService = createLanguageService(ngHost);
ngHost.setSite(ngService);

Expand Down
2 changes: 1 addition & 1 deletion modules/@angular/language-service/test/definitions_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('definitions', () => {
let mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts'], toh);
let service = ts.createLanguageService(mockHost, documentRegistry);
let program = service.getProgram();
let ngHost = new TypeScriptServiceHost(ts, mockHost, service);
let ngHost = new TypeScriptServiceHost(mockHost, service);
let ngService = createLanguageService(ngHost);
ngHost.setSite(ngService);

Expand Down
2 changes: 1 addition & 1 deletion modules/@angular/language-service/test/diagnostics_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('diagnostics', () => {
let mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts'], toh);
let service = ts.createLanguageService(mockHost, documentRegistry);
let program = service.getProgram();
let ngHost = new TypeScriptServiceHost(ts, mockHost, service);
let ngHost = new TypeScriptServiceHost(mockHost, service);
let ngService = createLanguageService(ngHost);
ngHost.setSite(ngService);

Expand Down
2 changes: 1 addition & 1 deletion modules/@angular/language-service/test/hover_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('hover', () => {
let mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts'], toh);
let service = ts.createLanguageService(mockHost, documentRegistry);
let program = service.getProgram();
let ngHost = new TypeScriptServiceHost(ts, mockHost, service);
let ngHost = new TypeScriptServiceHost(mockHost, service);
let ngService = createLanguageService(ngHost);
ngHost.setSite(ngService);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('references', () => {
let mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts'], toh);
let service = ts.createLanguageService(mockHost, documentRegistry);
let program = service.getProgram();
let ngHost = new TypeScriptServiceHost(ts, mockHost, service);
let ngHost = new TypeScriptServiceHost(mockHost, service);
let ngService = createLanguageService(ngHost);
ngHost.setSite(ngService);

Expand Down
3 changes: 1 addition & 2 deletions modules/@angular/language-service/test/ts_plugin_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ describe('plugin', () => {
}
});

let plugin =
new LanguageServicePlugin({ts: ts, host: mockHost, service, registry: documentRegistry});
let plugin = new LanguageServicePlugin({host: mockHost, service, registry: documentRegistry});

it('should not report template errors on tour of heroes', () => {
for (let source of program.getSourceFiles()) {
Expand Down