Skip to content

Commit

Permalink
chore: format typescript and json file in editors/vscode (#1667)
Browse files Browse the repository at this point in the history
1. just format, nothing else
  • Loading branch information
IWANABETHATGUY committed Dec 13, 2023
1 parent 90524c8 commit 7594a9d
Show file tree
Hide file tree
Showing 6 changed files with 801 additions and 322 deletions.
5 changes: 5 additions & 0 deletions editors/vscode/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target/
**/.git
**/.svn
**/.hg
**/node_modules
Empty file added editors/vscode/.prettierrc
Empty file.
118 changes: 64 additions & 54 deletions editors/vscode/client/extension.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@

import {
ExtensionContext,
window,
commands,
workspace,
} from "vscode";
import { ExtensionContext, window, commands, workspace } from "vscode";

import {
Executable,
Expand All @@ -13,71 +7,80 @@ import {
ServerOptions,
} from "vscode-languageclient/node";

import { join } from 'node:path'
import { join } from "node:path";

const languageClientId = 'oxc-client';
const languageClientName = 'oxc';
const outputChannelName = 'oxc';
const traceOutputChannelName = 'oxc.trace';
const languageClientId = "oxc-client";
const languageClientName = "oxc";
const outputChannelName = "oxc";
const traceOutputChannelName = "oxc.trace";

const enum OxcCommands {
RestartServer = "oxc.restartServer",
ApplyAllFixes = "oxc.applyAllFixes",
RestartServer = "oxc.restartServer",
ApplyAllFixes = "oxc.applyAllFixes",
ShowOutputChannel = "oxc.showOutputChannel",
ShowTraceOutputChannel = "oxc.showTraceOutputChannel"
};
ShowTraceOutputChannel = "oxc.showTraceOutputChannel",
}

let client: LanguageClient;


export async function activate(context: ExtensionContext) {
const restartCommand = commands.registerCommand(
OxcCommands.RestartServer,
async () => {
if (!client) {
window.showErrorMessage("oxc client not found");
return;
}

try {
if (client.isRunning()) {
await client.restart();

window.showInformationMessage("oxc server restarted.");
} else {
await client.start();
}
} catch (err) {
client.error("Restarting client failed", err, "force");
}
},
);

const restartCommand = commands.registerCommand(OxcCommands.RestartServer, async () => {
if(!client) {
window.showErrorMessage("oxc client not found");
return
}

try {
if (client.isRunning()) {
await client.restart();

window.showInformationMessage("oxc server restarted.");
} else {
await client.start();
}
} catch (err) {
client.error("Restarting client failed", err, "force");
}
})

const showOutputCommand = commands.registerCommand(OxcCommands.ShowOutputChannel, () => {
client?.outputChannel?.show()
})
const showOutputCommand = commands.registerCommand(
OxcCommands.ShowOutputChannel,
() => {
client?.outputChannel?.show();
},
);

const showTraceOutputCommand = commands.registerCommand(OxcCommands.ShowTraceOutputChannel, () => {
client?.traceOutputChannel?.show()
})
const showTraceOutputCommand = commands.registerCommand(
OxcCommands.ShowTraceOutputChannel,
() => {
client?.traceOutputChannel?.show();
},
);

context.subscriptions.push(
restartCommand,
showOutputCommand,
showTraceOutputCommand
showTraceOutputCommand,
);

const outputChannel = window.createOutputChannel(outputChannelName);
const traceOutputChannel = window.createOutputChannel(traceOutputChannelName);

const ext = process.platform === "win32" ? ".exe" : "";
// NOTE: The `./target/release` path is aligned with the path defined in .github/workflows/release_vscode.yml
const command = process.env.SERVER_PATH_DEV ?? join(context.extensionPath, `./target/release/oxc_vscode${ext}`);
const command =
process.env.SERVER_PATH_DEV ??
join(context.extensionPath, `./target/release/oxc_vscode${ext}`);

const run: Executable = {
command: command!,
options: {
env: {
...process.env,
RUST_LOG: 'debug',
...process.env,
RUST_LOG: "debug",
},
},
};
Expand All @@ -88,37 +91,44 @@ export async function activate(context: ExtensionContext) {
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
// Options to control the language client
let clientConfig: any = JSON.parse(JSON.stringify(workspace.getConfiguration('oxc-client')));
let clientConfig: any = JSON.parse(
JSON.stringify(workspace.getConfiguration("oxc-client")),
);
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [
"typescript",
"javascript",
"typescriptreact",
"javascriptreact",
].map(lang => ({ language: lang, scheme: "file" })),
].map((lang) => ({ language: lang, scheme: "file" })),
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher("**/.clientrc"),
},
initializationOptions: {
settings: clientConfig
settings: clientConfig,
},
outputChannel,
traceOutputChannel,
};

// Create the language client and start the client.
client = new LanguageClient(languageClientId, languageClientName, serverOptions, clientOptions);
client = new LanguageClient(
languageClientId,
languageClientName,
serverOptions,
clientOptions,
);
workspace.onDidChangeConfiguration((e) => {
let settings: any = {};
if (e.affectsConfiguration("oxc-client.run")) {
settings.run = workspace.getConfiguration('oxc-client').get("run")
settings.run = workspace.getConfiguration("oxc-client").get("run");
}
client.sendNotification("workspace/didChangeConfiguration", {
settings
})
})
settings,
});
});

client.start();
}
Expand Down
4 changes: 3 additions & 1 deletion editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@
"package": "vsce package --no-dependencies -o oxc_vscode.vsix",
"install-extension": "code --install-extension oxc_vscode.vsix --force",
"server:build:debug": "cargo build -p oxc_vscode",
"server:build:release": "cross-env CARGO_TARGET_DIR=./target cargo build -p oxc_vscode --release"
"server:build:release": "cross-env CARGO_TARGET_DIR=./target cargo build -p oxc_vscode --release",
"fmt:js": "prettier --write ./**/*.{js,ts,json}"
},
"devDependencies": {
"@types/node": "^18.19.3",
"@types/vscode": "1.80.0",
"@vscode/vsce": "^2.22.0",
"cross-env": "^7.0.3",
"esbuild": "^0.19.8",
"prettier": "^3.1.1",
"typescript": "^5.3.3"
},
"dependencies": {
Expand Down
Loading

0 comments on commit 7594a9d

Please sign in to comment.