Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a JSON parsing library for tasks.json #5954

Merged
merged 8 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,31 @@
"Snippets"
],
"activationEvents": [
"*"
"onLanguage:cpp",
sean-mcmanus marked this conversation as resolved.
Show resolved Hide resolved
"onLanguage:c",
"onCommand:extension.pickNativeProcess",
"onCommand:extension.pickRemoteNativeProcess",
"onCommand:C_Cpp.BuildAndDebugActiveFile",
"onCommand:C_Cpp.ConfigurationEditJSON",
"onCommand:C_Cpp.ConfigurationEditUI",
"onCommand:C_Cpp.ConfigurationSelect",
"onCommand:C_Cpp.ConfigurationProviderSelect",
"onCommand:C_Cpp.SwitchHeaderSource",
"onCommand:C_Cpp.EnableErrorSquiggles",
"onCommand:C_Cpp.DisableErrorSquiggles",
"onCommand:C_Cpp.ToggleIncludeFallback",
"onCommand:C_Cpp.ToggleDimInactiveRegions",
"onCommand:C_Cpp.ResetDatabase",
"onCommand:C_Cpp.TakeSurvey",
"onCommand:C_Cpp.LogDiagnostics",
"onCommand:C_Cpp.RescanWorkspace",
"onCommand:C_Cpp.VcpkgClipboardInstallSuggested",
"onCommand:C_Cpp.VcpkgClipboardOnlineHelpSuggested",
"onDebugInitialConfigurations",
"onDebugResolve:cppdbg",
"onDebugResolve:cppvsdbg",
"workspaceContains:/.vscode/c_cpp_properties.json",
"onFileSystem:cpptools-schema"
],
"main": "./dist/main",
"contributes": {
Expand Down Expand Up @@ -2219,6 +2243,7 @@
"@typescript-eslint/parser": "^2.19.2",
"async-child-process": "^1.1.1",
"await-notify": "^1.0.1",
"comment-json": "^3.0.3",
"escape-string-regexp": "^2.0.0",
"eslint": "^6.8.0",
"eslint-plugin-import": "^2.20.1",
Expand Down
6 changes: 3 additions & 3 deletions Extension/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { lookupString } from './nativeStrings';
import * as nls from 'vscode-nls';
import { Readable } from 'stream';
import { PackageManager, IPackage } from './packageManager';
import * as jsonc from 'comment-json';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
Expand Down Expand Up @@ -72,10 +73,9 @@ export function getRawTasksJson(): Promise<any> {
return resolve({});
}
let fileContents: string = fs.readFileSync(path).toString();
fileContents = fileContents.replace(/^\s*\/\/.*$/gm, ""); // Remove start of line // comments.
let rawTasks: any = {};
try {
rawTasks = JSON.parse(fileContents);
rawTasks = jsonc.parse(fileContents);
} catch (error) {
return reject(new Error(failedToParseTasksJson));
}
Expand Down Expand Up @@ -123,7 +123,7 @@ export async function ensureBuildTaskExists(taskName: string): Promise<void> {
throw new Error("Failed to get tasksJsonPath in ensureBuildTaskExists()");
}

await writeFileText(tasksJsonPath, JSON.stringify(rawTasksJson, null, settings.editorTabSize));
sean-mcmanus marked this conversation as resolved.
Show resolved Hide resolved
await writeFileText(tasksJsonPath, jsonc.stringify(rawTasksJson, null, settings.editorTabSize));
}

export function fileIsCOrCppSource(file: string): boolean {
Expand Down
19 changes: 17 additions & 2 deletions Extension/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,16 @@ commander@^2.12.1, commander@^2.20.0:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==

comment-json@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/comment-json/-/comment-json-3.0.3.tgz#0cadacd6278602b57b8c51b1814dc5d311d228c4"
integrity sha512-P7XwYkC3qjIK45EAa9c5Y3lR7SMXhJqwFdWg3niAIAcbk3zlpKDdajV8Hyz/Y3sGNn3l+YNMl8A2N/OubSArHg==
dependencies:
core-util-is "^1.0.2"
esprima "^4.0.1"
has-own-prop "^2.0.0"
repeat-string "^1.6.1"

comment-parser@^0.7.2:
version "0.7.2"
resolved "https://registry.yarnpkg.com/comment-parser/-/comment-parser-0.7.2.tgz#baf6d99b42038678b81096f15b630d18142f4b8a"
Expand Down Expand Up @@ -1330,7 +1340,7 @@ core-js@^2.4.0:
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.11.tgz#38831469f9922bded8ee21c9dc46985e0399308c"
integrity sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==

core-util-is@~1.0.0:
core-util-is@^1.0.2, core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
Expand Down Expand Up @@ -1911,7 +1921,7 @@ espree@^6.1.2:
acorn-jsx "^5.1.0"
eslint-visitor-keys "^1.1.0"

esprima@^4.0.0:
esprima@^4.0.0, esprima@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==
Expand Down Expand Up @@ -2632,6 +2642,11 @@ has-flag@^4.0.0:
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==

has-own-prop@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/has-own-prop/-/has-own-prop-2.0.0.tgz#f0f95d58f65804f5d218db32563bb85b8e0417af"
integrity sha512-Pq0h+hvsVm6dDEa8x82GnLSYHOzNDt7f0ddFa3FqcQlgzEiptPqL+XrOJNavjOzSYiYWIrgeVYYgGlLmnxwilQ==

has-symbols@^1.0.0, has-symbols@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.1.tgz#9f5214758a44196c406d9bd76cebf81ec2dd31e8"
Expand Down