diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2024-08-24 01:21:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-24 01:21:21 +0100 |
commit | 2ab4afc6b8e90f1315e0727c9b9c714c3667dc45 (patch) | |
tree | 05f07ba22d5d4a5f5120ab988320ad88ea20d542 /tests/util | |
parent | bbd3a7e637b0223647405adf76b23092ab957157 (diff) |
refactor(lsp): changes for lsp_types 0.97.0 (#25169)
Diffstat (limited to 'tests/util')
-rw-r--r-- | tests/util/server/src/fs.rs | 22 | ||||
-rw-r--r-- | tests/util/server/src/lsp.rs | 20 |
2 files changed, 31 insertions, 11 deletions
diff --git a/tests/util/server/src/fs.rs b/tests/util/server/src/fs.rs index fc27e4485..47d0d61fa 100644 --- a/tests/util/server/src/fs.rs +++ b/tests/util/server/src/fs.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use lsp_types::Uri; use pretty_assertions::assert_eq; use std::borrow::Cow; use std::collections::HashSet; @@ -10,12 +11,13 @@ use std::io::Write; use std::path::Path; use std::path::PathBuf; use std::process::Command; +use std::str::FromStr; use std::sync::Arc; use anyhow::Context; -use lsp_types::Url; use serde::de::DeserializeOwned; use serde::Serialize; +use url::Url; use crate::assertions::assert_wildcard_match; use crate::testdata_path; @@ -52,14 +54,22 @@ impl PathRef { PathRef(self.as_path().parent().unwrap().to_path_buf()) } - pub fn uri_dir(&self) -> Url { + pub fn url_dir(&self) -> Url { Url::from_directory_path(self.as_path()).unwrap() } - pub fn uri_file(&self) -> Url { + pub fn url_file(&self) -> Url { Url::from_file_path(self.as_path()).unwrap() } + pub fn uri_dir(&self) -> Uri { + Uri::from_str(self.url_dir().as_str()).unwrap() + } + + pub fn uri_file(&self) -> Uri { + Uri::from_str(self.url_file().as_str()).unwrap() + } + pub fn as_path(&self) -> &Path { self.0.as_path() } @@ -444,10 +454,14 @@ impl TempDir { })) } - pub fn uri(&self) -> Url { + pub fn url(&self) -> Url { Url::from_directory_path(self.path()).unwrap() } + pub fn uri(&self) -> Uri { + Uri::from_str(self.url().as_str()).unwrap() + } + pub fn path(&self) -> &PathRef { self.0.path() } diff --git a/tests/util/server/src/lsp.rs b/tests/util/server/src/lsp.rs index 85879d9d8..1c70978b6 100644 --- a/tests/util/server/src/lsp.rs +++ b/tests/util/server/src/lsp.rs @@ -21,7 +21,6 @@ use lsp_types::FoldingRangeClientCapabilities; use lsp_types::InitializeParams; use lsp_types::TextDocumentClientCapabilities; use lsp_types::TextDocumentSyncClientCapabilities; -use lsp_types::Url; use lsp_types::WorkspaceClientCapabilities; use once_cell::sync::Lazy; use parking_lot::Condvar; @@ -47,10 +46,12 @@ use std::process::ChildStdin; use std::process::ChildStdout; use std::process::Command; use std::process::Stdio; +use std::str::FromStr; use std::sync::mpsc; use std::sync::Arc; use std::time::Duration; use std::time::Instant; +use url::Url; static CONTENT_TYPE_REG: Lazy<Regex> = lazy_regex::lazy_regex!(r"(?i)^content-length:\s+(\d+)"); @@ -234,7 +235,6 @@ impl InitializeParamsBuilder { name: "test-harness".to_string(), version: Some("1.0.0".to_string()), }), - root_uri: None, initialization_options: Some(config_as_options), capabilities: ClientCapabilities { text_document: Some(TextDocumentClientCapabilities { @@ -289,8 +289,10 @@ impl InitializeParamsBuilder { } } + #[allow(deprecated)] pub fn set_maybe_root_uri(&mut self, value: Option<Url>) -> &mut Self { - self.params.root_uri = value; + self.params.root_uri = + value.map(|v| lsp::Uri::from_str(v.as_str()).unwrap()); self } @@ -871,7 +873,7 @@ impl LspClient { mut config: Value, ) { let mut builder = InitializeParamsBuilder::new(config.clone()); - builder.set_root_uri(self.root_dir.uri_dir()); + builder.set_root_uri(self.root_dir.url_dir()); do_build(&mut builder); let params: InitializeParams = builder.build(); // `config` must be updated to account for the builder changes. @@ -1234,7 +1236,7 @@ impl CollectedDiagnostics { self .all_messages() .iter() - .filter(|p| p.uri == *specifier) + .filter(|p| p.uri.as_str() == specifier.as_str()) .flat_map(|p| p.diagnostics.iter()) .cloned() .collect() @@ -1272,7 +1274,7 @@ impl CollectedDiagnostics { .all_messages() .iter() .find(|p| { - p.uri == specifier + p.uri.as_str() == specifier.as_str() && p .diagnostics .iter() @@ -1323,7 +1325,11 @@ impl SourceFile { range_of_nth(n, text, &self.src) } - pub fn uri(&self) -> lsp::Url { + pub fn url(&self) -> Url { + self.path.url_file() + } + + pub fn uri(&self) -> lsp::Uri { self.path.uri_file() } |