Fixed several bugs in hover and completion providers related to modules and submodules.

This commit is contained in:
Eric Traut 2019-12-20 22:34:38 -07:00
parent 546df5da08
commit c795854988
3 changed files with 24 additions and 4 deletions

View File

@ -626,7 +626,7 @@ export class ImportResolver {
if (!isLastPart) {
// We are not at the last part, and we found a directory,
// so continue to look for the next part.
resolvedPaths.push(dirPath);
resolvedPaths.push('');
continue;
}

View File

@ -22,7 +22,7 @@ import { Symbol, SymbolTable } from '../analyzer/symbol';
import * as SymbolNameUtils from '../analyzer/symbolNameUtils';
import { getLastTypedDeclaredForSymbol } from '../analyzer/symbolUtils';
import { TypeEvaluator } from '../analyzer/typeEvaluator';
import { FunctionType, OverloadedFunctionType, TypeCategory } from '../analyzer/types';
import { FunctionType, OverloadedFunctionType, Type, TypeCategory } from '../analyzer/types';
import { doForSubtypes, getMembersForClass, getMembersForModule } from '../analyzer/typeUtils';
import { ConfigOptions } from '../common/configOptions';
import { comparePositions, DiagnosticTextPosition } from '../common/diagnostic';
@ -972,6 +972,15 @@ export class CompletionProvider {
this._addNameToCompletionList(name, itemKind, priorWord, completionList,
undefined, undefined, autoImportText, textEdit,
additionalTextEdits, symbol.id);
} else {
// Does the symbol have no declaration but instead has an "undeclared" type?
const undeclaredType = symbol.getUndeclaredType();
if (undeclaredType) {
const itemKind: CompletionItemKind = CompletionItemKind.Variable;
this._addNameToCompletionList(name, itemKind, priorWord, completionList,
undefined, undefined, undefined, textEdit,
additionalTextEdits, symbol.id);
}
}
}

View File

@ -62,8 +62,19 @@ export class HoverProvider {
// is a directory (a namespace package), and we don't want to provide any hover
// information in that case.
if (results.parts.length === 0) {
this._addResultsPart(results.parts, node.value +
this._getTypeText(node, evaluator), true);
const type = evaluator.getType(node) || UnknownType.create();
let typeText = '';
if (type.category === TypeCategory.Module) {
// Handle modules specially because submodules aren't associated with
// declarations, but we want them to be presented in the same way as
// the top-level module, which does have a declaration.
typeText = '(module) ' + node.value;
} else {
typeText = node.value + ': ' + evaluator.printType(type);
}
this._addResultsPart(results.parts, typeText, true);
this._addDocumentationPart(results.parts, node, evaluator);
}
}