Skip to content

Commit 6f3ae65

Browse files
authored
Add setting to hide leading underscores for inlay hints. (#9500)
* Add setting to hide leading underscores for inlay hints.
1 parent a8e6695 commit 6f3ae65

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

Extension/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,6 +2235,12 @@
22352235
"markdownDescription": "%c_cpp.configuration.inlayHints.parameterNames.suppressWhenArgumentContainsName.markdownDescription%",
22362236
"scope": "application"
22372237
},
2238+
"C_Cpp.inlayHints.parameterNames.hideLeadingUnderscores": {
2239+
"type": "boolean",
2240+
"default": true,
2241+
"markdownDescription": "%c_cpp.configuration.inlayHints.parameterNames.hideLeadingUnderscores.markdownDescription%",
2242+
"scope": "application"
2243+
},
22382244
"C_Cpp.inlayHints.referenceOperator.enabled": {
22392245
"type": "boolean",
22402246
"default": false,

Extension/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
"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." ] },
170170
"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." ] },
171171
"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." ] },
172+
"c_cpp.configuration.inlayHints.parameterNames.hideLeadingUnderscores.markdownDescription": { "message": "Hide leading `_` in parameter name hints.", "comment": [ "Markdown text between `` is code and should not be localized." ] },
172173
"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." ] },
173174
"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." ] },
174175
"c_cpp.configuration.inlayHints.referenceOperator.showSpace.markdownDescription": { "message": "Controls whether a space is shown after `&` 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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ export class InlayHintsProvider implements vscode.InlayHintsProvider {
104104
let paramHintLabel: string = "";
105105
if (settings.inlayHintsParameterNames) {
106106
paramHintLabel = (settings.inlayHintsParameterNamesSuppressName && hint.hasParamName) ? "" : hint.label;
107+
if (paramHintLabel !== "" && settings.inlayHintsParameterNamesHideLeadingUnderscores) {
108+
let nonUnderscoreIndex: number = 0;
109+
for (let i: number = 0; i < paramHintLabel.length; ++i) {
110+
if (paramHintLabel[i] !== '_') {
111+
nonUnderscoreIndex = i;
112+
break;
113+
}
114+
}
115+
if (nonUnderscoreIndex > 0) {
116+
paramHintLabel = paramHintLabel.substring(nonUnderscoreIndex);
117+
}
118+
}
107119
}
108120
let refOperatorString: string = "";
109121
if (settings.inlayHintsReferenceOperator && hint.isValueRef) {

Extension/src/LanguageServer/settings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ export class CppSettings extends Settings {
268268
return super.Section.get<boolean>("inlayHints.parameterNames.suppressWhenArgumentContainsName") === true;
269269
}
270270

271+
public get inlayHintsParameterNamesHideLeadingUnderscores(): boolean {
272+
return super.Section.get<boolean>("inlayHints.parameterNames.hideLeadingUnderscores") === true;
273+
}
274+
271275
public get inlayHintsReferenceOperator(): boolean {
272276
return super.Section.get<boolean>("inlayHints.referenceOperator.enabled") === true;
273277
}

0 commit comments

Comments
 (0)