Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Sep 28, 2024
1 parent ae6a33c commit 3658c50
Showing 1 changed file with 43 additions and 48 deletions.
91 changes: 43 additions & 48 deletions editors/vscode/client/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from "node:fs";
import { existsSync } from 'node:fs';

import {
commands,
Expand All @@ -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;
Expand All @@ -42,20 +37,20 @@ export async function activate(context: ExtensionContext) {
OxcCommands.RestartServer,
async () => {
if (!client) {
window.showErrorMessage("oxc client not found");
window.showErrorMessage('oxc client not found');
return;
}

try {
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');
}
},
);
Expand All @@ -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);
},
);

Expand All @@ -98,9 +93,9 @@ export async function activate(context: ExtensionContext) {
const traceOutputChannel = window.createOutputChannel(traceOutputChannelName);

function findBinary(): string | null {
const cfg = workspace.getConfiguration("oxc");
const cfg = workspace.getConfiguration('oxc');

let bin = cfg.get<string>("binPath", "");
let bin = cfg.get<string>('binPath', '');
if (bin && existsSync(bin)) {
return bin;
}
Expand All @@ -110,21 +105,21 @@ 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;
}
}
}

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}`)
);
}

Expand All @@ -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',
},
},
};
Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 3658c50

Please sign in to comment.