Skip to content
Permalink
Browse files

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
  • Loading branch information...
kyliau authored and mhevery committed Aug 28, 2019
1 parent d4703d9 commit 852afb312aeb1c453177204288d296085a8aae68
Showing with 15 additions and 6 deletions.
  1. +6 −6 packages/language-service/src/locate_symbol.ts
  2. +9 −0 packages/language-service/src/types.ts
@@ -11,7 +11,7 @@ import {getExpressionScope} from '@angular/compiler-cli/src/language_services';

import {AstResult} from './common';
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';

export interface SymbolInfo {
@@ -58,15 +58,15 @@ export function locateSymbol(info: AstResult, position: number): SymbolInfo|unde
const component = ast.directives.find(d => d.directive.isComponent);
if (component) {
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);
} else {
// Find a directive that matches the element name
const directive = ast.directives.find(
d => d.directive.selector != null && d.directive.selector.indexOf(ast.name) >= 0);
if (directive) {
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);
}
}
@@ -79,7 +79,7 @@ export function locateSymbol(info: AstResult, position: number): SymbolInfo|unde
visitEvent(ast) {
if (!attributeValueSymbol(ast.handler, /* inEvent */ true)) {
symbol = findOutputBinding(info, path, ast);
symbol = symbol && new OverrideKindSymbol(symbol, 'event');
symbol = symbol && new OverrideKindSymbol(symbol, DirectiveKind.EVENT);
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.
*/
class OverrideKindSymbol implements Symbol {
public readonly kind: string;
constructor(private sym: Symbol, kindOverride: string) { this.kind = kindOverride; }
public readonly kind: DirectiveKind;
constructor(private sym: Symbol, kindOverride: DirectiveKind) { this.kind = kindOverride; }

get name(): string { return this.sym.name; }

@@ -249,6 +249,15 @@ export enum DiagnosticKind {
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
* DiagnosticMessageChain. The messages are intended to be formatted as separate

0 comments on commit 852afb3

Please sign in to comment.
You can’t perform that action at this time.