Skip to content

Commit a8e6695

Browse files
authored
Add setting to show inlay hints on the left. (#9506)
1 parent c7edc99 commit a8e6695

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

Extension/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,12 @@
22172217
"markdownDescription": "%c_cpp.configuration.inlayHints.autoDeclarationTypes.enabled.markdownDescription%",
22182218
"scope": "application"
22192219
},
2220+
"C_Cpp.inlayHints.autoDeclarationTypes.showOnLeft": {
2221+
"type": "boolean",
2222+
"default": false,
2223+
"markdownDescription": "%c_cpp.configuration.inlayHints.autoDeclarationTypes.showOnLeft.markdownDescription%",
2224+
"scope": "application"
2225+
},
22202226
"C_Cpp.inlayHints.parameterNames.enabled": {
22212227
"type": "boolean",
22222228
"default": false,

Extension/package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@
166166
"c_cpp.configuration.inactiveRegionOpacity.markdownDescription": { "message": "Controls the opacity of inactive preprocessor blocks. Scales between `0.1` and `1.0`. This setting only applies when inactive region dimming is enabled.", "comment": [ "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered." ] },
167167
"c_cpp.configuration.inactiveRegionForegroundColor.description": "Controls the font coloring of inactive preprocessor blocks. Input is in the form a hexadecimal color code or a valid Theme Color. If not set, this defaults to the syntax coloring scheme of the editor. This setting only applies when inactive region dimming is enabled.",
168168
"c_cpp.configuration.inactiveRegionBackgroundColor.description": "Controls the background coloring of inactive preprocessor blocks. Input is in the form a hexadecimal color code or a valid Theme Color. If not set, this defaults to transparent. This setting only applies when inactive region dimming is enabled.",
169-
"c_cpp.configuration.inlayHints.autoDeclarationTypes.enabled.markdownDescription": { "message": "Display inlay hints for deduced type when `auto` is used in a declaration:\n```cpp \n\n auto /* int */ index = 0;\n```", "comment": [ "Markdown text between `` and the text inside ``` block is code and should not be localized." ] },
169+
"c_cpp.configuration.inlayHints.autoDeclarationTypes.enabled.markdownDescription": { "message": "Display inlay hints for deduced type when `auto` is used in a declaration:\n```cpp \n\n auto index /* : int */ = 0;\n```", "comment": [ "Markdown text between `` and the text inside ``` block is code and should not be localized." ] },
170+
"c_cpp.configuration.inlayHints.autoDeclarationTypes.showOnLeft.markdownDescription": { "message": "Display inlay hints for deduced type when `auto` is used in a declaration on the left of the identifier:\n```cpp \n\n auto /* int */ index = 0;\n```", "comment": [ "Markdown text between `` and the text inside ``` block is code and should not be localized." ] },
170171
"c_cpp.configuration.inlayHints.parameterNames.enabled.markdownDescription": { "message": "Display inlay hints for parameter names:\n```cpp \n\n int a = getArea(/* width: */ x, /* height: */ y);\n```", "comment": [ "Markdown text between `` and the text inside ``` block is code and should not be localized." ] },
171172
"c_cpp.configuration.inlayHints.parameterNames.suppressWhenArgumentContainsName.markdownDescription": { "message": "Suppress parameter name hints when the argument text or inline comment contains the parameter name:\n```cpp \n\n int a = getArea(width, /* height: */ y);\n```", "comment": [ "Markdown text between `` and the text inside ``` block is code and should not be localized." ] },
172173
"c_cpp.configuration.inlayHints.referenceOperator.enabled.markdownDescription": { "message": "Display the inlay hint reference operator `&` for parameters passed by non-const reference:\n```cpp \n\n swap(/* &first: */ str1, /* &last: */ str2);\n```", "comment": [ "Markdown text between `` and the text inside ``` block is code and should not be localized." ] },

Extension/src/LanguageServer/Providers/inlayHintProvider.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ interface CppInlayHint {
2323
isValueRef: boolean;
2424
hasParamName: boolean;
2525
leftPadding: boolean;
26+
rightPadding: boolean;
27+
identifierLength: number;
2628
}
2729

2830
interface GetInlayHintsResult {
@@ -124,14 +126,17 @@ export class InlayHintsProvider implements vscode.InlayHintsProvider {
124126

125127
private createCacheEntry(inlayHintsResults: GetInlayHintsResult): InlayHintsCacheEntry {
126128
const typeHints: vscode.InlayHint[] = [];
129+
const settings: CppSettings = new CppSettings();
127130
for (const h of inlayHintsResults.inlayHints) {
128131
if (h.inlayHintKind === InlayHintKind.Type) {
132+
const showOnLeft: boolean = settings.inlayHintsAutoDeclarationTypesShowOnLeft && h.identifierLength > 0;
129133
const inlayHint: vscode.InlayHint = new vscode.InlayHint(
130-
new vscode.Position(h.position.line, h.position.character),
131-
h.label,
134+
new vscode.Position(h.position.line, h.position.character +
135+
(showOnLeft ? 0 : h.identifierLength)),
136+
(showOnLeft ? h.label : ": " + h.label),
132137
vscode.InlayHintKind.Type);
133-
inlayHint.paddingRight = true;
134-
inlayHint.paddingLeft = h.leftPadding;
138+
inlayHint.paddingRight = showOnLeft || h.rightPadding;
139+
inlayHint.paddingLeft = showOnLeft && h.leftPadding;
135140
typeHints.push(inlayHint);
136141
}
137142
}

Extension/src/LanguageServer/settings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ export class CppSettings extends Settings {
256256
return super.Section.get<boolean>("inlayHints.autoDeclarationTypes.enabled") === true;
257257
}
258258

259+
public get inlayHintsAutoDeclarationTypesShowOnLeft(): boolean {
260+
return super.Section.get<boolean>("inlayHints.autoDeclarationTypes.showOnLeft") === true;
261+
}
262+
259263
public get inlayHintsParameterNames(): boolean {
260264
return super.Section.get<boolean>("inlayHints.parameterNames.enabled") === true;
261265
}

0 commit comments

Comments
 (0)