Skip to content

Commit 2cc55ea

Browse files
authored
Add keyboard support for Inline Macro. (#11261)
* Add keyboard support for Inline Macro. * Enable inline macro without hover. * Standardize localize string naming. * Fix spelling errors involving strings types.
1 parent 121a657 commit 2cc55ea

File tree

16 files changed

+793
-155
lines changed

16 files changed

+793
-155
lines changed

Extension/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,6 +3222,15 @@
32223222
"command": "C_Cpp.SwitchHeaderSource",
32233223
"key": "Alt+O",
32243224
"when": "editorLangId =~ /^(c|(cuda-)?cpp)$/ && editorTextFocus && !(config.C_Cpp.intelliSenseEngine =~ /^[dD]isabled$/)"
3225+
},
3226+
{
3227+
"command": "editor.action.codeAction",
3228+
"key": "ctrl+shift+r ctrl+i",
3229+
"args": {
3230+
"kind": "refactor.inline.macro",
3231+
"apply": "first"
3232+
},
3233+
"when": "editorLangId =~ /^(c|(cuda-)?cpp)$/ && editorTextFocus && !(config.C_Cpp.intelliSenseEngine =~ /^[dD]isabled$/)"
32253234
}
32263235
],
32273236
"debuggers": [
@@ -6115,6 +6124,20 @@
61156124
]
61166125
}
61176126
}
6127+
],
6128+
"codeActions": [
6129+
{
6130+
"languages": [
6131+
"c",
6132+
"cpp",
6133+
"cude-cpp"
6134+
],
6135+
"actions": {
6136+
"kind": "refactor.inline.macro",
6137+
"title": "%c_cpp.codeActions.refactor.inline.macro.title%",
6138+
"description": "%c_cpp.codeActions.refactor.inline.macro.description%"
6139+
}
6140+
}
61186141
]
61196142
},
61206143
"scripts": {

Extension/package.nls.json

Lines changed: 689 additions & 122 deletions
Large diffs are not rendered by default.

Extension/src/Debugger/ParsedEnvironmentFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class ParsedEnvironmentFile {
7272
// show error message if single lines cannot get parsed
7373
let warning: string | undefined;
7474
if (parseErrors.length !== 0) {
75-
warning = localize("ignoring.lines.in.envfile", "Ignoring non-parseable lines in {0} {1}: ", "envFile", envFile);
75+
warning = localize("ignoring.lines.in.envfile", "Ignoring non-parsable lines in {0} {1}: ", "envFile", envFile);
7676
parseErrors.forEach(function (value, idx, array): void {
7777
warning += "\"" + value + "\"" + ((idx !== array.length - 1) ? ", " : ".");
7878
});

Extension/src/Debugger/debugAdapterDescriptorFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class CppvsdbgDebugAdapterDescriptorFactory extends AbstractDebugAdapterD
4040

4141
async createDebugAdapterDescriptor(_session: vscode.DebugSession, _executable?: vscode.DebugAdapterExecutable): Promise<vscode.DebugAdapterDescriptor | null> {
4242
if (os.platform() !== 'win32') {
43-
void vscode.window.showErrorMessage(localize("debugger.not.available", "Debugger type '{0}' is not avaliable for non-Windows machines.", "cppvsdbg"));
43+
void vscode.window.showErrorMessage(localize("debugger.not.available", "Debugger type '{0}' is not available for non-Windows machines.", "cppvsdbg"));
4444
return null;
4545
} else {
4646
return new vscode.DebugAdapterExecutable(

Extension/src/Debugger/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ async function addSshTargetImpl(): Promise<string> {
215215
async function removeSshTargetImpl(node: TargetLeafNode): Promise<boolean> {
216216
const labelYes: string = localize('yes', 'Yes');
217217
const labelNo: string = localize('no', 'No');
218-
const confirm: string | undefined = await vscode.window.showInformationMessage(localize('ssh.target.delete.confirmation', 'Are you sure you want to permanamtly delete "{0}"?', node.name), labelYes, labelNo);
218+
const confirm: string | undefined = await vscode.window.showInformationMessage(localize('ssh.target.delete.confirmation', 'Are you sure you want to permanently delete "{0}"?', node.name), labelYes, labelNo);
219219
if (!confirm || confirm === labelNo) {
220220
return false;
221221
}

Extension/src/LanguageServer/Providers/codeActionProvider.ts

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* ------------------------------------------------------------------------------------------ */
55
import * as vscode from 'vscode';
66
import { Position, Range, RequestType, TextEdit } from 'vscode-languageclient';
7+
import * as nls from 'vscode-nls';
78
import { DefaultClient } from '../client';
89
import {
910
CodeActionCodeInfo, CodeActionDiagnosticInfo, codeAnalysisAllFixes, codeAnalysisCodeToFixes, codeAnalysisFileToCodeActions
@@ -12,6 +13,9 @@ import { LocalizeStringParams, getLocalizedString } from '../localization';
1213
import { CppSettings } from '../settings';
1314
import { makeVscodeRange } from '../utils';
1415

16+
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
17+
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
18+
1519
interface GetCodeActionsRequestParams {
1620
uri: string;
1721
range: Range;
@@ -44,6 +48,8 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
4448
this.client = client;
4549
}
4650

51+
private static inlineMacroKind: vscode.CodeActionKind = vscode.CodeActionKind.RefactorInline.append("macro");
52+
4753
public async provideCodeActions(document: vscode.TextDocument, range: vscode.Range | vscode.Selection,
4854
context: vscode.CodeActionContext, token: vscode.CancellationToken): Promise<(vscode.Command | vscode.CodeAction)[]> {
4955
await this.client.ready;
@@ -66,7 +72,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
6672
uri: document.uri.toString()
6773
};
6874

69-
const response: GetCodeActionsResult = await this.client.languageClient.sendRequest(
75+
let response: GetCodeActionsResult = await this.client.languageClient.sendRequest(
7076
GetCodeActionsRequest, params, token);
7177

7278
const resultCodeActions: vscode.CodeAction[] = [];
@@ -86,15 +92,17 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
8692
!!this.client.configuration.CurrentConfiguration?.configurationProviderInCppPropertiesJson;
8793

8894
// Convert to vscode.CodeAction array
89-
response.commands.forEach((command) => {
95+
let hasInlineMacro: boolean = false;
96+
const processCommand = (command: CodeActionCommand) => {
9097
let title: string = getLocalizedString(command.localizeStringParams);
9198
let wsEdit: vscode.WorkspaceEdit | undefined;
9299
let codeActionKind: vscode.CodeActionKind = vscode.CodeActionKind.QuickFix;
93100
if (command.edit) {
94101
// Inline macro feature.
95-
codeActionKind = vscode.CodeActionKind.RefactorInline;
102+
codeActionKind = CodeActionProvider.inlineMacroKind;
96103
wsEdit = new vscode.WorkspaceEdit();
97104
wsEdit.replace(document.uri, makeVscodeRange(command.edit.range), command.edit.newText);
105+
hasInlineMacro = true;
98106
} else if (command.command === "C_Cpp.RemoveAllCodeAnalysisProblems" && command.uri !== undefined) {
99107
// The "RemoveAll" message is sent for all code analysis squiggles.
100108
const vsCodeRange: vscode.Range = makeVscodeRange(r);
@@ -218,7 +226,47 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
218226
kind: codeActionKind
219227
};
220228
resultCodeActions.push(vscodeCodeAction);
221-
});
229+
};
230+
231+
response.commands.forEach(processCommand);
232+
233+
// If the refactor.inline.macro code action is specifically invoked by the user,
234+
// then force a hover to ensure that the "Expands to" info is available.
235+
if (!hasInlineMacro && context.only?.value === "refactor.inline.macro") {
236+
const processInlineMacro = async (): Promise<boolean> => {
237+
const editor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
238+
if (!editor) {
239+
return false;
240+
}
241+
const result: vscode.Hover[] = <vscode.Hover[]>(await vscode.commands.executeCommand('vscode.executeHoverProvider', document.uri, range.start));
242+
if (result.length === 0) {
243+
return false;
244+
}
245+
const hoverResult: vscode.MarkdownString = <vscode.MarkdownString>result[0].contents[0];
246+
if (!hoverResult.value.includes(localize("expands.to", "Expands to:"))) {
247+
return false;
248+
}
249+
response = await this.client.languageClient.sendRequest(GetCodeActionsRequest, params, token);
250+
if (token.isCancellationRequested || response.commands === undefined) {
251+
return false;
252+
}
253+
for (const command of response.commands) {
254+
if (command.edit) {
255+
processCommand(command);
256+
return true;
257+
}
258+
}
259+
return false;
260+
};
261+
if (!await processInlineMacro()) {
262+
const disabledCodeAction: vscode.CodeAction = {
263+
title: localize({ key: "inline.macro", comment: ["'Inline' is a command and not an adjective, i.e. like 'Expand macro'."] }, "Inline macro"),
264+
kind: CodeActionProvider.inlineMacroKind,
265+
disabled: { reason: localize("inline.macro.not.available", "Inline macro is not available at this location.") }
266+
};
267+
resultCodeActions.push(disabledCodeAction);
268+
}
269+
}
222270
return resultCodeActions;
223271
}
224272
}

Extension/src/LanguageServer/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,7 @@ export class DefaultClient implements Client {
21212121
const settings: CppSettings = new CppSettings(this.RootUri);
21222122
if (settings.configurationWarnings && !this.isExternalHeader(docUri) && !vscode.debug.activeDebugSession) {
21232123
const dismiss: string = localize("dismiss.button", "Dismiss");
2124-
const disable: string = localize("diable.warnings.button", "Disable Warnings");
2124+
const disable: string = localize("disable.warnings.button", "Disable Warnings");
21252125
const configName: string | undefined = this.configuration.CurrentConfiguration?.name;
21262126
if (!configName) {
21272127
return;

Extension/src/LanguageServer/codeAnalysis.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export const codeAnalysisCodeToFixes: Map<string, CodeActionCodeInfo> = new Map<
118118
export const codeAnalysisAllFixes: CodeActionAllInfo = {
119119
version: 0,
120120
fixAllCodeAction: {
121-
title: localize("fix_all_code_analysis_problems", "Fix all code analysis problems"),
121+
title: localize("fix.all.code.analysis.problems", "Fix all code analysis problems"),
122122
command: {
123123
title: 'FixAllCodeAnalysisProblems',
124124
command: 'C_Cpp.FixAllCodeAnalysisProblems',
@@ -127,7 +127,7 @@ export const codeAnalysisAllFixes: CodeActionAllInfo = {
127127
kind: vscode.CodeActionKind.QuickFix
128128
},
129129
removeAllCodeAction: {
130-
title: localize("clear_all_code_analysis_problems", "Clear all code analysis problems"),
130+
title: localize("clear.all.code.analysis.problems", "Clear all code analysis problems"),
131131
command: { title: "RemoveAllCodeAnalysisProblems", command: "C_Cpp.RemoveAllCodeAnalysisProblems" },
132132
kind: vscode.CodeActionKind.QuickFix
133133
}
@@ -175,7 +175,7 @@ function rebuildCodeAnalysisCodeAndAllFixes(): void {
175175
}
176176
++numFixTypes;
177177
codeToFixes[1].fixAllTypeCodeAction = {
178-
title: localize("fix_all_type_problems", "Fix all {0} problems", codeToFixes[0]),
178+
title: localize("fix.all.type.problems", "Fix all {0} problems", codeToFixes[0]),
179179
command: {
180180
title: 'FixAllTypeCodeAnalysisProblems',
181181
command: 'C_Cpp.FixAllTypeCodeAnalysisProblems',
@@ -187,7 +187,7 @@ function rebuildCodeAnalysisCodeAndAllFixes(): void {
187187

188188
if (new CppSettings().clangTidyCodeActionShowDisable) {
189189
codeToFixes[1].disableAllTypeCodeAction = {
190-
title: localize("disable_all_type_problems", "Disable all {0} problems", codeToFixes[0]),
190+
title: localize("disable.all.type.problems", "Disable all {0} problems", codeToFixes[0]),
191191
command: {
192192
title: 'DisableAllTypeCodeAnalysisProblems',
193193
command: 'C_Cpp.DisableAllTypeCodeAnalysisProblems',
@@ -201,7 +201,7 @@ function rebuildCodeAnalysisCodeAndAllFixes(): void {
201201

202202
if (new CppSettings().clangTidyCodeActionShowClear !== "None") {
203203
codeToFixes[1].removeAllTypeCodeAction = {
204-
title: localize("clear_all_type_problems", "Clear all {0} problems", codeToFixes[0]),
204+
title: localize("clear.all.type.problems", "Clear all {0} problems", codeToFixes[0]),
205205
command: {
206206
title: 'RemoveAllTypeCodeAnalysisProblems',
207207
command: 'C_Cpp.RemoveCodeAnalysisProblems',
@@ -265,7 +265,7 @@ export function publishCodeAnalysisDiagnostics(params: PublishCodeAnalysisDiagno
265265
range: makeVscodeRange(identifier.range),
266266
code: identifier.code,
267267
removeCodeAction: {
268-
title: localize("clear_this_problem", "Clear this {0} problem", d.code),
268+
title: localize("clear.this.problem", "Clear this {0} problem", d.code),
269269
command: {
270270
title: 'RemoveCodeAnalysisProblems',
271271
command: 'C_Cpp.RemoveCodeAnalysisProblems',
@@ -281,7 +281,7 @@ export function publishCodeAnalysisDiagnostics(params: PublishCodeAnalysisDiagno
281281
workspaceEdit.workspaceEdit.set(vscode.Uri.parse(uriStr, true), makeVscodeTextEdits(edits));
282282
}
283283
const fixThisCodeAction: vscode.CodeAction = {
284-
title: localize("fix_this_problem", "Fix this {0} problem", d.code),
284+
title: localize("fix.this.problem", "Fix this {0} problem", d.code),
285285
command: {
286286
title: 'FixThisCodeAnalysisProblem',
287287
command: 'C_Cpp.FixThisCodeAnalysisProblem',
@@ -315,7 +315,7 @@ export function publishCodeAnalysisDiagnostics(params: PublishCodeAnalysisDiagno
315315
const relatedIdentifiersAndUri: CodeAnalysisDiagnosticIdentifiersAndUri = {
316316
uri: info.location.uri, identifiers: [ relatedIdentifier ] };
317317
const relatedCodeAction: vscode.CodeAction = {
318-
title: localize("fix_this_problem", "Fix this {0} problem", d.code),
318+
title: localize("fix.this.problem", "Fix this {0} problem", d.code),
319319
command: {
320320
title: 'FixThisCodeAnalysisProblem',
321321
command: 'C_Cpp.FixThisCodeAnalysisProblem',
@@ -384,7 +384,7 @@ export function publishCodeAnalysisDiagnostics(params: PublishCodeAnalysisDiagno
384384
if (new CppSettings().clangTidyCodeActionShowDocumentation) {
385385
if (codeActionCodeInfo.docCodeAction === undefined) {
386386
codeActionCodeInfo.docCodeAction = {
387-
title: localize("show_documentation_for", "Show documentation for {0}", primaryCode),
387+
title: localize("show.documentation.for", "Show documentation for {0}", primaryCode),
388388
command: {
389389
title: 'ShowDocumentation',
390390
command: 'C_Cpp.ShowCodeAnalysisDocumentation',

Extension/src/LanguageServer/cppBuildTaskProvider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class CppBuildTaskProvider implements TaskProvider {
179179
if (!definition) {
180180
const isWindows: boolean = os.platform() === 'win32';
181181
const taskLabel: string = ((appendSourceToName && !compilerPathBase.startsWith(ext.configPrefix)) ?
182-
ext.configPrefix : "") + compilerPathBase + " " + localize("build_active_file", "build active file");
182+
ext.configPrefix : "") + compilerPathBase + " " + localize("build.active.file", "build active file");
183183
const programName: string = util.defaultExePath();
184184
let args: string[] = isCl ?
185185
['/Zi', '/EHsc', '/nologo', `/Fe${programName}`, '${file}'] :
@@ -213,7 +213,7 @@ export class CppBuildTaskProvider implements TaskProvider {
213213
), isCl ? '$msCompile' : '$gcc');
214214

215215
task.group = TaskGroup.Build;
216-
task.detail = detail ? detail : localize("compiler_details", "compiler:") + " " + resolvedcompilerPath;
216+
task.detail = detail ? detail : localize("compiler.details", "compiler:") + " " + resolvedcompilerPath;
217217

218218
return task;
219219
};
@@ -294,7 +294,7 @@ export class CppBuildTaskProvider implements TaskProvider {
294294
...selectedTask.definition,
295295
problemMatcher: selectedTask.problemMatchers,
296296
group: setAsDefault ? { kind: "build", "isDefault": true } : "build",
297-
detail: localize("task_generated_by_debugger", "Task generated by Debugger.")
297+
detail: localize("task.generated.by.debugger", "Task generated by Debugger.")
298298
};
299299
rawTasksJson.tasks.push(newTask);
300300
}
@@ -372,7 +372,7 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
372372
}
373373
telemetry.logLanguageServerEvent("cppBuildTaskStarted");
374374
// At this point we can start using the terminal.
375-
this.writeEmitter.fire(localize("starting_build", "Starting build...") + this.endOfLine);
375+
this.writeEmitter.fire(localize("starting.build", "Starting build...") + this.endOfLine);
376376
await this.doBuild();
377377
}
378378

Extension/src/SSH/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ export function ssh(host: ISshHostInfo, command: string, sshPath?: string, jumpH
8282
function localForwardToArgs(localForward: ISshLocalForwardInfo): string[] {
8383
// Do not combine error checking and arg conversion for clarity.
8484
if (localForward.localSocket && (localForward.bindAddress || localForward.port)) {
85-
throw Error(localize('local.forward.local.conflict', '"localSocket" cannot be specifed at the same time with "bindAddress" or "port" in localForwards'));
85+
throw Error(localize('local.forward.local.conflict', '"localSocket" cannot be specified at the same time with "bindAddress" or "port" in localForwards'));
8686
}
8787
if (!localForward.localSocket && !localForward.port) {
8888
throw Error(localize('local.forward.local.missing', '"port" or "localSocket" required in localForwards'));
8989
}
9090
if (localForward.remoteSocket && (localForward.host || localForward.hostPort)) {
91-
throw Error(localize('local.forward.remote.conflict', '"remoteSocket" cannot be specifed at the same time with "host" or "hostPort" in localForwards'));
91+
throw Error(localize('local.forward.remote.conflict', '"remoteSocket" cannot be specified at the same time with "host" or "hostPort" in localForwards'));
9292
}
9393
if (!localForward.remoteSocket && (!localForward.host || !localForward.hostPort)) {
9494
throw Error(localize('local.forward.remote.missing', '"host" and "hostPort", or "remoteSocket" required in localForwards'));

0 commit comments

Comments
 (0)