chore(rome_lsp):  migration to tower_lsp crate
MODIFY
Cargo.lock
Cargo.lock
@@ -384,12 +384,13 @@ dependencies = [
[[package]]
name = "dashmap"
-version = "4.0.2"
+version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c"
+checksum = "4c8858831f7781322e539ea39e72449c46b059638250c14344fec8d0aa6e539c"
dependencies = [
"cfg-if",
"num_cpus",
+ "parking_lot",
]
[[package]]
@@ -596,7 +597,7 @@ checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
dependencies = [
"cfg-if",
"libc",
- "wasi",
+ "wasi 0.10.2+wasi-snapshot-preview1",
]
[[package]]
@@ -670,15 +671,6 @@ dependencies = [
"num-traits",
]
-[[package]]
-name = "heck"
-version = "0.3.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
-dependencies = [
- "unicode-segmentation",
-]
-
[[package]]
name = "hermit-abi"
version = "0.1.19"
@@ -775,15 +767,6 @@ dependencies = [
"walkdir",
]
-[[package]]
-name = "instant"
-version = "0.1.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
-dependencies = [
- "cfg-if",
-]
-
[[package]]
name = "itertools"
version = "0.10.3"
@@ -831,9 +814,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.113"
+version = "0.2.124"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eef78b64d87775463c549fbd80e19249ef436ea3bf1de2a1eb7e717ec7fab1e9"
+checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50"
[[package]]
name = "libgit2-sys"
@@ -885,9 +868,9 @@ dependencies = [
[[package]]
name = "lsp-types"
-version = "0.91.1"
+version = "0.93.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2368312c59425dd133cb9a327afee65be0a633a8ce471d248e2202a48f8f68ae"
+checksum = "70c74e2173b2b31f8655d33724b4b45ac13f439386f66290f539c22b144c2212"
dependencies = [
"bitflags",
"serde",
@@ -896,43 +879,6 @@ dependencies = [
"url",
]
-[[package]]
-name = "lspower"
-version = "1.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cc2242d4cb4071c7b9ae53001c8c658402b55bb8c3669a70d3ce9565f1144b30"
-dependencies = [
- "anyhow",
- "async-trait",
- "auto_impl",
- "bytes",
- "dashmap",
- "futures",
- "httparse",
- "log",
- "lsp-types",
- "lspower-macros",
- "serde",
- "serde_json",
- "thiserror",
- "tokio",
- "tokio-util",
- "tower-service",
- "twoway",
-]
-
-[[package]]
-name = "lspower-macros"
-version = "0.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca1d48da0e4a6100b4afd52fae99f36d47964a209624021280ad9ffdd410e83d"
-dependencies = [
- "heck",
- "proc-macro2",
- "quote",
- "syn",
-]
-
[[package]]
name = "matches"
version = "0.1.9"
@@ -966,14 +912,15 @@ dependencies = [
[[package]]
name = "mio"
-version = "0.7.14"
+version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc"
+checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9"
dependencies = [
"libc",
"log",
"miow",
"ntapi",
+ "wasi 0.11.0+wasi-snapshot-preview1",
"winapi",
]
@@ -1041,17 +988,6 @@ version = "11.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
-[[package]]
-name = "parking_lot"
-version = "0.11.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
-dependencies = [
- "instant",
- "lock_api",
- "parking_lot_core 0.8.5",
-]
-
[[package]]
name = "parking_lot"
version = "0.12.0"
@@ -1059,21 +995,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
dependencies = [
"lock_api",
- "parking_lot_core 0.9.1",
-]
-
-[[package]]
-name = "parking_lot_core"
-version = "0.8.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
-dependencies = [
- "cfg-if",
- "instant",
- "libc",
- "redox_syscall",
- "smallvec",
- "winapi",
+ "parking_lot_core",
]
[[package]]
@@ -1101,6 +1023,26 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468"
+[[package]]
+name = "pin-project"
+version = "1.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e"
+dependencies = [
+ "pin-project-internal",
+]
+
+[[package]]
+name = "pin-project-internal"
+version = "1.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "pin-project-lite"
version = "0.2.8"
@@ -1329,7 +1271,7 @@ dependencies = [
"crossbeam",
"hdrhistogram",
"lazy_static",
- "parking_lot 0.12.0",
+ "parking_lot",
"pico-args",
"rayon",
"rome_console",
@@ -1399,7 +1341,7 @@ version = "0.0.0"
dependencies = [
"crossbeam",
"indexmap",
- "parking_lot 0.12.0",
+ "parking_lot",
"rayon",
"tracing",
]
@@ -1412,7 +1354,7 @@ dependencies = [
"ctor",
"iai",
"insta",
- "parking_lot 0.12.0",
+ "parking_lot",
"quickcheck",
"quickcheck_macros",
"rome_core",
@@ -1471,8 +1413,7 @@ dependencies = [
"anyhow",
"futures",
"indexmap",
- "lspower",
- "parking_lot 0.12.0",
+ "parking_lot",
"rome_analyze",
"rome_diagnostics",
"rome_fs",
@@ -1482,6 +1423,7 @@ dependencies = [
"serde",
"serde_json",
"tokio",
+ "tower-lsp",
"tracing",
"tracing-subscriber",
"tracing-tree",
@@ -1712,6 +1654,16 @@ version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
+[[package]]
+name = "socket2"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0"
+dependencies = [
+ "libc",
+ "winapi",
+]
+
[[package]]
name = "spin"
version = "0.5.2"
@@ -1855,9 +1807,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
-version = "1.15.0"
+version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fbbf1c778ec206785635ce8ad57fe52b3009ae9e0c9f574a728f3049d3e55838"
+checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee"
dependencies = [
"bytes",
"libc",
@@ -1865,9 +1817,10 @@ dependencies = [
"mio",
"num_cpus",
"once_cell",
- "parking_lot 0.11.2",
+ "parking_lot",
"pin-project-lite",
"signal-hook-registry",
+ "socket2",
"tokio-macros",
"winapi",
]
@@ -1885,16 +1838,16 @@ dependencies = [
[[package]]
name = "tokio-util"
-version = "0.6.9"
+version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0"
+checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
- "log",
"pin-project-lite",
"tokio",
+ "tracing",
]
[[package]]
@@ -1906,6 +1859,60 @@ dependencies = [
"serde",
]
+[[package]]
+name = "tower"
+version = "0.4.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a89fd63ad6adf737582df5db40d286574513c69a11dac5214dc3b5603d6713e"
+dependencies = [
+ "futures-core",
+ "futures-util",
+ "pin-project",
+ "pin-project-lite",
+ "tower-layer",
+ "tower-service",
+]
+
+[[package]]
+name = "tower-layer"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62"
+
+[[package]]
+name = "tower-lsp"
+version = "0.17.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "43e094780b4447366c59f79acfd65b1375ecaa84e61dddbde1421aa506334024"
+dependencies = [
+ "async-trait",
+ "auto_impl",
+ "bytes",
+ "dashmap",
+ "futures",
+ "httparse",
+ "log",
+ "lsp-types",
+ "memchr",
+ "serde",
+ "serde_json",
+ "tokio",
+ "tokio-util",
+ "tower",
+ "tower-lsp-macros",
+]
+
+[[package]]
+name = "tower-lsp-macros"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7ebd99eec668d0a450c177acbc4d05e0d0d13b1f8d3db13cd706c52cbec4ac04"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "tower-service"
version = "0.3.1"
@@ -1920,9 +1927,21 @@ checksum = "f6c650a8ef0cd2dd93736f033d21cbd1224c5a967aa0c258d00fcf7dafef9b9f"
dependencies = [
"cfg-if",
"pin-project-lite",
+ "tracing-attributes",
"tracing-core",
]
+[[package]]
+name = "tracing-attributes"
+version = "0.1.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "tracing-core"
version = "0.1.23"
@@ -1985,22 +2004,6 @@ dependencies = [
"toml",
]
-[[package]]
-name = "twoway"
-version = "0.2.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c57ffb460d7c24cd6eda43694110189030a3d1dfe418416d9468fd1c1d290b47"
-dependencies = [
- "memchr",
- "unchecked-index",
-]
-
-[[package]]
-name = "unchecked-index"
-version = "0.2.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eeba86d422ce181a719445e51872fa30f1f7413b62becb52e95ec91aa262d85c"
-
[[package]]
name = "ungrammar"
version = "1.14.9"
@@ -2111,6 +2114,12 @@ version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
+[[package]]
+name = "wasi"
+version = "0.11.0+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
+
[[package]]
name = "wasm-bindgen"
version = "0.2.79"

MODIFY
crates/rome_lsp/Cargo.toml
crates/rome_lsp/Cargo.toml
@@ -16,7 +16,7 @@ rome_analyze = { path = "../rome_analyze" }
rome_diagnostics = { path = "../rome_diagnostics" }
rome_js_parser = { path = "../rome_js_parser" }
rome_js_syntax = { path = "../rome_js_syntax" }
-lspower = "1.5"
+tower-lsp = { version = "0.17.0"}
tokio = { version = "1.15.0", features = ["full" ] }
tracing = { version = "0.1.31", default-features = false, features = ["std", "max_level_trace", "release_max_level_warn"] }
tracing-tree = "0.2.0"

MODIFY
crates/rome_lsp/src/capabilities.rs
crates/rome_lsp/src/capabilities.rs
-use lspower::lsp::{
+use tower_lsp::lsp_types::{
CodeActionProviderCapability, DocumentOnTypeFormattingOptions, OneOf, ServerCapabilities,
TextDocumentSyncCapability, TextDocumentSyncKind,
};

MODIFY
crates/rome_lsp/src/handlers/analysis.rs
crates/rome_lsp/src/handlers/analysis.rs
-use lspower::lsp::CodeActionOrCommand;
-use lspower::{jsonrpc, lsp};
use rome_analyze::{AnalysisServer, FileId};
use rome_js_syntax::TextRange;
+use tower_lsp::lsp_types::CodeActionOrCommand;
+use tower_lsp::{jsonrpc, lsp_types};
use crate::line_index::LineIndex;
use crate::utils;
@@ -12,7 +12,7 @@ use crate::utils;
pub(crate) fn diagnostics(
analysis_server: AnalysisServer,
file_id: FileId,
-) -> jsonrpc::Result<Vec<lsp::Diagnostic>> {
+) -> jsonrpc::Result<Vec<lsp_types::Diagnostic>> {
let text = analysis_server
.get_file_text(file_id)
.ok_or_else(jsonrpc::Error::internal_error)?;
@@ -31,9 +31,9 @@ pub(crate) fn diagnostics(
pub(crate) fn code_actions(
analysis_server: AnalysisServer,
file_id: FileId,
- url: lsp::Url,
+ url: lsp_types::Url,
cursor_range: TextRange,
-) -> jsonrpc::Result<Vec<lsp::CodeActionOrCommand>> {
+) -> jsonrpc::Result<Vec<lsp_types::CodeActionOrCommand>> {
let text = analysis_server
.get_file_text(file_id)
.ok_or_else(jsonrpc::Error::internal_error)?;

MODIFY
crates/rome_lsp/src/handlers/formatting.rs
crates/rome_lsp/src/handlers/formatting.rs
use crate::config::{FormatterWorkspaceSettings, WorkspaceSettings};
use crate::line_index::{self, LineCol};
use anyhow::{bail, Result};
-use lspower::lsp::*;
use rome_analyze::FileId;
use rome_js_formatter::{FormatOptions, IndentStyle, QuoteStyle};
use rome_js_parser::{parse, SourceType};
use rome_js_syntax::{TextRange, TokenAtOffset};
use std::str::FromStr;
+use tower_lsp::lsp_types::*;
use tracing::info;
/// Utility function that takes formatting options from [LSP](lspower::lsp::FormattingOptions)

MODIFY
crates/rome_lsp/src/handlers/text_document.rs
crates/rome_lsp/src/handlers/text_document.rs
-use lspower::lsp;
use rome_fs::RomePath;
use std::sync::Arc;
+use tower_lsp::lsp_types;
use tracing::error;
use crate::{documents::Document, session::Session};
/// Handler for `textDocument/didOpen` LSP notification
-pub(crate) async fn did_open(session: Arc<Session>, params: lsp::DidOpenTextDocumentParams) {
+pub(crate) async fn did_open(session: Arc<Session>, params: lsp_types::DidOpenTextDocumentParams) {
let url = params.text_document.uri.clone();
let file_id = session.file_id(url.clone());
let version = params.text_document.version;
@@ -25,7 +25,10 @@ pub(crate) async fn did_open(session: Arc<Session>, params: lsp::DidOpenTextDocu
}
/// Handler for `textDocument/didChange` LSP notification
-pub(crate) async fn did_change(session: Arc<Session>, params: lsp::DidChangeTextDocumentParams) {
+pub(crate) async fn did_change(
+ session: Arc<Session>,
+ params: lsp_types::DidChangeTextDocumentParams,
+) {
let url = params.text_document.uri;
let version = params.text_document.version;
@@ -50,7 +53,10 @@ pub(crate) async fn did_change(session: Arc<Session>, params: lsp::DidChangeText
}
/// Handler for `textDocument/didClose` LSP notification
-pub(crate) async fn did_close(session: Arc<Session>, params: lsp::DidCloseTextDocumentParams) {
+pub(crate) async fn did_close(
+ session: Arc<Session>,
+ params: lsp_types::DidCloseTextDocumentParams,
+) {
let url = params.text_document.uri;
session.remove_document(&url);
let diagnostics = vec![];

MODIFY
crates/rome_lsp/src/requests/syntax_tree.rs
crates/rome_lsp/src/requests/syntax_tree.rs
use crate::documents::Document;
use anyhow::Result;
-use lspower::lsp::TextDocumentIdentifier;
use rome_js_parser::parse;
use serde::{Deserialize, Serialize};
+use tower_lsp::lsp_types::TextDocumentIdentifier;
use tracing::{info, trace};
pub const SYNTAX_TREE_REQUEST: &str = "rome/syntaxTree";

MODIFY
crates/rome_lsp/src/server.rs
crates/rome_lsp/src/server.rs
@@ -8,13 +8,13 @@ use crate::requests::syntax_tree::{syntax_tree, SyntaxTreePayload, SYNTAX_TREE_R
use crate::session::Session;
use crate::utils;
use crate::utils::into_lsp_error;
-use lspower::jsonrpc::Result as LspResult;
-use lspower::lsp::*;
-use lspower::{Client, LanguageServer, LspService, Server};
use rome_analyze::AnalysisServer;
use serde_json::Value;
use std::sync::Arc;
use tokio::io::{Stdin, Stdout};
+use tower_lsp::jsonrpc::Result as LspResult;
+use tower_lsp::lsp_types::*;
+use tower_lsp::{Client, LanguageServer, LspService, Server};
use tracing::{error, info, trace};
struct LSPServer {
@@ -27,9 +27,25 @@ impl LSPServer {
let session = Arc::new(Session::new(client.clone()));
Self { client, session }
}
+
+ async fn syntax_tree_request(&self, params: SyntaxTreePayload) -> LspResult<Option<Value>> {
+ trace!(
+ "Calling method: {}\n with params: {:?}",
+ SYNTAX_TREE_REQUEST,
+ &params
+ );
+
+ let params: SyntaxTreePayload = params;
+ let url = params.text_document.uri.clone();
+ let document = self.session.document(&url)?;
+ let task = utils::spawn_blocking_task(move || syntax_tree(document));
+ let result = task.await?;
+ let result = serde_json::to_value(result).map_err(into_lsp_error)?;
+ Ok(Some(result))
+ }
}
-#[lspower::async_trait]
+#[tower_lsp::async_trait]
impl LanguageServer for LSPServer {
async fn initialize(&self, params: InitializeParams) -> LspResult<InitializeResult> {
info!("Starting Rome Language Server...");
@@ -73,27 +89,6 @@ impl LanguageServer for LSPServer {
Ok(())
}
- async fn request_else(&self, method: &str, params: Option<Value>) -> LspResult<Option<Value>> {
- trace!("Calling method: {}\n with params: {:?}", method, &params);
-
- match method {
- SYNTAX_TREE_REQUEST => match params.map(serde_json::from_value) {
- Some(Ok(params)) => {
- let params: SyntaxTreePayload = params;
- let url = params.text_document.uri.clone();
- let document = self.session.document(&url)?;
- let task = utils::spawn_blocking_task(move || syntax_tree(document));
- let result = task.await?;
- let result = serde_json::to_value(result).map_err(into_lsp_error)?;
- Ok(Some(result))
- }
- _ => Ok(None),
- },
-
- _ => Ok(None),
- }
- }
-
async fn code_action(&self, params: CodeActionParams) -> LspResult<Option<CodeActionResponse>> {
let workspace_settings = self.session.config.read().get_workspace_settings();
if !workspace_settings.analysis.enable_code_actions {
@@ -209,9 +204,8 @@ impl LanguageServer for LSPServer {
}
pub async fn run_server(stdin: Stdin, stdout: Stdout) {
- let (service, messages) = LspService::new(LSPServer::new);
- Server::new(stdin, stdout)
- .interleave(messages)
- .serve(service)
- .await;
+ let (service, messages) = LspService::build(LSPServer::new)
+ .custom_method(SYNTAX_TREE_REQUEST, LSPServer::syntax_tree_request)
+ .finish();
+ Server::new(stdin, stdout, messages).serve(service).await;
}

MODIFY
crates/rome_lsp/src/session.rs
crates/rome_lsp/src/session.rs
@@ -4,30 +4,30 @@ use crate::config::CONFIGURATION_SECTION;
use crate::{documents::Document, handlers, url_interner::UrlInterner};
use futures::stream::futures_unordered::FuturesUnordered;
use futures::StreamExt;
-use lspower::jsonrpc::Error as LspError;
-use lspower::lsp;
use parking_lot::RwLock;
use rome_analyze::{AnalysisServer, FileId};
use std::{collections::HashMap, error::Error, fmt::Display};
+use tower_lsp::jsonrpc::Error as LspError;
+use tower_lsp::lsp_types;
use tracing::{error, trace};
/// Represents the state of an LSP server session.
pub(crate) struct Session {
/// The LSP client for this session.
- pub(crate) client: lspower::Client,
- /// The capabilities provided by the client as part of [`lsp::InitializeParams`]
- pub(crate) client_capabilities: RwLock<Option<lsp::ClientCapabilities>>,
+ pub(crate) client: tower_lsp::Client,
+ /// The capabilities provided by the client as part of [`lsp_types::InitializeParams`]
+ pub(crate) client_capabilities: RwLock<Option<lsp_types::ClientCapabilities>>,
/// the configuration of the LSP
pub(crate) config: RwLock<Config>,
- documents: RwLock<HashMap<lsp::Url, Document>>,
+ documents: RwLock<HashMap<lsp_types::Url, Document>>,
url_interner: RwLock<UrlInterner>,
}
#[derive(Debug)]
pub(crate) enum SessionError {
- DocumentNotFound { url: lsp::Url },
+ DocumentNotFound { url: lsp_types::Url },
}
impl Display for SessionError {
@@ -55,7 +55,7 @@ impl From<SessionError> for LspError {
}
impl Session {
- pub(crate) fn new(client: lspower::Client) -> Self {
+ pub(crate) fn new(client: tower_lsp::Client) -> Self {
let client_capabilities = RwLock::new(Default::default());
let documents = Default::default();
let url_interner = Default::default();
@@ -69,10 +69,10 @@ impl Session {
}
}
- /// Get a [`Document`] matching the provided [`lsp::Url`]
+ /// Get a [`Document`] matching the provided [`lsp_types::Url`]
///
/// If document does not exist, result is [SessionError::DocumentNotFound]
- pub(crate) fn document(&self, url: &lsp::Url) -> Result<Document, SessionError> {
+ pub(crate) fn document(&self, url: &lsp_types::Url) -> Result<Document, SessionError> {
self.documents
.read()
.get(url)
@@ -82,33 +82,33 @@ impl Session {
})
}
- /// Set the [`Document`] for the provided [`lsp::Url`]
+ /// Set the [`Document`] for the provided [`lsp_types::Url`]
///
/// Used by [`handlers::text_document] to synchronize documents with the client.
- pub(crate) fn insert_document(&self, url: lsp::Url, document: Document) {
+ pub(crate) fn insert_document(&self, url: lsp_types::Url, document: Document) {
self.documents.write().insert(url, document);
}
- /// Remove the [`Document`] matching the provided [`lsp::Url`]
- pub(crate) fn remove_document(&self, url: &lsp::Url) {
+ /// Remove the [`Document`] matching the provided [`lsp_types::Url`]
+ pub(crate) fn remove_document(&self, url: &lsp_types::Url) {
self.documents.write().remove(url);
}
/// Get the version for [`Document`] matching the url. Should increase with every edit.
- pub(crate) fn document_version(&self, url: &lsp::Url) -> Result<i32, SessionError> {
+ pub(crate) fn document_version(&self, url: &lsp_types::Url) -> Result<i32, SessionError> {
self.document(url).map(|d| d.version)
}
/// Return the unique [FileId] associated with the url for this [Session].
/// This will assign a new FileId if there isn't one for the provided url.
- pub(crate) fn file_id(&self, url: lsp::Url) -> FileId {
+ pub(crate) fn file_id(&self, url: lsp_types::Url) -> FileId {
self.url_interner.write().intern(url)
}
/// Computes diagnostics for the file matching the provided url and publishes
/// them to the client. Called from [`handlers::text_document`] when a file's
/// contents changes.
- pub(crate) async fn update_diagnostics(&self, url: lsp::Url) -> anyhow::Result<()> {
+ pub(crate) async fn update_diagnostics(&self, url: lsp_types::Url) -> anyhow::Result<()> {
let doc = self.document(&url)?;
let workspace_settings = self.config.read().get_workspace_settings();
@@ -177,7 +177,7 @@ impl Session {
/// Requests "workspace/configuration" from client and updates Session config
pub(crate) async fn fetch_client_configuration(&self) {
- let item = lsp::ConfigurationItem {
+ let item = lsp_types::ConfigurationItem {
scope_uri: None,
section: Some(String::from(CONFIGURATION_SECTION)),
};

MODIFY
crates/rome_lsp/src/url_interner.rs
crates/rome_lsp/src/url_interner.rs
//! Based on `path_interner` from `rust-analyzer`
use indexmap::IndexSet;
-use lspower::lsp::Url;
use rome_analyze::FileId;
+use tower_lsp::lsp_types::Url;
/// Structure to map between [`Url`] and [`FileId`].
#[derive(Default)]

MODIFY
crates/rome_lsp/src/utils.rs
crates/rome_lsp/src/utils.rs
@@ -2,26 +2,28 @@ use std::collections::HashMap;
use std::fmt::Display;
use crate::line_index::{LineCol, LineIndex};
-use lspower::jsonrpc::Error as LspError;
-use lspower::jsonrpc::Result as LspResult;
-use lspower::lsp::{self, CodeAction, CodeActionKind, Diagnostic, TextEdit, Url, WorkspaceEdit};
use rome_analyze::{DiagnosticExt, Indel, TextAction};
+use tower_lsp::jsonrpc::Error as LspError;
+use tower_lsp::jsonrpc::Result as LspResult;
+use tower_lsp::lsp_types::{
+ self, CodeAction, CodeActionKind, Diagnostic, TextEdit, Url, WorkspaceEdit,
+};
use tracing::{error, trace};
use rome_js_syntax::{TextRange, TextSize};
-pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> lsp::Position {
+pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> lsp_types::Position {
let line_col = line_index.line_col(offset);
- lsp::Position::new(line_col.line, line_col.col)
+ lsp_types::Position::new(line_col.line, line_col.col)
}
-pub(crate) fn range(line_index: &LineIndex, range: TextRange) -> lsp::Range {
+pub(crate) fn range(line_index: &LineIndex, range: TextRange) -> lsp_types::Range {
let start = position(line_index, range.start());
let end = position(line_index, range.end());
- lsp::Range::new(start, end)
+ lsp_types::Range::new(start, end)
}
-pub(crate) fn offset(line_index: &LineIndex, position: lsp::Position) -> TextSize {
+pub(crate) fn offset(line_index: &LineIndex, position: lsp_types::Position) -> TextSize {
let line_col = LineCol {
line: position.line as u32,
col: position.character as u32,
@@ -29,7 +31,7 @@ pub(crate) fn offset(line_index: &LineIndex, position: lsp::Position) -> TextSiz
line_index.offset(line_col)
}
-pub(crate) fn text_range(line_index: &LineIndex, range: lsp::Range) -> TextRange {
+pub(crate) fn text_range(line_index: &LineIndex, range: lsp_types::Range) -> TextRange {
let start = offset(line_index, range.start);
let end = offset(line_index, range.end);
TextRange::new(start, end)
@@ -76,24 +78,26 @@ pub(crate) fn text_action_to_lsp(
}
}
-/// Convert an [rome_diagnostics::Diagnostic] to a [lsp::Diagnostic], using the span
+/// Convert an [rome_diagnostics::Diagnostic] to a [lsp_types::Diagnostic], using the span
/// of the diagnostic's primary label as the diagnostic range.
/// Requires a [LineIndex] to convert a byte offset range to the line/col range
/// expected by LSP.
pub(crate) fn diagnostic_to_lsp(
diagnostic: rome_diagnostics::Diagnostic,
line_index: &LineIndex,
-) -> Option<lsp::Diagnostic> {
+) -> Option<lsp_types::Diagnostic> {
let text_range = diagnostic.primary_text_range()?;
let lsp_range = crate::utils::range(line_index, text_range);
let message = diagnostic.title;
- let code = diagnostic.code.map(lspower::lsp::NumberOrString::String);
+ let code = diagnostic
+ .code
+ .map(tower_lsp::lsp_types::NumberOrString::String);
let source = Some("rome".into());
let diagnostic = Diagnostic::new(lsp_range, None, code, source, message, None, None);
Some(diagnostic)
}
-/// Helper to create a [lspower::jsonrpc::Error] from a message
+/// Helper to create a [tower_lsp::jsonrpc::Error] from a message
pub(crate) fn into_lsp_error(msg: impl Display) -> LspError {
let mut error = LspError::internal_error();
error!("Error: {}", msg);

MODIFY
editors/vscode/src/main.ts
editors/vscode/src/main.ts
-import { ExtensionContext, Uri, window, workspace } from 'vscode';
-import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node';
+import { ExtensionContext, Uri, window, workspace } from "vscode";
+import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from "vscode-languageclient/node";
import { setContextValue } from "./utils";
import { Session } from "./session";
import { syntaxTree } from "./commands/syntaxTree";
@@ -10,7 +10,9 @@ let client: LanguageClient;
const IN_ROME_PROJECT = "inRomeProject";
export async function activate(context: ExtensionContext) {
- const command = await getServerPath(context);
+ const command = process.env.DEBUG_SERVER_PATH || (
+ await getServerPath(context)
+ );
if (!command) {
await window.showErrorMessage(
"The Rome extensions doesn't ship with prebuilt binaries for your platform yet. " +
@@ -25,6 +27,14 @@ export async function activate(context: ExtensionContext) {
transport: TransportKind.stdio,
};
+ // only override serverOptions.options when developing extension,
+ // this is convenient for debugging
+ // Before, every time we modify the client package, we need to rebuild vscode extension and install, for now, we could use Launching Client or press F5 to open a separate debug window and doing some check, finally we could bundle the vscode and do some final check.
+ // Passing such variable via `Launch.json`, you need not to add an extra environment variable or change the setting.json `rome.lspBin`,
+ if (process.env.DEBUG_SERVER_PATH) {
+ serverOptions.options = { env: { ...process.env } };
+ }
+
const clientOptions: LanguageClientOptions = {
documentSelector: [
{ scheme: "file", language: "javascript" },
@@ -44,7 +54,7 @@ export async function activate(context: ExtensionContext) {
client.start();
}
-type Architecture = 'x64' | 'arm64';
+type Architecture = "x64" | "arm64";
type PlatformTriplets = {
[P in NodeJS.Platform]?: {

chore(rome_lsp):  migration to tower_lsp crate (#2485)