refactor(language-service): Return ts.CompletionInfo for getCompletionsAt() (#32116)

Part 3/3 of language-service refactoring:
Change all language service APIs to return TS value since Angular LS
will be a proper tsserver plugin. This reduces the need to transform
results among Angular <--> TS <--> LSP.

PR Close #32116
This commit is contained in:
Keen Yee Liau
2019-08-12 16:54:36 -07:00
committed by Andrew Kushnir
parent d6bbc4d76d
commit 5a562d8a0a
7 changed files with 124 additions and 143 deletions

View File

@ -6,11 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as ts from 'typescript'; // used as value, passed in by tsserver at runtime
import * as tss from 'typescript/lib/tsserverlibrary'; // used as type only
import {createLanguageService} from './language_service';
import {Completion} from './types';
import {TypeScriptServiceHost} from './typescript_host';
const projectHostMap = new WeakMap<tss.server.Project, TypeScriptServiceHost>();
@ -24,16 +22,6 @@ export function getExternalFiles(project: tss.server.Project): string[]|undefine
}
}
function completionToEntry(c: Completion): tss.CompletionEntry {
return {
// TODO: remove any and fix type error.
kind: c.kind as any,
name: c.name,
sortText: c.sort,
kindModifiers: ''
};
}
export function create(info: tss.server.PluginCreateInfo): tss.LanguageService {
const {project, languageService: tsLS, languageServiceHost: tsLSHost, config} = info;
// This plugin could operate under two different modes:
@ -60,16 +48,7 @@ export function create(info: tss.server.PluginCreateInfo): tss.LanguageService {
return results;
}
}
const results = ngLS.getCompletionsAt(fileName, position);
if (!results || !results.length) {
return;
}
return {
isGlobalCompletion: false,
isMemberCompletion: false,
isNewIdentifierLocation: false,
entries: results.map(completionToEntry),
};
return ngLS.getCompletionsAt(fileName, position);
}
function getQuickInfoAtPosition(fileName: string, position: number): tss.QuickInfo|undefined {