From 703e2fec93d67b0123115df60ad52888a16960b9 Mon Sep 17 00:00:00 2001 From: shulaoda Date: Sat, 28 Sep 2024 11:30:04 +0800 Subject: [PATCH] fmt --- editors/vscode/.prettierrc | 3 + editors/vscode/client/extension.ts | 93 ++++++++++++++---------------- 2 files changed, 47 insertions(+), 49 deletions(-) diff --git a/editors/vscode/.prettierrc b/editors/vscode/.prettierrc index e69de29bb2d1d6..544138be45652a 100644 --- a/editors/vscode/.prettierrc +++ b/editors/vscode/.prettierrc @@ -0,0 +1,3 @@ +{ + "singleQuote": true +} diff --git a/editors/vscode/client/extension.ts b/editors/vscode/client/extension.ts index 67a702c5eaa015..ffb3c79c942f91 100644 --- a/editors/vscode/client/extension.ts +++ b/editors/vscode/client/extension.ts @@ -1,4 +1,4 @@ -import { existsSync } from "node:fs"; +import { existsSync } from 'node:fs'; import { commands, @@ -9,28 +9,23 @@ import { ThemeColor, window, workspace, -} from "vscode"; +} from 'vscode'; -import { - Executable, - LanguageClient, - LanguageClientOptions, - ServerOptions, -} from "vscode-languageclient/node"; +import { Executable, LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node'; -import { join } from "node:path"; +import { join } from 'node:path'; -const languageClientId = "oxc-vscode"; -const languageClientName = "oxc"; -const outputChannelName = "oxc_language_server"; -const traceOutputChannelName = "oxc_language_server.trace"; +const languageClientId = 'oxc-vscode'; +const languageClientName = 'oxc'; +const outputChannelName = 'oxc_language_server'; +const traceOutputChannelName = 'oxc_language_server.trace'; const enum OxcCommands { - RestartServer = "oxc.restartServer", - ApplyAllFixes = "oxc.applyAllFixes", - ShowOutputChannel = "oxc.showOutputChannel", - ShowTraceOutputChannel = "oxc.showTraceOutputChannel", - ToggleEnable = "oxc.toggleEnable", + RestartServer = 'oxc.restartServer', + ApplyAllFixes = 'oxc.applyAllFixes', + ShowOutputChannel = 'oxc.showOutputChannel', + ShowTraceOutputChannel = 'oxc.showTraceOutputChannel', + ToggleEnable = 'oxc.toggleEnable', } let client: LanguageClient; @@ -42,7 +37,7 @@ export async function activate(context: ExtensionContext) { OxcCommands.RestartServer, async () => { if (!client) { - window.showErrorMessage("oxc client not found"); + window.showErrorMessage('oxc client not found'); return; } @@ -50,12 +45,12 @@ export async function activate(context: ExtensionContext) { if (client.isRunning()) { await client.restart(); - window.showInformationMessage("oxc server restarted."); + window.showInformationMessage('oxc server restarted.'); } else { await client.start(); } } catch (err) { - client.error("Restarting client failed", err, "force"); + client.error('Restarting client failed', err, 'force'); } }, ); @@ -78,12 +73,12 @@ export async function activate(context: ExtensionContext) { OxcCommands.ToggleEnable, () => { let enabled = workspace - .getConfiguration("oxc_language_server") - .get("enable"); + .getConfiguration('oxc_language_server') + .get('enable'); let nextState = !enabled; workspace - .getConfiguration("oxc_language_server") - .update("enable", nextState, ConfigurationTarget.Global); + .getConfiguration('oxc_language_server') + .update('enable', nextState, ConfigurationTarget.Global); }, ); @@ -97,10 +92,10 @@ export async function activate(context: ExtensionContext) { const outputChannel = window.createOutputChannel(outputChannelName); const traceOutputChannel = window.createOutputChannel(traceOutputChannelName); - function findBinary(): string | null { - const cfg = workspace.getConfiguration("oxc"); + function findBinary(): string { + const cfg = workspace.getConfiguration('oxc'); - let bin = cfg.get("binPath", ""); + let bin = cfg.get('binPath', ''); if (bin && existsSync(bin)) { return bin; } @@ -110,9 +105,9 @@ export async function activate(context: ExtensionContext) { for (const folder of workspaceFolders) { const binPath = join( folder.uri.fsPath, - "node_modules", - ".bin", - "oxc_language_server", + 'node_modules', + '.bin', + 'oxc_language_server', ); if (existsSync(binPath)) { return binPath; @@ -120,11 +115,11 @@ export async function activate(context: ExtensionContext) { } } - const ext = process.platform === "win32" ? ".exe" : ""; + const ext = process.platform === 'win32' ? '.exe' : ''; // NOTE: The `./target/release` path is aligned with the path defined in .github/workflows/release_vscode.yml return ( process.env.SERVER_PATH_DEV ?? - join(context.extensionPath, `./target/release/oxc_language_server${ext}`) + join(context.extensionPath, `./target/release/oxc_language_server${ext}`) ); } @@ -134,7 +129,7 @@ export async function activate(context: ExtensionContext) { options: { env: { ...process.env, - RUST_LOG: process.env.RUST_LOG || "info", + RUST_LOG: process.env.RUST_LOG || 'info', }, }, }; @@ -146,24 +141,24 @@ export async function activate(context: ExtensionContext) { // Otherwise the run options are used // Options to control the language client let clientConfig: any = JSON.parse( - JSON.stringify(workspace.getConfiguration("oxc_language_server")), + JSON.stringify(workspace.getConfiguration('oxc_language_server')), ); let clientOptions: LanguageClientOptions = { // Register the server for plain text documents documentSelector: [ - "typescript", - "javascript", - "typescriptreact", - "javascriptreact", - "vue", - "svelte", + 'typescript', + 'javascript', + 'typescriptreact', + 'javascriptreact', + 'vue', + 'svelte', ].map((lang) => ({ language: lang, - scheme: "file", + scheme: 'file', })), synchronize: { // Notify the server about file changes to '.clientrc files contained in the workspace - fileEvents: workspace.createFileSystemWatcher("**/.clientrc"), + fileEvents: workspace.createFileSystemWatcher('**/.clientrc'), }, initializationOptions: { settings: clientConfig, @@ -180,15 +175,15 @@ export async function activate(context: ExtensionContext) { clientOptions, ); workspace.onDidChangeConfiguration((e) => { - let isAffected = e.affectsConfiguration("oxc_language_server"); + let isAffected = e.affectsConfiguration('oxc_language_server'); if (!isAffected) { return; } let settings: any = JSON.parse( - JSON.stringify(workspace.getConfiguration("oxc_language_server")), + JSON.stringify(workspace.getConfiguration('oxc_language_server')), ); updateStatsBar(settings.enable); - client.sendNotification("workspace/didChangeConfiguration", { settings }); + client.sendNotification('workspace/didChangeConfiguration', { settings }); }); function updateStatsBar(enable: boolean) { @@ -203,10 +198,10 @@ export async function activate(context: ExtensionContext) { } let bgColor = new ThemeColor( enable - ? "statusBarItem.activeBackground" - : "statusBarItem.errorBackground", + ? 'statusBarItem.activeBackground' + : 'statusBarItem.errorBackground', ); - myStatusBarItem.text = `oxc: ${enable ? "$(check-all)" : "$(circle-slash)"}`; + myStatusBarItem.text = `oxc: ${enable ? '$(check-all)' : '$(circle-slash)'}`; myStatusBarItem.backgroundColor = bgColor; }