Skip to content

Commit

Permalink
fix(language-service): Create DirectiveKind enum (angular#32376)
Browse files Browse the repository at this point in the history
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 angular#32376
  • Loading branch information
Keen Yee Liau authored and mhevery committed Aug 29, 2019
1 parent d4703d9 commit 852afb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/language-service/src/locate_symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
},
Expand Down Expand Up @@ -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; }

Expand Down
9 changes: 9 additions & 0 deletions packages/language-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 852afb3

Please sign in to comment.