Skip to content

Commit

Permalink
combine all origin selection ranges when having multiple go-to via mo…
Browse files Browse the repository at this point in the history
…use result (#165349)

fixes #160958
  • Loading branch information
jrieken authored Nov 3, 2022
1 parent e8ae985 commit 46face3
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,22 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
return;
}

const linkRange = results[0].originSelectionRange
? Range.lift(results[0].originSelectionRange)
: new Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn);

// Multiple results
if (results.length > 1) {

let combinedRange = linkRange;
for (const { originSelectionRange } of results) {
if (originSelectionRange) {
combinedRange = Range.plusRange(combinedRange, originSelectionRange);
}
}

this.addDecoration(
new Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn),
combinedRange,
new MarkdownString().appendText(nls.localize('multipleResults', "Click to show {0} definitions.", results.length))
);
}
Expand Down Expand Up @@ -197,17 +209,9 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
}

const previewValue = this.getPreviewValue(textEditorModel, startLineNumber, result);

let wordRange: Range;
if (result.originSelectionRange) {
wordRange = Range.lift(result.originSelectionRange);
} else {
wordRange = new Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn);
}

const languageId = this.languageService.guessLanguageIdByFilepathOrFirstLine(textEditorModel.uri);
this.addDecoration(
wordRange,
linkRange,
new MarkdownString().appendCodeblock(languageId ? languageId : '', previewValue)
);
ref.dispose();
Expand Down

0 comments on commit 46face3

Please sign in to comment.