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 Proposal: Check for biome config file on startup #274

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,21 @@ import { syntaxTree } from "./commands/syntaxTree";
import { selectAndDownload, updateToLatest } from "./downloader";
import { Session } from "./session";
import { StatusBar } from "./statusBar";
import { isMusl, setContextValue } from "./utils";
import { checkForBiomeJson, isMusl, setContextValue } from "./utils";

let client: LanguageClient;

const IN_BIOME_PROJECT = "inBiomeProject";

export async function activate(context: ExtensionContext) {

// Check if biome.json exists in the workspace.
const biomeJsonExists = await checkForBiomeJson();
if (!biomeJsonExists) {
window.showWarningMessage("Biome extension is disabled because biome.json is not found in the working directory.");
return;
}

// If the extension is disabled, abort the activation.
if (!workspace.getConfiguration("biome").get<boolean>("enabled", true)) {
return;
Expand Down
24 changes: 23 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawnSync } from "node:child_process";
import { type TextDocument, type TextEditor, commands } from "vscode";
import { type TextDocument, type TextEditor, commands, workspace, Uri } from "vscode";

const SUPPORTED_LANGUAGES = new Set(["javascript", "typescript"]);

Expand Down Expand Up @@ -50,3 +50,25 @@ export function isMusl() {
return false;
}
}

/**
* Checks if the current workspace has a biome.json or biome.jsonc file
* @returns boolean
*/
export async function checkForBiomeJson(): Promise<boolean> {
const folders = workspace.workspaceFolders;
if (!folders) return false;

for (const folder of folders) {
const biomeJsonPath = Uri.joinPath(folder.uri, "biome.json");
const biomeJsoncPath = Uri.joinPath(folder.uri, "biome.jsonc");

const biomeJsonExists = await workspace.fs.stat(biomeJsonPath.fsPath).then(() => true).catch(() => false);
const biomeJsoncExists = await workspace.fs.stat(biomeJsoncPath.fsPath).then(() => true).catch(() => false);

if (biomeJsonExists || biomeJsoncExists) {
return true;
}
}
return false;
}
Loading