Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
fannheyward committed Nov 23, 2023
1 parent 8e13dc7 commit 1f2ba58
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
22 changes: 13 additions & 9 deletions src/features/inlayHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export class TypeInlayHintsProvider implements InlayHintsProvider {
public readonly onDidChangeInlayHints: Event<void> = 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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -176,7 +181,6 @@ export class TypeInlayHintsProvider implements InlayHintsProvider {
return;
}
return label + ': ';

}

private enableForType(inlayHintType: string) {
Expand Down
6 changes: 3 additions & 3 deletions src/parsers/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 };
1 change: 0 additions & 1 deletion src/parsers/inlayHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1f2ba58

Please sign in to comment.