From 664189463c1871a0fe8ea071db2a54a3250144d9 Mon Sep 17 00:00:00 2001 From: DetachHead Date: Tue, 26 Mar 2024 23:31:28 +1000 Subject: [PATCH] add test for inlay hint range --- packages/pyright-internal/src/tests/testUtils.ts | 5 +++-- .../src/tests/typeInlayHintsWalker.test.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/pyright-internal/src/tests/testUtils.ts b/packages/pyright-internal/src/tests/testUtils.ts index d49a4c7bc7..2b411ce4bf 100644 --- a/packages/pyright-internal/src/tests/testUtils.ts +++ b/packages/pyright-internal/src/tests/testUtils.ts @@ -30,6 +30,7 @@ import { entries } from '@detachhead/ts-helpers/dist/functions/misc'; import { DiagnosticRule } from '../common/diagnosticRules'; import { SemanticTokenItem, SemanticTokensWalker } from '../analyzer/semanticTokensWalker'; import { TypeInlayHintsItemType, TypeInlayHintsWalker } from '../analyzer/typeInlayHintsWalker'; +import { Range } from 'vscode-languageserver-types'; // This is a bit gross, but it's necessary to allow the fallback typeshed // directory to be located when running within the jest environment. This @@ -146,11 +147,11 @@ export const semanticTokenizeSampleFile = (fileName: string): SemanticTokenItem[ return walker.items; }; -export const inlayHintSampleFile = (fileName: string): TypeInlayHintsItemType[] => { +export const inlayHintSampleFile = (fileName: string, range?: Range): TypeInlayHintsItemType[] => { const program = createProgram(); const fileUri = UriEx.file(resolveSampleFilePath(path.join('inlay_hints', fileName))); program.setTrackedFiles([fileUri]); - const walker = new TypeInlayHintsWalker(program, fileUri); + const walker = new TypeInlayHintsWalker(program, fileUri, range); walker.walk(program.getParseResults(fileUri)!.parseTree); program.dispose(); return walker.featureItems; diff --git a/packages/pyright-internal/src/tests/typeInlayHintsWalker.test.ts b/packages/pyright-internal/src/tests/typeInlayHintsWalker.test.ts index 23daa8e618..82b728b376 100644 --- a/packages/pyright-internal/src/tests/typeInlayHintsWalker.test.ts +++ b/packages/pyright-internal/src/tests/typeInlayHintsWalker.test.ts @@ -37,6 +37,20 @@ if (process.platform !== 'win32' || !process.env['CI']) { { inlayHintType: 'parameter', position: 446, value: 'b=' }, ]); }); + + test('range', () => { + const result = inlayHintSampleFile('variables.py', { + start: { line: 0, character: 0 }, + end: { line: 5, character: 0 }, + }); + expect(result).toStrictEqual([ + { + inlayHintType: 'variable', + position: 53, + value: ': str', + }, + ]); + }); } else { // prevent jest from failing because no tests were found test('windows placeholder', () => {});