Skip to content

Commit

Permalink
Merge pull request #11687 from microsoft/main
Browse files Browse the repository at this point in the history
Merge for 1.18.4
  • Loading branch information
sean-mcmanus authored Nov 15, 2023
2 parents e896231 + 7cb9f88 commit 4ba260c
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 47 deletions.
5 changes: 5 additions & 0 deletions Extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# C/C++ for Visual Studio Code Changelog

## Version 1.18.4: November 14, 2023
### Bug Fixes:
* Fix 'Extract to function' not scrolling to and selecting the added header declaration. [#11676](https://github.com/microsoft/vscode-cpptools/issues/11676)
* Fix the extension sometimes failing to activate with VS Code versions less than 1.18. [#11680](https://github.com/microsoft/vscode-cpptools/issues/11680)

## Version 1.18.3: November 13, 2023
### New Features
* Add an 'Extract to function' (or member function) code action after selecting code. [#1162](https://github.com/microsoft/vscode-cpptools/issues/1162)
Expand Down
154 changes: 126 additions & 28 deletions Extension/ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,29 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


---------------------------------------------------------

---------------------------------------------------------

webidl-conversions 3.0.1 - BSD-2-Clause
https://github.com/jsdom/webidl-conversions#readme

Copyright (c) 2014, Domenic Denicola

# The BSD 2-Clause License

Copyright (c) 2014, Domenic Denicola
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

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.

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.


---------------------------------------------------------

---------------------------------------------------------
Expand Down Expand Up @@ -1173,34 +1196,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


---------------------------------------------------------

---------------------------------------------------------

axios 1.6.1 - MIT
https://axios-http.com/

Copyright (c) 2014-present Matt Zabriskie & Collaborators

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:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

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.


---------------------------------------------------------

---------------------------------------------------------
Expand Down Expand Up @@ -1233,6 +1228,25 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


---------------------------------------------------------

---------------------------------------------------------

axios 1.6.1 - MIT
https://axios-http.com/

Copyright (c) 2023 Matt Zabriskie and contributors
Copyright (c) 2014-present Matt Zabriskie & Collaborators

# Copyright (c) 2014-present Matt Zabriskie & Collaborators

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.


---------------------------------------------------------

---------------------------------------------------------
Expand Down Expand Up @@ -2235,6 +2249,39 @@ 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.


---------------------------------------------------------

---------------------------------------------------------

node-fetch 2.7.0 - MIT
https://github.com/bitinn/node-fetch

Copyright (c) 2016 David Frank

The MIT License (MIT)

Copyright (c) 2016 David Frank

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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.



---------------------------------------------------------

---------------------------------------------------------
Expand Down Expand Up @@ -2716,6 +2763,24 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


---------------------------------------------------------

---------------------------------------------------------

tr46 0.0.3 - MIT
https://github.com/Sebmaster/tr46.js#readme


MIT License

Copyright (c) <year> <copyright holders>

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.

---------------------------------------------------------

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


---------------------------------------------------------

---------------------------------------------------------

whatwg-url 5.0.0 - MIT
https://github.com/jsdom/whatwg-url#readme

(c) extraPathPercentEncodeSet.has
Copyright (c) 2015-2016 Sebastian Mayr

The MIT License (MIT)

Copyright (c) 2015–2016 Sebastian Mayr

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:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

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.


---------------------------------------------------------

---------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cpptools",
"displayName": "C/C++",
"description": "C/C++ IntelliSense, debugging, and code browsing.",
"version": "1.18.3-main",
"version": "1.18.4-main",
"publisher": "ms-vscode",
"icon": "LanguageCCPP_color_128x.png",
"readme": "README.md",
Expand Down Expand Up @@ -6312,6 +6312,7 @@
"@types/mkdirp": "^0.5.2",
"@types/mocha": "^10.0.1",
"@types/node": "^18.11.9",
"@types/node-fetch": "^2.6.9",
"@types/plist": "^3.0.2",
"@types/semver": "^7.1.0",
"@types/shell-quote": "^1.7.1",
Expand Down Expand Up @@ -6359,6 +6360,7 @@
"glob": "^7.1.6",
"minimatch": "^3.0.5",
"mkdirp": "^0.5.5",
"node-fetch": "^2.6.9",
"node-loader": "^2.0.0",
"node-stream-zip": "^1.15.0",
"plist": "^3.0.5",
Expand Down
50 changes: 35 additions & 15 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3495,11 +3495,13 @@ export class DefaultClient implements Client {
}

let workspaceEdits: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
let replaceEditRange: vscode.Range | undefined;
let hasProcessedReplace: boolean = false;

// NOTE: References to source/header are in reference to the more common case when it's
// invoked on the source file (alternatively named the first file). When invoked on the header file,
// the header file operates as if it were the source file (isSourceFile stays true).
let sourceReplaceEditRange: vscode.Range | undefined;
let headerReplaceEditRange: vscode.Range | undefined;
let hasProcessedReplace: boolean = false;
const sourceFormatUriAndRanges: VsCodeUriAndRange[] = [];
const headerFormatUriAndRanges: VsCodeUriAndRange[] = [];
let lineOffset: number = 0;
Expand Down Expand Up @@ -3575,7 +3577,7 @@ export class DefaultClient implements Client {
} else {
headerFormatUriAndRanges.push({uri, range: newRange});
}
if (isReplace) {
if (isReplace || !isSourceFile) {
// Handle additional declaration lines added before the new function call.
let currentText: string = edit.newText.substring(rangeStartCharacter);
let currentTextNextLineStart: number = currentText.indexOf("\n");
Expand All @@ -3596,35 +3598,38 @@ export class DefaultClient implements Client {
"Extract to function failed. An invalid edit was generated: '{0}'", edit.newText)}`);
continue;
}
replaceEditRange = new vscode.Range(
const replaceEditRange = new vscode.Range(
new vscode.Position(rangeStartLine, rangeStartCharacter),
new vscode.Position(rangeStartLine, rangeStartCharacter + functionName.length));
if (isSourceFile) {
sourceReplaceEditRange = replaceEditRange;
} else {
headerReplaceEditRange = replaceEditRange;
}
nextLineOffset -= range.end.line - range.start.line;
}
}
}

if (replaceEditRange === undefined || sourceFormatUriAndRanges.length === 0) {
if (sourceReplaceEditRange === undefined || sourceFormatUriAndRanges.length === 0) {
return;
}

if (headerFormatUriAndRanges.length > 0) {
// Apply the extract to function text edits.
await vscode.workspace.applyEdit(workspaceEdits, { isRefactoring: true });

if (headerFormatUriAndRanges.length > 0 && headerReplaceEditRange !== undefined) {
// The header needs to be open and shown or the formatting will fail
// (due to issues/requirements in the cpptools process).
// It also seems strange and undesirable to have the header modified
// without being opened because otherwise users may not realize that
// the header had changed (unless they view source control differences).
await vscode.window.showTextDocument(headerFormatUriAndRanges[0].uri, { preserveFocus: true });
await vscode.window.showTextDocument(headerFormatUriAndRanges[0].uri, {
selection: headerReplaceEditRange, preserveFocus: false });
}

// Apply the extract to function text edits.
await vscode.workspace.applyEdit(workspaceEdits, { isRefactoring: true });

// Select the replaced code.
await vscode.window.showTextDocument(sourceFormatUriAndRanges[0].uri, { selection: replaceEditRange, preserveFocus: false });

// Format the new text edits.
const formatEdits: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
let formatEdits: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
const formatRanges = async (formatUriAndRanges: VsCodeUriAndRange[]) => {
if (formatUriAndRanges.length === 0) {
return;
Expand Down Expand Up @@ -3670,7 +3675,22 @@ export class DefaultClient implements Client {
}
};

await formatRanges(headerFormatUriAndRanges);
if (headerFormatUriAndRanges.length > 0 && headerReplaceEditRange !== undefined) {
await formatRanges(headerFormatUriAndRanges);
if (formatEdits.size > 0) {
// This showTextDocument is required in order to get the selection to be
// correct after the formatting edit is applied. It could be a VS Code bug.
await vscode.window.showTextDocument(headerFormatUriAndRanges[0].uri, {
selection: headerReplaceEditRange, preserveFocus: false });
await vscode.workspace.applyEdit(formatEdits, { isRefactoring: true });
formatEdits = new vscode.WorkspaceEdit();
}
}

// Select the replaced code.
await vscode.window.showTextDocument(sourceFormatUriAndRanges[0].uri, {
selection: sourceReplaceEditRange, preserveFocus: false });

await formatRanges(sourceFormatUriAndRanges);
if (formatEdits.size > 0) {
await vscode.workspace.applyEdit(formatEdits, { isRefactoring: true });
Expand Down
11 changes: 8 additions & 3 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
'use strict';

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

const data = await response?.json().catch(logAndReturn.undefined);
telemetry.logLanguageServerEvent("marketplaceFetch", undefined, { status: response?.status ?? 0 });

const data: any = await response?.json().catch(logAndReturn.undefined);

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

Expand Down
15 changes: 15 additions & 0 deletions Extension/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,14 @@
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.1.tgz#2f4f65bb08bc368ac39c96da7b2f09140b26851b"
integrity sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==

"@types/node-fetch@^2.6.9":
version "2.6.9"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.9.tgz#15f529d247f1ede1824f7e7acdaa192d5f28071e"
integrity sha512-bQVlnMLFJ2d35DkPNjEPmd9ueO/rh5EiaZt2bhqiSarPjZIuIV6bPQVqcrEyvNo+AfTrRGVazle1tl597w3gfA==
dependencies:
"@types/node" "*"
form-data "^4.0.0"

"@types/node@*":
version "20.4.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.4.1.tgz#a6033a8718653c50ac4962977e14d0f984d9527d"
Expand Down Expand Up @@ -3648,6 +3656,13 @@ node-fetch@^2.6.7:
dependencies:
whatwg-url "^5.0.0"

node-fetch@^2.6.9:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
dependencies:
whatwg-url "^5.0.0"

node-loader@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/node-loader/-/node-loader-2.0.0.tgz#9109a6d828703fd3e0aa03c1baec12a798071562"
Expand Down

0 comments on commit 4ba260c

Please sign in to comment.