Skip to content

Commit 4149493

Browse files
authored
Merge pull request #11607 from microsoft/main
Merge for 1.18.1
2 parents 43aad3f + c26054a commit 4149493

9 files changed

+114
-61
lines changed

Extension/CHANGELOG.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
# C/C++ for Visual Studio Code Changelog
22

3+
## Version 1.18.1: November 2, 2023
4+
### New Feature
5+
* Add `#include` code action suggestions for some IntelliSense errors related to symbols not being found. [#10791](https://github.com/microsoft/vscode-cpptools/issues/10791)
6+
* Since C code doesn't give an error for an undefined symbol, it usually won't be available for C.
7+
8+
### Enhancements
9+
* Improve the walkthrough wording. [#11320](https://github.com/microsoft/vscode-cpptools/issues/11320)
10+
* Change 'Extract to Function' to prompt for the name instead of doing a rename afterwards. [#11531](https://github.com/microsoft/vscode-cpptools/issues/11531)
11+
* Add a pre-release available notification. [PR #11569](https://github.com/microsoft/vscode-cpptools/pull/11569)
12+
13+
### Bug Fixes
14+
* Fix no error message getting shown if 'Extract to Function' creation fails. [#11567](https://github.com/microsoft/vscode-cpptools/issues/11567)
15+
* Fix an autocomplete crash bug (primarily on Mac).
16+
* Fix an IntelliSense crash when selecting code.
17+
318
## Version 1.18.0: October 12, 2023
419
### New Features
520
* Add an 'Extract to Function' (or Member Function) code action after selecting code. [#1162](https://github.com/microsoft/vscode-cpptools/issues/1162)
6-
* Currently, it's only enabled when `C_Cpp.experimentFeatures` is `true`. Also, 'Extract to Free Function' is disabled.
7-
* Add the option to install a compiler, accessible through the walkthrough. [PR #11286](https://github.com/microsoft/vscode-cpptools/pull/11286)
21+
* Currently, it's only enabled when `C_Cpp.experimentFeatures` is set to `enabled`. Also, 'Extract to Free Function' is disabled.
22+
* Compiler acquisition improvements. [#10525](https://github.com/microsoft/vscode-cpptools/issues/10525)
823

924
### Enhancements
1025
* Add setting `C_Cpp.refactoring.includeHeader` to customize whether or not to add an include header when doing a refactoring code action. [#11271](https://github.com/microsoft/vscode-cpptools/issues/11271)
@@ -13,6 +28,7 @@
1328
### Bug Fixes
1429
* Fix the debugger truncating long strings when inspecting values. [#1786](https://github.com/microsoft/vscode-cpptools/issues/1786)
1530
* Switch to using `XDG_CACHE_HOME` on Linux for the default database path. [#10191](https://github.com/microsoft/vscode-cpptools/issues/10191)
31+
* Fix an IntelliSense error with std::is_trivially_copyable_v. [#10712](https://github.com/microsoft/vscode-cpptools/issues/10712)
1632
* Fix incorrect status and commands with the tag parsing language status UI. [#10749](https://github.com/microsoft/vscode-cpptools/issues/10749)
1733
* Fix an empty (`""`) `compilerPath` in a base configuration overriding the compiler specified by a custom configuration provider or a `compile_commands.json`. [#11373](https://github.com/microsoft/vscode-cpptools/issues/11373)
1834
* Fix a startup crash when reading values from JSON (settings) that are not the type expected. [#11375](https://github.com/microsoft/vscode-cpptools/issues/11375)

Extension/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cpptools",
33
"displayName": "C/C++",
44
"description": "C/C++ IntelliSense, debugging, and code browsing.",
5-
"version": "1.18.0-main",
5+
"version": "1.18.1-main",
66
"publisher": "ms-vscode",
77
"icon": "LanguageCCPP_color_128x.png",
88
"readme": "README.md",

Extension/package.nls.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,9 @@
991991
"c_cpp.walkthrough.run.debug.windows.description": "Open your C++ file and click on the play button in the top right corner of the editor, or press F5 when on the file. Select \"cl.exe - Build and debug active file\" to run with the debugger.",
992992
"c_cpp.walkthrough.run.debug.windows.altText": "Image showing a breakpoint in a C++ file, the f5 buttobn, and the run symbol in the top right",
993993
"c_cpp.walkthrough.customize.debugging.title": "Customize debugging",
994-
"c_cpp.walkthrough.customize.debugging.mac.description": "You can customize your debug configuration (e.g. to pass arguments to your program at run time) by selecting \"Add Debug Configuration\" to the right of the play button. The custom debug configuration is saved in your project's launch.json file. \n[Learn More](https://code.visualstudio.com/docs/cpp/config-linux#_debug-helloworldcpp)",
995-
"c_cpp.walkthrough.customize.debugging.linux.description": "You can customize your debug configuration (e.g. to pass arguments to your program at run time) by selecting \"Add Debug Configuration\" to the right of the play button. The custom debug configuration is saved in your project's launch.json file. \n[Learn More](https://code.visualstudio.com/docs/cpp/config-msvc#_debug-helloworldcpp)",
996-
"c_cpp.walkthrough.customize.debugging.windows.description": "You can customize your debug configuration (e.g. to pass arguments to your program at run time) by selecting \"Add Debug Configuration\" to the right of the play button. The custom debug configuration is saved in your project's launch.json file. \n[Learn More](https://code.visualstudio.com/docs/cpp/config-clang-mac#_debug-helloworldcpp)",
994+
"c_cpp.walkthrough.customize.debugging.mac.description": "To customize your debug configuration, select the Explorer in the activity bar and open a folder that includes your C++ file. Open the C++ file, and select \"Add Debug Configuration\" to the right of the play button. The new debug configuration is saved to your project's launch.json file. \n[Learn More](https://code.visualstudio.com/docs/cpp/config-linux#_debug-helloworldcpp)",
995+
"c_cpp.walkthrough.customize.debugging.linux.description": "To customize your debug configuration, select the Explorer in the activity bar and open a folder that includes your C++ file. Open the C++ file, and select \"Add Debug Configuration\" to the right of the play button. The new debug configuration is saved to your project's launch.json file. \n[Learn More](https://code.visualstudio.com/docs/cpp/config-msvc#_debug-helloworldcpp)",
996+
"c_cpp.walkthrough.customize.debugging.windows.description": "To customize your debug configuration, select the Explorer in the activity bar and open a folder that includes your C++ file. Open the C++ file, and select \"Add Debug Configuration\" to the right of the play button. The new debug configuration is saved to your project's launch.json file. \n[Learn More](https://code.visualstudio.com/docs/cpp/config-clang-mac#_debug-helloworldcpp)",
997997
"c_cpp.walkthrough.customize.debugging.altText": "Image that shows Add Debug Configuration in the drop-down",
998998
"c_cpp.codeActions.refactor.inline.macro.title": "Inline macro",
999999
"c_cpp.codeActions.refactor.inline.macro.description": "Replace the macro invocation with the expanded code.",

Extension/src/LanguageServer/Providers/codeActionProvider.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,16 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
9797
let wsEdit: vscode.WorkspaceEdit | undefined;
9898
let codeActionKind: vscode.CodeActionKind = vscode.CodeActionKind.QuickFix;
9999
if (command.edit) {
100-
// Inline macro feature.
101-
codeActionKind = CodeActionProvider.inlineMacroKind;
102100
wsEdit = new vscode.WorkspaceEdit();
101+
if (command.command === 'C_Cpp.AddMissingInclude') {
102+
command.edit.newText += "\n";
103+
}
103104
wsEdit.replace(document.uri, makeVscodeRange(command.edit.range), command.edit.newText);
104-
hasInlineMacro = true;
105+
if (command.command === "edit") {
106+
// Inline macro feature.
107+
codeActionKind = CodeActionProvider.inlineMacroKind;
108+
hasInlineMacro = true;
109+
}
105110
} else if (command.command === "C_Cpp.RemoveAllCodeAnalysisProblems" && command.uri !== undefined) {
106111
// The "RemoveAll" message is sent for all code analysis squiggles.
107112
const vsCodeRange: vscode.Range = makeVscodeRange(r);

Extension/src/LanguageServer/Providers/renameProvider.ts

-10
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ export class RenameProvider implements vscode.RenameProvider {
2424
}
2525

2626
public async provideRenameEdits(document: vscode.TextDocument, position: vscode.Position, newName: string, _token: vscode.CancellationToken): Promise<vscode.WorkspaceEdit | undefined> {
27-
// Bypass the normal rename processing during Extract to function,
28-
// since we already know the locations of the required edits.
29-
if (this.client.renameDataForExtractToFunction.length > 0) {
30-
const workspaceEditResult: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
31-
for (const renameData of this.client.renameDataForExtractToFunction) {
32-
workspaceEditResult.replace(renameData.uri, renameData.range, newName);
33-
}
34-
this.client.renameDataForExtractToFunction = [];
35-
return workspaceEditResult;
36-
}
3727
await this.client.ready;
3828
workspaceReferences.cancelCurrentReferenceRequest(CancellationSender.NewRequest);
3929

Extension/src/LanguageServer/client.ts

+40-42
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ export interface CreateDeclarationOrDefinitionResult extends WorkspaceEditResult
342342

343343
export interface ExtractToFunctionParams extends SelectionParams {
344344
extractAsGlobal: boolean;
345+
name: string;
345346
}
346347

347348
interface ShowMessageWindowParams {
@@ -3452,10 +3453,14 @@ export class DefaultClient implements Client {
34523453
return;
34533454
}
34543455

3455-
// TODO: Show a quick pick to get the name before generating the code.
3456-
// That would allow the formatting to be done without waiting for the rename.
3457-
// Also, it's less error prone and eliminates a class of bugs in which the
3458-
// rename position can be incorrect.
3456+
let functionName: string | undefined = await vscode.window.showInputBox({
3457+
title: localize('handle.extract.name', 'Name the extracted function'),
3458+
placeHolder: localize('handle.extract.new.function', 'NewFunction')
3459+
});
3460+
3461+
if (functionName === undefined || functionName === "") {
3462+
functionName = "NewFunction";
3463+
}
34593464

34603465
const params: ExtractToFunctionParams = {
34613466
uri: editor.document.uri.toString(),
@@ -3469,7 +3474,8 @@ export class DefaultClient implements Client {
34693474
line: editor.selection.end.line
34703475
}
34713476
},
3472-
extractAsGlobal
3477+
extractAsGlobal,
3478+
name: functionName
34733479
};
34743480

34753481
const result: WorkspaceEditResult = await this.languageClient.sendRequest(ExtractToFunctionRequest, params);
@@ -3482,15 +3488,15 @@ export class DefaultClient implements Client {
34823488

34833489
// Handle error messaging
34843490
if (result.errorText) {
3485-
void vscode.window.showErrorMessage(result.errorText);
3491+
void vscode.window.showErrorMessage(`${localize("handle.extract.error",
3492+
"Extract to function failed: {0}", result.errorText)}`);
34863493
return;
34873494
}
34883495

34893496
let workspaceEdits: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
34903497
let replaceEditRange: vscode.Range | undefined;
34913498
let hasProcessedReplace: boolean = false;
34923499
const formatUriAndRanges: VsCodeUriAndRange[] = [];
3493-
this.renameDataForExtractToFunction = [];
34943500
let lineOffset: number = 0;
34953501
let headerFileLineOffset: number = 0;
34963502
let isSourceFile: boolean = true;
@@ -3515,7 +3521,7 @@ export class DefaultClient implements Client {
35153521
range = new vscode.Range(new vscode.Position(range.start.line + headerFileLineOffset, range.start.character),
35163522
new vscode.Position(range.end.line + headerFileLineOffset, range.end.character));
35173523
}
3518-
const isReplace: boolean = !range.isEmpty;
3524+
const isReplace: boolean = !range.isEmpty && isSourceFile;
35193525
lineOffset += nextLineOffset;
35203526
nextLineOffset = (edit.newText.match(/\n/g) ?? []).length;
35213527
let rangeStartLine: number = range.start.line + lineOffset;
@@ -3559,36 +3565,32 @@ export class DefaultClient implements Client {
35593565
new vscode.Position(rangeStartLine + (nextLineOffset < 0 ? 0 : nextLineOffset),
35603566
isReplace ? range.end.character :
35613567
range.end.character + edit.newText.length - rangeStartCharacter))});
3562-
const newFunctionString: string = "NewFunction";
3563-
3564-
// Handle additional declaration lines added before the new function call.
3565-
let currentText: string = edit.newText.substring(rangeStartCharacter);
3566-
let currentTextNextLineStart: number = currentText.indexOf("\n");
3567-
let currentTextNewFunctionStart: number = currentText.indexOf(newFunctionString);
3568-
let currentTextNextLineStartUpdated: boolean = false;
3569-
while (currentTextNextLineStart !== -1 && currentTextNextLineStart < currentTextNewFunctionStart) {
3570-
++rangeStartLine;
3571-
currentText = currentText.substring(currentTextNextLineStart + 1);
3572-
currentTextNextLineStart = currentText.indexOf("\n");
3573-
currentTextNewFunctionStart = currentText.indexOf(newFunctionString);
3574-
currentTextNextLineStartUpdated = true;
3575-
}
3576-
rangeStartCharacter = (rangeStartCharacter === 0 && !currentTextNextLineStartUpdated ? range.start.character : 0) +
3577-
currentTextNewFunctionStart;
3578-
if (rangeStartCharacter < 0) {
3579-
// newFunctionString is missing -- unexpected error.
3580-
void vscode.window.showErrorMessage(`${localize("invalid.edit",
3581-
"Extract to function failed. An invalid edit was generated: '{0}'", edit.newText)}`);
3582-
continue;
3583-
}
3584-
const currentEditRange: vscode.Range = new vscode.Range(
3585-
new vscode.Position(rangeStartLine, rangeStartCharacter),
3586-
new vscode.Position(rangeStartLine, rangeStartCharacter + newFunctionString.length));
35873568
if (isReplace) {
3588-
replaceEditRange = currentEditRange;
3569+
// Handle additional declaration lines added before the new function call.
3570+
let currentText: string = edit.newText.substring(rangeStartCharacter);
3571+
let currentTextNextLineStart: number = currentText.indexOf("\n");
3572+
let currentTextNewFunctionStart: number = currentText.indexOf(functionName);
3573+
let currentTextNextLineStartUpdated: boolean = false;
3574+
while (currentTextNextLineStart !== -1 && currentTextNextLineStart < currentTextNewFunctionStart) {
3575+
++rangeStartLine;
3576+
currentText = currentText.substring(currentTextNextLineStart + 1);
3577+
currentTextNextLineStart = currentText.indexOf("\n");
3578+
currentTextNewFunctionStart = currentText.indexOf(functionName);
3579+
currentTextNextLineStartUpdated = true;
3580+
}
3581+
rangeStartCharacter = (rangeStartCharacter === 0 && !currentTextNextLineStartUpdated ? range.start.character : 0) +
3582+
currentTextNewFunctionStart;
3583+
if (rangeStartCharacter < 0) {
3584+
// functionName is missing -- unexpected error.
3585+
void vscode.window.showErrorMessage(`${localize("invalid.edit",
3586+
"Extract to function failed. An invalid edit was generated: '{0}'", edit.newText)}`);
3587+
continue;
3588+
}
3589+
replaceEditRange = new vscode.Range(
3590+
new vscode.Position(rangeStartLine, rangeStartCharacter),
3591+
new vscode.Position(rangeStartLine, rangeStartCharacter + functionName.length));
35893592
nextLineOffset -= range.end.line - range.start.line;
35903593
}
3591-
this.renameDataForExtractToFunction.push({ uri, range: currentEditRange });
35923594
}
35933595
}
35943596

@@ -3601,15 +3603,15 @@ export class DefaultClient implements Client {
36013603

36023604
const firstUri: vscode.Uri = formatUriAndRanges[0].uri;
36033605
await vscode.window.showTextDocument(firstUri, { selection: replaceEditRange });
3604-
await vscode.commands.executeCommand("editor.action.rename", firstUri, replaceEditRange.start);
36053606

36063607
// Format the new text edits.
36073608
const formatEdits: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
36083609
for (const formatUriAndRange of formatUriAndRanges) {
36093610
const settings: OtherSettings = new OtherSettings(vscode.workspace.getWorkspaceFolder(formatUriAndRange.uri)?.uri);
36103611
const formatOptions: vscode.FormattingOptions = {
36113612
insertSpaces: settings.editorInsertSpaces ?? true,
3612-
tabSize: settings.editorTabSize ?? 4
3613+
tabSize: settings.editorTabSize ?? 4,
3614+
onChanges: true
36133615
};
36143616

36153617
const doFormat = async () => {
@@ -3618,10 +3620,8 @@ export class DefaultClient implements Client {
36183620
return true;
36193621
}
36203622

3621-
// TODO: Somehow invoke multiple range formatting (see https://github.com/microsoft/vscode/issues/193836).
3622-
// Maybe call DocumentRangeFormattingEditProvider.provideDocumentRangesFormattingEdits directly.
36233623
const formatTextEdits: vscode.TextEdit[] | undefined = await vscode.commands.executeCommand<vscode.TextEdit[] | undefined>(
3624-
"vscode.executeFormatRangeProvider", formatUriAndRange.uri, formatUriAndRange.range, formatOptions);
3624+
"vscode.executeFormatDocumentProvider", formatUriAndRange.uri, formatOptions);
36253625
if (!formatTextEdits || formatTextEdits.length === 0 || versionBeforeFormatting === undefined) {
36263626
return true;
36273627
}
@@ -3645,8 +3645,6 @@ export class DefaultClient implements Client {
36453645
}
36463646
}
36473647

3648-
public renameDataForExtractToFunction: VsCodeUriAndRange[] = [];
3649-
36503648
public onInterval(): void {
36513649
// These events can be discarded until the language client is ready.
36523650
// Don't queue them up with this.notifyWhenLanguageClientReady calls.

0 commit comments

Comments
 (0)