mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
refactor(lsp): migrate from lspower back to tower-lsp (#14163)
This commit is contained in:
parent
6c25b5135d
commit
a6e4b4297d
26 changed files with 253 additions and 228 deletions
127
Cargo.lock
generated
127
Cargo.lock
generated
|
@ -689,16 +689,6 @@ dependencies = [
|
|||
"syn 1.0.85",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dashmap"
|
||||
version = "4.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"num_cpus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dashmap"
|
||||
version = "5.2.0"
|
||||
|
@ -779,7 +769,6 @@ dependencies = [
|
|||
"jsonc-parser",
|
||||
"libc",
|
||||
"log",
|
||||
"lspower",
|
||||
"nix",
|
||||
"node_resolver",
|
||||
"notify",
|
||||
|
@ -804,6 +793,7 @@ dependencies = [
|
|||
"text_lines",
|
||||
"tokio",
|
||||
"tokio-util 0.7.0",
|
||||
"tower-lsp",
|
||||
"trust-dns-client",
|
||||
"trust-dns-server",
|
||||
"typed-arena",
|
||||
|
@ -2365,9 +2355,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "lsp-types"
|
||||
version = "0.91.1"
|
||||
version = "0.92.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2368312c59425dd133cb9a327afee65be0a633a8ce471d248e2202a48f8f68ae"
|
||||
checksum = "c79d4897790e8fd2550afa6d6125821edb5716e60e0e285046e070f0f6a06e0e"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"serde",
|
||||
|
@ -2376,43 +2366,6 @@ dependencies = [
|
|||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lspower"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c713fbfa0f03f0b8286a1e250281350aa07dee40e6ef5c0a4d5a2801146d7a54"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"auto_impl",
|
||||
"bytes",
|
||||
"dashmap 4.0.2",
|
||||
"futures",
|
||||
"httparse",
|
||||
"log",
|
||||
"lsp-types",
|
||||
"lspower-macros",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tokio-util 0.6.9",
|
||||
"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 1.0.36",
|
||||
"quote 1.0.14",
|
||||
"syn 1.0.85",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lzzzz"
|
||||
version = "0.8.0"
|
||||
|
@ -4180,7 +4133,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "dca63fd94ef598a08aa0a8bb46506896efe93acf5e0e6e03fef7b02bab094285"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"dashmap 5.2.0",
|
||||
"dashmap",
|
||||
"indexmap",
|
||||
"once_cell",
|
||||
"serde_json",
|
||||
|
@ -4222,7 +4175,7 @@ checksum = "4fd0f164c04335aa8b7c09004dc85643eb47f2aad0cd0c8975bb93f87e9b3796"
|
|||
dependencies = [
|
||||
"ahash",
|
||||
"base64 0.13.0",
|
||||
"dashmap 5.2.0",
|
||||
"dashmap",
|
||||
"indexmap",
|
||||
"once_cell",
|
||||
"regex",
|
||||
|
@ -4645,6 +4598,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.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "835e69c995865ed116986d68f74044393c21606c65e25e570031e6e793f21a7b"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"auto_impl",
|
||||
"bytes",
|
||||
"dashmap",
|
||||
"futures",
|
||||
"httparse",
|
||||
"log",
|
||||
"lsp-types",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"tokio-util 0.7.0",
|
||||
"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 1.0.36",
|
||||
"quote 1.0.14",
|
||||
"syn 1.0.85",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-service"
|
||||
version = "0.3.1"
|
||||
|
@ -4800,16 +4807,6 @@ dependencies = [
|
|||
"webpki",
|
||||
]
|
||||
|
||||
[[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 = "typed-arena"
|
||||
version = "2.0.1"
|
||||
|
@ -4828,12 +4825,6 @@ version = "0.1.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
|
||||
|
||||
[[package]]
|
||||
name = "unchecked-index"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eeba86d422ce181a719445e51872fa30f1f7413b62becb52e95ec91aa262d85c"
|
||||
|
||||
[[package]]
|
||||
name = "unic-char-property"
|
||||
version = "0.9.0"
|
||||
|
|
|
@ -74,7 +74,6 @@ import_map = "=0.9.0"
|
|||
jsonc-parser = { version = "=0.19.0", features = ["serde"] }
|
||||
libc = "=0.2.121"
|
||||
log = { version = "=0.4.14", features = ["serde"] }
|
||||
lspower = "=1.4.0"
|
||||
node_resolver = "=0.1.1"
|
||||
notify = "=5.0.0-pre.14"
|
||||
num-format = "=0.4.0"
|
||||
|
@ -95,6 +94,7 @@ text-size = "=1.1.0"
|
|||
text_lines = "=0.4.1"
|
||||
tokio = { version = "=1.17", features = ["full"] }
|
||||
tokio-util = "=0.7.0"
|
||||
tower-lsp = "=0.16.0"
|
||||
typed-arena = "2.0.1"
|
||||
uuid = { version = "=0.8.2", features = ["v4", "serde"] }
|
||||
walkdir = "=2.3.2"
|
||||
|
|
|
@ -6,12 +6,12 @@ use deno_core::serde_json;
|
|||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::url::Url;
|
||||
use lspower::lsp;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
use test_util::lsp::LspClient;
|
||||
use test_util::lsp::LspResponseError;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
static FIXTURE_CODE_LENS_TS: &str = include_str!("testdata/code_lens.ts");
|
||||
static FIXTURE_DB_TS: &str = include_str!("testdata/db.ts");
|
||||
|
|
|
@ -16,13 +16,13 @@ use deno_core::error::AnyError;
|
|||
use deno_core::serde::Deserialize;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use lspower::lsp;
|
||||
use lspower::lsp::Position;
|
||||
use lspower::lsp::Range;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::HashMap;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
use tower_lsp::lsp_types::Position;
|
||||
use tower_lsp::lsp_types::Range;
|
||||
|
||||
/// Diagnostic error codes which actually are the same, and so when grouping
|
||||
/// fixes we treat them the same.
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
///! client.
|
||||
///!
|
||||
use deno_core::serde_json::json;
|
||||
use lspower::lsp::*;
|
||||
use tower_lsp::lsp_types::*;
|
||||
|
||||
use super::refactor::ALL_KNOWN_REFACTOR_ACTION_KINDS;
|
||||
use super::semantic_tokens::get_legend;
|
||||
|
|
|
@ -8,8 +8,8 @@ use deno_core::error::AnyError;
|
|||
use deno_core::futures::future;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::Value;
|
||||
use lspower::lsp;
|
||||
use lspower::lsp::ConfigurationItem;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
use tower_lsp::lsp_types::ConfigurationItem;
|
||||
|
||||
use crate::lsp::repl::get_repl_workspace_settings;
|
||||
|
||||
|
@ -35,8 +35,8 @@ impl std::fmt::Debug for Client {
|
|||
}
|
||||
|
||||
impl Client {
|
||||
pub fn from_lspower(client: lspower::Client) -> Self {
|
||||
Self(Arc::new(LspowerClient(client)))
|
||||
pub fn from_tower(client: tower_lsp::Client) -> Self {
|
||||
Self(Arc::new(TowerClient(client)))
|
||||
}
|
||||
|
||||
pub fn new_for_repl() -> Self {
|
||||
|
@ -148,9 +148,9 @@ trait ClientTrait: Send + Sync {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct LspowerClient(lspower::Client);
|
||||
struct TowerClient(tower_lsp::Client);
|
||||
|
||||
impl ClientTrait for LspowerClient {
|
||||
impl ClientTrait for TowerClient {
|
||||
fn publish_diagnostics(
|
||||
&self,
|
||||
uri: lsp::Url,
|
||||
|
@ -170,9 +170,7 @@ impl ClientTrait for LspowerClient {
|
|||
let client = self.0.clone();
|
||||
Box::pin(async move {
|
||||
client
|
||||
.send_custom_notification::<lsp_custom::RegistryStateNotification>(
|
||||
params,
|
||||
)
|
||||
.send_notification::<lsp_custom::RegistryStateNotification>(params)
|
||||
.await
|
||||
})
|
||||
}
|
||||
|
@ -183,18 +181,18 @@ impl ClientTrait for LspowerClient {
|
|||
match notification {
|
||||
TestingNotification::Module(params) => {
|
||||
client
|
||||
.send_custom_notification::<testing_lsp_custom::TestModuleNotification>(
|
||||
.send_notification::<testing_lsp_custom::TestModuleNotification>(
|
||||
params,
|
||||
)
|
||||
.await
|
||||
}
|
||||
TestingNotification::DeleteModule(params) => client
|
||||
.send_custom_notification::<testing_lsp_custom::TestModuleDeleteNotification>(
|
||||
.send_notification::<testing_lsp_custom::TestModuleDeleteNotification>(
|
||||
params,
|
||||
)
|
||||
.await,
|
||||
TestingNotification::Progress(params) => client
|
||||
.send_custom_notification::<testing_lsp_custom::TestRunProgressNotification>(
|
||||
.send_notification::<testing_lsp_custom::TestRunProgressNotification>(
|
||||
params,
|
||||
)
|
||||
.await,
|
||||
|
|
|
@ -19,13 +19,13 @@ use deno_core::serde::Serialize;
|
|||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use lspower::lsp;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashSet;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
static ABSTRACT_MODIFIER: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"\babstract\b").unwrap());
|
||||
|
|
|
@ -20,10 +20,10 @@ use deno_core::serde::Serialize;
|
|||
use deno_core::url::Position;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use import_map::ImportMap;
|
||||
use lspower::lsp;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use std::sync::Arc;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
static FILE_PROTO_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r#"^file:/{2}(?:/[A-Za-z]:)?"#).unwrap());
|
||||
|
|
|
@ -9,10 +9,10 @@ use deno_core::serde::Serialize;
|
|||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use lspower::lsp;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
pub const SETTINGS_SECTION: &str = "deno";
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ use deno_core::ModuleSpecifier;
|
|||
use deno_graph::Resolved;
|
||||
use deno_runtime::tokio_util::create_basic_runtime;
|
||||
use log::error;
|
||||
use lspower::lsp;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
|
@ -35,6 +34,7 @@ use tokio::sync::mpsc;
|
|||
use tokio::sync::Mutex;
|
||||
use tokio::time::Duration;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
pub type SnapshotForDiagnostics =
|
||||
(Arc<StateSnapshot>, Arc<ConfigSnapshot>, Option<LintConfig>);
|
||||
|
|
|
@ -25,7 +25,6 @@ use deno_core::url;
|
|||
use deno_core::ModuleSpecifier;
|
||||
use deno_graph::Module;
|
||||
use deno_graph::Resolved;
|
||||
use lspower::lsp;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
|
@ -36,6 +35,7 @@ use std::path::Path;
|
|||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
static JS_HEADERS: Lazy<HashMap<String, String>> = Lazy::new(|| {
|
||||
([(
|
||||
|
|
|
@ -11,15 +11,15 @@ use deno_core::ModuleSpecifier;
|
|||
use import_map::ImportMap;
|
||||
use log::error;
|
||||
use log::warn;
|
||||
use lspower::jsonrpc::Error as LspError;
|
||||
use lspower::jsonrpc::Result as LspResult;
|
||||
use lspower::lsp::request::*;
|
||||
use lspower::lsp::*;
|
||||
use serde_json::from_value;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use tokio::fs;
|
||||
use tower_lsp::jsonrpc::Error as LspError;
|
||||
use tower_lsp::jsonrpc::Result as LspResult;
|
||||
use tower_lsp::lsp_types::request::*;
|
||||
use tower_lsp::lsp_types::*;
|
||||
|
||||
use super::analysis::fix_ts_import_changes;
|
||||
use super::analysis::ts_changes_to_edit;
|
||||
|
@ -132,6 +132,85 @@ impl LanguageServer {
|
|||
pub fn new(client: Client) -> Self {
|
||||
Self(Arc::new(tokio::sync::Mutex::new(Inner::new(client))))
|
||||
}
|
||||
|
||||
pub async fn cache_request(
|
||||
&self,
|
||||
params: Option<Value>,
|
||||
) -> LspResult<Option<Value>> {
|
||||
match params.map(serde_json::from_value) {
|
||||
Some(Ok(params)) => self.0.lock().await.cache(params).await,
|
||||
Some(Err(err)) => Err(LspError::invalid_params(err.to_string())),
|
||||
None => Err(LspError::invalid_params("Missing parameters")),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn performance_request(&self) -> LspResult<Option<Value>> {
|
||||
Ok(Some(self.0.lock().await.get_performance()))
|
||||
}
|
||||
|
||||
pub async fn reload_import_registries_request(
|
||||
&self,
|
||||
) -> LspResult<Option<Value>> {
|
||||
self.0.lock().await.reload_import_registries().await
|
||||
}
|
||||
|
||||
pub async fn task_request(&self) -> LspResult<Option<Value>> {
|
||||
self.0.lock().await.get_tasks()
|
||||
}
|
||||
|
||||
pub async fn test_run_request(
|
||||
&self,
|
||||
params: Option<Value>,
|
||||
) -> LspResult<Option<Value>> {
|
||||
let inner = self.0.lock().await;
|
||||
if let Some(testing_server) = &inner.maybe_testing_server {
|
||||
match params.map(serde_json::from_value) {
|
||||
Some(Ok(params)) => testing_server
|
||||
.run_request(params, inner.config.get_workspace_settings()),
|
||||
Some(Err(err)) => Err(LspError::invalid_params(err.to_string())),
|
||||
None => Err(LspError::invalid_params("Missing parameters")),
|
||||
}
|
||||
} else {
|
||||
Err(LspError::invalid_request())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn test_run_cancel_request(
|
||||
&self,
|
||||
params: Option<Value>,
|
||||
) -> LspResult<Option<Value>> {
|
||||
if let Some(testing_server) = &self.0.lock().await.maybe_testing_server {
|
||||
match params.map(serde_json::from_value) {
|
||||
Some(Ok(params)) => testing_server.run_cancel_request(params),
|
||||
Some(Err(err)) => Err(LspError::invalid_params(err.to_string())),
|
||||
None => Err(LspError::invalid_params("Missing parameters")),
|
||||
}
|
||||
} else {
|
||||
Err(LspError::invalid_request())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn virtual_text_document(
|
||||
&self,
|
||||
params: Option<Value>,
|
||||
) -> LspResult<Option<Value>> {
|
||||
match params.map(serde_json::from_value) {
|
||||
Some(Ok(params)) => Ok(Some(
|
||||
serde_json::to_value(
|
||||
self.0.lock().await.virtual_text_document(params).await?,
|
||||
)
|
||||
.map_err(|err| {
|
||||
error!(
|
||||
"Failed to serialize virtual_text_document response: {}",
|
||||
err
|
||||
);
|
||||
LspError::internal_error()
|
||||
})?,
|
||||
)),
|
||||
Some(Err(err)) => Err(LspError::invalid_params(err.to_string())),
|
||||
None => Err(LspError::invalid_params("Missing parameters")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Inner {
|
||||
|
@ -2144,68 +2223,6 @@ impl Inner {
|
|||
}
|
||||
}
|
||||
|
||||
async fn request_else(
|
||||
&mut self,
|
||||
method: &str,
|
||||
params: Option<Value>,
|
||||
) -> LspResult<Option<Value>> {
|
||||
match method {
|
||||
lsp_custom::CACHE_REQUEST => match params.map(serde_json::from_value) {
|
||||
Some(Ok(params)) => self.cache(params).await,
|
||||
Some(Err(err)) => Err(LspError::invalid_params(err.to_string())),
|
||||
None => Err(LspError::invalid_params("Missing parameters")),
|
||||
},
|
||||
lsp_custom::PERFORMANCE_REQUEST => Ok(Some(self.get_performance())),
|
||||
lsp_custom::RELOAD_IMPORT_REGISTRIES_REQUEST => {
|
||||
self.reload_import_registries().await
|
||||
}
|
||||
lsp_custom::TASK_REQUEST => self.get_tasks(),
|
||||
testing::TEST_RUN_REQUEST => {
|
||||
if let Some(testing_server) = &self.maybe_testing_server {
|
||||
match params.map(serde_json::from_value) {
|
||||
Some(Ok(params)) => testing_server
|
||||
.run_request(params, self.config.get_workspace_settings()),
|
||||
Some(Err(err)) => Err(LspError::invalid_params(err.to_string())),
|
||||
None => Err(LspError::invalid_params("Missing parameters")),
|
||||
}
|
||||
} else {
|
||||
Err(LspError::invalid_request())
|
||||
}
|
||||
}
|
||||
testing::TEST_RUN_CANCEL_REQUEST => {
|
||||
if let Some(testing_server) = &self.maybe_testing_server {
|
||||
match params.map(serde_json::from_value) {
|
||||
Some(Ok(params)) => testing_server.run_cancel_request(params),
|
||||
Some(Err(err)) => Err(LspError::invalid_params(err.to_string())),
|
||||
None => Err(LspError::invalid_params("Missing parameters")),
|
||||
}
|
||||
} else {
|
||||
Err(LspError::invalid_request())
|
||||
}
|
||||
}
|
||||
lsp_custom::VIRTUAL_TEXT_DOCUMENT => {
|
||||
match params.map(serde_json::from_value) {
|
||||
Some(Ok(params)) => Ok(Some(
|
||||
serde_json::to_value(self.virtual_text_document(params).await?)
|
||||
.map_err(|err| {
|
||||
error!(
|
||||
"Failed to serialize virtual_text_document response: {}",
|
||||
err
|
||||
);
|
||||
LspError::internal_error()
|
||||
})?,
|
||||
)),
|
||||
Some(Err(err)) => Err(LspError::invalid_params(err.to_string())),
|
||||
None => Err(LspError::invalid_params("Missing parameters")),
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
error!("Got a {} request, but no handler is defined", method);
|
||||
Err(LspError::method_not_found())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn selection_range(
|
||||
&mut self,
|
||||
params: SelectionRangeParams,
|
||||
|
@ -2441,8 +2458,8 @@ impl Inner {
|
|||
}
|
||||
}
|
||||
|
||||
#[lspower::async_trait]
|
||||
impl lspower::LanguageServer for LanguageServer {
|
||||
#[tower_lsp::async_trait]
|
||||
impl tower_lsp::LanguageServer for LanguageServer {
|
||||
async fn initialize(
|
||||
&self,
|
||||
params: InitializeParams,
|
||||
|
@ -2780,14 +2797,6 @@ impl lspower::LanguageServer for LanguageServer {
|
|||
self.0.lock().await.rename(params).await
|
||||
}
|
||||
|
||||
async fn request_else(
|
||||
&self,
|
||||
method: &str,
|
||||
params: Option<Value>,
|
||||
) -> LspResult<Option<Value>> {
|
||||
self.0.lock().await.request_else(method, params).await
|
||||
}
|
||||
|
||||
async fn selection_range(
|
||||
&self,
|
||||
params: SelectionRangeParams,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use deno_core::serde::Deserialize;
|
||||
use deno_core::serde::Serialize;
|
||||
use lspower::lsp;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
pub const CACHE_REQUEST: &str = "deno/cache";
|
||||
pub const PERFORMANCE_REQUEST: &str = "deno/performance";
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use deno_core::error::AnyError;
|
||||
use lspower::LspService;
|
||||
use lspower::Server;
|
||||
use tower_lsp::LspService;
|
||||
use tower_lsp::Server;
|
||||
|
||||
use crate::lsp::language_server::LanguageServer;
|
||||
pub use repl::ReplCompletionItem;
|
||||
pub use repl::ReplLanguageServer;
|
||||
|
||||
|
@ -35,13 +36,31 @@ pub async fn start() -> Result<(), AnyError> {
|
|||
let stdin = tokio::io::stdin();
|
||||
let stdout = tokio::io::stdout();
|
||||
|
||||
let (service, messages) = LspService::new(|client| {
|
||||
language_server::LanguageServer::new(client::Client::from_lspower(client))
|
||||
});
|
||||
Server::new(stdin, stdout)
|
||||
.interleave(messages)
|
||||
.serve(service)
|
||||
.await;
|
||||
let (service, socket) = LspService::build(|client| {
|
||||
language_server::LanguageServer::new(client::Client::from_tower(client))
|
||||
})
|
||||
.custom_method(lsp_custom::CACHE_REQUEST, LanguageServer::cache_request)
|
||||
.custom_method(
|
||||
lsp_custom::PERFORMANCE_REQUEST,
|
||||
LanguageServer::performance_request,
|
||||
)
|
||||
.custom_method(
|
||||
lsp_custom::RELOAD_IMPORT_REGISTRIES_REQUEST,
|
||||
LanguageServer::reload_import_registries_request,
|
||||
)
|
||||
.custom_method(lsp_custom::TASK_REQUEST, LanguageServer::task_request)
|
||||
.custom_method(testing::TEST_RUN_REQUEST, LanguageServer::test_run_request)
|
||||
.custom_method(
|
||||
testing::TEST_RUN_CANCEL_REQUEST,
|
||||
LanguageServer::test_run_cancel_request,
|
||||
)
|
||||
.custom_method(
|
||||
lsp_custom::VIRTUAL_TEXT_DOCUMENT,
|
||||
LanguageServer::virtual_text_document,
|
||||
)
|
||||
.finish();
|
||||
|
||||
Server::new(stdin, stdout, socket).serve(service).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
use deno_core::serde::Deserialize;
|
||||
use deno_core::serde::Serialize;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use lspower::lsp;
|
||||
use once_cell::sync::Lazy;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
pub struct RefactorCodeActionKind {
|
||||
pub kind: lsp::CodeActionKind,
|
||||
|
|
|
@ -31,12 +31,12 @@ use deno_graph::Dependency;
|
|||
use deno_runtime::deno_web::BlobStore;
|
||||
use deno_runtime::permissions::Permissions;
|
||||
use log::error;
|
||||
use lspower::lsp;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
const CONFIG_PATH: &str = "/.well-known/deno-import-intellisense.json";
|
||||
const COMPONENT: &percent_encoding::AsciiSet = &percent_encoding::CONTROLS
|
||||
|
|
|
@ -10,28 +10,28 @@ use deno_ast::SourceTextInfo;
|
|||
use deno_core::anyhow::anyhow;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::serde_json;
|
||||
use lspower::lsp::ClientCapabilities;
|
||||
use lspower::lsp::ClientInfo;
|
||||
use lspower::lsp::CompletionContext;
|
||||
use lspower::lsp::CompletionParams;
|
||||
use lspower::lsp::CompletionResponse;
|
||||
use lspower::lsp::CompletionTextEdit;
|
||||
use lspower::lsp::CompletionTriggerKind;
|
||||
use lspower::lsp::DidChangeTextDocumentParams;
|
||||
use lspower::lsp::DidCloseTextDocumentParams;
|
||||
use lspower::lsp::DidOpenTextDocumentParams;
|
||||
use lspower::lsp::InitializeParams;
|
||||
use lspower::lsp::InitializedParams;
|
||||
use lspower::lsp::PartialResultParams;
|
||||
use lspower::lsp::Position;
|
||||
use lspower::lsp::Range;
|
||||
use lspower::lsp::TextDocumentContentChangeEvent;
|
||||
use lspower::lsp::TextDocumentIdentifier;
|
||||
use lspower::lsp::TextDocumentItem;
|
||||
use lspower::lsp::TextDocumentPositionParams;
|
||||
use lspower::lsp::VersionedTextDocumentIdentifier;
|
||||
use lspower::lsp::WorkDoneProgressParams;
|
||||
use lspower::LanguageServer;
|
||||
use tower_lsp::lsp_types::ClientCapabilities;
|
||||
use tower_lsp::lsp_types::ClientInfo;
|
||||
use tower_lsp::lsp_types::CompletionContext;
|
||||
use tower_lsp::lsp_types::CompletionParams;
|
||||
use tower_lsp::lsp_types::CompletionResponse;
|
||||
use tower_lsp::lsp_types::CompletionTextEdit;
|
||||
use tower_lsp::lsp_types::CompletionTriggerKind;
|
||||
use tower_lsp::lsp_types::DidChangeTextDocumentParams;
|
||||
use tower_lsp::lsp_types::DidCloseTextDocumentParams;
|
||||
use tower_lsp::lsp_types::DidOpenTextDocumentParams;
|
||||
use tower_lsp::lsp_types::InitializeParams;
|
||||
use tower_lsp::lsp_types::InitializedParams;
|
||||
use tower_lsp::lsp_types::PartialResultParams;
|
||||
use tower_lsp::lsp_types::Position;
|
||||
use tower_lsp::lsp_types::Range;
|
||||
use tower_lsp::lsp_types::TextDocumentContentChangeEvent;
|
||||
use tower_lsp::lsp_types::TextDocumentIdentifier;
|
||||
use tower_lsp::lsp_types::TextDocumentItem;
|
||||
use tower_lsp::lsp_types::TextDocumentPositionParams;
|
||||
use tower_lsp::lsp_types::VersionedTextDocumentIdentifier;
|
||||
use tower_lsp::lsp_types::WorkDoneProgressParams;
|
||||
use tower_lsp::LanguageServer;
|
||||
|
||||
use super::client::Client;
|
||||
use super::config::CompletionSettings;
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
// and https://github.com/microsoft/vscode/blob/main/src/vs/workbench/api/common/extHostTypes.ts
|
||||
// for the SemanticTokensBuilder implementation.
|
||||
|
||||
use lspower::lsp::SemanticToken;
|
||||
use lspower::lsp::SemanticTokenModifier;
|
||||
use lspower::lsp::SemanticTokenType;
|
||||
use lspower::lsp::SemanticTokens;
|
||||
use lspower::lsp::SemanticTokensLegend;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use tower_lsp::lsp_types::SemanticToken;
|
||||
use tower_lsp::lsp_types::SemanticTokenModifier;
|
||||
use tower_lsp::lsp_types::SemanticTokenType;
|
||||
use tower_lsp::lsp_types::SemanticTokens;
|
||||
use tower_lsp::lsp_types::SemanticTokensLegend;
|
||||
|
||||
pub const MODIFIER_MASK: u32 = 255;
|
||||
pub const TYPE_OFFSET: u32 = 8;
|
||||
|
|
|
@ -8,8 +8,8 @@ use crate::lsp::client::TestingNotification;
|
|||
use deno_ast::swc::common::Span;
|
||||
use deno_ast::SourceTextInfo;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use lspower::lsp;
|
||||
use std::collections::HashMap;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
fn span_to_range(
|
||||
span: &Span,
|
||||
|
|
|
@ -28,7 +28,6 @@ use deno_core::serde_json::Value;
|
|||
use deno_core::ModuleSpecifier;
|
||||
use deno_runtime::permissions::Permissions;
|
||||
use deno_runtime::tokio_util::run_basic;
|
||||
use lspower::lsp;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
@ -36,6 +35,7 @@ use std::time::Duration;
|
|||
use std::time::Instant;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
/// Logic to convert a test request into a set of test modules to be tested and
|
||||
/// any filters to be applied to those tests
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use deno_core::serde::Deserialize;
|
||||
use deno_core::serde::Serialize;
|
||||
use lspower::lsp;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
pub const TEST_RUN_CANCEL_REQUEST: &str = "deno/testRunCancel";
|
||||
pub const TEST_RUN_REQUEST: &str = "deno/testRun";
|
||||
|
|
|
@ -18,14 +18,14 @@ use deno_core::serde_json::json;
|
|||
use deno_core::serde_json::Value;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_runtime::tokio_util::create_basic_runtime;
|
||||
use lspower::jsonrpc::Error as LspError;
|
||||
use lspower::jsonrpc::Result as LspResult;
|
||||
use lspower::lsp;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use tokio::sync::mpsc;
|
||||
use tower_lsp::jsonrpc::Error as LspError;
|
||||
use tower_lsp::jsonrpc::Result as LspResult;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
fn as_delete_notification(uri: ModuleSpecifier) -> TestingNotification {
|
||||
TestingNotification::DeleteModule(
|
||||
|
|
|
@ -6,14 +6,14 @@ use deno_core::serde_json::json;
|
|||
use deno_core::serde_json::Value;
|
||||
use dissimilar::diff;
|
||||
use dissimilar::Chunk;
|
||||
use lspower::jsonrpc;
|
||||
use lspower::lsp;
|
||||
use lspower::lsp::TextEdit;
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Bound;
|
||||
use std::ops::RangeBounds;
|
||||
use text_size::TextRange;
|
||||
use text_size::TextSize;
|
||||
use tower_lsp::jsonrpc;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
use tower_lsp::lsp_types::TextEdit;
|
||||
|
||||
fn partition_point<T, P>(slice: &[T], mut predicate: P) -> usize
|
||||
where
|
||||
|
|
|
@ -45,9 +45,6 @@ use deno_core::RuntimeOptions;
|
|||
use deno_runtime::tokio_util::create_basic_runtime;
|
||||
use log::error;
|
||||
use log::warn;
|
||||
use lspower::jsonrpc::Error as LspError;
|
||||
use lspower::jsonrpc::Result as LspResult;
|
||||
use lspower::lsp;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Captures;
|
||||
use regex::Regex;
|
||||
|
@ -63,6 +60,9 @@ use text_size::TextSize;
|
|||
use tokio::sync::mpsc;
|
||||
use tokio::sync::oneshot;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tower_lsp::jsonrpc::Error as LspError;
|
||||
use tower_lsp::jsonrpc::Result as LspResult;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
static BRACKET_ACCESSOR_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r#"^\[['"](.+)[\['"]\]$"#).unwrap());
|
||||
|
|
|
@ -8,7 +8,6 @@ use deno_core::serde_json;
|
|||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::url::Url;
|
||||
use lspower::lsp;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
|
@ -17,6 +16,7 @@ use test_util::http_server;
|
|||
use test_util::lsp::LspClient;
|
||||
use test_util::testdata_path;
|
||||
use test_util::TempDir;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
fn load_fixture(path: &str) -> Value {
|
||||
load_fixture_as(path)
|
||||
|
@ -605,7 +605,7 @@ fn lsp_deno_task() {
|
|||
.unwrap();
|
||||
|
||||
let (maybe_res, maybe_err) = client
|
||||
.write_request::<_, _, Value>("deno/task", json!({}))
|
||||
.write_request::<_, _, Value>("deno/task", json!(null))
|
||||
.unwrap();
|
||||
|
||||
assert!(maybe_err.is_none());
|
||||
|
@ -4280,7 +4280,7 @@ fn lsp_performance() {
|
|||
assert!(maybe_err.is_none());
|
||||
assert!(maybe_res.is_some());
|
||||
let (maybe_res, maybe_err) = client
|
||||
.write_request::<_, _, PerformanceAverages>("deno/performance", json!({}))
|
||||
.write_request::<_, _, PerformanceAverages>("deno/performance", json!(null))
|
||||
.unwrap();
|
||||
assert!(maybe_err.is_none());
|
||||
if let Some(res) = maybe_res {
|
||||
|
|
|
@ -11,8 +11,8 @@ use regex::Regex;
|
|||
use serde::de;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
use serde_json::Value;
|
||||
use serde_json::{json, to_value};
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
@ -324,12 +324,20 @@ impl LspClient {
|
|||
V: Serialize,
|
||||
R: de::DeserializeOwned,
|
||||
{
|
||||
let value = json!({
|
||||
let value = if to_value(¶ms).unwrap().is_null() {
|
||||
json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": self.request_id,
|
||||
"method": method.as_ref(),
|
||||
})
|
||||
} else {
|
||||
json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": self.request_id,
|
||||
"method": method.as_ref(),
|
||||
"params": params,
|
||||
});
|
||||
})
|
||||
};
|
||||
self.write(value)?;
|
||||
|
||||
self.reader.read_message(|msg| match msg {
|
||||
|
|
Loading…
Reference in a new issue