Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combine all origin selection ranges when having multiple go-to via mouse result #165349

Merged
merged 1 commit into from Nov 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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