Skip to content

Commit a68ca3b

Browse files
authored
fix: only start global session once (#744)
1 parent c95f083 commit a68ca3b

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

src/biome.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ export default class Biome {
185185
* Starts the Biome instance.
186186
*/
187187
public async start() {
188+
if (this._session && this.state !== "error") {
189+
return; // Avoid starting the same session multiple times.
190+
}
191+
188192
this.listenForLockfilesChanges();
189193
this.listenForConfigChanges();
190194

@@ -213,12 +217,6 @@ export default class Biome {
213217
this.singleFileFolder,
214218
);
215219

216-
if (!this._session) {
217-
this.state = "error";
218-
this.logger.error("Unable to create the Biome session.");
219-
return;
220-
}
221-
222220
try {
223221
await this._session?.start();
224222
this.logger.info("✅ Biome is ready.");

src/extension.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ export default class Extension {
110110
* Creates the extension from the context
111111
*/
112112
public static create(context: ExtensionContext): Extension {
113-
return Extension.instance ?? new Extension(context);
113+
Extension.instance ??= new Extension(context);
114+
return Extension.instance;
114115
}
115116

116117
/**
@@ -293,7 +294,10 @@ export default class Extension {
293294
private async createGlobalInstance(): Promise<void> {
294295
const createGlobalInstanceIfNotExists = async () => {
295296
if (!this.biomes.get("global")) {
296-
this.biomes.set("global", Biome.createGlobalInstance(this));
297+
const biome = Biome.createGlobalInstance(this);
298+
biome.start();
299+
300+
this.biomes.set("global", biome);
297301
}
298302
};
299303

@@ -343,8 +347,7 @@ export default class Extension {
343347
window.onDidChangeActiveTextEditor(
344348
debounce(async (editor?: TextEditor) => {
345349
await createGlobalInstanceIfNeeded(editor);
346-
await this.biomes.get("global")?.start();
347-
}, 0),
350+
}, 10),
348351
);
349352
}
350353

src/session.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ export default class Session {
7272
this.client = undefined;
7373
}
7474

75-
/**
76-
* Restarts the LSP session.
77-
*/
78-
public async restart() {
79-
await this.stop();
80-
await this.start();
81-
}
82-
8375
/**
8476
* Creates a new language client for the session.
8577
*/

0 commit comments

Comments
 (0)