Skip to content

Commit

Permalink
fix global session lifecycle (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhedger authored Oct 4, 2024
1 parent f9aa112 commit 7f290ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ export const isEnabled = (folder?: WorkspaceFolder) => {
return config("enabled", { default: true, scope: folder.uri }) === true;
};

/**
* Determines whether the extension is enabled globally
*
* This function determines whether the extension is enabled globally. This is
* useful to conditional enable or disable functionality based on the extension's
* configuration at the global/user level.
*/
export const isEnabledGlobally = (): boolean => {
return (
workspace.getConfiguration("biome").inspect<boolean>("enabled")
.globalValue === true
);
};

/**
* Determines whether a Biome configuration file is required in the given
* workspace folder for the extension to start.
Expand Down
11 changes: 9 additions & 2 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "vscode-languageclient/node";
import { displayName } from "../package.json";
import { findBiomeGlobally, findBiomeLocally } from "./binary-finder";
import { isEnabledGlobally } from "./config";
import { debug, error, info, error as logError, warn } from "./logger";
import { type Project, createProjects } from "./project";
import { state } from "./state";
Expand Down Expand Up @@ -170,14 +171,20 @@ export const createGlobalSessionWhenNecessary = async () => {

// If the editor has open Untitled documents, or VS Code User Data documents,
// we create a global session immeditaley so that the user can work with them.
if (hasUntitledDocuments() || hasVSCodeUserDataDocuments()) {
if (
isEnabledGlobally() &&
(hasUntitledDocuments() || hasVSCodeUserDataDocuments())
) {
await createGlobalSessionIfNotExists();
}

// Register a listener for text documents being opened so that we can create
// a global session if necessary.
workspace.onDidOpenTextDocument(async (document) => {
if (hasUntitledDocuments() || hasVSCodeUserDataDocuments()) {
if (
isEnabledGlobally() &&
(hasUntitledDocuments() || hasVSCodeUserDataDocuments())
) {
await createGlobalSessionIfNotExists();
}
});
Expand Down

0 comments on commit 7f290ae

Please sign in to comment.