Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Extension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 24 additions & 3 deletions Extension/src/LanguageServer/Providers/inlayHintProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export interface CppInlayHint {
leftPadding: boolean;
rightPadding: boolean;
identifierLength: number;
definitionUri?: vscode.Uri;
definitionLine?: number;
definitionCharacter?: number;
}

enum InlayHintKind {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Loading