Skip to content

Commit

Permalink
Improved hover text for methods that are synthesized (e.g. the get
Browse files Browse the repository at this point in the history
…method for TypedDict). This partly addresses microsoft/pylance-release#4098.
  • Loading branch information
msfterictraut committed Mar 17, 2023
1 parent 34e12fc commit cb9952a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/pyright-internal/src/languageService/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ 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) {
const type = evaluator.getType(node) || UnknownType.create();
let type = evaluator.getType(node) || UnknownType.create();

let typeText: string;
if (isModule(type)) {
Expand All @@ -162,7 +162,23 @@ export class HoverProvider {
// the top-level module, which does have a declaration.
typeText = '(module) ' + node.value;
} else {
typeText = node.value + ': ' + evaluator.printType(type);
type = this._limitOverloadBasedOnCall(node, evaluator, type);
let label = 'function';
let isProperty = false;

if (isMaybeDescriptorInstance(type, /* requireSetter */ false)) {
isProperty = true;
label = 'property';
}

typeText = getToolTipForType(
type,
label,
node.value,
evaluator,
isProperty,
functionSignatureDisplay
);
}

this._addResultsPart(results.parts, typeText, /* python */ true);
Expand Down

0 comments on commit cb9952a

Please sign in to comment.