Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fmt
  • Loading branch information
shulaoda committed Sep 28, 2024
commit 93448bde7af3cdbd223ed1b202a36e0540220ed6
3 changes: 3 additions & 0 deletions editors/vscode/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
93 changes: 44 additions & 49 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 @@ -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<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