Skip to content

Commit

Permalink
add test for inlay hint range
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Mar 26, 2024
1 parent 9a97344 commit 6641894
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/pyright-internal/src/tests/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions packages/pyright-internal/src/tests/typeInlayHintsWalker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {});
Expand Down

0 comments on commit 6641894

Please sign in to comment.