Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyboard support for Inline Macro. #11261

Merged
merged 26 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9bfbb67
Add keyboard support for Inline Macro.
sean-mcmanus Jul 28, 2023
31746e1
Change keyboard key.
sean-mcmanus Jul 28, 2023
7655985
Merge branch 'main' into seanmcm/inlineMacroKeyboardSupport
sean-mcmanus Jul 28, 2023
f4052c2
Change regex.
sean-mcmanus Jul 28, 2023
c15f064
Merge branch 'seanmcm/inlineMacroKeyboardSupport' of https://github.c…
sean-mcmanus Jul 28, 2023
4636878
Merge branch 'main' into seanmcm/inlineMacroKeyboardSupport
sean-mcmanus Jul 28, 2023
33600b0
Fix incorrect merge.
sean-mcmanus Jul 28, 2023
d6e9ecf
Enable inline macro without hover.
sean-mcmanus Aug 1, 2023
8f73406
Merge branch 'main' into seanmcm/inlineMacroKeyboardSupport
sean-mcmanus Aug 1, 2023
ab5e876
Forgot a change.
sean-mcmanus Aug 1, 2023
7b7880d
Merge branch 'seanmcm/inlineMacroKeyboardSupport' of https://github.c…
sean-mcmanus Aug 1, 2023
a72e38b
Merge branch 'main' into seanmcm/inlineMacroKeyboardSupport
sean-mcmanus Aug 3, 2023
7a9d150
Standardize localize string naming.
sean-mcmanus Aug 3, 2023
32ae163
Revert "Standardize localize string naming."
sean-mcmanus Aug 5, 2023
40bf0d4
Revert loc changes.
sean-mcmanus Aug 5, 2023
7ee77f8
Merge branch 'main' into seanmcm/inlineMacroKeyboardSupport
sean-mcmanus Aug 15, 2023
f36579a
Add back loc changes with dots.
sean-mcmanus Aug 16, 2023
f05f0ac
Fix spelling errors involving strings types.
sean-mcmanus Aug 16, 2023
0a70afe
Missed a fix.
sean-mcmanus Aug 16, 2023
da6d724
Fix .js.
sean-mcmanus Aug 16, 2023
a104ed3
Merge branch 'main' into seanmcm/inlineMacroKeyboardSupport
sean-mcmanus Aug 18, 2023
d9e8501
Merge branch 'main' into seanmcm/inlineMacroKeyboardSupport
sean-mcmanus Aug 21, 2023
2cb9ef3
Merge main.
sean-mcmanus Aug 30, 2023
eb51909
Merge branch 'seanmcm/inlineMacroKeyboardSupport' of https://github.c…
sean-mcmanus Aug 30, 2023
7cb09ac
Merge branch 'main' into seanmcm/inlineMacroKeyboardSupport
sean-mcmanus Sep 5, 2023
e4ffc12
Merge branch 'main' into seanmcm/inlineMacroKeyboardSupport
bobbrow Sep 8, 2023
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
23 changes: 23 additions & 0 deletions Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3222,6 +3222,15 @@
"command": "C_Cpp.SwitchHeaderSource",
"key": "Alt+O",
"when": "editorLangId =~ /^(c|(cuda-)?cpp)$/ && editorTextFocus && !(config.C_Cpp.intelliSenseEngine =~ /^[dD]isabled$/)"
},
{
"command": "editor.action.codeAction",
"key": "ctrl+shift+r ctrl+i",
"args": {
"kind": "refactor.inline.macro",
"apply": "first"
},
"when": "editorLangId =~ /^(c|(cuda-)?cpp)$/ && editorTextFocus && !(config.C_Cpp.intelliSenseEngine =~ /^[dD]isabled$/)"
}
],
"debuggers": [
Expand Down Expand Up @@ -6115,6 +6124,20 @@
]
}
}
],
"codeActions": [
{
"languages": [
"c",
"cpp",
"cude-cpp"
],
"actions": {
"kind": "refactor.inline.macro",
"title": "%c_cpp.codeActions.refactor.inline.macro.title%",
"description": "%c_cpp.codeActions.refactor.inline.macro.description%"
}
}
]
},
"scripts": {
Expand Down
811 changes: 689 additions & 122 deletions Extension/package.nls.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Extension/src/Debugger/ParsedEnvironmentFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class ParsedEnvironmentFile {
// show error message if single lines cannot get parsed
let warning: string | undefined;
if (parseErrors.length !== 0) {
warning = localize("ignoring.lines.in.envfile", "Ignoring non-parseable lines in {0} {1}: ", "envFile", envFile);
warning = localize("ignoring.lines.in.envfile", "Ignoring non-parsable lines in {0} {1}: ", "envFile", envFile);
parseErrors.forEach(function (value, idx, array): void {
warning += "\"" + value + "\"" + ((idx !== array.length - 1) ? ", " : ".");
});
Expand Down
2 changes: 1 addition & 1 deletion Extension/src/Debugger/debugAdapterDescriptorFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class CppvsdbgDebugAdapterDescriptorFactory extends AbstractDebugAdapterD

async createDebugAdapterDescriptor(_session: vscode.DebugSession, _executable?: vscode.DebugAdapterExecutable): Promise<vscode.DebugAdapterDescriptor | null> {
if (os.platform() !== 'win32') {
void vscode.window.showErrorMessage(localize("debugger.not.available", "Debugger type '{0}' is not avaliable for non-Windows machines.", "cppvsdbg"));
void vscode.window.showErrorMessage(localize("debugger.not.available", "Debugger type '{0}' is not available for non-Windows machines.", "cppvsdbg"));
return null;
} else {
return new vscode.DebugAdapterExecutable(
Expand Down
2 changes: 1 addition & 1 deletion Extension/src/Debugger/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async function addSshTargetImpl(): Promise<string> {
async function removeSshTargetImpl(node: TargetLeafNode): Promise<boolean> {
const labelYes: string = localize('yes', 'Yes');
const labelNo: string = localize('no', 'No');
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);
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);
if (!confirm || confirm === labelNo) {
return false;
}
Expand Down
56 changes: 52 additions & 4 deletions Extension/src/LanguageServer/Providers/codeActionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* ------------------------------------------------------------------------------------------ */
import * as vscode from 'vscode';
import { Position, Range, RequestType, TextEdit } from 'vscode-languageclient';
import * as nls from 'vscode-nls';
import { DefaultClient } from '../client';
import {
CodeActionCodeInfo, CodeActionDiagnosticInfo, codeAnalysisAllFixes, codeAnalysisCodeToFixes, codeAnalysisFileToCodeActions
Expand All @@ -12,6 +13,9 @@ import { LocalizeStringParams, getLocalizedString } from '../localization';
import { CppSettings } from '../settings';
import { makeVscodeRange } from '../utils';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();

interface GetCodeActionsRequestParams {
uri: string;
range: Range;
Expand Down Expand Up @@ -44,6 +48,8 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
this.client = client;
}

private static inlineMacroKind: vscode.CodeActionKind = vscode.CodeActionKind.RefactorInline.append("macro");

public async provideCodeActions(document: vscode.TextDocument, range: vscode.Range | vscode.Selection,
context: vscode.CodeActionContext, token: vscode.CancellationToken): Promise<(vscode.Command | vscode.CodeAction)[]> {
await this.client.ready;
Expand All @@ -66,7 +72,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
uri: document.uri.toString()
};

const response: GetCodeActionsResult = await this.client.languageClient.sendRequest(
let response: GetCodeActionsResult = await this.client.languageClient.sendRequest(
GetCodeActionsRequest, params, token);

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

// Convert to vscode.CodeAction array
response.commands.forEach((command) => {
let hasInlineMacro: boolean = false;
const processCommand = (command: CodeActionCommand) => {
let title: string = getLocalizedString(command.localizeStringParams);
let wsEdit: vscode.WorkspaceEdit | undefined;
let codeActionKind: vscode.CodeActionKind = vscode.CodeActionKind.QuickFix;
if (command.edit) {
// Inline macro feature.
codeActionKind = vscode.CodeActionKind.RefactorInline;
codeActionKind = CodeActionProvider.inlineMacroKind;
wsEdit = new vscode.WorkspaceEdit();
wsEdit.replace(document.uri, makeVscodeRange(command.edit.range), command.edit.newText);
hasInlineMacro = true;
} else if (command.command === "C_Cpp.RemoveAllCodeAnalysisProblems" && command.uri !== undefined) {
// The "RemoveAll" message is sent for all code analysis squiggles.
const vsCodeRange: vscode.Range = makeVscodeRange(r);
Expand Down Expand Up @@ -218,7 +226,47 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
kind: codeActionKind
};
resultCodeActions.push(vscodeCodeAction);
});
};

response.commands.forEach(processCommand);

// If the refactor.inline.macro code action is specifically invoked by the user,
// then force a hover to ensure that the "Expands to" info is available.
if (!hasInlineMacro && context.only?.value === "refactor.inline.macro") {
const processInlineMacro = async (): Promise<boolean> => {
const editor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
if (!editor) {
return false;
}
const result: vscode.Hover[] = <vscode.Hover[]>(await vscode.commands.executeCommand('vscode.executeHoverProvider', document.uri, range.start));
if (result.length === 0) {
return false;
}
const hoverResult: vscode.MarkdownString = <vscode.MarkdownString>result[0].contents[0];
if (!hoverResult.value.includes(localize("expands.to", "Expands to:"))) {
return false;
}
response = await this.client.languageClient.sendRequest(GetCodeActionsRequest, params, token);
if (token.isCancellationRequested || response.commands === undefined) {
return false;
}
for (const command of response.commands) {
if (command.edit) {
processCommand(command);
return true;
}
}
return false;
};
if (!await processInlineMacro()) {
const disabledCodeAction: vscode.CodeAction = {
title: localize({ key: "inline.macro", comment: ["'Inline' is a command and not an adjective, i.e. like 'Expand macro'."] }, "Inline macro"),
kind: CodeActionProvider.inlineMacroKind,
disabled: { reason: localize("inline.macro.not.available", "Inline macro is not available at this location.") }
};
resultCodeActions.push(disabledCodeAction);
}
}
return resultCodeActions;
}
}
2 changes: 1 addition & 1 deletion Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,7 @@ export class DefaultClient implements Client {
const settings: CppSettings = new CppSettings(this.RootUri);
if (settings.configurationWarnings && !this.isExternalHeader(docUri) && !vscode.debug.activeDebugSession) {
const dismiss: string = localize("dismiss.button", "Dismiss");
const disable: string = localize("diable.warnings.button", "Disable Warnings");
const disable: string = localize("disable.warnings.button", "Disable Warnings");
const configName: string | undefined = this.configuration.CurrentConfiguration?.name;
if (!configName) {
return;
Expand Down
18 changes: 9 additions & 9 deletions Extension/src/LanguageServer/codeAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const codeAnalysisCodeToFixes: Map<string, CodeActionCodeInfo> = new Map<
export const codeAnalysisAllFixes: CodeActionAllInfo = {
version: 0,
fixAllCodeAction: {
title: localize("fix_all_code_analysis_problems", "Fix all code analysis problems"),
title: localize("fix.all.code.analysis.problems", "Fix all code analysis problems"),
command: {
title: 'FixAllCodeAnalysisProblems',
command: 'C_Cpp.FixAllCodeAnalysisProblems',
Expand All @@ -127,7 +127,7 @@ export const codeAnalysisAllFixes: CodeActionAllInfo = {
kind: vscode.CodeActionKind.QuickFix
},
removeAllCodeAction: {
title: localize("clear_all_code_analysis_problems", "Clear all code analysis problems"),
title: localize("clear.all.code.analysis.problems", "Clear all code analysis problems"),
command: { title: "RemoveAllCodeAnalysisProblems", command: "C_Cpp.RemoveAllCodeAnalysisProblems" },
kind: vscode.CodeActionKind.QuickFix
}
Expand Down Expand Up @@ -175,7 +175,7 @@ function rebuildCodeAnalysisCodeAndAllFixes(): void {
}
++numFixTypes;
codeToFixes[1].fixAllTypeCodeAction = {
title: localize("fix_all_type_problems", "Fix all {0} problems", codeToFixes[0]),
title: localize("fix.all.type.problems", "Fix all {0} problems", codeToFixes[0]),
command: {
title: 'FixAllTypeCodeAnalysisProblems',
command: 'C_Cpp.FixAllTypeCodeAnalysisProblems',
Expand All @@ -187,7 +187,7 @@ function rebuildCodeAnalysisCodeAndAllFixes(): void {

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

if (new CppSettings().clangTidyCodeActionShowClear !== "None") {
codeToFixes[1].removeAllTypeCodeAction = {
title: localize("clear_all_type_problems", "Clear all {0} problems", codeToFixes[0]),
title: localize("clear.all.type.problems", "Clear all {0} problems", codeToFixes[0]),
command: {
title: 'RemoveAllTypeCodeAnalysisProblems',
command: 'C_Cpp.RemoveCodeAnalysisProblems',
Expand Down Expand Up @@ -265,7 +265,7 @@ export function publishCodeAnalysisDiagnostics(params: PublishCodeAnalysisDiagno
range: makeVscodeRange(identifier.range),
code: identifier.code,
removeCodeAction: {
title: localize("clear_this_problem", "Clear this {0} problem", d.code),
title: localize("clear.this.problem", "Clear this {0} problem", d.code),
command: {
title: 'RemoveCodeAnalysisProblems',
command: 'C_Cpp.RemoveCodeAnalysisProblems',
Expand All @@ -281,7 +281,7 @@ export function publishCodeAnalysisDiagnostics(params: PublishCodeAnalysisDiagno
workspaceEdit.workspaceEdit.set(vscode.Uri.parse(uriStr, true), makeVscodeTextEdits(edits));
}
const fixThisCodeAction: vscode.CodeAction = {
title: localize("fix_this_problem", "Fix this {0} problem", d.code),
title: localize("fix.this.problem", "Fix this {0} problem", d.code),
command: {
title: 'FixThisCodeAnalysisProblem',
command: 'C_Cpp.FixThisCodeAnalysisProblem',
Expand Down Expand Up @@ -315,7 +315,7 @@ export function publishCodeAnalysisDiagnostics(params: PublishCodeAnalysisDiagno
const relatedIdentifiersAndUri: CodeAnalysisDiagnosticIdentifiersAndUri = {
uri: info.location.uri, identifiers: [ relatedIdentifier ] };
const relatedCodeAction: vscode.CodeAction = {
title: localize("fix_this_problem", "Fix this {0} problem", d.code),
title: localize("fix.this.problem", "Fix this {0} problem", d.code),
command: {
title: 'FixThisCodeAnalysisProblem',
command: 'C_Cpp.FixThisCodeAnalysisProblem',
Expand Down Expand Up @@ -384,7 +384,7 @@ export function publishCodeAnalysisDiagnostics(params: PublishCodeAnalysisDiagno
if (new CppSettings().clangTidyCodeActionShowDocumentation) {
if (codeActionCodeInfo.docCodeAction === undefined) {
codeActionCodeInfo.docCodeAction = {
title: localize("show_documentation_for", "Show documentation for {0}", primaryCode),
title: localize("show.documentation.for", "Show documentation for {0}", primaryCode),
command: {
title: 'ShowDocumentation',
command: 'C_Cpp.ShowCodeAnalysisDocumentation',
Expand Down
8 changes: 4 additions & 4 deletions Extension/src/LanguageServer/cppBuildTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class CppBuildTaskProvider implements TaskProvider {
if (!definition) {
const isWindows: boolean = os.platform() === 'win32';
const taskLabel: string = ((appendSourceToName && !compilerPathBase.startsWith(ext.configPrefix)) ?
ext.configPrefix : "") + compilerPathBase + " " + localize("build_active_file", "build active file");
ext.configPrefix : "") + compilerPathBase + " " + localize("build.active.file", "build active file");
const programName: string = util.defaultExePath();
let args: string[] = isCl ?
['/Zi', '/EHsc', '/nologo', `/Fe${programName}`, '${file}'] :
Expand Down Expand Up @@ -213,7 +213,7 @@ export class CppBuildTaskProvider implements TaskProvider {
), isCl ? '$msCompile' : '$gcc');

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

return task;
};
Expand Down Expand Up @@ -294,7 +294,7 @@ export class CppBuildTaskProvider implements TaskProvider {
...selectedTask.definition,
problemMatcher: selectedTask.problemMatchers,
group: setAsDefault ? { kind: "build", "isDefault": true } : "build",
detail: localize("task_generated_by_debugger", "Task generated by Debugger.")
detail: localize("task.generated.by.debugger", "Task generated by Debugger.")
};
rawTasksJson.tasks.push(newTask);
}
Expand Down Expand Up @@ -372,7 +372,7 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
}
telemetry.logLanguageServerEvent("cppBuildTaskStarted");
// At this point we can start using the terminal.
this.writeEmitter.fire(localize("starting_build", "Starting build...") + this.endOfLine);
this.writeEmitter.fire(localize("starting.build", "Starting build...") + this.endOfLine);
await this.doBuild();
}

Expand Down
4 changes: 2 additions & 2 deletions Extension/src/SSH/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ export function ssh(host: ISshHostInfo, command: string, sshPath?: string, jumpH
function localForwardToArgs(localForward: ISshLocalForwardInfo): string[] {
// Do not combine error checking and arg conversion for clarity.
if (localForward.localSocket && (localForward.bindAddress || localForward.port)) {
throw Error(localize('local.forward.local.conflict', '"localSocket" cannot be specifed at the same time with "bindAddress" or "port" in localForwards'));
throw Error(localize('local.forward.local.conflict', '"localSocket" cannot be specified at the same time with "bindAddress" or "port" in localForwards'));
}
if (!localForward.localSocket && !localForward.port) {
throw Error(localize('local.forward.local.missing', '"port" or "localSocket" required in localForwards'));
}
if (localForward.remoteSocket && (localForward.host || localForward.hostPort)) {
throw Error(localize('local.forward.remote.conflict', '"remoteSocket" cannot be specifed at the same time with "host" or "hostPort" in localForwards'));
throw Error(localize('local.forward.remote.conflict', '"remoteSocket" cannot be specified at the same time with "host" or "hostPort" in localForwards'));
}
if (!localForward.remoteSocket && (!localForward.host || !localForward.hostPort)) {
throw Error(localize('local.forward.remote.missing', '"host" and "hostPort", or "remoteSocket" required in localForwards'));
Expand Down
2 changes: 1 addition & 1 deletion Extension/src/SSH/sshCommandRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function showPasswordInputBox(
prompt?: string,
cancelToken?: vscode.CancellationToken
): Promise<string | undefined> {
const msg: string = user ? localize('ssh.enter.password.for.user', 'Enter password for user "{0}"', user) : localize('ssh_message_enterPassword', 'Enter password');
const msg: string = user ? localize('ssh.enter.password.for.user', 'Enter password for user "{0}"', user) : localize('ssh.message.enter.password', 'Enter password');
return showInputBox(msg, prompt, cancelToken);
}

Expand Down
4 changes: 2 additions & 2 deletions Extension/src/SSH/sshCommandToConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const flags: {
return;
} else {
throw new CommandParseError(
`LocalFoward needs a listener and a destination separate by a colon. ${args} does not match.`
`LocalForward needs a listener and a destination separate by a colon. ${args} does not match.`
);
}
}
Expand All @@ -63,7 +63,7 @@ const flags: {
const delimiter: number = args.indexOf(':');
if (delimiter === -1) {
throw new CommandParseError(
`LocalFoward needs a listener and a destination separate by a colon. ${args} does not match.`
`LocalForward needs a listener and a destination separate by a colon. ${args} does not match.`
);
}

Expand Down
Loading