Add setting to hide leading underscores for inlay hints. (#9500)

* Add setting to hide leading underscores for inlay hints.
This commit is contained in:
Sean McManus 2022-06-28 16:25:03 -07:00 коммит произвёл GitHub
Родитель a8e6695b55
Коммит 6f3ae65833
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -2235,6 +2235,12 @@
"markdownDescription": "%c_cpp.configuration.inlayHints.parameterNames.suppressWhenArgumentContainsName.markdownDescription%",
"scope": "application"
},
"C_Cpp.inlayHints.parameterNames.hideLeadingUnderscores": {
"type": "boolean",
"default": true,
"markdownDescription": "%c_cpp.configuration.inlayHints.parameterNames.hideLeadingUnderscores.markdownDescription%",
"scope": "application"
},
"C_Cpp.inlayHints.referenceOperator.enabled": {
"type": "boolean",
"default": false,

Просмотреть файл

@ -169,6 +169,7 @@
"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." ] },
"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." ] },
"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." ] },
"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." ] },
"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." ] },
"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." ] },
"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." ] },

Просмотреть файл

@ -104,6 +104,18 @@ export class InlayHintsProvider implements vscode.InlayHintsProvider {
let paramHintLabel: string = "";
if (settings.inlayHintsParameterNames) {
paramHintLabel = (settings.inlayHintsParameterNamesSuppressName && hint.hasParamName) ? "" : hint.label;
if (paramHintLabel !== "" && settings.inlayHintsParameterNamesHideLeadingUnderscores) {
let nonUnderscoreIndex: number = 0;
for (let i: number = 0; i < paramHintLabel.length; ++i) {
if (paramHintLabel[i] !== '_') {
nonUnderscoreIndex = i;
break;
}
}
if (nonUnderscoreIndex > 0) {
paramHintLabel = paramHintLabel.substring(nonUnderscoreIndex);
}
}
}
let refOperatorString: string = "";
if (settings.inlayHintsReferenceOperator && hint.isValueRef) {

Просмотреть файл

@ -268,6 +268,10 @@ export class CppSettings extends Settings {
return super.Section.get<boolean>("inlayHints.parameterNames.suppressWhenArgumentContainsName") === true;
}
public get inlayHintsParameterNamesHideLeadingUnderscores(): boolean {
return super.Section.get<boolean>("inlayHints.parameterNames.hideLeadingUnderscores") === true;
}
public get inlayHintsReferenceOperator(): boolean {
return super.Section.get<boolean>("inlayHints.referenceOperator.enabled") === true;
}