diff --git a/Extension/CHANGELOG.md b/Extension/CHANGELOG.md index 4ac81cfed1..a0b53deb56 100644 --- a/Extension/CHANGELOG.md +++ b/Extension/CHANGELOG.md @@ -9,6 +9,7 @@ * Add support for passing an additional parameter to `C_Cpp.ConfigurationSelect` command. [PR #12993](https://github.com/microsoft/vscode-cpptools/pull/12993) * Thank you for the contribution. [@adrianstephens](https://github.com/adrianstephens) * Update clang-format and clang-tidy from 19.1.2 to 19.1.5. +* Add support for providing the definition with inlay hint for the specific symbol. [#13010](https://github.com/microsoft/vscode-cpptools/issues/13010) ### Bug Fixes * Increase clang-format timeout from 10 seconds to 30 seconds. [#10213](https://github.com/microsoft/vscode-cpptools/issues/10213) diff --git a/Extension/src/LanguageServer/Providers/inlayHintProvider.ts b/Extension/src/LanguageServer/Providers/inlayHintProvider.ts index 257703f770..a940c3786b 100644 --- a/Extension/src/LanguageServer/Providers/inlayHintProvider.ts +++ b/Extension/src/LanguageServer/Providers/inlayHintProvider.ts @@ -32,6 +32,9 @@ export interface CppInlayHint { leftPadding: boolean; rightPadding: boolean; identifierLength: number; + definitionUri?: vscode.Uri; + definitionLine?: number; + definitionCharacter?: number; } enum InlayHintKind { @@ -204,10 +207,11 @@ export class InlayHintsProvider implements vscode.InlayHintsProvider { const resolvedHints: vscode.InlayHint[] = []; for (const hint of hints) { const showOnLeft: boolean = settings.inlayHintsAutoDeclarationTypesShowOnLeft && hint.identifierLength > 0; + const labelPart: vscode.InlayHintLabelPart = this.createInlayHintLabelPart(hint, showOnLeft ? hint.label : ": " + hint.label); const inlayHint: vscode.InlayHint = new vscode.InlayHint( new vscode.Position(hint.line, hint.character + (showOnLeft ? 0 : hint.identifierLength)), - showOnLeft ? hint.label : ": " + hint.label, + [labelPart], vscode.InlayHintKind.Type); inlayHint.paddingRight = showOnLeft || hint.rightPadding; inlayHint.paddingLeft = showOnLeft && hint.leftPadding; @@ -244,14 +248,31 @@ export class InlayHintsProvider implements vscode.InlayHintsProvider { if (paramHintLabel === "" && refOperatorString === "") { continue; } - + const labelPart: vscode.InlayHintLabelPart = this.createInlayHintLabelPart(hint, refOperatorString + paramHintLabel + ":"); const inlayHint: vscode.InlayHint = new vscode.InlayHint( new vscode.Position(hint.line, hint.character), - refOperatorString + paramHintLabel + ":", + [labelPart], vscode.InlayHintKind.Parameter); inlayHint.paddingRight = true; resolvedHints.push(inlayHint); } return resolvedHints; } + + private createInlayHintLabelPart(hint: CppInlayHint, hintLabel: string): vscode.InlayHintLabelPart { + const labelPart: vscode.InlayHintLabelPart = new vscode.InlayHintLabelPart(hintLabel); + if (hint.definitionUri !== undefined) { + const definitionPos = new vscode.Position( + hint.definitionLine as number, + hint.character as number); + const option: vscode.TextDocumentShowOptions = { selection: new vscode.Range(definitionPos, definitionPos) }; + const commandOpen: vscode.Command = { + title: "Open Inlay Hint Definition File", + command: "vscode.openWith", + arguments: [hint.definitionUri, null, option] + }; + labelPart.command = commandOpen; + } + return labelPart; + } }