-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(lsp): remove useless logging & methods #16
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ mod requests; | |
mod response; | ||
mod server; | ||
use lsp_server::{Connection, Message}; | ||
use lsp_types::{notification::Notification, InitializeParams}; | ||
use lsp_types::InitializeParams; | ||
use server::get_server_capabilities; | ||
use std::{error::Error, process::ExitCode}; | ||
|
||
|
@@ -49,34 +49,25 @@ fn main_loop( | |
init_params: serde_json::Value, | ||
mut css_language_service: csslsrs::service::LanguageService, | ||
) -> Result<ExitCode, Box<dyn Error + Sync + Send>> { | ||
let mut awaiting_exit = false; | ||
let _init_params: InitializeParams = serde_json::from_value(init_params).unwrap(); | ||
|
||
for msg in &connection.receiver { | ||
// TODO: Handle trace levels and notifications instead of just printing them to stderr. | ||
eprintln!("new msg: {:?}", msg); | ||
|
||
// If we're waiting for an exit notification, any message other than it is an error, and will cause the server to exit with a failure exit code. | ||
// As such, we can handle this outside of the match statement. | ||
if awaiting_exit { | ||
if let Message::Notification(not) = &msg { | ||
if not.method == lsp_types::notification::Exit::METHOD { | ||
return Ok(ExitCode::SUCCESS); | ||
} | ||
} | ||
eprintln!("Shutting down without receiving `Exit` notification."); | ||
return Ok(ExitCode::FAILURE); | ||
} | ||
|
||
// Handle the rest of the messages. | ||
match msg { | ||
Message::Request(req) => { | ||
let request = | ||
requests::handle_request(req, &mut css_language_service, &connection)?; | ||
match connection.handle_shutdown(&req) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't know this existed when I made the initial shutdown support, turns out this does the same as what I did manually. We still need a global state eventually |
||
Ok(value) => { | ||
if value { | ||
return Ok(ExitCode::SUCCESS); | ||
} | ||
} | ||
Err(err) => { | ||
eprintln!("Error handling shutdown request: {:?}", err); | ||
return Ok(ExitCode::FAILURE); | ||
} | ||
}; | ||
|
||
if request.is_shutdown { | ||
awaiting_exit = true; | ||
} | ||
requests::handle_request(req, &mut css_language_service, &connection)?; | ||
} | ||
Message::Response(resp) => { | ||
response::handle_response(resp)?; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,58 @@ | ||
{ | ||
"name": "@weblsp/vscode", | ||
"displayName": "WEBlsp", | ||
"version": "1.0.0", | ||
"description": "A better Language Server for the Web, made with Rust — WORK IN PROGRESS ⚠️", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/web-lsp/weblsp" | ||
}, | ||
"license": "MIT", | ||
"engines": { | ||
"vscode": "^1.82.0" | ||
}, | ||
"categories": [ | ||
"Programming Languages" | ||
], | ||
"activationEvents": [ | ||
"onLanguage:css" | ||
], | ||
"main": "./dist/extension.js", | ||
"contributes": { | ||
"configuration": { | ||
"type": "object", | ||
"title": "CSS Language Server Settings", | ||
"properties": { | ||
"cssLanguageServer.path": { | ||
"type": "string", | ||
"description": "Path to the CSS language server executable", | ||
"default": "" | ||
} | ||
} | ||
} | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "npm run compile", | ||
"build": "tsc -p ./", | ||
"watch": "tsc -watch -p ./" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.9.1", | ||
"@types/vscode": "^1.95.0", | ||
"typescript": "^5.6.3" | ||
}, | ||
"dependencies": { | ||
"vscode-languageclient": "^9.0.1" | ||
} | ||
"name": "@weblsp/vscode", | ||
"displayName": "WEBlsp", | ||
"version": "1.0.0", | ||
"description": "A better Language Server for the Web, made with Rust — WORK IN PROGRESS ⚠️", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/web-lsp/weblsp" | ||
}, | ||
"license": "MIT", | ||
"engines": { | ||
"vscode": "^1.82.0" | ||
}, | ||
"categories": [ | ||
"Programming Languages" | ||
], | ||
"activationEvents": [ | ||
"onLanguage:css" | ||
], | ||
"main": "./dist/extension.js", | ||
"contributes": { | ||
"configuration": { | ||
"type": "object", | ||
"title": "WEBlsp configuration", | ||
"properties": { | ||
"weblsp.trace.server": { | ||
"scope": "window", | ||
"type": "string", | ||
"enum": [ | ||
"off", | ||
"messages", | ||
"verbose" | ||
], | ||
"default": "off", | ||
"description": "Traces the communication between VS Code and the language server." | ||
}, | ||
"weblsp.server.path": { | ||
"type": "string", | ||
"description": "Path to the WEBlsp executable", | ||
"default": "" | ||
} | ||
} | ||
} | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "npm run build", | ||
"build": "tsc -p ./", | ||
"watch": "tsc -watch -p ./" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.9.1", | ||
"@types/vscode": "^1.95.0", | ||
"typescript": "^5.6.3" | ||
}, | ||
"dependencies": { | ||
"vscode-languageclient": "^9.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,70 @@ | ||
import * as path from "path" | ||
import * as vscode from "vscode" | ||
import * as lsp from "vscode-languageclient/node" | ||
import * as path from "path"; | ||
import * as vscode from "vscode"; | ||
import * as lsp from "vscode-languageclient/node"; | ||
|
||
let client: lsp.LanguageClient | ||
let client: lsp.LanguageClient; | ||
|
||
/** | ||
* Turn on WEBlsp's vscode extension 🚀 | ||
*/ | ||
export async function activate(context: vscode.ExtensionContext) { | ||
const serverExecutable = getServerExecutablePath(context) | ||
const serverExecutable = getServerExecutablePath(context); | ||
|
||
const serverOptions: lsp.ServerOptions = { | ||
command: serverExecutable, | ||
args: [], | ||
options: { | ||
// vscode.workspace.rootPath is deprecated, so we'll just run on the first workspace folder | ||
cwd: | ||
(vscode.workspace.workspaceFolders && | ||
vscode.workspace.workspaceFolders[0].uri.fsPath) || | ||
process.cwd(), | ||
}, | ||
} | ||
const serverOptions: lsp.ServerOptions = { | ||
command: serverExecutable, | ||
}; | ||
|
||
const clientOptions: lsp.LanguageClientOptions = { | ||
// TODO: We should add the support of HTML later | ||
documentSelector: [{ scheme: "file", language: "css" }], | ||
synchronize: { | ||
fileEvents: vscode.workspace.createFileSystemWatcher("**/*.css"), | ||
}, | ||
} | ||
const clientOptions: lsp.LanguageClientOptions = { | ||
// TODO: We should add the support of HTML later | ||
documentSelector: [{ scheme: "file", language: "css" }], | ||
synchronize: { | ||
fileEvents: vscode.workspace.createFileSystemWatcher("**/*.css"), | ||
}, | ||
}; | ||
|
||
client = new lsp.LanguageClient( | ||
"cssLanguageServer", | ||
"CSS Language Server", | ||
serverOptions, | ||
clientOptions | ||
) | ||
client = new lsp.LanguageClient( | ||
"weblsp", | ||
"WEBlsp Language Server", | ||
serverOptions, | ||
clientOptions | ||
); | ||
|
||
await client.start() | ||
await client.start(); | ||
} | ||
|
||
/** | ||
* Cut off WEBlsp's vscode extension 😢 | ||
*/ | ||
export function deactivate(): Thenable<void> | undefined { | ||
if (!client) { | ||
return undefined | ||
} | ||
return client.stop() | ||
if (!client) { | ||
return undefined; | ||
} | ||
return client.stop(); | ||
} | ||
|
||
/** | ||
* Get the Rust WEBlsp binary path from the configuration. | ||
*/ | ||
function getServerExecutablePath(context: vscode.ExtensionContext): string { | ||
const config = vscode.workspace.getConfiguration("cssLanguageServer") | ||
let serverPath = config.get<string>("path") | ||
const config = vscode.workspace.getConfiguration("weblsp"); | ||
let serverPath = config.get<string>("server.path"); | ||
|
||
if (serverPath) { | ||
if (!path.isAbsolute(serverPath)) { | ||
if ( | ||
vscode.workspace.workspaceFolders && | ||
vscode.workspace.workspaceFolders.length > 0 | ||
) { | ||
const rootPath = vscode.workspace.workspaceFolders[0].uri.fsPath | ||
serverPath = path.join(rootPath, serverPath) | ||
} | ||
} | ||
} else { | ||
serverPath = vscode.Uri.joinPath( | ||
context.extensionUri, | ||
"../../target/debug/weblsp" | ||
).fsPath | ||
} | ||
if (serverPath) { | ||
if (!path.isAbsolute(serverPath)) { | ||
if ( | ||
vscode.workspace.workspaceFolders && | ||
vscode.workspace.workspaceFolders.length > 0 | ||
) { | ||
const rootPath = vscode.workspace.workspaceFolders[0].uri.fsPath; | ||
serverPath = path.join(rootPath, serverPath); | ||
} | ||
} | ||
} else { | ||
serverPath = vscode.Uri.joinPath( | ||
context.extensionUri, | ||
"../../target/debug/weblsp" | ||
).fsPath; | ||
} | ||
|
||
return serverPath | ||
return serverPath; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log is unnecessary, you can set
weblsp.trace.server
to eithermessages
orverbose
for the client to output what messages you received / sent