Skip to content

Commit 8bf5d6e

Browse files
authored
Address some issues where spread operator was used but deep copy needed (#10803)
1 parent 6fbf4df commit 8bf5d6e

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

Extension/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6004,8 +6004,8 @@
60046004
"@types/node": "^14.14.0",
60056005
"@types/plist": "^3.0.2",
60066006
"@types/semver": "^7.1.0",
6007-
"@types/tmp": "^0.1.0",
60086007
"@types/shell-quote": "^1.7.1",
6008+
"@types/tmp": "^0.1.0",
60096009
"@types/which": "^1.3.2",
60106010
"@types/yauzl": "^2.9.1",
60116011
"@typescript-eslint/eslint-plugin": "^4.31.1",
@@ -6043,12 +6043,14 @@
60436043
"xml2js": "^0.5.0"
60446044
},
60456045
"dependencies": {
6046+
"@types/lodash": "^4.14.192",
60466047
"@vscode/extension-telemetry": "^0.6.2",
60476048
"chokidar": "^3.5.3",
60486049
"comment-json": "^4.1.1",
60496050
"editorconfig": "^0.15.3",
60506051
"escape-string-regexp": "^2.0.0",
60516052
"glob": "^7.1.6",
6053+
"lodash": "^4.17.21",
60526054
"minimatch": "^3.0.5",
60536055
"mkdirp": "^0.5.5",
60546056
"node-loader": "^2.0.0",
@@ -6084,4 +6086,4 @@
60846086
"yargs-parser": "^15.0.1",
60856087
"y18n": "^5.0.5"
60866088
}
6087-
}
6089+
}

Extension/src/LanguageServer/client.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ import {
5151
removeCodeAnalysisProblems, RemoveCodeAnalysisProblemsParams
5252
} from './codeAnalysis';
5353
import { DebugProtocolParams, getDiagnosticsChannel, getOutputChannelLogger, logDebugProtocol, Logger, logLocalized, showWarning, ShowWarningParams } from '../logger';
54+
import _ = require('lodash');
5455

56+
const deepCopy = (obj: any) => _.cloneDeep(obj);
5557
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
5658
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
5759

@@ -2755,7 +2757,7 @@ export class DefaultClient implements Client {
27552757
// Clone each entry, as we make modifications before sending it, and don't
27562758
// want to add those modifications to the original objects.
27572759
configurations.forEach((c) => {
2758-
const modifiedConfig: configs.Configuration = { ...c };
2760+
const modifiedConfig: configs.Configuration = deepCopy(c);
27592761
// Separate compiler path and args before sending to language client
27602762
const compilerPathAndArgs: util.CompilerPathAndArgs =
27612763
util.extractCompilerPathAndArgs(!!settings.legacyCompilerArgsBehavior, c.compilerPath, c.compilerArgs);
@@ -2868,7 +2870,7 @@ export class DefaultClient implements Client {
28682870
console.warn("custom include paths should not use recursive includes ('**')");
28692871
}
28702872
// Separate compiler path and args before sending to language client
2871-
const itemConfig: util.Mutable<InternalSourceFileConfiguration> = { ...item.configuration };
2873+
const itemConfig: util.Mutable<InternalSourceFileConfiguration> = deepCopy(item.configuration);
28722874
if (util.isString(itemConfig.compilerPath)) {
28732875
const compilerPathAndArgs: util.CompilerPathAndArgs = util.extractCompilerPathAndArgs(
28742876
providerVersion < Version.v6,
@@ -2946,7 +2948,8 @@ export class DefaultClient implements Client {
29462948
return;
29472949
}
29482950

2949-
sanitized = { ...<InternalWorkspaceBrowseConfiguration>config };
2951+
const browseConfig: InternalWorkspaceBrowseConfiguration = <InternalWorkspaceBrowseConfiguration>config;
2952+
sanitized = deepCopy(browseConfig);
29502953
if (!this.isWorkspaceBrowseConfiguration(sanitized)) {
29512954
console.log("Received an invalid browse configuration from configuration provider: " + JSON.stringify(sanitized));
29522955
const configValue: WorkspaceBrowseConfiguration | undefined = this.lastCustomBrowseConfiguration.Value;

Extension/src/LanguageServer/settingsPanel.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import * as util from '../common';
1111
import * as config from './configurations';
1212
import * as telemetry from '../telemetry';
1313
import { getLocalizedHtmlPath } from './localization';
14+
import _ = require('lodash');
15+
16+
const deepCopy = (obj: any) => _.cloneDeep(obj);
1417

1518
// TODO: share ElementId between SettingsPanel and SettingsApp. Investigate why SettingsApp cannot import/export
1619
const elementId: { [key: string]: string } = {
@@ -220,7 +223,7 @@ export class SettingsPanel {
220223
}
221224

222225
private updateWebview(configSelection: string[], configuration: config.Configuration, errors: config.ConfigurationErrors | null): void {
223-
this.configValues = {...configuration}; // Copy configuration values
226+
this.configValues = deepCopy(configuration); // Copy configuration values
224227
this.isIntelliSenseModeDefined = (this.configValues.intelliSenseMode !== undefined);
225228
if (this.panel && this.initialized) {
226229
this.panel.webview.postMessage({ command: 'setKnownCompilers', compilers: this.compilerPaths });

Extension/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@
361361
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
362362
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
363363

364+
"@types/lodash@^4.14.192":
365+
version "4.14.192"
366+
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.192.tgz#5790406361a2852d332d41635d927f1600811285"
367+
integrity sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==
368+
364369
"@types/minimatch@*", "@types/minimatch@^3.0.5":
365370
version "3.0.5"
366371
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"

0 commit comments

Comments
 (0)