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

feat: add workspace initialization command #374

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
{
"title": "Biome: Troubleshoot - Reset",
"command": "biome.reset"
},
{
"title": "Biome: Initialize",
"command": "biome.initialize"
}
],
"configuration": {
Expand Down Expand Up @@ -191,7 +195,21 @@
"scopeName": "source.biome_syntax_tree",
"path": "./resources/grammars/biome-syntax-tree.tmGrammar.json"
}
]
],
"menus": {
"commandPalette": [
{
"command": "biome.initialize",
"when": "false"
}
],
"explorer/context": [
{
"command": "biome.initialize",
"when": "resourceFilename =~ /(\\.biome|biome.json|biome.jsonc)$/ || resourceFilename =~ /settings.json/"
}
]
}
},
"engines": {
"vscode": "^1.80.0"
Expand Down
50 changes: 49 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ConfigurationTarget, Uri, 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
*
Expand Down Expand Up @@ -51,3 +51,51 @@ export const resetCommand = async () => {
info("Biome extension was reset");
await start();
};

export const initializeCommand = async (args: Uri) => {
const subconfigs = [
"[javascript]",
"[typescript]",
"[typescriptreact]",
"[javascriptreact]",
"[json]",
"[jsonc]",
Comment on lines +57 to +62
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add vue, astro, svelte, css and graphql

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added it in as well

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ematipico If this means Biome will take precedence over the built-in extensions for vue/astro/svelte files, I'm not sure that's a great idea until support has progressed further and stabilized. I suspect anyone using these frameworks in earnest will prefer the official extensions at the moment, which means we'll need to document how to remove these lines from settings.json/.code-workspace (which is the kind of complexity that tends to intimidate new users).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a valid point, I left it generic in the beginning as I wasn't sure if I should add specific languages as well but yeah this is definitely something to think about from the maintainers side of view!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @colinhacks makes a good point here. We should only include languages for which we have full formatting support.

This would mean removing vue, svelte, and astro for now.

"[vue]",
"[astro]",
"[svelte]",
"[css]",
"[graphql]",
].join("");
nhedger marked this conversation as resolved.
Show resolved Hide resolved

// 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 },
{
name: "editor.codeActionsOnSave",
value: {
...config.get<object | undefined>(
"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.WorkspaceFolder,
);
}

info("Workspace configuration updated");
} catch (e) {}
};
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "vscode";
import {
downloadCommand,
initializeCommand,
resetCommand,
restartCommand,
startCommand,
Expand Down Expand Up @@ -52,6 +53,7 @@ const registerUserFacingCommands = () => {
commands.registerCommand("biome.restart", restartCommand),
commands.registerCommand("biome.download", downloadCommand),
commands.registerCommand("biome.reset", resetCommand),
commands.registerCommand("biome.initialize", initializeCommand),
);

info("User-facing commands registered");
Expand Down