
committed by
Matias Niemelä

parent
c230173716
commit
5653fada32
@ -27,7 +27,7 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
|
||||
let oldLS: ts.LanguageService = info.languageService;
|
||||
|
||||
function tryCall<T>(fileName: string | undefined, callback: () => T): T {
|
||||
if (fileName && !oldLS.getProgram().getSourceFile(fileName)) {
|
||||
if (fileName && !oldLS.getProgram() !.getSourceFile(fileName)) {
|
||||
return undefined as any as T;
|
||||
}
|
||||
try {
|
||||
@ -84,10 +84,11 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
|
||||
getCompletionsAtPosition: tryFilenameTwoCall(ls.getCompletionsAtPosition),
|
||||
getCompletionEntryDetails: tryFilenameFiveCall(ls.getCompletionEntryDetails),
|
||||
getCompletionEntrySymbol: tryFilenameThreeCall(ls.getCompletionEntrySymbol),
|
||||
getJsxClosingTagAtPosition: tryFilenameOneCall(ls.getJsxClosingTagAtPosition),
|
||||
getQuickInfoAtPosition: tryFilenameOneCall(ls.getQuickInfoAtPosition),
|
||||
getNameOrDottedNameSpan: tryFilenameTwoCall(ls.getNameOrDottedNameSpan),
|
||||
getBreakpointStatementAtPosition: tryFilenameOneCall(ls.getBreakpointStatementAtPosition),
|
||||
getSignatureHelpItems: tryFilenameOneCall(ls.getSignatureHelpItems),
|
||||
getSignatureHelpItems: tryFilenameTwoCall(ls.getSignatureHelpItems),
|
||||
getRenameInfo: tryFilenameOneCall(ls.getRenameInfo),
|
||||
findRenameLocations: tryFilenameThreeCall(ls.findRenameLocations),
|
||||
getDefinitionAtPosition: tryFilenameOneCall(ls.getDefinitionAtPosition),
|
||||
@ -229,32 +230,33 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
|
||||
return base;
|
||||
};
|
||||
|
||||
proxy.getQuickInfoAtPosition = function(fileName: string, position: number): ts.QuickInfo {
|
||||
let base = oldLS.getQuickInfoAtPosition(fileName, position);
|
||||
// TODO(vicb): the tags property has been removed in TS 2.2
|
||||
tryOperation('get quick info', () => {
|
||||
const ours = ls.getHoverAt(fileName, position);
|
||||
if (ours) {
|
||||
const displayParts: ts.SymbolDisplayPart[] = [];
|
||||
for (const part of ours.text) {
|
||||
displayParts.push({kind: part.language || 'angular', text: part.text});
|
||||
}
|
||||
const tags = base && (<any>base).tags;
|
||||
base = <any>{
|
||||
displayParts,
|
||||
documentation: [],
|
||||
kind: 'angular',
|
||||
kindModifiers: 'what does this do?',
|
||||
textSpan: {start: ours.span.start, length: ours.span.end - ours.span.start},
|
||||
};
|
||||
if (tags) {
|
||||
(<any>base).tags = tags;
|
||||
}
|
||||
}
|
||||
});
|
||||
proxy.getQuickInfoAtPosition = function(fileName: string, position: number): ts.QuickInfo |
|
||||
undefined {
|
||||
let base = oldLS.getQuickInfoAtPosition(fileName, position);
|
||||
// TODO(vicb): the tags property has been removed in TS 2.2
|
||||
tryOperation('get quick info', () => {
|
||||
const ours = ls.getHoverAt(fileName, position);
|
||||
if (ours) {
|
||||
const displayParts: ts.SymbolDisplayPart[] = [];
|
||||
for (const part of ours.text) {
|
||||
displayParts.push({kind: part.language || 'angular', text: part.text});
|
||||
}
|
||||
const tags = base && (<any>base).tags;
|
||||
base = <any>{
|
||||
displayParts,
|
||||
documentation: [],
|
||||
kind: 'angular',
|
||||
kindModifiers: 'what does this do?',
|
||||
textSpan: {start: ours.span.start, length: ours.span.end - ours.span.start},
|
||||
};
|
||||
if (tags) {
|
||||
(<any>base).tags = tags;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return base;
|
||||
};
|
||||
return base;
|
||||
};
|
||||
|
||||
proxy.getSemanticDiagnostics = function(fileName: string) {
|
||||
let result = oldLS.getSemanticDiagnostics(fileName);
|
||||
@ -263,7 +265,7 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
|
||||
info.project.projectService.logger.info(`Computing Angular semantic diagnostics...`);
|
||||
const ours = ls.getDiagnostics(fileName);
|
||||
if (ours && ours.length) {
|
||||
const file = oldLS.getProgram().getSourceFile(fileName);
|
||||
const file = oldLS.getProgram() !.getSourceFile(fileName);
|
||||
if (file) {
|
||||
base.push.apply(base, ours.map(d => diagnosticToDiagnostic(d, file)));
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
|
||||
};
|
||||
} else {
|
||||
const analyzeHost = {isSourceFile(filePath: string) { return true; }};
|
||||
const programFiles = this.program.getSourceFiles().map(sf => sf.fileName);
|
||||
const programFiles = this.program !.getSourceFiles().map(sf => sf.fileName);
|
||||
analyzedModules =
|
||||
analyzeNgModules(programFiles, analyzeHost, this.staticSymbolResolver, this.resolver);
|
||||
}
|
||||
@ -224,7 +224,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
|
||||
}
|
||||
|
||||
getSourceFile(fileName: string): ts.SourceFile|undefined {
|
||||
return this.tsService.getProgram().getSourceFile(fileName);
|
||||
return this.tsService.getProgram() !.getSourceFile(fileName);
|
||||
}
|
||||
|
||||
updateAnalyzedModules() {
|
||||
@ -244,7 +244,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
|
||||
private get checker() {
|
||||
let checker = this._checker;
|
||||
if (!checker) {
|
||||
checker = this._checker = this.program.getTypeChecker();
|
||||
checker = this._checker = this.program !.getTypeChecker();
|
||||
}
|
||||
return checker;
|
||||
}
|
||||
@ -257,7 +257,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
|
||||
this._staticSymbolResolver.invalidateFile(fileName);
|
||||
this.clearCaches();
|
||||
const seen = new Set<string>();
|
||||
for (let sourceFile of this.program.getSourceFiles()) {
|
||||
for (let sourceFile of this.program !.getSourceFiles()) {
|
||||
const fileName = sourceFile.fileName;
|
||||
seen.add(fileName);
|
||||
const version = this.host.getScriptVersion(fileName);
|
||||
@ -325,14 +325,14 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
|
||||
span,
|
||||
type,
|
||||
get members() {
|
||||
return getClassMembersFromDeclaration(t.program, t.checker, sourceFile, declaration);
|
||||
return getClassMembersFromDeclaration(t.program !, t.checker, sourceFile, declaration);
|
||||
},
|
||||
get query() {
|
||||
if (!queryCache) {
|
||||
const pipes = t.service.getPipesAt(fileName, node.getStart());
|
||||
queryCache = getSymbolQuery(
|
||||
t.program, t.checker, sourceFile,
|
||||
() => getPipesTable(sourceFile, t.program, t.checker, pipes));
|
||||
t.program !, t.checker, sourceFile,
|
||||
() => getPipesTable(sourceFile, t.program !, t.checker, pipes));
|
||||
}
|
||||
return queryCache;
|
||||
}
|
||||
@ -394,7 +394,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
|
||||
// The host's getCurrentDirectory() is not reliable as it is always "" in
|
||||
// tsserver. We don't need the exact base directory, just one that contains
|
||||
// a source file.
|
||||
const source = this.tsService.getProgram().getSourceFile(this.context);
|
||||
const source = this.tsService.getProgram() !.getSourceFile(this.context);
|
||||
if (!source) {
|
||||
throw new Error('Internal error: no context could be determined');
|
||||
}
|
||||
@ -410,7 +410,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
|
||||
options.paths = compilerOptions.paths;
|
||||
}
|
||||
result = this._reflectorHost =
|
||||
new ReflectorHost(() => this.tsService.getProgram(), this.host, options);
|
||||
new ReflectorHost(() => this.tsService.getProgram() !, this.host, options);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user