Skip to content

Commit

Permalink
attempt to fix inlay hint crash on neovim
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Aug 31, 2024
1 parent fc0998f commit cdc2ff6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions packages/pyright-internal/src/analyzer/typeInlayHintsWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { isLiteralType } from './typeUtils';
import { TextRange } from '../common/textRange';
import { convertRangeToTextRange } from '../common/positionUtils';
import { TextRangeCollection } from '../common/textRangeCollection';
import { Uri } from '../common/uri/uri';
import { ParseFileResults } from '../parser/parser';

Expand Down Expand Up @@ -82,16 +81,17 @@ function isLeftSideOfAssignment(node: ParseNode): boolean {

export class TypeInlayHintsWalker extends ParseTreeWalker {
featureItems: TypeInlayHintsItemType[] = [];
parseResults: ParseFileResults | undefined;
lines: TextRangeCollection<TextRange>;
parseResults?: ParseFileResults;
private _range: TextRange | undefined;

constructor(private readonly _program: ProgramView, fileUri: Uri, range?: Range) {
super();
this.parseResults = this._program.getParseResults(fileUri);
this.lines = this.parseResults!.tokenizerOutput.lines;
if (range) {
this._range = convertRangeToTextRange(range, this.lines);
if (this.parseResults) {
const lines = this.parseResults.tokenizerOutput.lines;
if (range && lines) {
this._range = convertRangeToTextRange(range, lines);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ export class InlayHintsProvider {
}

async onInlayHints(): Promise<InlayHint[] | null> {
if (!this._walker.parseResults) {
const parseResults = this._walker.parseResults;
if (!parseResults) {
return null;
}
this._walker.walk(this._walker.parseResults.parserOutput.parseTree);
this._walker.walk(parseResults.parserOutput.parseTree);

return this._walker.featureItems.map((item) => ({
label: [InlayHintLabelPart.create(item.value)],
position: convertOffsetToPosition(item.position, this._walker.lines),
position: convertOffsetToPosition(item.position, parseResults.tokenizerOutput.lines),
paddingLeft: item.inlayHintType === 'functionReturn',
kind: item.inlayHintType === 'parameter' ? InlayHintKind.Parameter : InlayHintKind.Type,
}));
Expand Down

0 comments on commit cdc2ff6

Please sign in to comment.