diff --git a/src/features/inlayHints.ts b/src/features/inlayHints.ts index 2780cf2f..de176839 100644 --- a/src/features/inlayHints.ts +++ b/src/features/inlayHints.ts @@ -23,12 +23,12 @@ export class TypeInlayHintsProvider implements InlayHintsProvider { public readonly onDidChangeInlayHints: Event = this._onDidChangeInlayHints.event; constructor(private client: LanguageClient) { - workspace.onDidChangeConfiguration(e => { + workspace.onDidChangeConfiguration((e) => { if (e.affectsConfiguration('pyright.inlayHints')) { this._onDidChangeInlayHints.fire(); } }); - workspace.onDidChangeTextDocument(e => { + workspace.onDidChangeTextDocument((e) => { const doc = workspace.getDocument(e.bufnr); if (doc.languageId === 'python') { this._onDidChangeInlayHints.fire(); @@ -47,11 +47,13 @@ export class TypeInlayHintsProvider implements InlayHintsProvider { const walker = new parser.TypeInlayHintsWalker(parsed); walker.walk(parsed.parseTree); - const featureItems = walker.featureItems.filter(item => this.enableForType(item.inlayHintType)).filter(item => { - const startPosition = document.positionAt(item.startOffset); - const endPosition = document.positionAt(item.endOffset); - return positionInRange(startPosition, range) === 0 || positionInRange(endPosition, range) === 0; - }); + const featureItems = walker.featureItems + .filter((item) => this.enableForType(item.inlayHintType)) + .filter((item) => { + const startPosition = document.positionAt(item.startOffset); + const endPosition = document.positionAt(item.endOffset); + return positionInRange(startPosition, range) === 0 || positionInRange(endPosition, range) === 0; + }); if (featureItems.length === 0) return []; for (const item of featureItems) { @@ -130,7 +132,10 @@ export class TypeInlayHintsProvider implements InlayHintsProvider { } const firstIdx = contents.value.indexOf(': '); if (firstIdx > -1) { - const text = contents.value.substring(firstIdx + 2).split('\n')[0].trim(); + const text = contents.value + .substring(firstIdx + 2) + .split('\n')[0] + .trim(); if (text === 'Any' || text.startsWith('Literal[')) { return; } @@ -176,7 +181,6 @@ export class TypeInlayHintsProvider implements InlayHintsProvider { return; } return label + ': '; - } private enableForType(inlayHintType: string) { diff --git a/src/parsers/index.ts b/src/parsers/index.ts index a680959f..01647e32 100644 --- a/src/parsers/index.ts +++ b/src/parsers/index.ts @@ -1,8 +1,8 @@ import { DiagnosticSink } from '@zzzen/pyright-internal/dist/common/diagnosticSink'; import { ParseOptions, ParseResults, Parser } from '@zzzen/pyright-internal/dist/parser/parser'; -import { SemanticTokensWalker, TokenTypes } from './semanticTokens'; -import { FunctionFormatItemType, TestFrameworkWalker } from './testFramework'; import { TypeInlayHintsItemType, TypeInlayHintsWalker } from './inlayHints'; +import { SemanticTokensWalker } from './semanticTokens'; +import { FunctionFormatItemType, TestFrameworkWalker } from './testFramework'; function parse(source: string) { let result: ParseResults | undefined = undefined; @@ -15,4 +15,4 @@ function parse(source: string) { return result; } -export { parse, SemanticTokensWalker, TestFrameworkWalker, TypeInlayHintsWalker, FunctionFormatItemType, TypeInlayHintsItemType, TokenTypes }; +export { parse, SemanticTokensWalker, TestFrameworkWalker, TypeInlayHintsWalker, FunctionFormatItemType, TypeInlayHintsItemType }; diff --git a/src/parsers/inlayHints.ts b/src/parsers/inlayHints.ts index 8020bb57..3250daf2 100644 --- a/src/parsers/inlayHints.ts +++ b/src/parsers/inlayHints.ts @@ -66,7 +66,6 @@ export class TypeInlayHintsWalker extends ParseTreeWalker { return super.visitArgument(node); } - override visitFunction(node: FunctionNode): boolean { // If the code describes a type, do not add the item. // Add item only if "node.returnTypeAnnotation" does not exist.