fix(language-service): Create DirectiveKind enum (#32376)
Hovering over a selector, the QuickInfo display string is something like: ``` (component) AppComponent ``` where `component` is the symbol kind. Prior to this, there was no types to indicate the possible values of a symbol. This PR creates an enum to represent that. PR Close #32376
This commit is contained in:
parent
d4703d9316
commit
852afb312a
|
@ -11,7 +11,7 @@ import {getExpressionScope} from '@angular/compiler-cli/src/language_services';
|
||||||
|
|
||||||
import {AstResult} from './common';
|
import {AstResult} from './common';
|
||||||
import {getExpressionSymbol} from './expressions';
|
import {getExpressionSymbol} from './expressions';
|
||||||
import {Definition, Span, Symbol} from './types';
|
import {Definition, DirectiveKind, Span, Symbol} from './types';
|
||||||
import {diagnosticInfoFromTemplateInfo, findTemplateAstAt, inSpan, offsetSpan, spanOf} from './utils';
|
import {diagnosticInfoFromTemplateInfo, findTemplateAstAt, inSpan, offsetSpan, spanOf} from './utils';
|
||||||
|
|
||||||
export interface SymbolInfo {
|
export interface SymbolInfo {
|
||||||
|
@ -58,7 +58,7 @@ export function locateSymbol(info: AstResult, position: number): SymbolInfo|unde
|
||||||
const component = ast.directives.find(d => d.directive.isComponent);
|
const component = ast.directives.find(d => d.directive.isComponent);
|
||||||
if (component) {
|
if (component) {
|
||||||
symbol = info.template.query.getTypeSymbol(component.directive.type.reference);
|
symbol = info.template.query.getTypeSymbol(component.directive.type.reference);
|
||||||
symbol = symbol && new OverrideKindSymbol(symbol, 'component');
|
symbol = symbol && new OverrideKindSymbol(symbol, DirectiveKind.COMPONENT);
|
||||||
span = spanOf(ast);
|
span = spanOf(ast);
|
||||||
} else {
|
} else {
|
||||||
// Find a directive that matches the element name
|
// Find a directive that matches the element name
|
||||||
|
@ -66,7 +66,7 @@ export function locateSymbol(info: AstResult, position: number): SymbolInfo|unde
|
||||||
d => d.directive.selector != null && d.directive.selector.indexOf(ast.name) >= 0);
|
d => d.directive.selector != null && d.directive.selector.indexOf(ast.name) >= 0);
|
||||||
if (directive) {
|
if (directive) {
|
||||||
symbol = info.template.query.getTypeSymbol(directive.directive.type.reference);
|
symbol = info.template.query.getTypeSymbol(directive.directive.type.reference);
|
||||||
symbol = symbol && new OverrideKindSymbol(symbol, 'directive');
|
symbol = symbol && new OverrideKindSymbol(symbol, DirectiveKind.DIRECTIVE);
|
||||||
span = spanOf(ast);
|
span = spanOf(ast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ export function locateSymbol(info: AstResult, position: number): SymbolInfo|unde
|
||||||
visitEvent(ast) {
|
visitEvent(ast) {
|
||||||
if (!attributeValueSymbol(ast.handler, /* inEvent */ true)) {
|
if (!attributeValueSymbol(ast.handler, /* inEvent */ true)) {
|
||||||
symbol = findOutputBinding(info, path, ast);
|
symbol = findOutputBinding(info, path, ast);
|
||||||
symbol = symbol && new OverrideKindSymbol(symbol, 'event');
|
symbol = symbol && new OverrideKindSymbol(symbol, DirectiveKind.EVENT);
|
||||||
span = spanOf(ast);
|
span = spanOf(ast);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -170,8 +170,8 @@ function invertMap(obj: {[name: string]: string}): {[name: string]: string} {
|
||||||
* Wrap a symbol and change its kind to component.
|
* Wrap a symbol and change its kind to component.
|
||||||
*/
|
*/
|
||||||
class OverrideKindSymbol implements Symbol {
|
class OverrideKindSymbol implements Symbol {
|
||||||
public readonly kind: string;
|
public readonly kind: DirectiveKind;
|
||||||
constructor(private sym: Symbol, kindOverride: string) { this.kind = kindOverride; }
|
constructor(private sym: Symbol, kindOverride: DirectiveKind) { this.kind = kindOverride; }
|
||||||
|
|
||||||
get name(): string { return this.sym.name; }
|
get name(): string { return this.sym.name; }
|
||||||
|
|
||||||
|
|
|
@ -249,6 +249,15 @@ export enum DiagnosticKind {
|
||||||
Warning,
|
Warning,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of Angular directive. Used for QuickInfo in template.
|
||||||
|
*/
|
||||||
|
export enum DirectiveKind {
|
||||||
|
COMPONENT = 'component',
|
||||||
|
DIRECTIVE = 'directive',
|
||||||
|
EVENT = 'event',
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A template diagnostics message chain. This is similar to the TypeScript
|
* A template diagnostics message chain. This is similar to the TypeScript
|
||||||
* DiagnosticMessageChain. The messages are intended to be formatted as separate
|
* DiagnosticMessageChain. The messages are intended to be formatted as separate
|
||||||
|
|
Loading…
Reference in New Issue