From 9897cab220e2b47a56bdbc32c77a45918ad37709 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Fri, 24 Nov 2023 15:05:27 +0800 Subject: [PATCH] chore(vscode): improve dx (#1528) --- .vscode/launch.json | 1 - .vscode/tasks.json | 5 +---- Cargo.lock | 1 + editors/vscode/client/extension.ts | 4 ++-- editors/vscode/package.json | 25 ++++++++++++++++++++++++- editors/vscode/server/Cargo.toml | 1 + editors/vscode/server/src/main.rs | 4 +++- tasks/common/Cargo.toml | 4 ++-- 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 5459afdaa7e81..5933fb8e6db5f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,6 @@ "args": ["--extensionDevelopmentPath=${workspaceFolder}/editors/vscode" ], "sourceMaps": true, "outFiles": ["${workspaceFolder}/editors/vscode/dist/*.js"], - "preLaunchTask": "watch", "env": { "SERVER_PATH_DEV": "${workspaceRoot}/target/debug/oxc_vscode" } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ccbc715a3e472..78926f5aaf4e1 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -30,10 +30,7 @@ "presentation": { "panel": "dedicated", "reveal": "never" - }, - "problemMatcher": [ - "$tsc-watch" - ] + } } ] } diff --git a/Cargo.lock b/Cargo.lock index c0255d609515d..518749b4e2d60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1952,6 +1952,7 @@ dependencies = [ "env_logger", "futures", "ignore", + "log", "miette", "oxc_allocator", "oxc_diagnostics", diff --git a/editors/vscode/client/extension.ts b/editors/vscode/client/extension.ts index 9b817a6994512..1be6a0cfaf471 100644 --- a/editors/vscode/client/extension.ts +++ b/editors/vscode/client/extension.ts @@ -27,7 +27,6 @@ const enum OxcCommands { ShowTraceOutputChannel = "oxc.showTraceOutputChannel" }; - let client: LanguageClient; @@ -70,7 +69,8 @@ export async function activate(context: ExtensionContext) { const traceOutputChannel = window.createOutputChannel(traceOutputChannelName); const ext = process.platform === "win32" ? ".exe" : ""; - const command = join(context.extensionPath, `./target/release/oxc_vscode${ext}`); + let serverPath = process.env.SERVER_PATH_DEV ?? `oxc_vscode${ext}`; + const command = join(serverPath); // window.showInformationMessage(`oxc server path: ${command}`); diff --git a/editors/vscode/package.json b/editors/vscode/package.json index ee73b251acc4d..88349cd781832 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -50,12 +50,35 @@ "title": "Show Trace Output Channel", "category": "Oxc" } - ] + ], + "configuration": { + "type": "object", + "title": "oxc", + "properties": { + "oxc-client.trace.server": { + "type": "string", + "scope": "window", + "enum": [ + "off", + "messages", + "verbose" + ], + "enumDescriptions": [ + "No traces", + "Error only", + "Full log" + ], + "default": "off", + "description": "Traces the communication between VS Code and the language server." + } + } + } }, "scripts": { "preinstall": "[ -f icon.png ] || curl https://raw.githubusercontent.com/Boshen/oxc-assets/main/logo-square.png --output icon.png", "build": "pnpm run server:build:release && pnpm run compile && pnpm run package", "compile": "esbuild client/extension.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node --target=node16 --minify", + "watch": "pnpm run compile --watch", "package": "vsce package --no-dependencies -o oxc_lsp.vsix", "publish": "vsce publish --no-dependencies", "install-extension": "code --install-extension oxc_lsp.vsix --force", diff --git a/editors/vscode/server/Cargo.toml b/editors/vscode/server/Cargo.toml index d9efbd1e07322..23524b8416a4f 100644 --- a/editors/vscode/server/Cargo.toml +++ b/editors/vscode/server/Cargo.toml @@ -36,3 +36,4 @@ rayon = { workspace = true } ropey = { workspace = true } tokio = { workspace = true, features = ["full"] } tower-lsp = { workspace = true, features = ["proposed"] } +log = "0.4.20" diff --git a/editors/vscode/server/src/main.rs b/editors/vscode/server/src/main.rs index b755d631ecff2..5899258234df9 100644 --- a/editors/vscode/server/src/main.rs +++ b/editors/vscode/server/src/main.rs @@ -4,6 +4,7 @@ mod options; mod walk; use crate::linter::{DiagnosticReport, ServerLinter}; +use log::debug; use std::collections::HashMap; use std::fmt::Debug; use std::path::PathBuf; @@ -56,7 +57,7 @@ impl LanguageServer for Backend { } async fn initialized(&self, _: InitializedParams) { - self.client.log_message(MessageType::INFO, "oxc initialized.").await; + debug!("oxc initialized."); if let Some(Some(root_uri)) = self.root_uri.get() { self.server_linter.make_plugin(root_uri); @@ -77,6 +78,7 @@ impl LanguageServer for Backend { } async fn did_save(&self, params: DidSaveTextDocumentParams) { + debug!("oxc server did save"); self.handle_file_update(params.text_document.uri).await; } diff --git a/tasks/common/Cargo.toml b/tasks/common/Cargo.toml index 19f934d6fcbff..2c1f233fbd2e4 100644 --- a/tasks/common/Cargo.toml +++ b/tasks/common/Cargo.toml @@ -13,13 +13,13 @@ test = false doctest = false [dependencies] -console = "0.15.7" +console = "0.15.7" oxc_syntax = { workspace = true, features = ["serde"] } project-root = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } -similar = "2.3.0" +similar = "2.3.0" ureq = { workspace = true } url = { workspace = true }