From 99ee725674d3bbb7641a20f06c3e99c0788f14c5 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 10 Jan 2023 14:14:24 +0000 Subject: [PATCH] feat(vscode): enable JSON formatting (#4146) Co-authored-by: Superchupu <53496941+SuperchupuDev@users.noreply.github.com> Co-authored-by: Micha Reiser Co-authored-by: Micha Reiser --- crates/rome_fs/src/fs/os.rs | 2 +- editors/vscode/package-lock.json | 2 +- editors/vscode/package.json | 8 +++++--- npm/js-api/tests/formatContent.test.ts | 16 +++++++++++++++- npm/js-api/tsconfig.json | 3 ++- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/crates/rome_fs/src/fs/os.rs b/crates/rome_fs/src/fs/os.rs index eaac18bca21..391dc5ff1c0 100644 --- a/crates/rome_fs/src/fs/os.rs +++ b/crates/rome_fs/src/fs/os.rs @@ -259,7 +259,7 @@ fn handle_dir_entry<'scope>( if file_type.is_file() { if matches!( path.file_name().and_then(OsStr::to_str), - Some("package.json" | "package-lock.json" | "tsconfig.json") + Some("package.json" | "package-lock.json" | "tsconfig.json" | "jsconfig.json") ) { return; } diff --git a/editors/vscode/package-lock.json b/editors/vscode/package-lock.json index 85c2bca8e4f..67416e76acb 100644 --- a/editors/vscode/package-lock.json +++ b/editors/vscode/package-lock.json @@ -21,7 +21,7 @@ "vsce": "^2.11.0" }, "engines": { - "npm": "^8", + "npm": "^9", "vscode": "^1.70.0" } }, diff --git a/editors/vscode/package.json b/editors/vscode/package.json index 713df69cd28..6662276226e 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -10,19 +10,21 @@ "onLanguage:javascriptreact", "onLanguage:typescript", "onLanguage:typescriptreact", + "onLanguage:json", "onCommand:rome.syntaxTree" ], "main": "./out/main.js", "repository": { "type": "git", - "url": "https://github.com/rome/tools.git" + "url": "https://github.com/rome/tools.git", + "directory": "editors/vscode" }, "bugs": { "url": "https://github.com/rome/tools/issues" }, "engines": { "vscode": "^1.70.0", - "npm": "^8" + "npm": "^9" }, "capabilities": { "untrustedWorkspaces": { @@ -150,4 +152,4 @@ "resolve": "^1.22.1", "vscode-languageclient": "^8.0.2" } -} \ No newline at end of file +} diff --git a/npm/js-api/tests/formatContent.test.ts b/npm/js-api/tests/formatContent.test.ts index e6825ea2b72..43c9325cb3b 100644 --- a/npm/js-api/tests/formatContent.test.ts +++ b/npm/js-api/tests/formatContent.test.ts @@ -13,7 +13,7 @@ describe("Rome WebAssembly formatContent", () => { rome.shutdown(); }); - it("should format content", () => { + it("should format JavaScript content", () => { const result = rome.formatContent("function f () { }", { filePath: "example.js", }); @@ -22,6 +22,20 @@ describe("Rome WebAssembly formatContent", () => { expect(result.diagnostics).toEqual([]); }); + it("should format JSON content", () => { + const result = rome.formatContent( + '{ "lorem": "ipsum", "foo": false, "bar": 23, "lorem": "ipsum", "foo": false, "bar": 23 }', + { + filePath: "example.json", + }, + ); + + expect(result.content).toEqual( + '{\n\t"lorem": "ipsum",\n\t"foo": false,\n\t"bar": 23,\n\t"lorem": "ipsum",\n\t"foo": false,\n\t"bar": 23\n}\n', + ); + expect(result.diagnostics).toEqual([]); + }); + it("should not format and have diagnostics", () => { const content = "function () { }"; const result = rome.formatContent(content, { diff --git a/npm/js-api/tsconfig.json b/npm/js-api/tsconfig.json index b495ae47b1b..cfeaaa64b89 100644 --- a/npm/js-api/tsconfig.json +++ b/npm/js-api/tsconfig.json @@ -11,7 +11,8 @@ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ "strict": true, /* Enable all strict type-checking options. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "lib": ["ES2021"] }, "exclude": [ "./tests",