Skip to content

Commit 4ba260c

Browse files
authored
Merge pull request #11687 from microsoft/main
Merge for 1.18.4
2 parents e896231 + 7cb9f88 commit 4ba260c

File tree

6 files changed

+192
-47
lines changed

6 files changed

+192
-47
lines changed

Extension/CHANGELOG.md

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

3+
## Version 1.18.4: November 14, 2023
4+
### Bug Fixes:
5+
* Fix 'Extract to function' not scrolling to and selecting the added header declaration. [#11676](https://github.com/microsoft/vscode-cpptools/issues/11676)
6+
* Fix the extension sometimes failing to activate with VS Code versions less than 1.18. [#11680](https://github.com/microsoft/vscode-cpptools/issues/11680)
7+
38
## Version 1.18.3: November 13, 2023
49
### New Features
510
* Add an 'Extract to function' (or member function) code action after selecting code. [#1162](https://github.com/microsoft/vscode-cpptools/issues/1162)

Extension/ThirdPartyNotices.txt

+126-28
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,29 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
332332
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
333333

334334

335+
---------------------------------------------------------
336+
337+
---------------------------------------------------------
338+
339+
webidl-conversions 3.0.1 - BSD-2-Clause
340+
https://github.com/jsdom/webidl-conversions#readme
341+
342+
Copyright (c) 2014, Domenic Denicola
343+
344+
# The BSD 2-Clause License
345+
346+
Copyright (c) 2014, Domenic Denicola
347+
All rights reserved.
348+
349+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
350+
351+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
352+
353+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
354+
355+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
356+
357+
335358
---------------------------------------------------------
336359

337360
---------------------------------------------------------
@@ -1173,34 +1196,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
11731196
THE SOFTWARE.
11741197

11751198

1176-
---------------------------------------------------------
1177-
1178-
---------------------------------------------------------
1179-
1180-
axios 1.6.1 - MIT
1181-
https://axios-http.com/
1182-
1183-
Copyright (c) 2014-present Matt Zabriskie & Collaborators
1184-
1185-
Permission is hereby granted, free of charge, to any person obtaining a copy
1186-
of this software and associated documentation files (the "Software"), to deal
1187-
in the Software without restriction, including without limitation the rights
1188-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1189-
copies of the Software, and to permit persons to whom the Software is
1190-
furnished to do so, subject to the following conditions:
1191-
1192-
The above copyright notice and this permission notice shall be included in
1193-
all copies or substantial portions of the Software.
1194-
1195-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1196-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1197-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1198-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1199-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1200-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1201-
THE SOFTWARE.
1202-
1203-
12041199
---------------------------------------------------------
12051200

12061201
---------------------------------------------------------
@@ -1233,6 +1228,25 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
12331228
SOFTWARE.
12341229

12351230

1231+
---------------------------------------------------------
1232+
1233+
---------------------------------------------------------
1234+
1235+
axios 1.6.1 - MIT
1236+
https://axios-http.com/
1237+
1238+
Copyright (c) 2023 Matt Zabriskie and contributors
1239+
Copyright (c) 2014-present Matt Zabriskie & Collaborators
1240+
1241+
# Copyright (c) 2014-present Matt Zabriskie & Collaborators
1242+
1243+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1244+
1245+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1246+
1247+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1248+
1249+
12361250
---------------------------------------------------------
12371251

12381252
---------------------------------------------------------
@@ -2235,6 +2249,39 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22352249
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22362250

22372251

2252+
---------------------------------------------------------
2253+
2254+
---------------------------------------------------------
2255+
2256+
node-fetch 2.7.0 - MIT
2257+
https://github.com/bitinn/node-fetch
2258+
2259+
Copyright (c) 2016 David Frank
2260+
2261+
The MIT License (MIT)
2262+
2263+
Copyright (c) 2016 David Frank
2264+
2265+
Permission is hereby granted, free of charge, to any person obtaining a copy
2266+
of this software and associated documentation files (the "Software"), to deal
2267+
in the Software without restriction, including without limitation the rights
2268+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2269+
copies of the Software, and to permit persons to whom the Software is
2270+
furnished to do so, subject to the following conditions:
2271+
2272+
The above copyright notice and this permission notice shall be included in all
2273+
copies or substantial portions of the Software.
2274+
2275+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2276+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2277+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2278+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2279+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2280+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2281+
SOFTWARE.
2282+
2283+
2284+
22382285
---------------------------------------------------------
22392286

22402287
---------------------------------------------------------
@@ -2716,6 +2763,24 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27162763
THE SOFTWARE.
27172764

27182765

2766+
---------------------------------------------------------
2767+
2768+
---------------------------------------------------------
2769+
2770+
tr46 0.0.3 - MIT
2771+
https://github.com/Sebmaster/tr46.js#readme
2772+
2773+
2774+
MIT License
2775+
2776+
Copyright (c) <year> <copyright holders>
2777+
2778+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
2779+
2780+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
2781+
2782+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2783+
27192784
---------------------------------------------------------
27202785

27212786
---------------------------------------------------------
@@ -2856,6 +2921,39 @@ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CON
28562921
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28572922

28582923

2924+
---------------------------------------------------------
2925+
2926+
---------------------------------------------------------
2927+
2928+
whatwg-url 5.0.0 - MIT
2929+
https://github.com/jsdom/whatwg-url#readme
2930+
2931+
(c) extraPathPercentEncodeSet.has
2932+
Copyright (c) 2015-2016 Sebastian Mayr
2933+
2934+
The MIT License (MIT)
2935+
2936+
Copyright (c) 2015–2016 Sebastian Mayr
2937+
2938+
Permission is hereby granted, free of charge, to any person obtaining a copy
2939+
of this software and associated documentation files (the "Software"), to deal
2940+
in the Software without restriction, including without limitation the rights
2941+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2942+
copies of the Software, and to permit persons to whom the Software is
2943+
furnished to do so, subject to the following conditions:
2944+
2945+
The above copyright notice and this permission notice shall be included in
2946+
all copies or substantial portions of the Software.
2947+
2948+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2949+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2950+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2951+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2952+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2953+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2954+
THE SOFTWARE.
2955+
2956+
28592957
---------------------------------------------------------
28602958

28612959
---------------------------------------------------------

Extension/package.json

+3-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.3-main",
5+
"version": "1.18.4-main",
66
"publisher": "ms-vscode",
77
"icon": "LanguageCCPP_color_128x.png",
88
"readme": "README.md",
@@ -6312,6 +6312,7 @@
63126312
"@types/mkdirp": "^0.5.2",
63136313
"@types/mocha": "^10.0.1",
63146314
"@types/node": "^18.11.9",
6315+
"@types/node-fetch": "^2.6.9",
63156316
"@types/plist": "^3.0.2",
63166317
"@types/semver": "^7.1.0",
63176318
"@types/shell-quote": "^1.7.1",
@@ -6359,6 +6360,7 @@
63596360
"glob": "^7.1.6",
63606361
"minimatch": "^3.0.5",
63616362
"mkdirp": "^0.5.5",
6363+
"node-fetch": "^2.6.9",
63626364
"node-loader": "^2.0.0",
63636365
"node-stream-zip": "^1.15.0",
63646366
"plist": "^3.0.5",

Extension/src/LanguageServer/client.ts

+35-15
Original file line numberDiff line numberDiff line change
@@ -3495,11 +3495,13 @@ export class DefaultClient implements Client {
34953495
}
34963496

34973497
let workspaceEdits: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
3498-
let replaceEditRange: vscode.Range | undefined;
3499-
let hasProcessedReplace: boolean = false;
3498+
35003499
// NOTE: References to source/header are in reference to the more common case when it's
35013500
// invoked on the source file (alternatively named the first file). When invoked on the header file,
35023501
// the header file operates as if it were the source file (isSourceFile stays true).
3502+
let sourceReplaceEditRange: vscode.Range | undefined;
3503+
let headerReplaceEditRange: vscode.Range | undefined;
3504+
let hasProcessedReplace: boolean = false;
35033505
const sourceFormatUriAndRanges: VsCodeUriAndRange[] = [];
35043506
const headerFormatUriAndRanges: VsCodeUriAndRange[] = [];
35053507
let lineOffset: number = 0;
@@ -3575,7 +3577,7 @@ export class DefaultClient implements Client {
35753577
} else {
35763578
headerFormatUriAndRanges.push({uri, range: newRange});
35773579
}
3578-
if (isReplace) {
3580+
if (isReplace || !isSourceFile) {
35793581
// Handle additional declaration lines added before the new function call.
35803582
let currentText: string = edit.newText.substring(rangeStartCharacter);
35813583
let currentTextNextLineStart: number = currentText.indexOf("\n");
@@ -3596,35 +3598,38 @@ export class DefaultClient implements Client {
35963598
"Extract to function failed. An invalid edit was generated: '{0}'", edit.newText)}`);
35973599
continue;
35983600
}
3599-
replaceEditRange = new vscode.Range(
3601+
const replaceEditRange = new vscode.Range(
36003602
new vscode.Position(rangeStartLine, rangeStartCharacter),
36013603
new vscode.Position(rangeStartLine, rangeStartCharacter + functionName.length));
3604+
if (isSourceFile) {
3605+
sourceReplaceEditRange = replaceEditRange;
3606+
} else {
3607+
headerReplaceEditRange = replaceEditRange;
3608+
}
36023609
nextLineOffset -= range.end.line - range.start.line;
36033610
}
36043611
}
36053612
}
36063613

3607-
if (replaceEditRange === undefined || sourceFormatUriAndRanges.length === 0) {
3614+
if (sourceReplaceEditRange === undefined || sourceFormatUriAndRanges.length === 0) {
36083615
return;
36093616
}
36103617

3611-
if (headerFormatUriAndRanges.length > 0) {
3618+
// Apply the extract to function text edits.
3619+
await vscode.workspace.applyEdit(workspaceEdits, { isRefactoring: true });
3620+
3621+
if (headerFormatUriAndRanges.length > 0 && headerReplaceEditRange !== undefined) {
36123622
// The header needs to be open and shown or the formatting will fail
36133623
// (due to issues/requirements in the cpptools process).
36143624
// It also seems strange and undesirable to have the header modified
36153625
// without being opened because otherwise users may not realize that
36163626
// the header had changed (unless they view source control differences).
3617-
await vscode.window.showTextDocument(headerFormatUriAndRanges[0].uri, { preserveFocus: true });
3627+
await vscode.window.showTextDocument(headerFormatUriAndRanges[0].uri, {
3628+
selection: headerReplaceEditRange, preserveFocus: false });
36183629
}
36193630

3620-
// Apply the extract to function text edits.
3621-
await vscode.workspace.applyEdit(workspaceEdits, { isRefactoring: true });
3622-
3623-
// Select the replaced code.
3624-
await vscode.window.showTextDocument(sourceFormatUriAndRanges[0].uri, { selection: replaceEditRange, preserveFocus: false });
3625-
36263631
// Format the new text edits.
3627-
const formatEdits: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
3632+
let formatEdits: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
36283633
const formatRanges = async (formatUriAndRanges: VsCodeUriAndRange[]) => {
36293634
if (formatUriAndRanges.length === 0) {
36303635
return;
@@ -3670,7 +3675,22 @@ export class DefaultClient implements Client {
36703675
}
36713676
};
36723677

3673-
await formatRanges(headerFormatUriAndRanges);
3678+
if (headerFormatUriAndRanges.length > 0 && headerReplaceEditRange !== undefined) {
3679+
await formatRanges(headerFormatUriAndRanges);
3680+
if (formatEdits.size > 0) {
3681+
// This showTextDocument is required in order to get the selection to be
3682+
// correct after the formatting edit is applied. It could be a VS Code bug.
3683+
await vscode.window.showTextDocument(headerFormatUriAndRanges[0].uri, {
3684+
selection: headerReplaceEditRange, preserveFocus: false });
3685+
await vscode.workspace.applyEdit(formatEdits, { isRefactoring: true });
3686+
formatEdits = new vscode.WorkspaceEdit();
3687+
}
3688+
}
3689+
3690+
// Select the replaced code.
3691+
await vscode.window.showTextDocument(sourceFormatUriAndRanges[0].uri, {
3692+
selection: sourceReplaceEditRange, preserveFocus: false });
3693+
36743694
await formatRanges(sourceFormatUriAndRanges);
36753695
if (formatEdits.size > 0) {
36763696
await vscode.workspace.applyEdit(formatEdits, { isRefactoring: true });

Extension/src/LanguageServer/extension.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
'use strict';
66

77
import * as fs from 'fs';
8+
// Node.js 18 fetch isn't available until VS 1.82.
9+
import fetch from 'node-fetch';
810
import * as StreamZip from 'node-stream-zip';
911
import * as os from 'os';
1012
import * as path from 'path';
@@ -1184,13 +1186,16 @@ export async function preReleaseCheck(): Promise<void> {
11841186
const response = await fetch('https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery', {
11851187
method: 'POST',
11861188
headers: {
1187-
Accept : 'application/json; api-version=3.0-preview',
1188-
'Content-Type' : 'application/json'
1189+
Accept: 'application/json; api-version=3.0-preview',
1190+
'Content-Type': 'application/json',
1191+
'User-Agent': 'vscode-cpptools'
11891192
},
11901193
body: '{"filters": [{"criteria": [{"filterType": 7, "value": "ms-vscode.cpptools"}]}], "flags": 529}'
11911194
}).catch(logAndReturn.undefined);
11921195

1193-
const data = await response?.json().catch(logAndReturn.undefined);
1196+
telemetry.logLanguageServerEvent("marketplaceFetch", undefined, { status: response?.status ?? 0 });
1197+
1198+
const data: any = await response?.json().catch(logAndReturn.undefined);
11941199

11951200
const preReleaseAvailable = data?.results[0].extensions[0].versions[0].properties.some((e: object) => Object.values(e).includes("Microsoft.VisualStudio.Code.PreRelease"));
11961201

Extension/yarn.lock

+15
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,14 @@
400400
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.1.tgz#2f4f65bb08bc368ac39c96da7b2f09140b26851b"
401401
integrity sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==
402402

403+
"@types/node-fetch@^2.6.9":
404+
version "2.6.9"
405+
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.9.tgz#15f529d247f1ede1824f7e7acdaa192d5f28071e"
406+
integrity sha512-bQVlnMLFJ2d35DkPNjEPmd9ueO/rh5EiaZt2bhqiSarPjZIuIV6bPQVqcrEyvNo+AfTrRGVazle1tl597w3gfA==
407+
dependencies:
408+
"@types/node" "*"
409+
form-data "^4.0.0"
410+
403411
"@types/node@*":
404412
version "20.4.1"
405413
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.4.1.tgz#a6033a8718653c50ac4962977e14d0f984d9527d"
@@ -3648,6 +3656,13 @@ node-fetch@^2.6.7:
36483656
dependencies:
36493657
whatwg-url "^5.0.0"
36503658

3659+
node-fetch@^2.6.9:
3660+
version "2.7.0"
3661+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
3662+
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
3663+
dependencies:
3664+
whatwg-url "^5.0.0"
3665+
36513666
node-loader@^2.0.0:
36523667
version "2.0.0"
36533668
resolved "https://registry.yarnpkg.com/node-loader/-/node-loader-2.0.0.tgz#9109a6d828703fd3e0aa03c1baec12a798071562"

0 commit comments

Comments
 (0)