From 9804a42c1f10b6ddd319e3d994746bd6f9e6b871 Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Wed, 2 Oct 2024 15:45:28 +0200 Subject: [PATCH 1/7] feature: Add initialize project command --- package.json | 14 +++++++++++++- src/commands.ts | 44 +++++++++++++++++++++++++++++++++++++++++++- src/extension.ts | 5 +++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2752a591..996b49a4 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,10 @@ { "title": "Biome: Troubleshoot - Reset", "command": "biome.reset" + }, + { + "title": "Biome: Initialize Workspace", + "command": "biome.initializeWorkspace" } ], "configuration": { @@ -191,7 +195,15 @@ "scopeName": "source.biome_syntax_tree", "path": "./resources/grammars/biome-syntax-tree.tmGrammar.json" } - ] + ], + "menus": { + "explorer/context": [ + { + "command": "biome.initializeWorkspace", + "when": "resourceFilename =~ /(\\.biome|biome.json|biome.jsonc)$/ || resourceFilename =~ /settings.json/" + } + ] + } }, "engines": { "vscode": "^1.80.0" diff --git a/src/commands.ts b/src/commands.ts index 9ef44a2b..4c0bbafb 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,9 +1,9 @@ +import { ConfigurationTarget, workspace } from "vscode"; import { downloadBiome } from "./downloader"; import { restart, start, stop } from "./lifecycle"; import { info } from "./logger"; import { state } from "./state"; import { clearTemporaryBinaries } from "./utils"; - /** * Starts the Biome extension * @@ -51,3 +51,45 @@ export const resetCommand = async () => { info("Biome extension was reset"); await start(); }; + +export const initializeWorkspaceCommand = async () => { + const subconfigs = [ + "[javascript]", + "[typescript]", + "[typescriptreact]", + "[javascriptreact]", + "[json]", + "[jsonc]", + ].join(""); + + // Get the root workspace configuration + const config = workspace.getConfiguration(); + try { + // Set biome to enabled + await config.update( + "biome.enabled", + true, + ConfigurationTarget.Workspace, + ); + + await config.update("editor.codeActionsOnSave", { + ...config.get("editor.codeActionsOnSave"), + "source.organizeImports.biome": "always", + "quickfix.biome": "always", + }); + + // Set it to default formatter + await config.update( + "editor.defaultFormatter", + "biomejs.biome", + ConfigurationTarget.Workspace, + ); + // Set it to default formatter for all languages it supports + await config.update( + `${subconfigs}`, + { "editor.defaultFormatter": "biomejs.biome" }, + ConfigurationTarget.Workspace, + ); + info("Workspace configuration updated"); + } catch (e) {} +}; diff --git a/src/extension.ts b/src/extension.ts index e6f5607c..4723a938 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,6 +6,7 @@ import { } from "vscode"; import { downloadCommand, + initializeWorkspaceCommand, resetCommand, restartCommand, startCommand, @@ -52,6 +53,10 @@ const registerUserFacingCommands = () => { commands.registerCommand("biome.restart", restartCommand), commands.registerCommand("biome.download", downloadCommand), commands.registerCommand("biome.reset", resetCommand), + commands.registerCommand( + "biome.initializeWorkspace", + initializeWorkspaceCommand, + ), ); info("User-facing commands registered"); From 4dfff1a4e2dada57f992936e78bcd9602cada4ad Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Wed, 2 Oct 2024 16:03:49 +0200 Subject: [PATCH 2/7] chore: update config generation --- src/commands.ts | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index 4c0bbafb..59b0ddc9 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -65,31 +65,28 @@ export const initializeWorkspaceCommand = async () => { // Get the root workspace configuration const config = workspace.getConfiguration(); try { - // Set biome to enabled - await config.update( - "biome.enabled", - true, - ConfigurationTarget.Workspace, - ); + const configsToUpdate = [ + { name: "biome.enabled", value: true }, + { + name: "editor.codeActionsOnSave", + value: { + ...config.get( + "editor.codeActionsOnSave", + ), + "source.organizeImports.biome": "always", + "quickfix.biome": "always", + }, + }, + { name: "editor.defaultFormatter", value: "biomejs.biome" }, + { + name: `${subconfigs}`, + value: { "editor.defaultFormatter": "biomejs.biome" }, + }, + ]; + for (const { name, value } of configsToUpdate) { + await config.update(name, value, ConfigurationTarget.Workspace); + } - await config.update("editor.codeActionsOnSave", { - ...config.get("editor.codeActionsOnSave"), - "source.organizeImports.biome": "always", - "quickfix.biome": "always", - }); - - // Set it to default formatter - await config.update( - "editor.defaultFormatter", - "biomejs.biome", - ConfigurationTarget.Workspace, - ); - // Set it to default formatter for all languages it supports - await config.update( - `${subconfigs}`, - { "editor.defaultFormatter": "biomejs.biome" }, - ConfigurationTarget.Workspace, - ); info("Workspace configuration updated"); } catch (e) {} }; From d52af399c70b7b6a1aaab8b93d26ea25a29b4414 Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Wed, 2 Oct 2024 18:25:52 +0200 Subject: [PATCH 3/7] chore: fix workspace settings and add missing file parsers --- package.json | 2 +- src/commands.ts | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 996b49a4..28a25318 100644 --- a/package.json +++ b/package.json @@ -200,7 +200,7 @@ "explorer/context": [ { "command": "biome.initializeWorkspace", - "when": "resourceFilename =~ /(\\.biome|biome.json|biome.jsonc)$/ || resourceFilename =~ /settings.json/" + "when": "resourceFilename =~ /(\\.biome|biome.json|biome.jsonc)$/ || resourceFilename =~ /settings.json/ || resourceFilename =~ /.code-workspace/" } ] } diff --git a/src/commands.ts b/src/commands.ts index 59b0ddc9..e92d4837 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,4 +1,4 @@ -import { ConfigurationTarget, workspace } from "vscode"; +import { ConfigurationTarget, Uri, workspace } from "vscode"; import { downloadBiome } from "./downloader"; import { restart, start, stop } from "./lifecycle"; import { info } from "./logger"; @@ -52,7 +52,7 @@ export const resetCommand = async () => { await start(); }; -export const initializeWorkspaceCommand = async () => { +export const initializeWorkspaceCommand = async (args: { path: string }) => { const subconfigs = [ "[javascript]", "[typescript]", @@ -60,10 +60,15 @@ export const initializeWorkspaceCommand = async () => { "[javascriptreact]", "[json]", "[jsonc]", + "[vue]", + "[astro]", + "[svelte]", + "[css]", + "[graphql]", ].join(""); - // Get the root workspace configuration - const config = workspace.getConfiguration(); + // Scopes the config down to the current workspace folder + const config = workspace.getConfiguration(undefined, Uri.parse(args.path)); try { const configsToUpdate = [ { name: "biome.enabled", value: true }, @@ -84,7 +89,11 @@ export const initializeWorkspaceCommand = async () => { }, ]; for (const { name, value } of configsToUpdate) { - await config.update(name, value, ConfigurationTarget.Workspace); + await config.update( + name, + value, + ConfigurationTarget.WorkspaceFolder, + ); } info("Workspace configuration updated"); From 555437797a5b9820f17ec12c49a1e00c7807b260 Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Wed, 2 Oct 2024 19:06:00 +0200 Subject: [PATCH 4/7] fix: revert .code-workspace --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 28a25318..996b49a4 100644 --- a/package.json +++ b/package.json @@ -200,7 +200,7 @@ "explorer/context": [ { "command": "biome.initializeWorkspace", - "when": "resourceFilename =~ /(\\.biome|biome.json|biome.jsonc)$/ || resourceFilename =~ /settings.json/ || resourceFilename =~ /.code-workspace/" + "when": "resourceFilename =~ /(\\.biome|biome.json|biome.jsonc)$/ || resourceFilename =~ /settings.json/" } ] } From 80d9db6ad03812a8e8b290f69b1ebc03ba200af2 Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Wed, 2 Oct 2024 19:11:44 +0200 Subject: [PATCH 5/7] fix: fix types --- src/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands.ts b/src/commands.ts index e92d4837..a8f40c65 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -52,7 +52,7 @@ export const resetCommand = async () => { await start(); }; -export const initializeWorkspaceCommand = async (args: { path: string }) => { +export const initializeWorkspaceCommand = async (args: Uri) => { const subconfigs = [ "[javascript]", "[typescript]", From 8bd30854701ca611c56a3436f82c4a45bd1cc033 Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Thu, 3 Oct 2024 10:07:30 +0200 Subject: [PATCH 6/7] fix: rename the function --- package.json | 6 +++--- src/commands.ts | 2 +- src/extension.ts | 7 ++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 996b49a4..eb21aca9 100644 --- a/package.json +++ b/package.json @@ -54,8 +54,8 @@ "command": "biome.reset" }, { - "title": "Biome: Initialize Workspace", - "command": "biome.initializeWorkspace" + "title": "Biome: Initialize", + "command": "biome.initialize" } ], "configuration": { @@ -199,7 +199,7 @@ "menus": { "explorer/context": [ { - "command": "biome.initializeWorkspace", + "command": "biome.initialize", "when": "resourceFilename =~ /(\\.biome|biome.json|biome.jsonc)$/ || resourceFilename =~ /settings.json/" } ] diff --git a/src/commands.ts b/src/commands.ts index a8f40c65..3166d4ee 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -52,7 +52,7 @@ export const resetCommand = async () => { await start(); }; -export const initializeWorkspaceCommand = async (args: Uri) => { +export const initializeCommand = async (args: Uri) => { const subconfigs = [ "[javascript]", "[typescript]", diff --git a/src/extension.ts b/src/extension.ts index 4723a938..ef59c58f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,7 +6,7 @@ import { } from "vscode"; import { downloadCommand, - initializeWorkspaceCommand, + initializeCommand, resetCommand, restartCommand, startCommand, @@ -53,10 +53,7 @@ const registerUserFacingCommands = () => { commands.registerCommand("biome.restart", restartCommand), commands.registerCommand("biome.download", downloadCommand), commands.registerCommand("biome.reset", resetCommand), - commands.registerCommand( - "biome.initializeWorkspace", - initializeWorkspaceCommand, - ), + commands.registerCommand("biome.initialize", initializeCommand), ); info("User-facing commands registered"); From a104d79687e19e0cf53d237eea37b90281c0108f Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Tue, 17 Dec 2024 19:37:43 +0100 Subject: [PATCH 7/7] chore: Hide the biome init command from the command palette --- package.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package.json b/package.json index ea88ef13..b5ad5b2f 100644 --- a/package.json +++ b/package.json @@ -197,6 +197,12 @@ } ], "menus": { + "commandPalette": [ + { + "command": "biome.initialize", + "when": "false" + } + ], "explorer/context": [ { "command": "biome.initialize",