Skip to content

Commit 07efeb4

Browse files
authored
Merge pull request #10233 from microsoft/seanmcm/1_13_6_release_2
Cherry-picks for 1.13.6
2 parents 4abec44 + 3555e2f commit 07efeb4

File tree

5 files changed

+45
-30
lines changed

5 files changed

+45
-30
lines changed

Extension/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# C/C++ for Visual Studio Code Changelog
22

3-
## Version 1.13.6: November 30, 2022
3+
## Version 1.13.6: December 6, 2022
44
### New Features
55
* Add the ability to generate definitions from declarations and vice versa. [#664](https://github.com/microsoft/vscode-cpptools/issues/664)
66
* Add SSH Target Selector. [PR #9760](https://github.com/microsoft/vscode-cpptools/pull/9760)
@@ -58,6 +58,7 @@
5858
* Fix clang-tidy and clang-format not working on CentOS7 and other Linux OS's without glibc 2.27 or greater. [#10019](https://github.com/microsoft/vscode-cpptools/issues/10019)
5959
* Fix various bugs with the `C_Cpp.codeAnalysis.clangTidy.headerFilter` setting. [#10023](https://github.com/microsoft/vscode-cpptools/issues/10023)
6060
* Fix Doxygen comment generation when there's a selection. [#10028](https://github.com/microsoft/vscode-cpptools/issues/10028)
61+
* Fix issue that could cause document corruption. [#10035](https://github.com/microsoft/vscode-cpptools/issues/10035)
6162
* Fixed crash on Linux/Mac when a full command line is specified in `compilerPath` containing invalid arguments. [PR #10070](https://github.com/microsoft/vscode-cpptools/pull/10070)
6263
* Fix random "Failed to spawn IntelliSense process: 65520" on Mac. [#10091](https://github.com/microsoft/vscode-cpptools/issues/10091)
6364
* Fix "Don't hardcode path to kill in UnixUtilities". [#10124](https://github.com/microsoft/vscode-cpptools/issues/10124)
@@ -67,6 +68,7 @@
6768
* Fix include completion sorting extensionless headers (e.g. string) after headers with an extension (e.g. string.h).
6869
* Fix extensionHost logging an error related to onWillSaveTextDocument whenever a save is done.
6970
* Fix random "Failed to spawn IntelliSense process" on Mac.
71+
* Fix a deadlock when IntelliSense errors are updating.
7072
* Fix redundant rescan when adding a workspace folder.
7173

7274
### Removed Feature

Extension/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5986,6 +5986,7 @@
59865986
"ajv": "^6.12.3",
59875987
"ansi-regex": "^5.0.1",
59885988
"browserslist": "^4.16.6",
5989+
"decode-uri-component": "^0.2.1",
59895990
"follow-redirects": "1.14.8",
59905991
"glob-parent": "^5.1.2",
59915992
"hosted-git-info": "^3.0.8",

Extension/src/LanguageServer/client.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3004,34 +3004,51 @@ export class DefaultClient implements Client {
30043004
return;
30053005
}
30063006

3007-
const workspaceEdit: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
3007+
const workspaceEdits: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
30083008
let modifiedDocument: vscode.Uri | undefined;
30093009
let lastEdit: vscode.TextEdit | undefined;
3010-
let numNewlinesFromPreviousEdits: number = 0;
3010+
let editPositionAdjustment: number = 0;
3011+
let selectionPositionAdjustment: number = 0;
30113012
for (const file in result.changes) {
30123013
const uri: vscode.Uri = vscode.Uri.file(file);
3013-
const edits: vscode.TextEdit[] = [];
3014+
// At most, there will only be two text edits:
3015+
// 1.) an edit for: #include header file
3016+
// 2.) an edit for: definition or declaration
30143017
for (const edit of result.changes[file]) {
30153018
const range: vscode.Range = makeVscodeRange(edit.range);
3016-
if (lastEdit && lastEdit.range.isEqual(range)) {
3017-
numNewlinesFromPreviousEdits += (lastEdit.newText.match(/\n/g) || []).length;
3019+
// Get new lines from an edit for: #include header file.
3020+
if (lastEdit && lastEdit.newText.includes("#include")) {
3021+
if (lastEdit.range.isEqual(range)) {
3022+
// Destination file is empty.
3023+
// The edit positions for #include header file and definition or declaration are the same.
3024+
selectionPositionAdjustment = (lastEdit.newText.match(/\n/g) || []).length;
3025+
} else {
3026+
// Destination file is not empty.
3027+
// VS Code workspace.applyEdit calculates the position of subsequent edits.
3028+
// That is, the positions of text edits that are originally calculated by the language server
3029+
// are adjusted based on the number of text edits applied by VS Code workspace.applyEdit.
3030+
// Since the language server's refactoring API already pre-calculates the positions of multiple text edits,
3031+
// re-adjust the new line of the next text edit for the VS Code applyEdit to calculate again.
3032+
editPositionAdjustment = (lastEdit.newText.match(/\n/g) || []).length;
3033+
}
30183034
}
30193035
lastEdit = new vscode.TextEdit(range, edit.newText);
3020-
edits.push(lastEdit);
3036+
const position: vscode.Position = new vscode.Position(edit.range.start.line - editPositionAdjustment, edit.range.start.character);
3037+
workspaceEdits.insert(uri, position, edit.newText);
30213038
}
3022-
workspaceEdit.set(uri, edits);
30233039
modifiedDocument = uri;
30243040
};
30253041

30263042
if (modifiedDocument === undefined || lastEdit === undefined) {
30273043
return;
30283044
}
30293045

3030-
await vscode.workspace.applyEdit(workspaceEdit);
3031-
let numNewlines: number = (lastEdit.newText.match(/\n/g) || []).length;
3046+
// Apply the create declaration/definition text edits.
3047+
await vscode.workspace.applyEdit(workspaceEdits);
30323048

3033-
// Move the cursor to the new code, accounting for \n or \n\n at the start.
3049+
// Move the cursor to the new declaration/definition edit, accounting for \n or \n\n at the start.
30343050
let startLine: number = lastEdit.range.start.line;
3051+
let numNewlines: number = (lastEdit.newText.match(/\n/g) || []).length;
30353052
if (lastEdit.newText.startsWith("\r\n\r\n") || lastEdit.newText.startsWith("\n\n")) {
30363053
startLine += 2;
30373054
numNewlines -= 2;
@@ -3043,11 +3060,11 @@ export class DefaultClient implements Client {
30433060
numNewlines++; // Increase the format range.
30443061
}
30453062

3046-
const selectionPosition: vscode.Position = new vscode.Position(startLine + numNewlinesFromPreviousEdits, 0);
3063+
const selectionPosition: vscode.Position = new vscode.Position(startLine + selectionPositionAdjustment, 0);
30473064
const selectionRange: vscode.Range = new vscode.Range(selectionPosition, selectionPosition);
30483065
await vscode.window.showTextDocument(modifiedDocument, { selection: selectionRange });
30493066

3050-
// Run formatRange.
3067+
// Format the new text edits.
30513068
const formatEdits: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
30523069
const formatRange: vscode.Range = new vscode.Range(selectionRange.start, new vscode.Position(selectionRange.start.line + numNewlines, 0));
30533070
const settings: OtherSettings = new OtherSettings(vscode.workspace.getWorkspaceFolder(modifiedDocument)?.uri);

Extension/src/LanguageServer/protocolFilter.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Middleware } from 'vscode-languageclient';
99
import { Client } from './client';
1010
import * as vscode from 'vscode';
1111
import { CppSettings } from './settings';
12-
import { clients, onDidChangeActiveTextEditor, processDelayedDidOpen } from './extension';
12+
import { clients, onDidChangeActiveTextEditor } from './extension';
1313

1414
export function createProtocolFilter(): Middleware {
1515
// Disabling lint for invoke handlers
@@ -36,13 +36,11 @@ export function createProtocolFilter(): Middleware {
3636
me.TrackedDocuments.add(document);
3737
const finishDidOpen = (doc: vscode.TextDocument) => {
3838
me.provideCustomConfiguration(doc.uri, undefined);
39-
me.notifyWhenLanguageClientReady(() => {
40-
sendMessage(doc);
41-
me.onDidOpenTextDocument(doc);
42-
if (editor && editor === vscode.window.activeTextEditor) {
43-
onDidChangeActiveTextEditor(editor);
44-
}
45-
});
39+
sendMessage(doc);
40+
me.onDidOpenTextDocument(doc);
41+
if (editor && editor === vscode.window.activeTextEditor) {
42+
onDidChangeActiveTextEditor(editor);
43+
}
4644
};
4745
let languageChanged: boolean = false;
4846
if ((document.uri.path.endsWith(".C") || document.uri.path.endsWith(".H")) && document.languageId === "c") {
@@ -75,11 +73,8 @@ export function createProtocolFilter(): Middleware {
7573
},
7674
didChange: async (textDocumentChangeEvent, sendMessage) => {
7775
const me: Client = clients.getClientFor(textDocumentChangeEvent.document.uri);
78-
if (!me.TrackedDocuments.has(textDocumentChangeEvent.document)) {
79-
processDelayedDidOpen(textDocumentChangeEvent.document);
80-
}
8176
me.onDidChangeTextDocument(textDocumentChangeEvent);
82-
me.notifyWhenLanguageClientReady(() => sendMessage(textDocumentChangeEvent));
77+
sendMessage(textDocumentChangeEvent);
8378
},
8479
willSave: defaultHandler,
8580
willSaveWaitUntil: async (event, sendMessage) => {
@@ -97,7 +92,7 @@ export function createProtocolFilter(): Middleware {
9792
if (me.TrackedDocuments.has(document)) {
9893
me.onDidCloseTextDocument(document);
9994
me.TrackedDocuments.delete(document);
100-
me.notifyWhenLanguageClientReady(() => sendMessage(document));
95+
sendMessage(document);
10196
}
10297
},
10398

Extension/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,10 +1616,10 @@ decamelize@^4.0.0:
16161616
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-4.0.0.tgz#aa472d7bf660eb15f3494efd531cab7f2a709837"
16171617
integrity sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==
16181618

1619-
decode-uri-component@^0.2.0:
1620-
version "0.2.0"
1621-
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
1622-
integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=
1619+
decode-uri-component@^0.2.0, decode-uri-component@^0.2.1:
1620+
version "0.2.2"
1621+
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.2.tgz#e69dbe25d37941171dd540e024c444cd5188e1e9"
1622+
integrity sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ==
16231623

16241624
deep-is@^0.1.3, deep-is@~0.1.3:
16251625
version "0.1.3"

0 commit comments

Comments
 (0)