feat(language-service): Introduce 'angularOnly' flag (#31935)
This PR changes the language service to work in two different modes: 1. TS + Angular Plugin augments TS language service to provide additonal Angular information. This only works with inline template and is meant to be used as a local plugin (configured via tsconfig.json). 2. Angular only Plugin only provides information on Angular templates, no TS info at all. This effectively disables native TS features and is meant for internal use only. Default mode is `angularOnly = false` so that we don't break any users already using Angular LS as local plugin. As part of the refactoring, `undefined` is removed from type aliases because it is considered bad practice. go/tsstyle#nullableundefined-type-aliases ``` Type aliases must not include |null or |undefined in a union type. Nullable aliases typically indicate that null values are being passed around through too many layers of an application, and this clouds the source of the original issue that resulted in null. They also make it unclear when specific values on a class or interface might be absent. ``` PR Close #31935
This commit is contained in:

committed by
Alex Rickabaugh

parent
a2183ddb7a
commit
7b9891d7cd
@ -13,7 +13,7 @@ import {getTemplateCompletions} from './completions';
|
||||
import {getDefinition} from './definitions';
|
||||
import {getDeclarationDiagnostics} from './diagnostics';
|
||||
import {getHover} from './hover';
|
||||
import {Completions, Definition, Diagnostic, DiagnosticKind, Diagnostics, Hover, LanguageService, LanguageServiceHost, Span, TemplateSource} from './types';
|
||||
import {Completion, Diagnostic, DiagnosticKind, Diagnostics, Hover, LanguageService, LanguageServiceHost, Location, Span, TemplateSource} from './types';
|
||||
import {offsetSpan, spanOf} from './utils';
|
||||
|
||||
|
||||
@ -34,14 +34,14 @@ class LanguageServiceImpl implements LanguageService {
|
||||
|
||||
getTemplateReferences(): string[] { return this.host.getTemplateReferences(); }
|
||||
|
||||
getDiagnostics(fileName: string): Diagnostics|undefined {
|
||||
let results: Diagnostics = [];
|
||||
let templates = this.host.getTemplates(fileName);
|
||||
getDiagnostics(fileName: string): Diagnostic[] {
|
||||
const results: Diagnostic[] = [];
|
||||
const templates = this.host.getTemplates(fileName);
|
||||
if (templates && templates.length) {
|
||||
results.push(...this.getTemplateDiagnostics(fileName, templates));
|
||||
}
|
||||
|
||||
let declarations = this.host.getDeclarations(fileName);
|
||||
const declarations = this.host.getDeclarations(fileName);
|
||||
if (declarations && declarations.length) {
|
||||
const summary = this.host.getAnalyzedModules();
|
||||
results.push(...getDeclarationDiagnostics(declarations, summary));
|
||||
@ -58,14 +58,14 @@ class LanguageServiceImpl implements LanguageService {
|
||||
return [];
|
||||
}
|
||||
|
||||
getCompletionsAt(fileName: string, position: number): Completions {
|
||||
getCompletionsAt(fileName: string, position: number): Completion[]|undefined {
|
||||
let templateInfo = this.host.getTemplateAstAtPosition(fileName, position);
|
||||
if (templateInfo) {
|
||||
return getTemplateCompletions(templateInfo);
|
||||
}
|
||||
}
|
||||
|
||||
getDefinitionAt(fileName: string, position: number): Definition {
|
||||
getDefinitionAt(fileName: string, position: number): Location[]|undefined {
|
||||
let templateInfo = this.host.getTemplateAstAtPosition(fileName, position);
|
||||
if (templateInfo) {
|
||||
return getDefinition(templateInfo);
|
||||
@ -112,25 +112,20 @@ class LanguageServiceImpl implements LanguageService {
|
||||
}
|
||||
}
|
||||
|
||||
function uniqueBySpan < T extends {
|
||||
span: Span;
|
||||
}
|
||||
> (elements: T[] | undefined): T[]|undefined {
|
||||
if (elements) {
|
||||
const result: T[] = [];
|
||||
const map = new Map<number, Set<number>>();
|
||||
for (const element of elements) {
|
||||
let span = element.span;
|
||||
let set = map.get(span.start);
|
||||
if (!set) {
|
||||
set = new Set();
|
||||
map.set(span.start, set);
|
||||
}
|
||||
if (!set.has(span.end)) {
|
||||
set.add(span.end);
|
||||
result.push(element);
|
||||
}
|
||||
function uniqueBySpan<T extends{span: Span}>(elements: T[]): T[] {
|
||||
const result: T[] = [];
|
||||
const map = new Map<number, Set<number>>();
|
||||
for (const element of elements) {
|
||||
const {span} = element;
|
||||
let set = map.get(span.start);
|
||||
if (!set) {
|
||||
set = new Set();
|
||||
map.set(span.start, set);
|
||||
}
|
||||
if (!set.has(span.end)) {
|
||||
set.add(span.end);
|
||||
result.push(element);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user