From 150c7aaf848bee669d469ebb460af3878e48e81e Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Mon, 28 Nov 2022 12:55:54 -0800 Subject: [PATCH 1/3] Fix selection and formatting for CDD (and extra newlines with clang-format) (#10177) * Fix selection and formatting for CDD. * Fix multiple edit at the same spot case. --- Extension/src/LanguageServer/client.ts | 38 +++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index 0dcb41854d..33a11e2249 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -3000,11 +3000,15 @@ export class DefaultClient implements Client { const workspaceEdit: vscode.WorkspaceEdit = new vscode.WorkspaceEdit(); let modifiedDocument: vscode.Uri | undefined; let lastEdit: vscode.TextEdit | undefined; + let numNewlinesFromPreviousEdits: number = 0; for (const file in result.changes) { const uri: vscode.Uri = vscode.Uri.file(file); const edits: vscode.TextEdit[] = []; for (const edit of result.changes[file]) { const range: vscode.Range = makeVscodeRange(edit.range); + if (lastEdit && lastEdit.range.isEqual(range)) { + numNewlinesFromPreviousEdits += (lastEdit.newText.match(/\n/g) || []).length; + } lastEdit = new vscode.TextEdit(range, edit.newText); edits.push(lastEdit); } @@ -3013,8 +3017,40 @@ export class DefaultClient implements Client { }; if (modifiedDocument && lastEdit) { await vscode.workspace.applyEdit(workspaceEdit); - const selectionRange: vscode.Range = lastEdit.range; // TODO: range should be the new range after text edit was applied. + let numNewlines: number = (lastEdit.newText.match(/\n/g) || []).length; + + // Move the cursor to the new code, accounting for \n or \n\n at the start. + let startLine: number = lastEdit.range.start.line; + if (lastEdit.newText.startsWith("\r\n\r\n") || lastEdit.newText.startsWith("\n\n")) { + startLine += 2; + numNewlines -= 2; + } else if (lastEdit.newText.startsWith("\r\n") || lastEdit.newText.startsWith("\n")) { + startLine += 1; + numNewlines -= 1; + } + if (!lastEdit.newText.endsWith("\n")) { + numNewlines++; // Increase the format range. + } + + const selectionPosition: vscode.Position = new vscode.Position(startLine + numNewlinesFromPreviousEdits, 0); + const selectionRange: vscode.Range = new vscode.Range(selectionPosition, selectionPosition); await vscode.window.showTextDocument(modifiedDocument, { selection: selectionRange }); + + // Run formatRange. + const formatEdits: vscode.WorkspaceEdit = new vscode.WorkspaceEdit(); + const formatRange: vscode.Range = new vscode.Range(selectionRange.start, new vscode.Position(selectionRange.start.line + numNewlines, 0)); + const settings: OtherSettings = new OtherSettings(vscode.workspace.getWorkspaceFolder(modifiedDocument)?.uri); + const formatOptions: vscode.FormattingOptions = { + insertSpaces: settings.editorInsertSpaces ?? true, + tabSize: settings.editorTabSize ?? 4 + }; + const formatTextEdits: vscode.TextEdit[] | undefined = await vscode.commands.executeCommand("vscode.executeFormatRangeProvider", modifiedDocument, formatRange, formatOptions); + if (formatTextEdits && formatTextEdits.length > 0) { + formatEdits.set(modifiedDocument, formatTextEdits); + } + if (formatEdits.size > 0) { + await vscode.workspace.applyEdit(formatEdits); + } } } } From 6a063be33f5fe85a21b40e6895a0c082b6921961 Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Mon, 28 Nov 2022 13:03:56 -0800 Subject: [PATCH 2/3] Update changelog for 1.13.5. (#10187) * Update changelog for 1.13.5. --- Extension/CHANGELOG.md | 12 ++++++++++++ Extension/package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Extension/CHANGELOG.md b/Extension/CHANGELOG.md index 395d9c5192..4c5d813da3 100644 --- a/Extension/CHANGELOG.md +++ b/Extension/CHANGELOG.md @@ -1,5 +1,17 @@ # C/C++ for Visual Studio Code Changelog +## Version 1.13.5: November 28, 2022 +### Bug Fixes +* Fix "Step Over past a logpoint stops at the wrong place". [#9995](https://github.com/microsoft/vscode-cpptools/issues/9995) +* Fix "Don't hardcode path to kill in UnixUtilities". [#10124](https://github.com/microsoft/vscode-cpptools/issues/10124) + * Ellie Hermaszewska (@expipiplus1) [PR #1373](https://github.com/microsoft/MIEngine/pull/1373) +* Fix the create declaration/definition feature not adding the definition if a new source file needs to be created. [#10159](https://github.com/microsoft/vscode-cpptools/issues/10159) +* Fix the create declaration/definition feature not having the correct cursor location after adding a definition. [#10160](https://github.com/microsoft/vscode-cpptools/issues/10160) +* Fix the create declaration/definition feature not formatting inserted definitions. [#10161](https://github.com/microsoft/vscode-cpptools/issues/10161) + * This has the side-effect of fixing the extra newlines created in a new file if clang-format is used. [#10164](https://github.com/microsoft/vscode-cpptools/issues/10164) + * However, clang-format 15 has a bug which can cause formatting of newly inserted definitions to fail in some cases: [LLVM#59178](https://github.com/llvm/llvm-project/issues/59178) +* Fix formatting when clang-format 11 or earlier is used (and another issue for version 8 or earlier). [#10178](https://github.com/microsoft/vscode-cpptools/issues/10178) + ## Version 1.13.4: November 17, 2022 ### New Features * Add the ability to generate definitions from declarations and vice versa. [#664](https://github.com/microsoft/vscode-cpptools/issues/664) diff --git a/Extension/package.json b/Extension/package.json index 0fe0546e50..ab2a8baa51 100644 --- a/Extension/package.json +++ b/Extension/package.json @@ -2,7 +2,7 @@ "name": "cpptools", "displayName": "C/C++", "description": "C/C++ IntelliSense, debugging, and code browsing.", - "version": "1.13.4-main", + "version": "1.13.5-main", "publisher": "ms-vscode", "icon": "LanguageCCPP_color_128x.png", "readme": "README.md", From 24f5fdd1224952320317ee256c8a19b2d42462a9 Mon Sep 17 00:00:00 2001 From: Andrew Wang Date: Mon, 28 Nov 2022 13:14:15 -0800 Subject: [PATCH 3/3] Change engine logging and add natvis diagnostics (#10171) * Change engine logging and add natvis diagnostics This PR adds logging categories to engineLogging and adds in the option for natvisDiagnostics with different categories. * change nls nativisDiagnostics to category --- Extension/package.json | 108 +++++++++++++++++++++++++++-- Extension/package.nls.json | 7 +- Extension/tools/OptionsSchema.json | 53 +++++++++++++- 3 files changed, 157 insertions(+), 11 deletions(-) diff --git a/Extension/package.json b/Extension/package.json index ab2a8baa51..dbadc98906 100644 --- a/Extension/package.json +++ b/Extension/package.json @@ -286,7 +286,7 @@ "name": "iar", "source": "iar", "owner": "cpptools", - "fileLocation" : "absolute", + "fileLocation": "absolute", "pattern": { "regexp": "^\"(.*?)\",(\\d+)\\s+(?:[Ff]atal\\s+)?([Ww]arning|[Ee]rror)\\[(\\w+\\d+)\\]:\\s+(.*)$", "file": 1, @@ -3453,9 +3453,30 @@ "default": true }, "engineLogging": { - "type": "boolean", - "description": "%c_cpp.debuggers.logging.engineLogging.description%", - "default": false + "anyOf": [ + { + "type": "string", + "enum": [ + "verbose", + "warning", + "error", + "none" + ], + "enumDescriptions": [ + "%c_cpp.debuggers.logging.category.verbose.description%", + "%c_cpp.debuggers.logging.category.warning.description%", + "%c_cpp.debuggers.logging.category.error.description%", + "%c_cpp.debuggers.logging.category.none.description%" + ], + "description": "%c_cpp.debuggers.logging.engineLogging.description%", + "default": "none" + }, + { + "type": "boolean", + "description": "%c_cpp.debuggers.logging.engineLogging.description%", + "default": false + } + ] }, "trace": { "type": "boolean", @@ -3466,6 +3487,32 @@ "type": "boolean", "description": "%c_cpp.debuggers.logging.traceResponse.description%", "default": false + }, + "natvisDiagnostics": { + "anyOf": [ + { + "type": "string", + "enum": [ + "verbose", + "warning", + "error", + "none" + ], + "enumDescriptions": [ + "%c_cpp.debuggers.logging.category.verbose.description%", + "%c_cpp.debuggers.logging.category.warning.description%", + "%c_cpp.debuggers.logging.category.error.description%", + "%c_cpp.debuggers.logging.category.none.description%" + ], + "description": "%c_cpp.debuggers.logging.natvisDiagnostics.description%", + "default": "none" + }, + { + "type": "boolean", + "description": "%c_cpp.debuggers.logging.engineLogging.description%", + "default": false + } + ] } } }, @@ -4194,9 +4241,30 @@ "default": true }, "engineLogging": { - "type": "boolean", - "description": "%c_cpp.debuggers.logging.engineLogging.description%", - "default": false + "anyOf": [ + { + "type": "string", + "enum": [ + "verbose", + "warning", + "error", + "none" + ], + "enumDescriptions": [ + "%c_cpp.debuggers.logging.category.verbose.description%", + "%c_cpp.debuggers.logging.category.warning.description%", + "%c_cpp.debuggers.logging.category.error.description%", + "%c_cpp.debuggers.logging.category.none.description%" + ], + "description": "%c_cpp.debuggers.logging.engineLogging.description%", + "default": "none" + }, + { + "type": "boolean", + "description": "%c_cpp.debuggers.logging.engineLogging.description%", + "default": false + } + ] }, "trace": { "type": "boolean", @@ -4207,6 +4275,32 @@ "type": "boolean", "description": "%c_cpp.debuggers.logging.traceResponse.description%", "default": false + }, + "natvisDiagnostics": { + "anyOf": [ + { + "type": "string", + "enum": [ + "verbose", + "warning", + "error", + "none" + ], + "enumDescriptions": [ + "%c_cpp.debuggers.logging.category.verbose.description%", + "%c_cpp.debuggers.logging.category.warning.description%", + "%c_cpp.debuggers.logging.category.error.description%", + "%c_cpp.debuggers.logging.category.none.description%" + ], + "description": "%c_cpp.debuggers.logging.natvisDiagnostics.description%", + "default": "none" + }, + { + "type": "boolean", + "description": "%c_cpp.debuggers.logging.engineLogging.description%", + "default": false + } + ] } } }, diff --git a/Extension/package.nls.json b/Extension/package.nls.json index 9e4c8eda13..dddb6a81c5 100644 --- a/Extension/package.nls.json +++ b/Extension/package.nls.json @@ -394,5 +394,10 @@ "c_cpp.semanticTokenTypes.numberLiteral.description": "Style for C++ user-defined literal numbers.", "c_cpp.semanticTokenTypes.stringLiteral.description": "Style for C++ user-defined literal strings.", "c_cpp.semanticTokenModifiers.global.description": "Style to use for symbols that are global.", - "c_cpp.semanticTokenModifiers.local.description": "Style to use for symbols that are local." + "c_cpp.semanticTokenModifiers.local.description": "Style to use for symbols that are local.", + "c_cpp.debuggers.logging.natvisDiagnostics.description": "Optional flag to determine whether diagnostic natvis messages should be logged to the Debug Console. Defaults to None.", + "c_cpp.debuggers.logging.category.verbose.description": "Logs that are used for interactive investigation during development. These logs should primarily contain information useful for debugging and have no long-term value.", + "c_cpp.debuggers.logging.category.warning.description": "Logs that highlight an abnormal or unexpected event in the application flow, but do not otherwise cause the application execution to stop.", + "c_cpp.debuggers.logging.category.error.description": "Logs that highlight when the current flow of execution is stopped due to a failure. These should indicate a failure in the current activity, not an application-wide failure.", + "c_cpp.debuggers.logging.category.none.description": "Not used for writing log messages. Specifies that a logging category should not write any messages." } diff --git a/Extension/tools/OptionsSchema.json b/Extension/tools/OptionsSchema.json index bccb67b523..98c90c7d50 100644 --- a/Extension/tools/OptionsSchema.json +++ b/Extension/tools/OptionsSchema.json @@ -76,9 +76,30 @@ "default": true }, "engineLogging": { - "type": "boolean", - "description": "%c_cpp.debuggers.logging.engineLogging.description%", - "default": false + "anyOf": [ + { + "type": "string", + "enum": [ + "verbose", + "warning", + "error", + "none" + ], + "enumDescriptions": [ + "%c_cpp.debuggers.logging.category.verbose.description%", + "%c_cpp.debuggers.logging.category.warning.description%", + "%c_cpp.debuggers.logging.category.error.description%", + "%c_cpp.debuggers.logging.category.none.description%" + ], + "description": "%c_cpp.debuggers.logging.engineLogging.description%", + "default": "none" + }, + { + "type": "boolean", + "description": "%c_cpp.debuggers.logging.engineLogging.description%", + "default": false + } + ] }, "trace": { "type": "boolean", @@ -89,6 +110,32 @@ "type": "boolean", "description": "%c_cpp.debuggers.logging.traceResponse.description%", "default": false + }, + "natvisDiagnostics": { + "anyOf": [ + { + "type": "string", + "enum": [ + "verbose", + "warning", + "error", + "none" + ], + "enumDescriptions": [ + "%c_cpp.debuggers.logging.category.verbose.description%", + "%c_cpp.debuggers.logging.category.warning.description%", + "%c_cpp.debuggers.logging.category.error.description%", + "%c_cpp.debuggers.logging.category.none.description%" + ], + "description": "%c_cpp.debuggers.logging.natvisDiagnostics.description%", + "default": "none" + }, + { + "type": "boolean", + "description": "%c_cpp.debuggers.logging.engineLogging.description%", + "default": false + } + ] } } },