feat(language-service): Show documentation on hover (#34506)

This commit adds dpcumentation to the hover tooltip.

PR closes https://github.com/angular/vscode-ng-language-service/issues/321

PR Close #34506
This commit is contained in:
Keen Yee Liau
2019-12-19 18:33:26 -08:00
committed by Alex Rickabaugh
parent ba2fd31e62
commit c079f38cbb
8 changed files with 70 additions and 4 deletions

View File

@ -8,11 +8,14 @@
import {CompileSummaryKind, StaticSymbol} from '@angular/compiler';
import * as ts from 'typescript';
import {AstResult} from './common';
import {locateSymbol} from './locate_symbol';
import * as ng from './types';
import {TypeScriptServiceHost} from './typescript_host';
import {findTightestNode} from './utils';
// Reverse mappings of enum would generate strings
const SYMBOL_SPACE = ts.SymbolDisplayPartKind[ts.SymbolDisplayPartKind.space];
const SYMBOL_PUNC = ts.SymbolDisplayPartKind[ts.SymbolDisplayPartKind.punctuation];
@ -37,7 +40,7 @@ export function getHover(info: AstResult, position: number, host: Readonly<TypeS
const textSpan = {start: span.start, length: span.end - span.start};
if (compileTypeSummary && compileTypeSummary.summaryKind === CompileSummaryKind.Directive) {
return getDirectiveModule(compileTypeSummary.type.reference, textSpan, host);
return getDirectiveModule(compileTypeSummary.type.reference, textSpan, host, symbol);
}
const containerDisplayParts: ts.SymbolDisplayPart[] = symbol.container ?
@ -57,6 +60,7 @@ export function getHover(info: AstResult, position: number, host: Readonly<TypeS
kind: symbol.kind as ts.ScriptElementKind,
kindModifiers: '', // kindModifier info not available on 'ng.Symbol'
textSpan,
documentation: symbol.documentation,
// this would generate a string like '(property) ClassX.propY: type'
// 'kind' in displayParts does not really matter because it's dropped when
// displayParts get converted to string.
@ -105,11 +109,13 @@ export function getTsHover(
/**
* Attempts to get quick info for the NgModule a Directive is declared in.
* @param directive identifier on a potential Directive class declaration
* @param textSpan span of the symbol
* @param host Language Service host to query
* @param symbol the internal symbol that represents the directive
*/
function getDirectiveModule(
directive: StaticSymbol, textSpan: ts.TextSpan,
host: Readonly<TypeScriptServiceHost>): ts.QuickInfo|undefined {
directive: StaticSymbol, textSpan: ts.TextSpan, host: Readonly<TypeScriptServiceHost>,
symbol?: ng.Symbol): ts.QuickInfo|undefined {
const analyzedModules = host.getAnalyzedModules(false);
const ngModule = analyzedModules.ngModuleByPipeOrDirective.get(directive);
if (!ngModule) return;
@ -124,6 +130,7 @@ function getDirectiveModule(
kindModifiers:
ts.ScriptElementKindModifier.none, // kindModifier info not available on 'ng.Symbol'
textSpan,
documentation: symbol ? symbol.documentation : undefined,
// This generates a string like '(directive) NgModule.Directive: class'
// 'kind' in displayParts does not really matter because it's dropped when
// displayParts get converted to string.