diff --git a/Cargo.lock b/Cargo.lock index 2acf11d677..ceb8fb795a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -752,6 +752,7 @@ dependencies = [ "deno_lockfile", "deno_terminal 0.2.0", "deno_tls", + "deno_tower_lsp", "fastwebsockets", "file_test_runner", "flaky_test", @@ -768,7 +769,6 @@ dependencies = [ "serde", "test_server", "tokio", - "tower-lsp", "trust-dns-client", "trust-dns-server", "url", @@ -1178,6 +1178,7 @@ dependencies = [ "deno_semver", "deno_task_shell", "deno_terminal 0.2.0", + "deno_tower_lsp", "dissimilar", "dotenvy", "dprint-plugin-json", @@ -1244,7 +1245,6 @@ dependencies = [ "thiserror", "tokio", "tokio-util", - "tower-lsp", "tracing", "twox-hash", "typed-arena", @@ -1258,6 +1258,17 @@ dependencies = [ "zstd", ] +[[package]] +name = "deno-tower-lsp-macros" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d59a1cfd445fd86f63616127a434aabca000e03d963b01b03ce813520565b9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + [[package]] name = "deno_ast" version = "0.41.2" @@ -2060,6 +2071,29 @@ dependencies = [ "webpki-roots", ] +[[package]] +name = "deno_tower_lsp" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afb4d257c084fd889e8cf1ba3ad58db0002428c819cc7717815f996f97777a" +dependencies = [ + "async-trait", + "auto_impl", + "bytes", + "dashmap", + "deno-tower-lsp-macros", + "futures", + "httparse", + "lsp-types", + "memchr", + "serde", + "serde_json", + "tokio", + "tokio-util", + "tower", + "tracing", +] + [[package]] name = "deno_unsync" version = "0.4.1" @@ -2981,6 +3015,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "fluent-uri" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17c704e9dbe1ddd863da1e6ff3567795087b1eb201ce80d8fa81162e1516500d" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "fnv" version = "1.0.7" @@ -4254,15 +4297,15 @@ dependencies = [ [[package]] name = "lsp-types" -version = "0.94.1" +version = "0.97.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66bfd44a06ae10647fe3f8214762e9369fd4248df1350924b4ef9e770a85ea1" +checksum = "53353550a17c04ac46c585feb189c2db82154fc84b79c7a66c96c2c644f66071" dependencies = [ "bitflags 1.3.2", + "fluent-uri", "serde", "serde_json", "serde_repr", - "url", ] [[package]] @@ -7535,40 +7578,6 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" -[[package]] -name = "tower-lsp" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4ba052b54a6627628d9b3c34c176e7eda8359b7da9acd497b9f20998d118508" -dependencies = [ - "async-trait", - "auto_impl", - "bytes", - "dashmap", - "futures", - "httparse", - "lsp-types", - "memchr", - "serde", - "serde_json", - "tokio", - "tokio-util", - "tower", - "tower-lsp-macros", - "tracing", -] - -[[package]] -name = "tower-lsp-macros" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84fd902d4e0b9a4b27f2f440108dc034e1758628a9b702f8ec61ad66355422fa" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", -] - [[package]] name = "tower-service" version = "0.3.2" diff --git a/Cargo.toml b/Cargo.toml index c6df3a8e7b..6e250bc926 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -133,7 +133,7 @@ lazy-regex = "3" libc = "0.2.126" libz-sys = { version = "1.1", default-features = false } log = "0.4.20" -lsp-types = "=0.94.1" # used by tower-lsp and "proposed" feature is unstable in patch releases +lsp-types = "=0.97.0" # used by tower-lsp and "proposed" feature is unstable in patch releases memmem = "0.1.1" monch = "=0.5.0" notify = "=6.1.1" @@ -184,7 +184,7 @@ tokio-socks = "0.5.1" tokio-util = "0.7.4" tower = { version = "0.4.13", default-features = false, features = ["util"] } tower-http = { version = "0.5.2", features = ["decompression-br", "decompression-gzip"] } -tower-lsp = { version = "=0.20.0", features = ["proposed"] } +tower-lsp = { package = "deno_tower_lsp", version = "0.1.0", features = ["proposed"] } tower-service = "0.3.2" twox-hash = "=1.6.3" # Upgrading past 2.4.1 may cause WPT failures diff --git a/cli/bench/lsp.rs b/cli/bench/lsp.rs index f2070eb216..b088865c6b 100644 --- a/cli/bench/lsp.rs +++ b/cli/bench/lsp.rs @@ -4,9 +4,10 @@ use deno_core::serde::Deserialize; use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::serde_json::Value; -use deno_core::url::Url; +use lsp_types::Uri; use std::collections::HashMap; use std::path::Path; +use std::str::FromStr; use std::time::Duration; use test_util::lsp::LspClientBuilder; use test_util::PathRef; @@ -91,7 +92,7 @@ fn bench_deco_apps_edits(deno_exe: &Path) -> Duration { .build(); client.initialize(|c| { c.set_workspace_folders(vec![lsp_types::WorkspaceFolder { - uri: Url::from_file_path(&apps).unwrap(), + uri: apps.uri_dir(), name: "apps".to_string(), }]); c.set_deno_enable(true); @@ -283,7 +284,7 @@ fn bench_find_replace(deno_exe: &Path) -> Duration { "textDocument/didChange", lsp::DidChangeTextDocumentParams { text_document: lsp::VersionedTextDocumentIdentifier { - uri: Url::parse(&file_name).unwrap(), + uri: Uri::from_str(&file_name).unwrap(), version: 2, }, content_changes: vec![lsp::TextDocumentContentChangeEvent { @@ -310,7 +311,7 @@ fn bench_find_replace(deno_exe: &Path) -> Duration { "textDocument/formatting", lsp::DocumentFormattingParams { text_document: lsp::TextDocumentIdentifier { - uri: Url::parse(&file_name).unwrap(), + uri: Uri::from_str(&file_name).unwrap(), }, options: lsp::FormattingOptions { tab_size: 2, diff --git a/cli/clippy.toml b/cli/clippy.toml index c4afef17c4..e20c56c47a 100644 --- a/cli/clippy.toml +++ b/cli/clippy.toml @@ -4,3 +4,6 @@ disallowed-methods = [ disallowed-types = [ { path = "reqwest::Client", reason = "use crate::http_util::HttpClient instead" }, ] +ignore-interior-mutability = [ + "lsp_types::Uri", +] diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs index 9f2c7ffc86..bea6268419 100644 --- a/cli/lsp/analysis.rs +++ b/cli/lsp/analysis.rs @@ -6,6 +6,7 @@ use super::documents::Documents; use super::language_server; use super::resolver::LspResolver; use super::tsc; +use super::urls::url_to_uri; use crate::args::jsr_url; use crate::tools::lint::CliLinter; @@ -750,10 +751,11 @@ impl CodeActionCollection { .as_ref() .and_then(|d| serde_json::from_value::>(d.clone()).ok()) { + let uri = url_to_uri(specifier); for quick_fix in data_quick_fixes { let mut changes = HashMap::new(); changes.insert( - specifier.clone(), + uri.clone(), quick_fix .changes .into_iter() @@ -795,6 +797,7 @@ impl CodeActionCollection { maybe_text_info: Option<&SourceTextInfo>, maybe_parsed_source: Option<&deno_ast::ParsedSource>, ) -> Result<(), AnyError> { + let uri = url_to_uri(specifier); let code = diagnostic .code .as_ref() @@ -811,7 +814,7 @@ impl CodeActionCollection { let mut changes = HashMap::new(); changes.insert( - specifier.clone(), + uri.clone(), vec![lsp::TextEdit { new_text: prepend_whitespace( format!("// deno-lint-ignore {code}\n"), @@ -892,7 +895,7 @@ impl CodeActionCollection { } let mut changes = HashMap::new(); - changes.insert(specifier.clone(), vec![lsp::TextEdit { new_text, range }]); + changes.insert(uri.clone(), vec![lsp::TextEdit { new_text, range }]); let ignore_file_action = lsp::CodeAction { title: format!("Disable {code} for the entire file"), kind: Some(lsp::CodeActionKind::QUICKFIX), @@ -913,7 +916,7 @@ impl CodeActionCollection { let mut changes = HashMap::new(); changes.insert( - specifier.clone(), + uri, vec![lsp::TextEdit { new_text: "// deno-lint-ignore-file\n".to_string(), range: lsp::Range { diff --git a/cli/lsp/capabilities.rs b/cli/lsp/capabilities.rs index 650fea5718..e93d3b7c20 100644 --- a/cli/lsp/capabilities.rs +++ b/cli/lsp/capabilities.rs @@ -154,5 +154,7 @@ pub fn server_capabilities( // TODO(nayeemrmn): Support pull-based diagnostics. diagnostic_provider: None, inline_value_provider: None, + inline_completion_provider: None, + notebook_document_sync: None, } } diff --git a/cli/lsp/client.rs b/cli/lsp/client.rs index 719ce53f6e..6ed0c04301 100644 --- a/cli/lsp/client.rs +++ b/cli/lsp/client.rs @@ -58,7 +58,7 @@ impl Client { ) { self .0 - .publish_diagnostics(uri.into_url(), diags, version) + .publish_diagnostics(uri.to_uri(), diags, version) .await; } @@ -149,7 +149,7 @@ impl OutsideLockClient { pub async fn workspace_configuration( &self, - scopes: Vec>, + scopes: Vec>, ) -> Result, AnyError> { self.0.workspace_configuration(scopes).await } @@ -159,7 +159,7 @@ impl OutsideLockClient { trait ClientTrait: Send + Sync { async fn publish_diagnostics( &self, - uri: lsp::Url, + uri: lsp::Uri, diagnostics: Vec, version: Option, ); @@ -182,7 +182,7 @@ trait ClientTrait: Send + Sync { ); async fn workspace_configuration( &self, - scopes: Vec>, + scopes: Vec>, ) -> Result, AnyError>; async fn show_message(&self, message_type: lsp::MessageType, text: String); async fn register_capability( @@ -198,7 +198,7 @@ struct TowerClient(tower_lsp::Client); impl ClientTrait for TowerClient { async fn publish_diagnostics( &self, - uri: lsp::Url, + uri: lsp::Uri, diagnostics: Vec, version: Option, ) { @@ -276,7 +276,7 @@ impl ClientTrait for TowerClient { async fn workspace_configuration( &self, - scopes: Vec>, + scopes: Vec>, ) -> Result, AnyError> { let config_response = self .0 @@ -349,7 +349,7 @@ struct ReplClient; impl ClientTrait for ReplClient { async fn publish_diagnostics( &self, - _uri: lsp::Url, + _uri: lsp::Uri, _diagnostics: Vec, _version: Option, ) { @@ -383,7 +383,7 @@ impl ClientTrait for ReplClient { async fn workspace_configuration( &self, - scopes: Vec>, + scopes: Vec>, ) -> Result, AnyError> { Ok(vec![get_repl_workspace_settings(); scopes.len()]) } diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs index ab2d8000c7..1e5504d75c 100644 --- a/cli/lsp/completions.rs +++ b/cli/lsp/completions.rs @@ -838,7 +838,7 @@ mod tests { fs_sources: &[(&str, &str)], ) -> Documents { let temp_dir = TempDir::new(); - let cache = LspCache::new(Some(temp_dir.uri().join(".deno_dir").unwrap())); + let cache = LspCache::new(Some(temp_dir.url().join(".deno_dir").unwrap())); let mut documents = Documents::default(); documents.update_config( &Default::default(), @@ -859,7 +859,7 @@ mod tests { .set(&specifier, HashMap::default(), source.as_bytes()) .expect("could not cache file"); let document = documents - .get_or_load(&specifier, Some(&temp_dir.uri().join("$").unwrap())); + .get_or_load(&specifier, Some(&temp_dir.url().join("$").unwrap())); assert!(document.is_some(), "source could not be setup"); } documents diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index f99f1fa103..4a279a7c41 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -30,6 +30,7 @@ use deno_core::serde::Serialize; use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::serde_json::Value; +use deno_core::url::Url; use deno_core::ModuleSpecifier; use deno_lint::linter::LintConfig as DenoLintConfig; use deno_npm::npm_rc::ResolvedNpmRc; @@ -38,7 +39,6 @@ use deno_runtime::deno_node::PackageJson; use deno_runtime::deno_permissions::PermissionsContainer; use deno_runtime::fs_util::specifier_to_file_path; use indexmap::IndexSet; -use lsp::Url; use lsp_types::ClientCapabilities; use std::collections::BTreeMap; use std::collections::HashMap; @@ -844,14 +844,17 @@ pub struct Config { impl Config { #[cfg(test)] - pub fn new_with_roots(root_uris: impl IntoIterator) -> Self { + pub fn new_with_roots(root_urls: impl IntoIterator) -> Self { + use super::urls::url_to_uri; + let mut config = Self::default(); let mut folders = vec![]; - for root_uri in root_uris { - let name = root_uri.path_segments().and_then(|s| s.last()); + for root_url in root_urls { + let root_uri = url_to_uri(&root_url); + let name = root_url.path_segments().and_then(|s| s.last()); let name = name.unwrap_or_default().to_string(); folders.push(( - root_uri.clone(), + root_url, lsp::WorkspaceFolder { uri: root_uri, name, diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index 5054aa9310..d871ffbe46 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -12,6 +12,7 @@ use super::language_server::StateSnapshot; use super::performance::Performance; use super::tsc; use super::tsc::TsServer; +use super::urls::url_to_uri; use super::urls::LspClientUrl; use super::urls::LspUrlMap; @@ -37,6 +38,7 @@ use deno_core::serde_json::json; use deno_core::unsync::spawn; use deno_core::unsync::spawn_blocking; use deno_core::unsync::JoinHandle; +use deno_core::url::Url; use deno_core::ModuleSpecifier; use deno_graph::source::ResolutionMode; use deno_graph::source::ResolveError; @@ -52,9 +54,11 @@ use deno_semver::package::PackageReq; use import_map::ImportMap; use import_map::ImportMapError; use log::error; +use lsp_types::Uri; use std::collections::HashMap; use std::collections::HashSet; use std::path::PathBuf; +use std::str::FromStr; use std::sync::atomic::AtomicUsize; use std::sync::Arc; use std::thread; @@ -737,7 +741,7 @@ fn to_lsp_related_information( if let (Some(file_name), Some(start), Some(end)) = (&ri.file_name, &ri.start, &ri.end) { - let uri = lsp::Url::parse(file_name).unwrap(); + let uri = Uri::from_str(file_name).unwrap(); Some(lsp::DiagnosticRelatedInformation { location: lsp::Location { uri, @@ -1070,7 +1074,7 @@ impl DenoDiagnostic { diagnostics: Some(vec![diagnostic.clone()]), edit: Some(lsp::WorkspaceEdit { changes: Some(HashMap::from([( - specifier.clone(), + url_to_uri(specifier), vec![lsp::TextEdit { new_text: format!("\"{to}\""), range: diagnostic.range, @@ -1087,7 +1091,7 @@ impl DenoDiagnostic { diagnostics: Some(vec![diagnostic.clone()]), edit: Some(lsp::WorkspaceEdit { changes: Some(HashMap::from([( - specifier.clone(), + url_to_uri(specifier), vec![lsp::TextEdit { new_text: " with { type: \"json\" }".to_string(), range: lsp::Range { @@ -1138,7 +1142,7 @@ impl DenoDiagnostic { diagnostics: Some(vec![diagnostic.clone()]), edit: Some(lsp::WorkspaceEdit { changes: Some(HashMap::from([( - specifier.clone(), + url_to_uri(specifier), vec![lsp::TextEdit { new_text: format!( "\"{}\"", @@ -1164,7 +1168,7 @@ impl DenoDiagnostic { diagnostics: Some(vec![diagnostic.clone()]), edit: Some(lsp::WorkspaceEdit { changes: Some(HashMap::from([( - specifier.clone(), + url_to_uri(specifier), vec![lsp::TextEdit { new_text: format!( "\"{}\"", @@ -1190,7 +1194,7 @@ impl DenoDiagnostic { diagnostics: Some(vec![diagnostic.clone()]), edit: Some(lsp::WorkspaceEdit { changes: Some(HashMap::from([( - specifier.clone(), + url_to_uri(specifier), vec![lsp::TextEdit { new_text: format!("\"node:{}\"", data.specifier), range: diagnostic.range, @@ -1308,10 +1312,7 @@ impl DenoDiagnostic { } } -fn specifier_text_for_redirected( - redirect: &lsp::Url, - referrer: &lsp::Url, -) -> String { +fn specifier_text_for_redirected(redirect: &Url, referrer: &Url) -> String { if redirect.scheme() == "file" && referrer.scheme() == "file" { // use a relative specifier when it's going to a file url relative_specifier(redirect, referrer) @@ -1320,7 +1321,7 @@ fn specifier_text_for_redirected( } } -fn relative_specifier(specifier: &lsp::Url, referrer: &lsp::Url) -> String { +fn relative_specifier(specifier: &Url, referrer: &Url) -> String { match referrer.make_relative(specifier) { Some(relative) => { if relative.starts_with('.') { @@ -1640,7 +1641,8 @@ mod tests { use test_util::TempDir; fn mock_config() -> Config { - let root_uri = resolve_url("file:///").unwrap(); + let root_url = resolve_url("file:///").unwrap(); + let root_uri = url_to_uri(&root_url); Config { settings: Arc::new(Settings { unscoped: Arc::new(WorkspaceSettings { @@ -1651,7 +1653,7 @@ mod tests { ..Default::default() }), workspace_folders: Arc::new(vec![( - root_uri.clone(), + root_url, lsp::WorkspaceFolder { uri: root_uri, name: "".to_string(), @@ -1666,7 +1668,7 @@ mod tests { maybe_import_map: Option<(&str, &str)>, ) -> (TempDir, StateSnapshot) { let temp_dir = TempDir::new(); - let root_uri = temp_dir.uri(); + let root_uri = temp_dir.url(); let cache = LspCache::new(Some(root_uri.join(".deno_dir").unwrap())); let mut config = Config::new_with_roots([root_uri.clone()]); if let Some((relative_path, json_string)) = maybe_import_map { @@ -1833,7 +1835,7 @@ let c: number = "a"; assert_eq!(actual.len(), 2); for record in actual { let relative_specifier = - temp_dir.uri().make_relative(&record.specifier).unwrap(); + temp_dir.url().make_relative(&record.specifier).unwrap(); match relative_specifier.as_str() { "std/assert/mod.ts" => { assert_eq!(json!(record.versioned.diagnostics), json!([])) @@ -2052,7 +2054,7 @@ let c: number = "a"; "source": "deno", "message": format!( "Unable to load a local module: {}🦕.ts\nPlease check the file path.", - temp_dir.uri(), + temp_dir.url(), ), } ]) diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index e91cfe0ac2..a8ddc8fd7d 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -1607,7 +1607,7 @@ mod tests { async fn setup() -> (Documents, LspCache, TempDir) { let temp_dir = TempDir::new(); temp_dir.create_dir_all(".deno_dir"); - let cache = LspCache::new(Some(temp_dir.uri().join(".deno_dir").unwrap())); + let cache = LspCache::new(Some(temp_dir.url().join(".deno_dir").unwrap())); let config = Config::default(); let resolver = Arc::new(LspResolver::from_config(&config, &cache, None).await); @@ -1690,7 +1690,7 @@ console.log(b, "hello deno"); // but we'll guard against it anyway let (mut documents, _, temp_dir) = setup().await; let file_path = temp_dir.path().join("file.ts"); - let file_specifier = temp_dir.uri().join("file.ts").unwrap(); + let file_specifier = temp_dir.url().join("file.ts").unwrap(); file_path.write(""); // open the document @@ -1718,18 +1718,18 @@ console.log(b, "hello deno"); let (mut documents, cache, temp_dir) = setup().await; let file1_path = temp_dir.path().join("file1.ts"); - let file1_specifier = temp_dir.uri().join("file1.ts").unwrap(); + let file1_specifier = temp_dir.url().join("file1.ts").unwrap(); fs::write(&file1_path, "").unwrap(); let file2_path = temp_dir.path().join("file2.ts"); - let file2_specifier = temp_dir.uri().join("file2.ts").unwrap(); + let file2_specifier = temp_dir.url().join("file2.ts").unwrap(); fs::write(&file2_path, "").unwrap(); let file3_path = temp_dir.path().join("file3.ts"); - let file3_specifier = temp_dir.uri().join("file3.ts").unwrap(); + let file3_specifier = temp_dir.url().join("file3.ts").unwrap(); fs::write(&file3_path, "").unwrap(); - let mut config = Config::new_with_roots([temp_dir.uri()]); + let mut config = Config::new_with_roots([temp_dir.url()]); let workspace_settings = serde_json::from_str(r#"{ "enable": true }"#).unwrap(); config.set_workspace_settings(workspace_settings, vec![]); diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 04863c2519..86277ab416 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -12,6 +12,7 @@ use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::unsync::spawn; use deno_core::url; +use deno_core::url::Url; use deno_core::ModuleSpecifier; use deno_graph::GraphKind; use deno_graph::Resolution; @@ -85,6 +86,8 @@ use super::tsc::ChangeKind; use super::tsc::GetCompletionDetailsArgs; use super::tsc::TsServer; use super::urls; +use super::urls::uri_to_url; +use super::urls::url_to_uri; use crate::args::create_default_npmrc; use crate::args::get_root_cert_store; use crate::args::has_flag_env_var; @@ -728,14 +731,17 @@ impl Inner { } // rootUri is deprecated by the LSP spec. If it's specified, merge it into // workspace_folders. + #[allow(deprecated)] if let Some(root_uri) = params.root_uri { if !workspace_folders.iter().any(|(_, f)| f.uri == root_uri) { - let name = root_uri.path_segments().and_then(|s| s.last()); + let root_url = + self.url_map.normalize_url(&root_uri, LspUrlKind::Folder); + let name = root_url.path_segments().and_then(|s| s.last()); let name = name.unwrap_or_default().to_string(); workspace_folders.insert( 0, ( - self.url_map.normalize_url(&root_uri, LspUrlKind::Folder), + root_url, WorkspaceFolder { uri: root_uri, name, @@ -1008,7 +1014,10 @@ impl Inner { async fn did_open(&mut self, params: DidOpenTextDocumentParams) { let mark = self.performance.mark_with_args("lsp.did_open", ¶ms); - if params.text_document.uri.scheme() == "deno" { + let Some(scheme) = params.text_document.uri.scheme() else { + return; + }; + if scheme.as_str() == "deno" { // we can ignore virtual text documents opening, as they don't need to // be tracked in memory, as they are static assets that won't change // already managed by the language service @@ -1027,13 +1036,11 @@ impl Inner { lsp_warn!( "Unsupported language id \"{}\" received for document \"{}\".", params.text_document.language_id, - params.text_document.uri + params.text_document.uri.as_str() ); } - let file_referrer = (self - .documents - .is_valid_file_referrer(¶ms.text_document.uri)) - .then(|| params.text_document.uri.clone()); + let file_referrer = Some(uri_to_url(¶ms.text_document.uri)) + .filter(|s| self.documents.is_valid_file_referrer(s)); let specifier = self .url_map .normalize_url(¶ms.text_document.uri, LspUrlKind::File); @@ -1130,8 +1137,10 @@ impl Inner { async fn did_close(&mut self, params: DidCloseTextDocumentParams) { let mark = self.performance.mark_with_args("lsp.did_close", ¶ms); - self.diagnostics_state.clear(¶ms.text_document.uri); - if params.text_document.uri.scheme() == "deno" { + let Some(scheme) = params.text_document.uri.scheme() else { + return; + }; + if scheme.as_str() == "deno" { // we can ignore virtual text documents closing, as they don't need to // be tracked in memory, as they are static assets that won't change // already managed by the language service @@ -1140,6 +1149,7 @@ impl Inner { let specifier = self .url_map .normalize_url(¶ms.text_document.uri, LspUrlKind::File); + self.diagnostics_state.clear(&specifier); if self.is_diagnosable(&specifier) { self.refresh_npm_specifiers().await; self.diagnostics_server.invalidate(&[specifier.clone()]); @@ -1211,7 +1221,7 @@ impl Inner { _ => return None, }; Some(lsp_custom::DenoConfigurationChangeEvent { - scope_uri: t.0.clone(), + scope_uri: url_to_uri(t.0), file_uri: e.uri.clone(), typ: lsp_custom::DenoConfigurationChangeType::from_file_change_type( e.typ, @@ -1246,7 +1256,7 @@ impl Inner { _ => return None, }; Some(lsp_custom::DenoConfigurationChangeEvent { - scope_uri: t.0.clone(), + scope_uri: url_to_uri(t.0), file_uri: e.uri.clone(), typ: lsp_custom::DenoConfigurationChangeType::from_file_change_type( e.typ, @@ -1312,10 +1322,8 @@ impl Inner { &self, params: DocumentFormattingParams, ) -> LspResult>> { - let file_referrer = (self - .documents - .is_valid_file_referrer(¶ms.text_document.uri)) - .then(|| params.text_document.uri.clone()); + let file_referrer = Some(uri_to_url(¶ms.text_document.uri)) + .filter(|s| self.documents.is_valid_file_referrer(s)); let mut specifier = self .url_map .normalize_url(¶ms.text_document.uri, LspUrlKind::File); @@ -1339,9 +1347,9 @@ impl Inner { // counterparts, but for formatting we want to favour the file URL. // TODO(nayeemrmn): Implement `Document::file_resource_path()` or similar. if specifier.scheme() != "file" - && params.text_document.uri.scheme() == "file" + && params.text_document.uri.scheme().map(|s| s.as_str()) == Some("file") { - specifier = params.text_document.uri.clone(); + specifier = uri_to_url(¶ms.text_document.uri); } let file_path = specifier_to_file_path(&specifier).map_err(|err| { error!("{:#}", err); @@ -2870,7 +2878,7 @@ impl Inner { let mut changes = vec![]; for rename in params.files { let old_specifier = self.url_map.normalize_url( - &resolve_url(&rename.old_uri).unwrap(), + &url_to_uri(&resolve_url(&rename.old_uri).unwrap()), LspUrlKind::File, ); let options = self @@ -2896,7 +2904,7 @@ impl Inner { self.snapshot(), old_specifier, self.url_map.normalize_url( - &resolve_url(&rename.new_uri).unwrap(), + &url_to_uri(&resolve_url(&rename.new_uri).unwrap()), LspUrlKind::File, ), format_code_settings, @@ -3494,19 +3502,20 @@ impl Inner { } let mut config_events = vec![]; - for (scope_uri, config_data) in self.config.tree.data_by_scope().iter() { + for (scope_url, config_data) in self.config.tree.data_by_scope().iter() { + let scope_uri = url_to_uri(scope_url); if let Some(config_file) = config_data.maybe_deno_json() { config_events.push(lsp_custom::DenoConfigurationChangeEvent { scope_uri: scope_uri.clone(), - file_uri: config_file.specifier.clone(), + file_uri: url_to_uri(&config_file.specifier), typ: lsp_custom::DenoConfigurationChangeType::Added, configuration_type: lsp_custom::DenoConfigurationType::DenoJson, }); } if let Some(package_json) = config_data.maybe_pkg_json() { config_events.push(lsp_custom::DenoConfigurationChangeEvent { - scope_uri: scope_uri.clone(), - file_uri: package_json.specifier(), + scope_uri, + file_uri: url_to_uri(&package_json.specifier()), typ: lsp_custom::DenoConfigurationChangeType::Added, configuration_type: lsp_custom::DenoConfigurationType::PackageJson, }); @@ -3715,7 +3724,7 @@ impl Inner { result.push(TaskDefinition { name: name.clone(), command: command.to_string(), - source_uri: config_file.specifier.clone(), + source_uri: url_to_uri(&config_file.specifier), }); } }; @@ -3726,7 +3735,7 @@ impl Inner { result.push(TaskDefinition { name: name.clone(), command: command.clone(), - source_uri: package_json.specifier(), + source_uri: url_to_uri(&package_json.specifier()), }); } } @@ -3956,11 +3965,11 @@ mod tests { temp_dir.write("root4_parent/root4/main.ts", ""); // yes, enabled let mut config = Config::new_with_roots(vec![ - temp_dir.uri().join("root1/").unwrap(), - temp_dir.uri().join("root2/").unwrap(), - temp_dir.uri().join("root2/root2.1/").unwrap(), - temp_dir.uri().join("root3/").unwrap(), - temp_dir.uri().join("root4_parent/root4/").unwrap(), + temp_dir.url().join("root1/").unwrap(), + temp_dir.url().join("root2/").unwrap(), + temp_dir.url().join("root2/root2.1/").unwrap(), + temp_dir.url().join("root3/").unwrap(), + temp_dir.url().join("root4_parent/root4/").unwrap(), ]); config.set_client_capabilities(ClientCapabilities { workspace: Some(Default::default()), @@ -3970,14 +3979,14 @@ mod tests { Default::default(), vec![ ( - temp_dir.uri().join("root1/").unwrap(), + temp_dir.url().join("root1/").unwrap(), WorkspaceSettings { enable: Some(true), ..Default::default() }, ), ( - temp_dir.uri().join("root2/").unwrap(), + temp_dir.url().join("root2/").unwrap(), WorkspaceSettings { enable: Some(true), enable_paths: Some(vec![ @@ -3989,21 +3998,21 @@ mod tests { }, ), ( - temp_dir.uri().join("root2/root2.1/").unwrap(), + temp_dir.url().join("root2/root2.1/").unwrap(), WorkspaceSettings { enable: Some(true), ..Default::default() }, ), ( - temp_dir.uri().join("root3/").unwrap(), + temp_dir.url().join("root3/").unwrap(), WorkspaceSettings { enable: Some(false), ..Default::default() }, ), ( - temp_dir.uri().join("root4_parent/root4/").unwrap(), + temp_dir.url().join("root4_parent/root4/").unwrap(), WorkspaceSettings { enable: Some(true), ..Default::default() @@ -4017,22 +4026,22 @@ mod tests { assert_eq!( json!(workspace_files), json!([ - temp_dir.uri().join("root4_parent/deno.json").unwrap(), - temp_dir.uri().join("root1/mod0.ts").unwrap(), - temp_dir.uri().join("root1/mod1.js").unwrap(), - temp_dir.uri().join("root1/mod2.tsx").unwrap(), - temp_dir.uri().join("root1/mod3.d.ts").unwrap(), - temp_dir.uri().join("root1/mod4.jsx").unwrap(), - temp_dir.uri().join("root1/mod5.mjs").unwrap(), - temp_dir.uri().join("root1/mod6.mts").unwrap(), - temp_dir.uri().join("root1/mod7.d.mts").unwrap(), - temp_dir.uri().join("root1/mod8.json").unwrap(), - temp_dir.uri().join("root1/mod9.jsonc").unwrap(), - temp_dir.uri().join("root2/file1.ts").unwrap(), - temp_dir.uri().join("root4_parent/root4/main.ts").unwrap(), - temp_dir.uri().join("root1/folder/mod.ts").unwrap(), - temp_dir.uri().join("root2/folder/main.ts").unwrap(), - temp_dir.uri().join("root2/root2.1/main.ts").unwrap(), + temp_dir.url().join("root4_parent/deno.json").unwrap(), + temp_dir.url().join("root1/mod0.ts").unwrap(), + temp_dir.url().join("root1/mod1.js").unwrap(), + temp_dir.url().join("root1/mod2.tsx").unwrap(), + temp_dir.url().join("root1/mod3.d.ts").unwrap(), + temp_dir.url().join("root1/mod4.jsx").unwrap(), + temp_dir.url().join("root1/mod5.mjs").unwrap(), + temp_dir.url().join("root1/mod6.mts").unwrap(), + temp_dir.url().join("root1/mod7.d.mts").unwrap(), + temp_dir.url().join("root1/mod8.json").unwrap(), + temp_dir.url().join("root1/mod9.jsonc").unwrap(), + temp_dir.url().join("root2/file1.ts").unwrap(), + temp_dir.url().join("root4_parent/root4/main.ts").unwrap(), + temp_dir.url().join("root1/folder/mod.ts").unwrap(), + temp_dir.url().join("root2/folder/main.ts").unwrap(), + temp_dir.url().join("root2/root2.1/main.ts").unwrap(), ]) ); } diff --git a/cli/lsp/lsp_custom.rs b/cli/lsp/lsp_custom.rs index 637a88bdae..5f485db7ac 100644 --- a/cli/lsp/lsp_custom.rs +++ b/cli/lsp/lsp_custom.rs @@ -17,7 +17,7 @@ pub struct TaskDefinition { // TODO(nayeemrmn): Rename this to `command` in vscode_deno. #[serde(rename = "detail")] pub command: String, - pub source_uri: lsp::Url, + pub source_uri: lsp::Uri, } #[derive(Debug, Deserialize, Serialize)] @@ -75,8 +75,8 @@ pub enum DenoConfigurationType { #[derive(Debug, Eq, Hash, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct DenoConfigurationChangeEvent { - pub scope_uri: lsp::Url, - pub file_uri: lsp::Url, + pub scope_uri: lsp::Uri, + pub file_uri: lsp::Uri, #[serde(rename = "type")] pub typ: DenoConfigurationChangeType, pub configuration_type: DenoConfigurationType, diff --git a/cli/lsp/repl.rs b/cli/lsp/repl.rs index 2db7b1f725..ada30f8374 100644 --- a/cli/lsp/repl.rs +++ b/cli/lsp/repl.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use std::collections::HashMap; +use std::str::FromStr; use deno_ast::LineAndColumnIndex; use deno_ast::ModuleSpecifier; @@ -8,6 +9,7 @@ use deno_ast::SourceTextInfo; use deno_core::anyhow::anyhow; use deno_core::error::AnyError; use deno_core::serde_json; +use lsp_types::Uri; use tower_lsp::lsp_types::ClientCapabilities; use tower_lsp::lsp_types::ClientInfo; use tower_lsp::lsp_types::CompletionContext; @@ -40,6 +42,7 @@ use super::config::LanguageWorkspaceSettings; use super::config::ObjectLiteralMethodSnippets; use super::config::TestingSettings; use super::config::WorkspaceSettings; +use super::urls::url_to_uri; #[derive(Debug)] pub struct ReplCompletionItem { @@ -73,7 +76,7 @@ impl ReplLanguageServer { .initialize(InitializeParams { process_id: None, root_path: None, - root_uri: Some(cwd_uri.clone()), + root_uri: Some(url_to_uri(&cwd_uri)), initialization_options: Some( serde_json::to_value(get_repl_workspace_settings()).unwrap(), ), @@ -84,6 +87,7 @@ impl ReplLanguageServer { general: None, experimental: None, offset_encoding: None, + notebook_document: None, }, trace: None, workspace_folders: None, @@ -92,6 +96,7 @@ impl ReplLanguageServer { version: None, }), locale: None, + work_done_progress_params: Default::default(), }) .await?; @@ -133,7 +138,7 @@ impl ReplLanguageServer { .completion(CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { - uri: self.get_document_specifier(), + uri: self.get_document_uri(), }, position: Position { line: line_and_column.line_index as u32, @@ -208,7 +213,7 @@ impl ReplLanguageServer { .language_server .did_change(DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { - uri: self.get_document_specifier(), + uri: self.get_document_uri(), version: self.document_version, }, content_changes: vec![TextDocumentContentChangeEvent { @@ -233,7 +238,7 @@ impl ReplLanguageServer { .language_server .did_close(DidCloseTextDocumentParams { text_document: TextDocumentIdentifier { - uri: self.get_document_specifier(), + uri: self.get_document_uri(), }, }) .await; @@ -248,7 +253,7 @@ impl ReplLanguageServer { .language_server .did_open(DidOpenTextDocumentParams { text_document: TextDocumentItem { - uri: self.get_document_specifier(), + uri: self.get_document_uri(), language_id: "typescript".to_string(), version: self.document_version, text: format!("{}{}", self.document_text, self.pending_text), @@ -257,8 +262,8 @@ impl ReplLanguageServer { .await; } - fn get_document_specifier(&self) -> ModuleSpecifier { - self.cwd_uri.join("$deno$repl.ts").unwrap() + fn get_document_uri(&self) -> Uri { + Uri::from_str(self.cwd_uri.join("$deno$repl.ts").unwrap().as_str()).unwrap() } } diff --git a/cli/lsp/testing/definitions.rs b/cli/lsp/testing/definitions.rs index 43a07c2e31..69baf053e2 100644 --- a/cli/lsp/testing/definitions.rs +++ b/cli/lsp/testing/definitions.rs @@ -5,6 +5,7 @@ use super::lsp_custom::TestData; use crate::lsp::client::TestingNotification; use crate::lsp::logging::lsp_warn; +use crate::lsp::urls::url_to_uri; use crate::tools::test::TestDescription; use crate::tools::test::TestStepDescription; use crate::util::checksum; @@ -147,7 +148,7 @@ impl TestModule { let label = self.label(maybe_root_uri); TestingNotification::Module(lsp_custom::TestModuleNotificationParams { text_document: lsp::TextDocumentIdentifier { - uri: self.specifier.clone(), + uri: url_to_uri(&self.specifier), }, kind: lsp_custom::TestModuleNotificationKind::Replace, label, diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs index 14196baa36..aec91b3e7d 100644 --- a/cli/lsp/testing/execution.rs +++ b/cli/lsp/testing/execution.rs @@ -12,6 +12,8 @@ use crate::lsp::client::Client; use crate::lsp::client::TestingNotification; use crate::lsp::config; use crate::lsp::logging::lsp_log; +use crate::lsp::urls::uri_to_url; +use crate::lsp::urls::url_to_uri; use crate::tools::test; use crate::tools::test::create_test_event_channel; use crate::tools::test::FailFastTracker; @@ -30,9 +32,11 @@ use deno_core::ModuleSpecifier; use deno_runtime::deno_permissions::Permissions; use deno_runtime::tokio_util::create_and_run_current_thread; use indexmap::IndexMap; +use lsp_types::Uri; use std::collections::HashMap; use std::collections::HashSet; use std::num::NonZeroUsize; +use std::str::FromStr; use std::sync::Arc; use std::time::Duration; use std::time::Instant; @@ -53,12 +57,12 @@ fn as_queue_and_filters( if let Some(include) = ¶ms.include { for item in include { - if let Some((test_definitions, _)) = tests.get(&item.text_document.uri) { - queue.insert(item.text_document.uri.clone()); + let url = uri_to_url(&item.text_document.uri); + if let Some((test_definitions, _)) = tests.get(&url) { + queue.insert(url.clone()); if let Some(id) = &item.id { if let Some(test) = test_definitions.get(id) { - let filter = - filters.entry(item.text_document.uri.clone()).or_default(); + let filter = filters.entry(url).or_default(); if let Some(include) = filter.include.as_mut() { include.insert(test.id.clone(), test.clone()); } else { @@ -75,19 +79,19 @@ fn as_queue_and_filters( } for item in ¶ms.exclude { - if let Some((test_definitions, _)) = tests.get(&item.text_document.uri) { + let url = uri_to_url(&item.text_document.uri); + if let Some((test_definitions, _)) = tests.get(&url) { if let Some(id) = &item.id { // there is no way to exclude a test step if item.step_id.is_none() { if let Some(test) = test_definitions.get(id) { - let filter = - filters.entry(item.text_document.uri.clone()).or_default(); + let filter = filters.entry(url.clone()).or_default(); filter.exclude.insert(test.id.clone(), test.clone()); } } } else { // the entire test module is excluded - queue.remove(&item.text_document.uri); + queue.remove(&url); } } } @@ -193,7 +197,7 @@ impl TestRun { Vec::new() }; lsp_custom::EnqueuedTestModule { - text_document: lsp::TextDocumentIdentifier { uri: s.clone() }, + text_document: lsp::TextDocumentIdentifier { uri: url_to_uri(s) }, ids, } }) @@ -523,7 +527,7 @@ impl LspTestDescription { &self, tests: &IndexMap, ) -> lsp_custom::TestIdentifier { - let uri = ModuleSpecifier::parse(&self.location().file_name).unwrap(); + let uri = Uri::from_str(&self.location().file_name).unwrap(); let static_id = self.static_id(); let mut root_desc = self; while let Some(parent_id) = root_desc.parent_id() { @@ -598,7 +602,7 @@ impl LspTestReporter { .send_test_notification(TestingNotification::Module( lsp_custom::TestModuleNotificationParams { text_document: lsp::TextDocumentIdentifier { - uri: test_module.specifier.clone(), + uri: url_to_uri(&test_module.specifier), }, kind: lsp_custom::TestModuleNotificationKind::Insert, label: test_module.label(self.maybe_root_uri.as_ref()), @@ -711,7 +715,7 @@ impl LspTestReporter { .send_test_notification(TestingNotification::Module( lsp_custom::TestModuleNotificationParams { text_document: lsp::TextDocumentIdentifier { - uri: test_module.specifier.clone(), + uri: url_to_uri(&test_module.specifier), }, kind: lsp_custom::TestModuleNotificationKind::Insert, label: test_module.label(self.maybe_root_uri.as_ref()), @@ -796,14 +800,14 @@ mod tests { include: Some(vec![ lsp_custom::TestIdentifier { text_document: lsp::TextDocumentIdentifier { - uri: specifier.clone(), + uri: url_to_uri(&specifier), }, id: None, step_id: None, }, lsp_custom::TestIdentifier { text_document: lsp::TextDocumentIdentifier { - uri: non_test_specifier.clone(), + uri: url_to_uri(&non_test_specifier), }, id: None, step_id: None, @@ -811,7 +815,7 @@ mod tests { ]), exclude: vec![lsp_custom::TestIdentifier { text_document: lsp::TextDocumentIdentifier { - uri: specifier.clone(), + uri: url_to_uri(&specifier), }, id: Some( "69d9fe87f64f5b66cb8b631d4fd2064e8224b8715a049be54276c42189ff8f9f" diff --git a/cli/lsp/testing/server.rs b/cli/lsp/testing/server.rs index ff59e1033d..0c34ea7bc2 100644 --- a/cli/lsp/testing/server.rs +++ b/cli/lsp/testing/server.rs @@ -10,6 +10,7 @@ use crate::lsp::config; use crate::lsp::documents::DocumentsFilter; use crate::lsp::language_server::StateSnapshot; use crate::lsp::performance::Performance; +use crate::lsp::urls::url_to_uri; use deno_core::error::AnyError; use deno_core::parking_lot::Mutex; @@ -26,10 +27,12 @@ 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 { +fn as_delete_notification(url: ModuleSpecifier) -> TestingNotification { TestingNotification::DeleteModule( lsp_custom::TestModuleDeleteNotificationParams { - text_document: lsp::TextDocumentIdentifier { uri }, + text_document: lsp::TextDocumentIdentifier { + uri: url_to_uri(&url), + }, }, ) } diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 3ac25507cd..566c619779 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -19,6 +19,7 @@ use super::refactor::EXTRACT_TYPE; use super::semantic_tokens; use super::semantic_tokens::SemanticTokensBuilder; use super::text::LineIndex; +use super::urls::url_to_uri; use super::urls::LspClientUrl; use super::urls::INVALID_SPECIFIER; @@ -2071,7 +2072,7 @@ impl DocumentSpan { }; let link = lsp::LocationLink { origin_selection_range, - target_uri: target_uri.into_url(), + target_uri: target_uri.to_uri(), target_range, target_selection_range, }; @@ -2158,7 +2159,7 @@ impl NavigateToItem { .ok()?; let range = self.text_span.to_range(line_index); let location = lsp::Location { - uri: uri.into_url(), + uri: uri.to_uri(), range, }; @@ -2418,7 +2419,7 @@ impl ImplementationLocation { LspClientUrl::new(ModuleSpecifier::parse("deno://invalid").unwrap()) }); lsp::Location { - uri: uri.into_url(), + uri: uri.to_uri(), range: self.document_span.text_span.to_range(line_index), } } @@ -2483,7 +2484,7 @@ impl RenameLocations { uri.clone(), lsp::TextDocumentEdit { text_document: lsp::OptionalVersionedTextDocumentIdentifier { - uri: uri.as_url().clone(), + uri: uri.to_uri(), version: asset_or_doc.document_lsp_version(), }, edits: @@ -2685,7 +2686,7 @@ impl FileTextChanges { .collect(); Ok(lsp::TextDocumentEdit { text_document: lsp::OptionalVersionedTextDocumentIdentifier { - uri: specifier, + uri: url_to_uri(&specifier), version: asset_or_doc.document_lsp_version(), }, edits, @@ -2712,7 +2713,7 @@ impl FileTextChanges { if self.is_new_file.unwrap_or(false) { ops.push(lsp::DocumentChangeOperation::Op(lsp::ResourceOp::Create( lsp::CreateFile { - uri: specifier.clone(), + uri: url_to_uri(&specifier), options: Some(lsp::CreateFileOptions { ignore_if_exists: Some(true), overwrite: None, @@ -2729,7 +2730,7 @@ impl FileTextChanges { .collect(); ops.push(lsp::DocumentChangeOperation::Edit(lsp::TextDocumentEdit { text_document: lsp::OptionalVersionedTextDocumentIdentifier { - uri: specifier, + uri: url_to_uri(&specifier), version: maybe_asset_or_document.and_then(|d| d.document_lsp_version()), }, edits, @@ -3130,7 +3131,7 @@ impl ReferenceEntry { .normalize_specifier(&specifier, file_referrer.as_deref()) .unwrap_or_else(|_| LspClientUrl::new(INVALID_SPECIFIER.clone())); lsp::Location { - uri: uri.into_url(), + uri: uri.to_uri(), range: self.document_span.text_span.to_range(line_index), } } @@ -3237,7 +3238,7 @@ impl CallHierarchyItem { lsp::CallHierarchyItem { name, tags, - uri: uri.into_url(), + uri: uri.to_uri(), detail: Some(detail), kind: self.kind.clone().into(), range: self.span.to_range(line_index.clone()), @@ -5398,7 +5399,7 @@ mod tests { sources: &[(&str, &str, i32, LanguageId)], ) -> (TempDir, TsServer, Arc, LspCache) { let temp_dir = TempDir::new(); - let cache = LspCache::new(Some(temp_dir.uri().join(".deno_dir").unwrap())); + let cache = LspCache::new(Some(temp_dir.url().join(".deno_dir").unwrap())); let mut config = Config::default(); config .tree @@ -5408,7 +5409,7 @@ mod tests { "compilerOptions": ts_config, }) .to_string(), - temp_dir.uri().join("deno.json").unwrap(), + temp_dir.url().join("deno.json").unwrap(), &Default::default(), ) .unwrap(), @@ -5419,7 +5420,7 @@ mod tests { let mut documents = Documents::default(); documents.update_config(&config, &resolver, &cache, &Default::default()); for (relative_specifier, source, version, language_id) in sources { - let specifier = temp_dir.uri().join(relative_specifier).unwrap(); + let specifier = temp_dir.url().join(relative_specifier).unwrap(); documents.open(specifier, *version, *language_id, (*source).into(), None); } let snapshot = Arc::new(StateSnapshot { @@ -5489,7 +5490,7 @@ mod tests { )], ) .await; - let specifier = temp_dir.uri().join("a.ts").unwrap(); + let specifier = temp_dir.url().join("a.ts").unwrap(); let diagnostics = ts_server .get_diagnostics(snapshot, vec![specifier.clone()], Default::default()) .await @@ -5536,7 +5537,7 @@ mod tests { )], ) .await; - let specifier = temp_dir.uri().join("a.ts").unwrap(); + let specifier = temp_dir.url().join("a.ts").unwrap(); let diagnostics = ts_server .get_diagnostics(snapshot, vec![specifier.clone()], Default::default()) .await @@ -5567,7 +5568,7 @@ mod tests { )], ) .await; - let specifier = temp_dir.uri().join("a.ts").unwrap(); + let specifier = temp_dir.url().join("a.ts").unwrap(); let diagnostics = ts_server .get_diagnostics(snapshot, vec![specifier.clone()], Default::default()) .await @@ -5594,7 +5595,7 @@ mod tests { )], ) .await; - let specifier = temp_dir.uri().join("a.ts").unwrap(); + let specifier = temp_dir.url().join("a.ts").unwrap(); let diagnostics = ts_server .get_diagnostics(snapshot, vec![specifier.clone()], Default::default()) .await @@ -5644,7 +5645,7 @@ mod tests { )], ) .await; - let specifier = temp_dir.uri().join("a.ts").unwrap(); + let specifier = temp_dir.url().join("a.ts").unwrap(); let diagnostics = ts_server .get_diagnostics(snapshot, vec![specifier.clone()], Default::default()) .await @@ -5678,7 +5679,7 @@ mod tests { )], ) .await; - let specifier = temp_dir.uri().join("a.ts").unwrap(); + let specifier = temp_dir.url().join("a.ts").unwrap(); let diagnostics = ts_server .get_diagnostics(snapshot, vec![specifier.clone()], Default::default()) .await @@ -5736,7 +5737,7 @@ mod tests { )], ) .await; - let specifier = temp_dir.uri().join("a.ts").unwrap(); + let specifier = temp_dir.url().join("a.ts").unwrap(); let diagnostics = ts_server .get_diagnostics(snapshot, vec![specifier.clone()], Default::default()) .await @@ -5829,7 +5830,7 @@ mod tests { b"export const b = \"b\";\n", ) .unwrap(); - let specifier = temp_dir.uri().join("a.ts").unwrap(); + let specifier = temp_dir.url().join("a.ts").unwrap(); let diagnostics = ts_server .get_diagnostics( snapshot.clone(), @@ -5879,7 +5880,7 @@ mod tests { [(&specifier_dep, ChangeKind::Opened)], None, ); - let specifier = temp_dir.uri().join("a.ts").unwrap(); + let specifier = temp_dir.url().join("a.ts").unwrap(); let diagnostics = ts_server .get_diagnostics( snapshot.clone(), @@ -5951,7 +5952,7 @@ mod tests { &[("a.ts", fixture, 1, LanguageId::TypeScript)], ) .await; - let specifier = temp_dir.uri().join("a.ts").unwrap(); + let specifier = temp_dir.url().join("a.ts").unwrap(); let info = ts_server .get_completions( snapshot.clone(), @@ -5966,7 +5967,7 @@ mod tests { trigger_kind: None, }, Default::default(), - Some(temp_dir.uri()), + Some(temp_dir.url()), ) .await .unwrap(); @@ -5983,7 +5984,7 @@ mod tests { preferences: None, data: None, }, - Some(temp_dir.uri()), + Some(temp_dir.url()), ) .await .unwrap() @@ -6105,7 +6106,7 @@ mod tests { ], ) .await; - let specifier = temp_dir.uri().join("a.ts").unwrap(); + let specifier = temp_dir.url().join("a.ts").unwrap(); let fmt_options_config = FmtOptionsConfig { semi_colons: Some(false), single_quote: Some(true), @@ -6126,7 +6127,7 @@ mod tests { ..Default::default() }, FormatCodeSettings::from(&fmt_options_config), - Some(temp_dir.uri()), + Some(temp_dir.url()), ) .await .unwrap(); @@ -6152,7 +6153,7 @@ mod tests { }), data: entry.data.clone(), }, - Some(temp_dir.uri()), + Some(temp_dir.url()), ) .await .unwrap() @@ -6217,8 +6218,8 @@ mod tests { let changes = ts_server .get_edits_for_file_rename( snapshot, - temp_dir.uri().join("b.ts").unwrap(), - temp_dir.uri().join("🦕.ts").unwrap(), + temp_dir.url().join("b.ts").unwrap(), + temp_dir.url().join("🦕.ts").unwrap(), FormatCodeSettings::default(), UserPreferences::default(), ) @@ -6227,7 +6228,7 @@ mod tests { assert_eq!( changes, vec![FileTextChanges { - file_name: temp_dir.uri().join("a.ts").unwrap().to_string(), + file_name: temp_dir.url().join("a.ts").unwrap().to_string(), text_changes: vec![TextChange { span: TextSpan { start: 8, @@ -6286,7 +6287,7 @@ mod tests { let resolved = op_resolve_inner( &mut state, ResolveArgs { - base: temp_dir.uri().join("a.ts").unwrap().to_string(), + base: temp_dir.url().join("a.ts").unwrap().to_string(), is_base_cjs: false, specifiers: vec!["./b.ts".to_string()], }, @@ -6295,7 +6296,7 @@ mod tests { assert_eq!( resolved, vec![Some(( - temp_dir.uri().join("b.ts").unwrap().to_string(), + temp_dir.url().join("b.ts").unwrap().to_string(), MediaType::TypeScript.as_ts_extension().to_string() ))] ); diff --git a/cli/lsp/urls.rs b/cli/lsp/urls.rs index 594c223b43..4a960d3667 100644 --- a/cli/lsp/urls.rs +++ b/cli/lsp/urls.rs @@ -6,8 +6,10 @@ use deno_core::parking_lot::Mutex; use deno_core::url::Position; use deno_core::url::Url; use deno_core::ModuleSpecifier; +use lsp_types::Uri; use once_cell::sync::Lazy; use std::collections::HashMap; +use std::str::FromStr; use std::sync::Arc; use super::cache::LspCache; @@ -111,6 +113,10 @@ impl LspClientUrl { self.0 } + pub fn to_uri(&self) -> Uri { + url_to_uri(&self.0) + } + pub fn as_str(&self) -> &str { self.0.as_str() } @@ -145,6 +151,14 @@ impl LspUrlMapInner { } } +pub fn url_to_uri(url: &Url) -> Uri { + Uri::from_str(url.as_str()).unwrap() +} + +pub fn uri_to_url(uri: &Uri) -> Url { + Url::parse(uri.as_str()).unwrap() +} + #[derive(Debug, Clone, Copy)] pub enum LspUrlKind { File, @@ -218,12 +232,13 @@ impl LspUrlMap { /// Note: Sometimes the url provided by the client may not have a trailing slash, /// so we need to force it to in the mapping and nee to explicitly state whether /// this is a file or directory url. - pub fn normalize_url(&self, url: &Url, kind: LspUrlKind) -> ModuleSpecifier { - if let Some(remote_url) = self.cache.unvendored_specifier(url) { + pub fn normalize_url(&self, uri: &Uri, kind: LspUrlKind) -> ModuleSpecifier { + let url = uri_to_url(uri); + if let Some(remote_url) = self.cache.unvendored_specifier(&url) { return remote_url; } let mut inner = self.inner.lock(); - if let Some(specifier) = inner.get_specifier(url).cloned() { + if let Some(specifier) = inner.get_specifier(&url).cloned() { return specifier; } let mut specifier = None; @@ -234,13 +249,13 @@ impl LspUrlMap { LspUrlKind::File => Url::from_file_path(path).unwrap(), }); } - } else if let Some(s) = file_like_to_file_specifier(url) { + } else if let Some(s) = file_like_to_file_specifier(&url) { specifier = Some(s); - } else if let Some(s) = from_deno_url(url) { + } else if let Some(s) = from_deno_url(&url) { specifier = Some(s); } let specifier = specifier.unwrap_or_else(|| url.clone()); - inner.put(specifier.clone(), LspClientUrl(url.clone())); + inner.put(specifier.clone(), LspClientUrl(url)); specifier } } @@ -296,7 +311,7 @@ mod tests { assert_eq!(actual_url.as_url(), &expected_url); let actual_specifier = - map.normalize_url(actual_url.as_url(), LspUrlKind::File); + map.normalize_url(&actual_url.to_uri(), LspUrlKind::File); assert_eq!(actual_specifier, fixture); } @@ -304,7 +319,7 @@ mod tests { fn test_lsp_url_reverse() { let map = LspUrlMap::default(); let fixture = - resolve_url("deno:/https/deno.land/x/pkg%401.0.0/mod.ts").unwrap(); + Uri::from_str("deno:/https/deno.land/x/pkg%401.0.0/mod.ts").unwrap(); let actual_specifier = map.normalize_url(&fixture, LspUrlKind::File); let expected_specifier = Url::parse("https://deno.land/x/pkg@1.0.0/mod.ts").unwrap(); @@ -313,7 +328,7 @@ mod tests { let actual_url = map .normalize_specifier(&actual_specifier, None) .unwrap() - .as_url() + .to_uri() .clone(); assert_eq!(actual_url, fixture); } @@ -330,7 +345,7 @@ mod tests { assert_eq!(actual_url.as_url(), &expected_url); let actual_specifier = - map.normalize_url(actual_url.as_url(), LspUrlKind::File); + map.normalize_url(&actual_url.to_uri(), LspUrlKind::File); assert_eq!(actual_specifier, fixture); } @@ -345,7 +360,7 @@ mod tests { assert_eq!(actual_url.as_url(), &expected_url); let actual_specifier = - map.normalize_url(actual_url.as_url(), LspUrlKind::File); + map.normalize_url(&actual_url.to_uri(), LspUrlKind::File); assert_eq!(actual_specifier, fixture); } @@ -361,7 +376,7 @@ mod tests { assert_eq!(actual_url.as_url(), &expected_url); let actual_specifier = - map.normalize_url(actual_url.as_url(), LspUrlKind::File); + map.normalize_url(&actual_url.to_uri(), LspUrlKind::File); assert_eq!(actual_specifier, fixture); } @@ -369,7 +384,7 @@ mod tests { #[test] fn test_normalize_windows_path() { let map = LspUrlMap::default(); - let fixture = resolve_url( + let fixture = Uri::from_str( "file:///c%3A/Users/deno/Desktop/file%20with%20spaces%20in%20name.txt", ) .unwrap(); @@ -384,7 +399,7 @@ mod tests { #[test] fn test_normalize_percent_encoded_path() { let map = LspUrlMap::default(); - let fixture = resolve_url( + let fixture = Uri::from_str( "file:///Users/deno/Desktop/file%20with%20spaces%20in%20name.txt", ) .unwrap(); @@ -398,9 +413,9 @@ mod tests { #[test] fn test_normalize_deno_status() { let map = LspUrlMap::default(); - let fixture = resolve_url("deno:/status.md").unwrap(); + let fixture = Uri::from_str("deno:/status.md").unwrap(); let actual = map.normalize_url(&fixture, LspUrlKind::File); - assert_eq!(actual, fixture); + assert_eq!(actual.as_str(), fixture.as_str()); } #[test] diff --git a/cli/resolver.rs b/cli/resolver.rs index a62828b6ec..bd88ecd9a8 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -1246,15 +1246,15 @@ mod test { for (ext_from, ext_to) in [("js", "ts"), ("js", "tsx"), ("mjs", "mts")] { let ts_file = temp_dir.join(format!("file.{}", ext_to)); ts_file.write(""); - assert_eq!(resolve(&ts_file.uri_file()), None); + assert_eq!(resolve(&ts_file.url_file()), None); assert_eq!( resolve( &temp_dir - .uri_dir() + .url_dir() .join(&format!("file.{}", ext_from)) .unwrap() ), - Some(SloppyImportsResolution::JsToTs(ts_file.uri_file())), + Some(SloppyImportsResolution::JsToTs(ts_file.url_file())), ); ts_file.remove_file(); } @@ -1266,11 +1266,11 @@ mod test { assert_eq!( resolve( &temp_dir - .uri_dir() + .url_dir() .join("file") // no ext .unwrap() ), - Some(SloppyImportsResolution::NoExtension(file.uri_file())) + Some(SloppyImportsResolution::NoExtension(file.url_file())) ); file.remove_file(); } @@ -1281,15 +1281,15 @@ mod test { ts_file.write(""); let js_file = temp_dir.join("file.js"); js_file.write(""); - assert_eq!(resolve(&js_file.uri_file()), None); + assert_eq!(resolve(&js_file.url_file()), None); } // only js exists, .js specified { let js_only_file = temp_dir.join("js_only.js"); js_only_file.write(""); - assert_eq!(resolve(&js_only_file.uri_file()), None); - assert_eq!(resolve_types(&js_only_file.uri_file()), None); + assert_eq!(resolve(&js_only_file.url_file()), None); + assert_eq!(resolve_types(&js_only_file.url_file()), None); } // resolving a directory to an index file @@ -1299,8 +1299,8 @@ mod test { let index_file = routes_dir.join("index.ts"); index_file.write(""); assert_eq!( - resolve(&routes_dir.uri_file()), - Some(SloppyImportsResolution::Directory(index_file.uri_file())), + resolve(&routes_dir.url_file()), + Some(SloppyImportsResolution::Directory(index_file.url_file())), ); } @@ -1313,8 +1313,8 @@ mod test { let api_file = temp_dir.join("api.ts"); api_file.write(""); assert_eq!( - resolve(&api_dir.uri_file()), - Some(SloppyImportsResolution::NoExtension(api_file.uri_file())), + resolve(&api_dir.url_file()), + Some(SloppyImportsResolution::NoExtension(api_file.url_file())), ); } } diff --git a/cli/tools/registry/api.rs b/cli/tools/registry/api.rs index c382aa9ac8..2f27cb2fea 100644 --- a/cli/tools/registry/api.rs +++ b/cli/tools/registry/api.rs @@ -3,8 +3,8 @@ use crate::http_util; use deno_core::error::AnyError; use deno_core::serde_json; +use deno_core::url::Url; use deno_runtime::deno_fetch; -use lsp_types::Url; use serde::de::DeserializeOwned; use crate::http_util::HttpClient; diff --git a/cli/tools/registry/diagnostics.rs b/cli/tools/registry/diagnostics.rs index 69434f1ea8..c53a39683e 100644 --- a/cli/tools/registry/diagnostics.rs +++ b/cli/tools/registry/diagnostics.rs @@ -21,9 +21,9 @@ use deno_ast::SourceRanged; use deno_ast::SourceTextInfo; use deno_core::anyhow::anyhow; use deno_core::error::AnyError; +use deno_core::url::Url; use deno_graph::FastCheckDiagnostic; use deno_semver::Version; -use lsp_types::Url; use super::unfurl::SpecifierUnfurlerDiagnostic; diff --git a/cli/tools/registry/graph.rs b/cli/tools/registry/graph.rs index bdcb27aa16..d14e4cd845 100644 --- a/cli/tools/registry/graph.rs +++ b/cli/tools/registry/graph.rs @@ -8,13 +8,13 @@ use deno_ast::ParsedSource; use deno_ast::SourceRangedForSpanned; use deno_ast::SourceTextInfo; use deno_core::error::AnyError; +use deno_core::url::Url; use deno_graph::ModuleEntryRef; use deno_graph::ModuleGraph; use deno_graph::ResolutionResolved; use deno_graph::WalkOptions; use deno_semver::jsr::JsrPackageReqReference; use deno_semver::npm::NpmPackageReqReference; -use lsp_types::Url; use crate::cache::ParsedSourceCache; diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs index ee3204dc74..24b3051e4f 100644 --- a/cli/tools/registry/mod.rs +++ b/cli/tools/registry/mod.rs @@ -25,9 +25,9 @@ use deno_core::futures::StreamExt; use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::serde_json::Value; +use deno_core::url::Url; use deno_terminal::colors; use http_body_util::BodyExt; -use lsp_types::Url; use serde::Deserialize; use serde::Serialize; use sha2::Digest; diff --git a/cli/tools/registry/unfurl.rs b/cli/tools/registry/unfurl.rs index 2babedb367..0f5b9fdd32 100644 --- a/cli/tools/registry/unfurl.rs +++ b/cli/tools/registry/unfurl.rs @@ -203,7 +203,7 @@ impl SpecifierUnfurler { /// or `false` when the import was not analyzable. fn try_unfurl_dynamic_dep( &self, - module_url: &lsp_types::Url, + module_url: &ModuleSpecifier, text_info: &SourceTextInfo, dep: &deno_graph::DynamicDependencyDescriptor, text_changes: &mut Vec, diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index ac7fc48e37..cf7a55d8c8 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -22,6 +22,7 @@ use deno_core::serde::Serialize; use deno_core::serde::Serializer; use deno_core::serde_json::json; use deno_core::serde_v8; +use deno_core::url::Url; use deno_core::JsRuntime; use deno_core::ModuleSpecifier; use deno_core::OpState; @@ -32,7 +33,6 @@ use deno_graph::ModuleGraph; use deno_graph::ResolutionResolved; use deno_runtime::deno_node::NodeResolver; use deno_semver::npm::NpmPackageReqReference; -use lsp_types::Url; use node_resolver::errors::NodeJsErrorCode; use node_resolver::errors::NodeJsErrorCoded; use node_resolver::NodeModuleKind; diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index a0d12da3a9..5d4640ce65 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -8,6 +8,7 @@ use deno_core::serde_json::Value; use deno_core::url::Url; use pretty_assertions::assert_eq; use std::fs; +use std::str::FromStr; use test_util::assert_starts_with; use test_util::assertions::assert_json_subset; use test_util::deno_cmd_with_deno_dir; @@ -91,7 +92,7 @@ fn lsp_tsconfig_types() { let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("test.ts").unwrap(), + "uri": temp_dir.url().join("test.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "console.log(a);\n" @@ -136,7 +137,7 @@ fn lsp_tsconfig_types_config_sub_dir() { let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("test.ts").unwrap(), + "uri": temp_dir.url().join("test.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "console.log(a);\n" @@ -159,7 +160,7 @@ fn lsp_triple_slash_types() { let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("test.ts").unwrap(), + "uri": temp_dir.url().join("test.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "/// \n\nconsole.log(a);\n" @@ -206,13 +207,13 @@ fn unadded_dependency_message_with_import_map() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("file.ts").unwrap()], }), ); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": temp_dir.read_to_string("file.ts"), @@ -265,13 +266,13 @@ fn unadded_dependency_message() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("file.ts").unwrap()], }), ); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": temp_dir.read_to_string("file.ts"), @@ -314,7 +315,7 @@ fn lsp_import_map() { builder.set_import_map("import-map.json"); }); - let uri = temp_dir.uri().join("a.ts").unwrap(); + let uri = temp_dir.url().join("a.ts").unwrap(); let diagnostics = client.did_open(json!({ "textDocument": { @@ -386,13 +387,13 @@ fn lsp_import_map_remote() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("file.ts").unwrap()], }), ); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": temp_dir.read_to_string("file.ts"), @@ -412,7 +413,7 @@ fn lsp_import_map_data_url() { }); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import example from \"example\";\n" @@ -454,7 +455,7 @@ fn lsp_import_map_config_file() { builder.set_config("./deno.import_map.jsonc"); }); - let uri = temp_dir.uri().join("a.ts").unwrap(); + let uri = temp_dir.url().join("a.ts").unwrap(); let diagnostics = client.did_open(json!({ "textDocument": { @@ -516,7 +517,7 @@ fn lsp_import_map_embedded_in_config_file() { builder.set_config("./deno.embedded_import_map.jsonc"); }); - let uri = temp_dir.uri().join("a.ts").unwrap(); + let uri = temp_dir.url().join("a.ts").unwrap(); let diagnostics = client.did_open(json!({ "textDocument": { @@ -570,7 +571,7 @@ fn lsp_import_map_embedded_in_config_file_after_initialize() { builder.set_config("./deno.embedded_import_map.jsonc"); }); - let uri = temp_dir.uri().join("a.ts").unwrap(); + let uri = temp_dir.url().join("a.ts").unwrap(); let diagnostics = client.did_open(json!({ "textDocument": { @@ -595,7 +596,7 @@ fn lsp_import_map_embedded_in_config_file_after_initialize() { client.did_change_watched_files(json!({ "changes": [{ - "uri": temp_dir.uri().join("deno.embedded_import_map.jsonc").unwrap(), + "uri": temp_dir.url().join("deno.embedded_import_map.jsonc").unwrap(), "type": 2 }] })); @@ -644,7 +645,7 @@ fn lsp_import_map_config_file_auto_discovered() { temp_dir.write("deno.jsonc", r#"{ "imports": { "/~/": "./lib/" } }"#); client.did_change_watched_files(json!({ "changes": [{ - "uri": temp_dir.uri().join("deno.jsonc").unwrap(), + "uri": temp_dir.url().join("deno.jsonc").unwrap(), "type": 2 }] })); @@ -652,7 +653,7 @@ fn lsp_import_map_config_file_auto_discovered() { line.contains(" Resolved Deno configuration file:") }); - let uri = temp_dir.uri().join("a.ts").unwrap(); + let uri = temp_dir.url().join("a.ts").unwrap(); let diagnostics = client.did_open(json!({ "textDocument": { @@ -695,7 +696,7 @@ fn lsp_import_map_config_file_auto_discovered() { temp_dir.write("deno.jsonc", r#",,#,#,,"#); client.did_change_watched_files(json!({ "changes": [{ - "uri": temp_dir.uri().join("deno.jsonc").unwrap(), + "uri": temp_dir.url().join("deno.jsonc").unwrap(), "type": 2 }] })); @@ -705,7 +706,7 @@ fn lsp_import_map_config_file_auto_discovered() { temp_dir.write("deno.jsonc", r#"{ "imports": { "/~/": "./lib/" } }"#); client.did_change_watched_files(json!({ "changes": [{ - "uri": temp_dir.uri().join("deno.jsonc").unwrap(), + "uri": temp_dir.url().join("deno.jsonc").unwrap(), "type": 2 }] })); @@ -771,7 +772,7 @@ fn lsp_import_map_config_file_auto_discovered_symlink() { client.did_change_watched_files(json!({ "changes": [{ // the client will give a watched file changed event for the symlink's target - "uri": temp_dir.path().join("subdir/deno.json").canonicalize().uri_file(), + "uri": temp_dir.path().join("subdir/deno.json").canonicalize().url_file(), "type": 2 }] })); @@ -779,14 +780,14 @@ fn lsp_import_map_config_file_auto_discovered_symlink() { // this will discover the deno.json in the root let search_line = format!( " Resolved Deno configuration file: \"{}\"", - temp_dir.uri().join("deno.json").unwrap().as_str() + temp_dir.url().join("deno.json").unwrap().as_str() ); client.wait_until_stderr_line(|line| line.contains(&search_line)); // now open a file which will cause a diagnostic because the import map is empty let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("a.ts").unwrap(), + "uri": temp_dir.url().join("a.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import { b } from \"/~/b.ts\";\n\nconsole.log(b);\n" @@ -799,7 +800,7 @@ fn lsp_import_map_config_file_auto_discovered_symlink() { client.did_change_watched_files(json!({ "changes": [{ // now still say that the target path has changed - "uri": temp_dir.path().join("subdir/deno.json").canonicalize().uri_file(), + "uri": temp_dir.path().join("subdir/deno.json").canonicalize().url_file(), "type": 2 }] })); @@ -837,13 +838,13 @@ fn lsp_deno_json_imports_comments_cache() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("file.ts").unwrap()], }), ); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": temp_dir.read_to_string("file.ts"), @@ -875,7 +876,7 @@ fn lsp_import_map_node_specifiers() { let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("a.ts").unwrap(), + "uri": temp_dir.url().join("a.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import fs from \"fs\";\nconsole.log(fs);" @@ -906,7 +907,7 @@ fn lsp_format_vendor_path() { client.initialize_default(); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#"import "http://localhost:4545/run/002_hello.ts";"#, @@ -928,7 +929,7 @@ fn lsp_format_vendor_path() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("file.ts").unwrap()], }), ); assert!(temp_dir @@ -937,7 +938,7 @@ fn lsp_format_vendor_path() { .exists()); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("vendor/http_localhost_4545/run/002_hello.ts").unwrap(), + "uri": temp_dir.url().join("vendor/http_localhost_4545/run/002_hello.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#"console.log("Hello World");"#, @@ -947,7 +948,7 @@ fn lsp_format_vendor_path() { "textDocument/formatting", json!({ "textDocument": { - "uri": temp_dir.uri().join("vendor/http_localhost_4545/run/002_hello.ts").unwrap(), + "uri": temp_dir.url().join("vendor/http_localhost_4545/run/002_hello.ts").unwrap(), }, "options": { "tabSize": 2, @@ -993,13 +994,13 @@ fn lsp_workspace_enable_paths_no_workspace_configuration() { uri: temp_dir.uri(), name: "project".to_string(), }]); - builder.set_root_uri(temp_dir.uri()); + builder.set_root_uri(temp_dir.url()); builder.set_enable_paths(vec!["./main_enabled.ts".to_string()]); }); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("main_disabled.ts").unwrap(), + "uri": temp_dir.url().join("main_disabled.ts").unwrap(), "languageId": "typescript", "version": 1, "text": temp_dir.read_to_string("main_disabled.ts"), @@ -1008,7 +1009,7 @@ fn lsp_workspace_enable_paths_no_workspace_configuration() { client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("main_enabled.ts").unwrap(), + "uri": temp_dir.url().join("main_enabled.ts").unwrap(), "languageId": "typescript", "version": 1, "text": temp_dir.read_to_string("main_enabled.ts"), @@ -1019,7 +1020,7 @@ fn lsp_workspace_enable_paths_no_workspace_configuration() { "textDocument/hover", json!({ "textDocument": { - "uri": temp_dir.uri().join("main_disabled.ts").unwrap(), + "uri": temp_dir.url().join("main_disabled.ts").unwrap(), }, "position": { "line": 0, "character": 5 } }), @@ -1030,7 +1031,7 @@ fn lsp_workspace_enable_paths_no_workspace_configuration() { "textDocument/hover", json!({ "textDocument": { - "uri": temp_dir.uri().join("main_enabled.ts").unwrap(), + "uri": temp_dir.url().join("main_enabled.ts").unwrap(), }, "position": { "line": 0, "character": 5 } }), @@ -1071,14 +1072,14 @@ fn lsp_did_change_deno_configuration_notification() { Some(json!({ "changes": [ { - "scopeUri": temp_dir.uri(), - "fileUri": temp_dir.uri().join("deno.json").unwrap(), + "scopeUri": temp_dir.url(), + "fileUri": temp_dir.url().join("deno.json").unwrap(), "type": "added", "configurationType": "denoJson" }, { - "scopeUri": temp_dir.uri(), - "fileUri": temp_dir.uri().join("package.json").unwrap(), + "scopeUri": temp_dir.url(), + "fileUri": temp_dir.url().join("package.json").unwrap(), "type": "added", "configurationType": "packageJson" }, @@ -1092,7 +1093,7 @@ fn lsp_did_change_deno_configuration_notification() { ); client.did_change_watched_files(json!({ "changes": [{ - "uri": temp_dir.uri().join("deno.json").unwrap(), + "uri": temp_dir.url().join("deno.json").unwrap(), "type": 2, }], })); @@ -1102,8 +1103,8 @@ fn lsp_did_change_deno_configuration_notification() { res, Some(json!({ "changes": [{ - "scopeUri": temp_dir.uri(), - "fileUri": temp_dir.uri().join("deno.json").unwrap(), + "scopeUri": temp_dir.url(), + "fileUri": temp_dir.url().join("deno.json").unwrap(), "type": "changed", "configurationType": "denoJson" }], @@ -1113,7 +1114,7 @@ fn lsp_did_change_deno_configuration_notification() { temp_dir.remove_file("deno.json"); client.did_change_watched_files(json!({ "changes": [{ - "uri": temp_dir.uri().join("deno.json").unwrap(), + "uri": temp_dir.url().join("deno.json").unwrap(), "type": 3, }], })); @@ -1123,8 +1124,8 @@ fn lsp_did_change_deno_configuration_notification() { res, Some(json!({ "changes": [{ - "scopeUri": temp_dir.uri(), - "fileUri": temp_dir.uri().join("deno.json").unwrap(), + "scopeUri": temp_dir.url(), + "fileUri": temp_dir.url().join("deno.json").unwrap(), "type": "removed", "configurationType": "denoJson" }], @@ -1134,7 +1135,7 @@ fn lsp_did_change_deno_configuration_notification() { temp_dir.write("package.json", json!({ "type": "module" }).to_string()); client.did_change_watched_files(json!({ "changes": [{ - "uri": temp_dir.uri().join("package.json").unwrap(), + "uri": temp_dir.url().join("package.json").unwrap(), "type": 2, }], })); @@ -1144,8 +1145,8 @@ fn lsp_did_change_deno_configuration_notification() { res, Some(json!({ "changes": [{ - "scopeUri": temp_dir.uri(), - "fileUri": temp_dir.uri().join("package.json").unwrap(), + "scopeUri": temp_dir.url(), + "fileUri": temp_dir.url().join("package.json").unwrap(), "type": "changed", "configurationType": "packageJson" }], @@ -1155,7 +1156,7 @@ fn lsp_did_change_deno_configuration_notification() { temp_dir.remove_file("package.json"); client.did_change_watched_files(json!({ "changes": [{ - "uri": temp_dir.uri().join("package.json").unwrap(), + "uri": temp_dir.url().join("package.json").unwrap(), "type": 3, }], })); @@ -1165,8 +1166,8 @@ fn lsp_did_change_deno_configuration_notification() { res, Some(json!({ "changes": [{ - "scopeUri": temp_dir.uri(), - "fileUri": temp_dir.uri().join("package.json").unwrap(), + "scopeUri": temp_dir.url(), + "fileUri": temp_dir.url().join("package.json").unwrap(), "type": "removed", "configurationType": "packageJson" }], @@ -1202,11 +1203,11 @@ fn lsp_deno_task() { { "name": "build", "detail": "deno test", - "sourceUri": temp_dir.uri().join("deno.jsonc").unwrap(), + "sourceUri": temp_dir.url().join("deno.jsonc").unwrap(), }, { "name": "some:test", "detail": "deno bundle mod.ts", - "sourceUri": temp_dir.uri().join("deno.jsonc").unwrap(), + "sourceUri": temp_dir.url().join("deno.jsonc").unwrap(), } ]) ); @@ -1368,7 +1369,7 @@ fn lsp_import_map_import_completions() { let mut client = context.new_lsp_command().build(); client.initialize_default(); - let uri = temp_dir.uri().join("a.ts").unwrap(); + let uri = temp_dir.url().join("a.ts").unwrap(); client.did_open(json!({ "textDocument": { @@ -1551,7 +1552,7 @@ fn lsp_hover_asset() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "console.log(Date.now());\n" @@ -1561,7 +1562,7 @@ fn lsp_hover_asset() { "textDocument/definition", json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap() + "uri": temp_dir.url().join("file.ts").unwrap() }, "position": { "line": 0, "character": 14 } }), @@ -1795,7 +1796,7 @@ fn lsp_workspace_disable_enable_paths() { temp_dir.write("worker/other.ts", "import { a } from './shared.ts';\na;"); temp_dir.write("worker/node.ts", "Buffer.alloc(1);"); - let root_specifier = temp_dir.uri(); + let root_specifier = temp_dir.url(); let mut client = context.new_lsp_command().build(); client.initialize_with_config( @@ -1806,9 +1807,9 @@ fn lsp_workspace_disable_enable_paths() { .set_root_uri(root_specifier.clone()) .set_workspace_folders(vec![lsp::WorkspaceFolder { uri: if use_trailing_slash { - root_specifier.clone() + lsp::Uri::from_str(root_specifier.as_str()).unwrap() } else { - ModuleSpecifier::parse( + lsp::Uri::from_str( root_specifier.as_str().strip_suffix('/').unwrap(), ) .unwrap() @@ -2022,7 +2023,7 @@ fn lsp_exclude_config() { "exclude": ["other"], }"#, ); - let root_specifier = temp_dir.uri(); + let root_specifier = temp_dir.url(); let mut client = context.new_lsp_command().build(); client.initialize_default(); @@ -2298,8 +2299,8 @@ fn lsp_hover_closed_document() { temp_dir.write("b.ts", r#"export * from "./a.ts";"#); temp_dir.write("c.ts", "import { a } from \"./b.ts\";\nconsole.log(a);\n"); - let b_specifier = temp_dir.uri().join("b.ts").unwrap(); - let c_specifier = temp_dir.uri().join("c.ts").unwrap(); + let b_specifier = temp_dir.url().join("b.ts").unwrap(); + let c_specifier = temp_dir.url().join("c.ts").unwrap(); let mut client = context.new_lsp_command().build(); client.initialize_default(); @@ -2656,7 +2657,7 @@ fn lsp_rename_synbol_file_scheme_edits_only() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#" @@ -2669,7 +2670,7 @@ fn lsp_rename_synbol_file_scheme_edits_only() { "textDocument/rename", json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), }, "position": { "line": 1, "character": 17 }, "newName": "PATH_SEPARATOR", @@ -2681,7 +2682,7 @@ fn lsp_rename_synbol_file_scheme_edits_only() { "documentChanges": [ { "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "version": 1, }, "edits": [ @@ -2726,8 +2727,8 @@ fn lsp_document_preload_limit_zero_deno_json_detection() { res, Some(json!({ "changes": [{ - "scopeUri": temp_dir.uri(), - "fileUri": temp_dir.uri().join("deno.json").unwrap(), + "scopeUri": temp_dir.url(), + "fileUri": temp_dir.url().join("deno.json").unwrap(), "type": "added", "configurationType": "denoJson", }], @@ -2761,7 +2762,7 @@ fn lsp_import_map_setting_with_deno_json() { }); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"file2\";\n", @@ -2835,7 +2836,7 @@ fn lsp_hover_jsr() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"jsr:@denotest/add@1.0.0\";\n", @@ -2845,14 +2846,14 @@ fn lsp_hover_jsr() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("file.ts").unwrap()], }), ); let res = client.write_request( "textDocument/hover", json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -5202,7 +5203,7 @@ fn lsp_code_actions_deno_cache_jsr() { client.initialize_default(); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#" @@ -5214,7 +5215,7 @@ fn lsp_code_actions_deno_cache_jsr() { assert_eq!( json!(diagnostics.messages_with_source("deno")), json!({ - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "diagnostics": [{ "range": { "start": { "line": 1, "character": 28 }, @@ -5232,7 +5233,7 @@ fn lsp_code_actions_deno_cache_jsr() { let res = client.write_request( "textDocument/codeAction", json!({ - "textDocument": { "uri": temp_dir.uri().join("file.ts").unwrap() }, + "textDocument": { "uri": temp_dir.url().join("file.ts").unwrap() }, "range": { "start": { "line": 1, "character": 28 }, "end": { "line": 1, "character": 49 }, @@ -5274,7 +5275,7 @@ fn lsp_code_actions_deno_cache_jsr() { "command": "deno.cache", "arguments": [ ["jsr:@denotest/add@1"], - temp_dir.uri().join("file.ts").unwrap(), + temp_dir.url().join("file.ts").unwrap(), ], }, }]) @@ -5285,7 +5286,7 @@ fn lsp_code_actions_deno_cache_jsr() { "command": "deno.cache", "arguments": [ ["jsr:@denotest/add@1"], - temp_dir.uri().join("file.ts").unwrap(), + temp_dir.url().join("file.ts").unwrap(), ], }), ); @@ -5321,7 +5322,7 @@ fn lsp_jsr_lockfile() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#" @@ -5336,7 +5337,7 @@ fn lsp_jsr_lockfile() { "command": "deno.cache", "arguments": [ [], - temp_dir.uri().join("file.ts").unwrap(), + temp_dir.url().join("file.ts").unwrap(), ], }), ); @@ -5366,20 +5367,20 @@ fn lsp_jsr_auto_import_completion() { "command": "deno.cache", "arguments": [ [], - temp_dir.uri().join("main.ts").unwrap(), + temp_dir.url().join("main.ts").unwrap(), ], }), ); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#"add"#, } })); let list = client.get_completion_list( - temp_dir.uri().join("file.ts").unwrap(), + temp_dir.url().join("file.ts").unwrap(), (0, 3), json!({ "triggerKind": 1 }), ); @@ -5446,20 +5447,20 @@ fn lsp_jsr_auto_import_completion_import_map() { "command": "deno.cache", "arguments": [ [], - temp_dir.uri().join("main.ts").unwrap(), + temp_dir.url().join("main.ts").unwrap(), ], }), ); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#"add"#, } })); let list = client.get_completion_list( - temp_dir.uri().join("file.ts").unwrap(), + temp_dir.url().join("file.ts").unwrap(), (0, 3), json!({ "triggerKind": 1 }), ); @@ -5523,13 +5524,13 @@ fn lsp_jsr_auto_import_completion_import_map_sub_path() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], file.uri()], + "arguments": [[], file.url()], }), ); client.read_diagnostics(); client.did_open_file(&file); let list = client.get_completion_list( - file.uri(), + file.url(), (3, 15), json!({ "triggerKind": 1 }), ); @@ -5587,7 +5588,7 @@ fn lsp_jsr_code_action_missing_declaration() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], file.uri()], + "arguments": [[], file.url()], }), ); client.did_open_file(&file); @@ -5595,7 +5596,7 @@ fn lsp_jsr_code_action_missing_declaration() { "textDocument/codeAction", json!({ "textDocument": { - "uri": file.uri(), + "uri": file.url(), }, "range": { "start": { "line": 2, "character": 6 }, @@ -5648,7 +5649,7 @@ fn lsp_jsr_code_action_missing_declaration() { "documentChanges": [ { "textDocument": { - "uri": file.uri(), + "uri": file.url(), "version": 1, }, "edits": [ @@ -5942,7 +5943,7 @@ fn lsp_cache_on_save() { let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": temp_dir.read_to_string("file.ts"), @@ -5951,7 +5952,7 @@ fn lsp_cache_on_save() { assert_eq!( diagnostics.messages_with_source("deno"), serde_json::from_value(json!({ - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "diagnostics": [{ "range": { "start": { "line": 1, "character": 33 }, @@ -5968,7 +5969,7 @@ fn lsp_cache_on_save() { .unwrap() ); client.did_save(json!({ - "textDocument": { "uri": temp_dir.uri().join("file.ts").unwrap() }, + "textDocument": { "uri": temp_dir.url().join("file.ts").unwrap() }, })); assert_eq!(client.read_diagnostics().all(), vec![]); @@ -5987,7 +5988,7 @@ fn lsp_cache_then_definition() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#"import "http://localhost:4545/run/002_hello.ts";"#, @@ -6003,14 +6004,14 @@ fn lsp_cache_then_definition() { "command": "deno.cache", "arguments": [ ["http://localhost:4545/run/002_hello.ts"], - temp_dir.uri().join("file.ts").unwrap(), + temp_dir.url().join("file.ts").unwrap(), ], }), ); let res = client.write_request( "textDocument/definition", json!({ - "textDocument": { "uri": temp_dir.uri().join("file.ts").unwrap() }, + "textDocument": { "uri": temp_dir.url().join("file.ts").unwrap() }, "position": { "line": 0, "character": 8 }, }), ); @@ -6296,7 +6297,7 @@ fn lsp_code_actions_imports_dts() { client.initialize_default(); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#" @@ -6309,7 +6310,7 @@ fn lsp_code_actions_imports_dts() { "textDocument/codeAction", json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), }, "range": { "start": { "line": 1, "character": 17 }, @@ -6339,7 +6340,7 @@ fn lsp_code_actions_imports_dts() { "edit": { "documentChanges": [{ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "version": 1, }, "edits": [{ @@ -6601,7 +6602,7 @@ fn lsp_code_actions_imports_respects_fmt_config() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file00.ts").unwrap(), + "uri": temp_dir.url().join("file00.ts").unwrap(), "languageId": "typescript", "version": 1, "text": temp_dir.read_to_string("file00.ts"), @@ -6609,7 +6610,7 @@ fn lsp_code_actions_imports_respects_fmt_config() { })); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file01.ts").unwrap(), + "uri": temp_dir.url().join("file01.ts").unwrap(), "languageId": "typescript", "version": 1, "text": temp_dir.read_to_string("file01.ts"), @@ -6620,7 +6621,7 @@ fn lsp_code_actions_imports_respects_fmt_config() { "textDocument/codeAction", json!({ "textDocument": { - "uri": temp_dir.uri().join("file00.ts").unwrap() + "uri": temp_dir.url().join("file00.ts").unwrap() }, "range": { "start": { "line": 0, "character": 0 }, @@ -6659,7 +6660,7 @@ fn lsp_code_actions_imports_respects_fmt_config() { "edit": { "documentChanges": [{ "textDocument": { - "uri": temp_dir.uri().join("file00.ts").unwrap(), + "uri": temp_dir.url().join("file00.ts").unwrap(), "version": 1 }, "edits": [{ @@ -6689,7 +6690,7 @@ fn lsp_code_actions_imports_respects_fmt_config() { "message": "Cannot find name 'DuckConfigOptions'." }], "data": { - "specifier": temp_dir.uri().join("file00.ts").unwrap(), + "specifier": temp_dir.url().join("file00.ts").unwrap(), "fixId": "fixMissingImport" } }), @@ -6712,7 +6713,7 @@ fn lsp_code_actions_imports_respects_fmt_config() { "edit": { "documentChanges": [{ "textDocument": { - "uri": temp_dir.uri().join("file00.ts").unwrap(), + "uri": temp_dir.url().join("file00.ts").unwrap(), "version": 1 }, "edits": [{ @@ -6725,7 +6726,7 @@ fn lsp_code_actions_imports_respects_fmt_config() { }] }, "data": { - "specifier": temp_dir.uri().join("file00.ts").unwrap(), + "specifier": temp_dir.url().join("file00.ts").unwrap(), "fixId": "fixMissingImport" } }) @@ -6770,7 +6771,7 @@ fn lsp_quote_style_from_workspace_settings() { let code_action_params = json!({ "textDocument": { - "uri": temp_dir.uri().join("file00.ts").unwrap(), + "uri": temp_dir.url().join("file00.ts").unwrap(), }, "range": { "start": { "line": 0, "character": 0 }, @@ -6812,7 +6813,7 @@ fn lsp_quote_style_from_workspace_settings() { "edit": { "documentChanges": [{ "textDocument": { - "uri": temp_dir.uri().join("file00.ts").unwrap(), + "uri": temp_dir.url().join("file00.ts").unwrap(), "version": null, }, "edits": [{ @@ -6831,7 +6832,7 @@ fn lsp_quote_style_from_workspace_settings() { temp_dir.write("./deno.json", json!({}).to_string()); client.did_change_watched_files(json!({ "changes": [{ - "uri": temp_dir.uri().join("deno.json").unwrap(), + "uri": temp_dir.url().join("deno.json").unwrap(), "type": 1, }], })); @@ -6856,7 +6857,7 @@ fn lsp_quote_style_from_workspace_settings() { "edit": { "documentChanges": [{ "textDocument": { - "uri": temp_dir.uri().join("file00.ts").unwrap(), + "uri": temp_dir.url().join("file00.ts").unwrap(), "version": null, }, "edits": [{ @@ -7239,7 +7240,7 @@ fn lsp_completions_auto_import() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": "file:///a/🦕.ts", + "uri": Url::parse("file:///a/🦕.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "/**\n *\n * @example\n * ```ts\n * const result = add(1, 2);\n * console.log(result); // 3\n * ```\n *\n * @param {number} a - The first number\n * @param {number} b - The second number\n */\nexport function add(a: number, b: number) {\n return a + b;\n}", @@ -7591,14 +7592,14 @@ fn lsp_completions_node_specifier() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import fs from \"node:as\";\n", }, })); let list = client.get_completion_list( - temp_dir.uri().join("file.ts").unwrap(), + temp_dir.url().join("file.ts").unwrap(), (0, 23), json!({ "triggerKind": 2, @@ -7720,7 +7721,7 @@ fn lsp_infer_return_type() { let res = client.write_request( "textDocument/codeAction", json!({ - "textDocument": { "uri": file.uri() }, + "textDocument": { "uri": file.url() }, "range": { "start": { "line": 1, "character": 15 }, "end": { "line": 1, "character": 18 }, @@ -7739,7 +7740,7 @@ fn lsp_infer_return_type() { "kind": "refactor.rewrite.function.returnType", "isPreferred": false, "data": { - "specifier": file.uri(), + "specifier": file.url(), "range": { "start": { "line": 1, "character": 15 }, "end": { "line": 1, "character": 18 }, @@ -7759,7 +7760,7 @@ fn lsp_infer_return_type() { "kind": "refactor.rewrite.function.returnType", "isPreferred": false, "data": { - "specifier": file.uri(), + "specifier": file.url(), "range": { "start": { "line": 1, "character": 15 }, "end": { "line": 1, "character": 18 }, @@ -7770,14 +7771,14 @@ fn lsp_infer_return_type() { "edit": { "documentChanges": [ { - "textDocument": { "uri": file.uri(), "version": null }, + "textDocument": { "uri": file.url(), "version": null }, "edits": [ { "range": { "start": { "line": 1, "character": 20 }, "end": { "line": 1, "character": 20 }, }, - "newText": format!(": import(\"{}\").SomeInterface", types_file.uri()), + "newText": format!(": import(\"{}\").SomeInterface", types_file.url()), }, ], }, @@ -7810,7 +7811,7 @@ fn lsp_npm_types_nested_js_dts() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], file.uri()], + "arguments": [[], file.url()], }), ); let diagnostics = client.did_open_file(&file); @@ -7891,7 +7892,7 @@ fn lsp_npm_always_caches() { // create the lsp and cache a different npm specifier let mut client = context.new_lsp_command().build(); client.initialize_default(); - let opened_file_uri = temp_dir_path.join("file.ts").uri_file(); + let opened_file_uri = temp_dir_path.join("file.ts").url_file(); client.did_open( json!({ "textDocument": { @@ -7914,7 +7915,7 @@ fn lsp_npm_always_caches() { ); // now open a new file and chalk should be working - let new_file_uri = temp_dir_path.join("new_file.ts").uri_file(); + let new_file_uri = temp_dir_path.join("new_file.ts").url_file(); client.did_open(json!({ "textDocument": { "uri": new_file_uri, @@ -8003,7 +8004,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { client.did_open( json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": concat!( @@ -8030,7 +8031,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { "npm:chalk@~5", "http://localhost:4545/subdir/print_hello.ts", ], - temp_dir.uri().join("file.ts").unwrap(), + temp_dir.url().join("file.ts").unwrap(), ], }), ); @@ -8038,14 +8039,14 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { // try auto-import with path client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("a.ts").unwrap(), + "uri": temp_dir.url().join("a.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "getClie", } })); let list = client.get_completion_list( - temp_dir.uri().join("a.ts").unwrap(), + temp_dir.url().join("a.ts").unwrap(), (0, 7), json!({ "triggerKind": 1 }), ); @@ -8086,7 +8087,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { // try quick fix with path let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("b.ts").unwrap(), + "uri": temp_dir.url().join("b.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "getClient", @@ -8094,7 +8095,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { })); let diagnostics = diagnostics .messages_with_file_and_source( - temp_dir.uri().join("b.ts").unwrap().as_str(), + temp_dir.url().join("b.ts").unwrap().as_str(), "deno-ts", ) .diagnostics; @@ -8102,7 +8103,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { "textDocument/codeAction", json!(json!({ "textDocument": { - "uri": temp_dir.uri().join("b.ts").unwrap() + "uri": temp_dir.url().join("b.ts").unwrap() }, "range": { "start": { "line": 0, "character": 0 }, @@ -8134,7 +8135,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { "edit": { "documentChanges": [{ "textDocument": { - "uri": temp_dir.uri().join("b.ts").unwrap(), + "uri": temp_dir.url().join("b.ts").unwrap(), "version": 1, }, "edits": [{ @@ -8152,7 +8153,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { // try auto-import without path client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("c.ts").unwrap(), + "uri": temp_dir.url().join("c.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "chal", @@ -8160,7 +8161,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { })); let list = client.get_completion_list( - temp_dir.uri().join("c.ts").unwrap(), + temp_dir.url().join("c.ts").unwrap(), (0, 4), json!({ "triggerKind": 1 }), ); @@ -8199,7 +8200,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { // try quick fix without path let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("d.ts").unwrap(), + "uri": temp_dir.url().join("d.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "chalk", @@ -8207,7 +8208,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { })); let diagnostics = diagnostics .messages_with_file_and_source( - temp_dir.uri().join("d.ts").unwrap().as_str(), + temp_dir.url().join("d.ts").unwrap().as_str(), "deno-ts", ) .diagnostics; @@ -8215,7 +8216,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { "textDocument/codeAction", json!(json!({ "textDocument": { - "uri": temp_dir.uri().join("d.ts").unwrap() + "uri": temp_dir.url().join("d.ts").unwrap() }, "range": { "start": { "line": 0, "character": 0 }, @@ -8247,7 +8248,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { "edit": { "documentChanges": [{ "textDocument": { - "uri": temp_dir.uri().join("d.ts").unwrap(), + "uri": temp_dir.url().join("d.ts").unwrap(), "version": 1, }, "edits": [{ @@ -8265,7 +8266,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { // try auto-import with http import map client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("e.ts").unwrap(), + "uri": temp_dir.url().join("e.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "printH", @@ -8273,7 +8274,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { })); let list = client.get_completion_list( - temp_dir.uri().join("e.ts").unwrap(), + temp_dir.url().join("e.ts").unwrap(), (0, 6), json!({ "triggerKind": 1 }), ); @@ -8312,7 +8313,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { // try quick fix with http import let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("f.ts").unwrap(), + "uri": temp_dir.url().join("f.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "printHello", @@ -8320,7 +8321,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { })); let diagnostics = diagnostics .messages_with_file_and_source( - temp_dir.uri().join("f.ts").unwrap().as_str(), + temp_dir.url().join("f.ts").unwrap().as_str(), "deno-ts", ) .diagnostics; @@ -8328,7 +8329,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { "textDocument/codeAction", json!(json!({ "textDocument": { - "uri": temp_dir.uri().join("f.ts").unwrap() + "uri": temp_dir.url().join("f.ts").unwrap() }, "range": { "start": { "line": 0, "character": 0 }, @@ -8360,7 +8361,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { "edit": { "documentChanges": [{ "textDocument": { - "uri": temp_dir.uri().join("f.ts").unwrap(), + "uri": temp_dir.url().join("f.ts").unwrap(), "version": 1, }, "edits": [{ @@ -8378,14 +8379,14 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { // try auto-import with npm package with sub-path on value side of import map client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("nested_path.ts").unwrap(), + "uri": temp_dir.url().join("nested_path.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "entry", } })); let list = client.get_completion_list( - temp_dir.uri().join("nested_path.ts").unwrap(), + temp_dir.url().join("nested_path.ts").unwrap(), (0, 5), json!({ "triggerKind": 1 }), ); @@ -8763,7 +8764,7 @@ fn lsp_npm_specifier_unopened_file() { // open main.ts, which imports other.ts (unopened) client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("main.ts").unwrap(), + "uri": temp_dir.url().join("main.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import { chalk } from './other.ts';\n\n", @@ -8774,7 +8775,7 @@ fn lsp_npm_specifier_unopened_file() { "textDocument/didChange", json!({ "textDocument": { - "uri": temp_dir.uri().join("main.ts").unwrap(), + "uri": temp_dir.url().join("main.ts").unwrap(), "version": 2 }, "contentChanges": [ @@ -8792,7 +8793,7 @@ fn lsp_npm_specifier_unopened_file() { // now ensure completions work let list = client.get_completion_list( - temp_dir.uri().join("main.ts").unwrap(), + temp_dir.url().join("main.ts").unwrap(), (2, 6), json!({ "triggerKind": 2, @@ -9042,7 +9043,7 @@ fn lsp_completions_node_specifier_node_modules_dir() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import fs from \"node:fs\";\n", @@ -9052,14 +9053,14 @@ fn lsp_completions_node_specifier_node_modules_dir() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("file.ts").unwrap()], }), ); client.write_notification( "textDocument/didChange", json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "version": 2, }, "contentChanges": [ @@ -9074,7 +9075,7 @@ fn lsp_completions_node_specifier_node_modules_dir() { }), ); let list = client.get_completion_list( - temp_dir.uri().join("file.ts").unwrap(), + temp_dir.url().join("file.ts").unwrap(), (1, 3), json!({ "triggerKind": 2, @@ -9478,7 +9479,7 @@ fn lsp_npmrc() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], file.uri()], + "arguments": [[], file.url()], }), ); let diagnostics = client.did_open_file(&file); @@ -9538,7 +9539,7 @@ fn lsp_diagnostics_warn_redirect() { assert_eq!( diagnostics.messages_with_source("deno"), lsp::PublishDiagnosticsParams { - uri: Url::parse("file:///a/file.ts").unwrap(), + uri: lsp::Uri::from_str("file:///a/file.ts").unwrap(), diagnostics: vec![ lsp::Diagnostic { range: lsp::Range { @@ -9688,7 +9689,7 @@ fn lsp_lockfile_redirect_resolution() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"http://localhost:4545/subdir/mod1.ts\";\n", @@ -9698,14 +9699,14 @@ fn lsp_lockfile_redirect_resolution() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("file.ts").unwrap()], }), ); client.read_diagnostics(); let res = client.write_request( "textDocument/definition", json!({ - "textDocument": { "uri": temp_dir.uri().join("file.ts").unwrap() }, + "textDocument": { "uri": temp_dir.url().join("file.ts").unwrap() }, "position": { "line": 0, "character": 7 }, }), ); @@ -9829,7 +9830,7 @@ fn lsp_root_with_global_reference_types() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], file2.uri()], + "arguments": [[], file2.url()], }), ); let diagnostics = client.did_open_file(&file); @@ -9922,7 +9923,7 @@ fn lsp_ts_diagnostics_refresh_on_lsp_version_reset() { client.initialize_default(); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": temp_dir.read_to_string("file.ts"), @@ -9933,7 +9934,7 @@ fn lsp_ts_diagnostics_refresh_on_lsp_version_reset() { "textDocument/didClose", json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), }, }), ); @@ -9942,7 +9943,7 @@ fn lsp_ts_diagnostics_refresh_on_lsp_version_reset() { // diagnostics are still refreshed. client.did_open_raw(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "", @@ -9951,7 +9952,7 @@ fn lsp_ts_diagnostics_refresh_on_lsp_version_reset() { temp_dir.write("file.ts", r#""#); client.did_save(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), }, })); let diagnostics = client.read_diagnostics(); @@ -9978,7 +9979,7 @@ fn lsp_diagnostics_none_for_resolving_types() { // run in Deno or Node. let diagnostics = client.did_open(json!({ "textDocument": { - "uri": context.temp_dir().path().join("file.ts").uri_file(), + "uri": context.temp_dir().path().join("file.ts").url_file(), "languageId": "typescript", "version": 1, "text": concat!( @@ -10292,7 +10293,7 @@ fn lsp_format_exclude_with_config() { builder.set_config("./deno.fmt.jsonc"); }); - let file_uri = temp_dir.uri().join("ignored.ts").unwrap(); + let file_uri = temp_dir.url().join("ignored.ts").unwrap(); client.did_open(json!({ "textDocument": { "uri": file_uri, @@ -10345,7 +10346,7 @@ fn lsp_format_exclude_default_config() { builder.set_config("./deno.fmt.jsonc"); }); - let file_uri = temp_dir.uri().join("ignored.ts").unwrap(); + let file_uri = temp_dir.url().join("ignored.ts").unwrap(); client.did_open(json!({ "textDocument": { "uri": file_uri, @@ -10383,7 +10384,7 @@ fn lsp_format_json() { "textDocument/formatting", json!({ "textDocument": { - "uri": json_file.uri(), + "uri": json_file.url(), }, "options": { "tabSize": 2, @@ -10433,7 +10434,7 @@ fn lsp_format_editor_options() { "textDocument/formatting", json!({ "textDocument": { - "uri": file.uri(), + "uri": file.url(), }, "options": { "tabSize": 4, @@ -10457,7 +10458,7 @@ fn lsp_format_editor_options() { "textDocument/formatting", json!({ "textDocument": { - "uri": file.uri(), + "uri": file.url(), }, "options": { "tabSize": 2, @@ -10534,7 +10535,7 @@ fn lsp_json_import_with_query_string() { client.initialize_default(); client.did_open_raw(json!({ "textDocument": { - "uri": temp_dir.uri().join("data.json").unwrap(), + "uri": temp_dir.url().join("data.json").unwrap(), "languageId": "json", "version": 1, "text": temp_dir.read_to_string("data.json"), @@ -10542,7 +10543,7 @@ fn lsp_json_import_with_query_string() { })); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("main.ts").unwrap(), + "uri": temp_dir.url().join("main.ts").unwrap(), "languageId": "typescript", "version": 1, "text": temp_dir.read_to_string("main.ts"), @@ -10565,7 +10566,7 @@ fn lsp_format_markdown() { "textDocument/formatting", json!({ "textDocument": { - "uri": markdown_file.uri() + "uri": markdown_file.url() }, "options": { "tabSize": 2, @@ -10625,7 +10626,7 @@ fn lsp_format_with_config() { .did_open( json!({ "textDocument": { - "uri": ts_file.uri_file(), + "uri": ts_file.url_file(), "languageId": "typescript", "version": 1, "text": "export async function someVeryLongFunctionName() {\nconst response = fetch(\"http://localhost:4545/some/non/existent/path.json\");\nconsole.log(response.text());\nconsole.log(\"finished!\")\n}" @@ -10638,7 +10639,7 @@ fn lsp_format_with_config() { "textDocument/formatting", json!({ "textDocument": { - "uri": ts_file.uri_file() + "uri": ts_file.url_file() }, "options": { "tabSize": 2, @@ -11548,7 +11549,7 @@ fn lsp_lint_with_config() { let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "// TODO: fixme\nexport async function non_camel_case() {\nconsole.log(\"finished!\")\n}" @@ -11691,7 +11692,7 @@ fn lsp_jsx_import_source_config_file_automatic_cache() { client.initialize_default(); let mut diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.tsx").unwrap(), + "uri": temp_dir.url().join("file.tsx").unwrap(), "languageId": "typescriptreact", "version": 1, "text": " @@ -11710,7 +11711,7 @@ fn lsp_jsx_import_source_config_file_automatic_cache() { // reason. Force it with this notification. diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.tsx").unwrap(), + "uri": temp_dir.url().join("file.tsx").unwrap(), "languageId": "typescriptreact", "version": 1, "text": " @@ -11762,7 +11763,7 @@ fn lsp_jsx_import_source_byonm_preact() { let res = client.write_request( "textDocument/hover", json!({ - "textDocument": { "uri": file.uri() }, + "textDocument": { "uri": file.url() }, "position": { "line": 0, "character": 1 }, }), ); @@ -11907,7 +11908,7 @@ Deno.test({ "#; temp_dir.write("./test.ts", contents); temp_dir.write("./deno.jsonc", "{}"); - let specifier = temp_dir.uri().join("test.ts").unwrap(); + let specifier = temp_dir.url().join("test.ts").unwrap(); let mut client = context.new_lsp_command().build(); client.initialize_default(); @@ -11925,7 +11926,7 @@ Deno.test({ client.read_notification_with_method::("deno/testModule"); let params: TestModuleNotificationParams = serde_json::from_value(notification.unwrap()).unwrap(); - assert_eq!(params.text_document.uri, specifier); + assert_eq!(params.text_document.uri.as_str(), specifier.as_str()); assert_eq!(params.kind, TestModuleNotificationKind::Replace); assert_eq!(params.label, "test.ts"); assert_eq!(params.tests.len(), 1); @@ -11970,7 +11971,10 @@ Deno.test({ }), ); assert_eq!(res.enqueued.len(), 1); - assert_eq!(res.enqueued[0].text_document.uri, specifier); + assert_eq!( + res.enqueued[0].text_document.uri.as_str(), + specifier.as_str() + ); assert_eq!(res.enqueued[0].ids.len(), 1); let id = res.enqueued[0].ids[0].clone(); let notification = @@ -12119,7 +12123,7 @@ Deno.test({ "textDocument/didChange", json!({ "textDocument": { - "uri": temp_dir.uri().join("test.ts").unwrap(), + "uri": temp_dir.url().join("test.ts").unwrap(), "version": 2 }, "contentChanges": [{ "text": "" }], @@ -12134,7 +12138,7 @@ Deno.test({ notification, Some(json!({ "textDocument": { - "uri": temp_dir.uri().join("test.ts").unwrap() + "uri": temp_dir.url().join("test.ts").unwrap() } })) ); @@ -12151,7 +12155,7 @@ fn lsp_closed_file_find_references() { "./mod.test.ts", "import { a } from './mod.ts'; console.log(a);", ); - let temp_dir_url = temp_dir.uri(); + let temp_dir_url = temp_dir.url(); let mut client = context.new_lsp_command().build(); client.initialize_default(); client.did_open(json!({ @@ -12206,7 +12210,7 @@ fn lsp_closed_file_find_references_low_document_pre_load() { "./sub_dir/mod.test.ts", "import { a } from './mod.ts'; console.log(a);", ); - let temp_dir_url = temp_dir.uri(); + let temp_dir_url = temp_dir.url(); let mut client = context.new_lsp_command().build(); client.initialize(|builder| { builder.set_preload_limit(1); @@ -12264,7 +12268,7 @@ fn lsp_closed_file_find_references_excluded_path() { ] }"#, ); - let temp_dir_url = temp_dir.uri(); + let temp_dir_url = temp_dir.url(); let mut client = context.new_lsp_command().build(); client.initialize_default(); client.did_open(json!({ @@ -12306,7 +12310,7 @@ fn lsp_data_urls_with_jsx_compiler_option() { let mut client = context.new_lsp_command().build(); client.initialize_default(); - let uri = temp_dir.uri().join("main.ts").unwrap(); + let uri = temp_dir.url().join("main.ts").unwrap(); let diagnostics = client.did_open(json!({ "textDocument": { @@ -12372,7 +12376,7 @@ fn lsp_node_modules_dir() { let mut client = context.new_lsp_command().build(); client.initialize_default(); - let file_uri = temp_dir.uri().join("file.ts").unwrap(); + let file_uri = temp_dir.url().join("file.ts").unwrap(); client.did_open(json!({ "textDocument": { "uri": file_uri, @@ -12492,7 +12496,7 @@ fn lsp_vendor_dir() { let mut client = context.new_lsp_command().build(); client.initialize_default(); - let local_file_uri = temp_dir.uri().join("file.ts").unwrap(); + let local_file_uri = temp_dir.url().join("file.ts").unwrap(); client.did_open(json!({ "textDocument": { "uri": local_file_uri, @@ -12596,7 +12600,7 @@ fn lsp_vendor_dir() { let file_path = temp_dir .path() .join("vendor/http_localhost_4545/subdir/mod1.ts"); - let remote_file_uri = file_path.uri_file(); + let remote_file_uri = file_path.url_file(); assert_eq!(uri, remote_file_uri.as_str()); let file_text = file_path.read_to_string(); @@ -12757,7 +12761,7 @@ fn lsp_deno_json_scopes_import_map() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"foo\";\n", @@ -12767,7 +12771,7 @@ fn lsp_deno_json_scopes_import_map() { "textDocument/hover", json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -12777,7 +12781,7 @@ fn lsp_deno_json_scopes_import_map() { json!({ "contents": { "kind": "markdown", - "value": format!("**Resolved Dependency**\n\n**Code**: file​{}\n", temp_dir.uri().join("project1/foo1.ts").unwrap().as_str().trim_start_matches("file")), + "value": format!("**Resolved Dependency**\n\n**Code**: file​{}\n", temp_dir.url().join("project1/foo1.ts").unwrap().as_str().trim_start_matches("file")), }, "range": { "start": { "line": 0, "character": 7 }, @@ -12787,7 +12791,7 @@ fn lsp_deno_json_scopes_import_map() { ); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"foo\";\n", @@ -12797,7 +12801,7 @@ fn lsp_deno_json_scopes_import_map() { "textDocument/hover", json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -12807,7 +12811,7 @@ fn lsp_deno_json_scopes_import_map() { json!({ "contents": { "kind": "markdown", - "value": format!("**Resolved Dependency**\n\n**Code**: file​{}\n", temp_dir.uri().join("project2/foo2.ts").unwrap().as_str().trim_start_matches("file")), + "value": format!("**Resolved Dependency**\n\n**Code**: file​{}\n", temp_dir.url().join("project2/foo2.ts").unwrap().as_str().trim_start_matches("file")), }, "range": { "start": { "line": 0, "character": 7 }, @@ -12817,7 +12821,7 @@ fn lsp_deno_json_scopes_import_map() { ); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/project3/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/project3/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"foo\";\n", @@ -12827,7 +12831,7 @@ fn lsp_deno_json_scopes_import_map() { "textDocument/hover", json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/project3/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/project3/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -12837,7 +12841,7 @@ fn lsp_deno_json_scopes_import_map() { json!({ "contents": { "kind": "markdown", - "value": format!("**Resolved Dependency**\n\n**Code**: file​{}\n", temp_dir.uri().join("project2/project3/foo3.ts").unwrap().as_str().trim_start_matches("file")), + "value": format!("**Resolved Dependency**\n\n**Code**: file​{}\n", temp_dir.url().join("project2/project3/foo3.ts").unwrap().as_str().trim_start_matches("file")), }, "range": { "start": { "line": 0, "character": 7 }, @@ -12882,7 +12886,7 @@ fn lsp_deno_json_scopes_vendor_dir() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"http://localhost:4545/subdir/mod1.ts\";\n", @@ -12892,14 +12896,14 @@ fn lsp_deno_json_scopes_vendor_dir() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("project1/file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("project1/file.ts").unwrap()], }), ); let res = client.write_request( "textDocument/definition", json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -12907,7 +12911,7 @@ fn lsp_deno_json_scopes_vendor_dir() { assert_eq!( res, json!([{ - "targetUri": temp_dir.uri().join("project1/vendor/http_localhost_4545/subdir/mod1.ts").unwrap(), + "targetUri": temp_dir.url().join("project1/vendor/http_localhost_4545/subdir/mod1.ts").unwrap(), "targetRange": { "start": { "line": 0, @@ -12932,7 +12936,7 @@ fn lsp_deno_json_scopes_vendor_dir() { ); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"http://localhost:4545/subdir/mod2.ts\";\n", @@ -12942,14 +12946,14 @@ fn lsp_deno_json_scopes_vendor_dir() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("project2/file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("project2/file.ts").unwrap()], }), ); let res = client.write_request( "textDocument/definition", json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -12957,7 +12961,7 @@ fn lsp_deno_json_scopes_vendor_dir() { assert_eq!( res, json!([{ - "targetUri": temp_dir.uri().join("project2/vendor/http_localhost_4545/subdir/mod2.ts").unwrap(), + "targetUri": temp_dir.url().join("project2/vendor/http_localhost_4545/subdir/mod2.ts").unwrap(), "targetRange": { "start": { "line": 0, @@ -12982,7 +12986,7 @@ fn lsp_deno_json_scopes_vendor_dir() { ); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/project3/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/project3/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"http://localhost:4545/subdir/mod3.js\";\n", @@ -12992,14 +12996,14 @@ fn lsp_deno_json_scopes_vendor_dir() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("project2/project3/file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("project2/project3/file.ts").unwrap()], }), ); let res = client.write_request( "textDocument/definition", json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/project3/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/project3/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -13007,7 +13011,7 @@ fn lsp_deno_json_scopes_vendor_dir() { assert_eq!( res, json!([{ - "targetUri": temp_dir.uri().join("project2/project3/vendor/http_localhost_4545/subdir/mod3.js").unwrap(), + "targetUri": temp_dir.url().join("project2/project3/vendor/http_localhost_4545/subdir/mod3.js").unwrap(), "targetRange": { "start": { "line": 0, @@ -13067,7 +13071,7 @@ fn lsp_deno_json_scopes_node_modules_dir() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"npm:@denotest/add@1\";\n", @@ -13077,14 +13081,14 @@ fn lsp_deno_json_scopes_node_modules_dir() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("project1/file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("project1/file.ts").unwrap()], }), ); let res = client.write_request( "textDocument/definition", json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -13120,7 +13124,7 @@ fn lsp_deno_json_scopes_node_modules_dir() { ); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"npm:@denotest/add@1\";\n", @@ -13130,14 +13134,14 @@ fn lsp_deno_json_scopes_node_modules_dir() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("project2/file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("project2/file.ts").unwrap()], }), ); let res = client.write_request( "textDocument/definition", json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -13170,7 +13174,7 @@ fn lsp_deno_json_scopes_node_modules_dir() { ); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/project3/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/project3/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"npm:@denotest/add@1\";\n", @@ -13180,14 +13184,14 @@ fn lsp_deno_json_scopes_node_modules_dir() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("project2/project3/file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("project2/project3/file.ts").unwrap()], }), ); let res = client.write_request( "textDocument/definition", json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/project3/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/project3/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -13241,7 +13245,7 @@ fn lsp_deno_json_scopes_ts_config() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "Window;\nWorkerGlobalScope;\n", @@ -13249,7 +13253,7 @@ fn lsp_deno_json_scopes_ts_config() { })); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "Window;\nWorkerGlobalScope;\n", @@ -13259,7 +13263,7 @@ fn lsp_deno_json_scopes_ts_config() { json!(diagnostics.all_messages()), json!([ { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), "version": 1, "diagnostics": [ { @@ -13275,7 +13279,7 @@ fn lsp_deno_json_scopes_ts_config() { ], }, { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), "version": 1, "diagnostics": [ { @@ -13309,7 +13313,7 @@ fn lsp_deno_json_scopes_declaration_files() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "export const foo: Foo = 1;\nexport const bar: Bar = 1;\n", @@ -13317,7 +13321,7 @@ fn lsp_deno_json_scopes_declaration_files() { })); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "export const foo: Foo = 1;\nexport const bar: Bar = 1;\n", @@ -13327,7 +13331,7 @@ fn lsp_deno_json_scopes_declaration_files() { json!(diagnostics.all_messages()), json!([ { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), "version": 1, "diagnostics": [ { @@ -13343,7 +13347,7 @@ fn lsp_deno_json_scopes_declaration_files() { ], }, { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), "version": 1, "diagnostics": [ { @@ -13395,11 +13399,11 @@ fn lsp_deno_json_scopes_find_references() { res, json!([ { - "uri": file1.uri(), + "uri": file1.url(), "range": file1.range_of("foo"), }, { - "uri": file2.uri(), + "uri": file2.url(), "range": file2.range_of("foo"), }, ]), @@ -13427,8 +13431,8 @@ fn lsp_deno_json_scopes_file_rename_import_edits() { json!({ "files": [ { - "oldUri": file1.uri(), - "newUri": file1.uri().join("file_renamed.ts").unwrap(), + "oldUri": file1.url(), + "newUri": file1.url().join("file_renamed.ts").unwrap(), }, ], }), @@ -13439,7 +13443,7 @@ fn lsp_deno_json_scopes_file_rename_import_edits() { "documentChanges": [ { "textDocument": { - "uri": file2.uri(), + "uri": file2.url(), "version": null, }, "edits": [ @@ -13487,7 +13491,7 @@ fn lsp_deno_json_scopes_goto_implementations() { res, json!([ { - "targetUri": file2.uri(), + "targetUri": file2.url(), "targetRange": file2.range_of("export class SomeFoo implements Foo {}"), "targetSelectionRange": file2.range_of("SomeFoo"), }, @@ -13544,7 +13548,7 @@ fn lsp_deno_json_scopes_call_hierarchy() { "name": "bar", "kind": 12, "detail": "", - "uri": file2.uri(), + "uri": file2.url(), "range": { "start": { "line": 2, "character": 6 }, "end": { "line": 4, "character": 7 }, @@ -13564,7 +13568,7 @@ fn lsp_deno_json_scopes_call_hierarchy() { "name": "file.ts", "kind": 2, "detail": "project3", - "uri": file3.uri(), + "uri": file3.url(), "range": { "start": { "line": 1, "character": 6 }, "end": { "line": 3, "character": 4 }, @@ -13593,7 +13597,7 @@ fn lsp_deno_json_scopes_call_hierarchy() { "name": "foo", "kind": 12, "detail": "", - "uri": file1.uri(), + "uri": file1.url(), "range": file1.range_of("export function foo() {}"), "selectionRange": file1.range_of("foo"), }, @@ -13641,7 +13645,7 @@ fn lsp_deno_json_scopes_rename_symbol() { "documentChanges": [ { "textDocument": { - "uri": file1.uri(), + "uri": file1.url(), "version": null, }, "edits": [ @@ -13653,7 +13657,7 @@ fn lsp_deno_json_scopes_rename_symbol() { }, { "textDocument": { - "uri": file2.uri(), + "uri": file2.url(), "version": null, }, "edits": [ @@ -13696,7 +13700,7 @@ fn lsp_deno_json_scopes_search_symbol() { "name": "someSymbol1", "kind": 13, "location": { - "uri": file1.uri(), + "uri": file1.url(), "range": file1.range_of("someSymbol1 = 1"), }, "containerName": "", @@ -13705,7 +13709,7 @@ fn lsp_deno_json_scopes_search_symbol() { "name": "someSymbol2", "kind": 13, "location": { - "uri": file2.uri(), + "uri": file2.url(), "range": file2.range_of("someSymbol2 = 2"), }, "containerName": "", @@ -13745,7 +13749,7 @@ fn lsp_deno_json_workspace_fmt_config() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "console.log(\"\");\n", @@ -13755,7 +13759,7 @@ fn lsp_deno_json_workspace_fmt_config() { "textDocument/formatting", json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), }, "options": { "tabSize": 2, @@ -13775,7 +13779,7 @@ fn lsp_deno_json_workspace_fmt_config() { ); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "console.log(\"\");\n", @@ -13785,7 +13789,7 @@ fn lsp_deno_json_workspace_fmt_config() { "textDocument/formatting", json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), }, "options": { "tabSize": 2, @@ -13807,7 +13811,7 @@ fn lsp_deno_json_workspace_fmt_config() { // has no fmt field. client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "console.log(\"\");\n", @@ -13817,7 +13821,7 @@ fn lsp_deno_json_workspace_fmt_config() { "textDocument/formatting", json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), }, "options": { "tabSize": 2, @@ -13872,7 +13876,7 @@ fn lsp_deno_json_workspace_lint_config() { client.initialize_default(); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#" @@ -13885,7 +13889,7 @@ fn lsp_deno_json_workspace_lint_config() { assert_eq!( json!(diagnostics.messages_with_source("deno-lint")), json!({ - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "diagnostics": [{ "range": { "start": { "line": 2, "character": 14 }, @@ -13903,13 +13907,13 @@ fn lsp_deno_json_workspace_lint_config() { "textDocument/didClose", json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), }, }), ); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#" @@ -13922,7 +13926,7 @@ fn lsp_deno_json_workspace_lint_config() { assert_eq!( json!(diagnostics.messages_with_source("deno-lint")), json!({ - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), "diagnostics": [{ "range": { "start": { "line": 1, "character": 8 }, @@ -13949,7 +13953,7 @@ fn lsp_deno_json_workspace_lint_config() { "textDocument/didClose", json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), }, }), ); @@ -13957,7 +13961,7 @@ fn lsp_deno_json_workspace_lint_config() { // has no lint field. let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#" @@ -13970,7 +13974,7 @@ fn lsp_deno_json_workspace_lint_config() { assert_eq!( json!(diagnostics.messages_with_source("deno-lint")), json!({ - "uri": temp_dir.uri().join("project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project2/file.ts").unwrap(), "diagnostics": [{ "range": { "start": { "line": 2, "character": 14 }, @@ -14021,7 +14025,7 @@ fn lsp_deno_json_workspace_import_map() { { client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"foo\";\n", @@ -14031,7 +14035,7 @@ fn lsp_deno_json_workspace_import_map() { "textDocument/hover", json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -14041,7 +14045,7 @@ fn lsp_deno_json_workspace_import_map() { json!({ "contents": { "kind": "markdown", - "value": format!("**Resolved Dependency**\n\n**Code**: file​{}\n", temp_dir.uri().join("project1/foo1.ts").unwrap().as_str().trim_start_matches("file")), + "value": format!("**Resolved Dependency**\n\n**Code**: file​{}\n", temp_dir.url().join("project1/foo1.ts").unwrap().as_str().trim_start_matches("file")), }, "range": { "start": { "line": 0, "character": 7 }, @@ -14055,7 +14059,7 @@ fn lsp_deno_json_workspace_import_map() { { client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/project2/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"foo\";\n", @@ -14065,7 +14069,7 @@ fn lsp_deno_json_workspace_import_map() { "textDocument/hover", json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/project2/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -14075,7 +14079,7 @@ fn lsp_deno_json_workspace_import_map() { json!({ "contents": { "kind": "markdown", - "value": format!("**Resolved Dependency**\n\n**Code**: file​{}\n", temp_dir.uri().join("project1/project2/foo2.ts").unwrap().as_str().trim_start_matches("file")), + "value": format!("**Resolved Dependency**\n\n**Code**: file​{}\n", temp_dir.url().join("project1/project2/foo2.ts").unwrap().as_str().trim_start_matches("file")), }, "range": { "start": { "line": 0, "character": 7 }, @@ -14114,7 +14118,7 @@ fn lsp_workspace_lockfile() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/project2/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"http://localhost:4545/subdir/mod1.ts\";\n", @@ -14124,14 +14128,14 @@ fn lsp_workspace_lockfile() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("project1/project2/file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("project1/project2/file.ts").unwrap()], }), ); client.read_diagnostics(); let res = client.write_request( "textDocument/definition", json!({ - "textDocument": { "uri": temp_dir.uri().join("project1/project2/file.ts").unwrap() }, + "textDocument": { "uri": temp_dir.url().join("project1/project2/file.ts").unwrap() }, "position": { "line": 0, "character": 7 }, }), ); @@ -14173,7 +14177,7 @@ fn lsp_deno_json_workspace_vendor_dir() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/project2/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"http://localhost:4545/subdir/mod1.ts\";\n", @@ -14183,14 +14187,14 @@ fn lsp_deno_json_workspace_vendor_dir() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("project1/project2/file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("project1/project2/file.ts").unwrap()], }), ); let res = client.write_request( "textDocument/definition", json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/project2/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -14198,7 +14202,7 @@ fn lsp_deno_json_workspace_vendor_dir() { assert_eq!( res, json!([{ - "targetUri": temp_dir.uri().join("project1/vendor/http_localhost_4545/subdir/mod1.ts").unwrap(), + "targetUri": temp_dir.url().join("project1/vendor/http_localhost_4545/subdir/mod1.ts").unwrap(), "targetRange": { "start": { "line": 0, @@ -14245,7 +14249,7 @@ fn lsp_deno_json_workspace_node_modules_dir() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/project2/file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"npm:@denotest/add@1\";\n", @@ -14255,14 +14259,14 @@ fn lsp_deno_json_workspace_node_modules_dir() { "workspace/executeCommand", json!({ "command": "deno.cache", - "arguments": [[], temp_dir.uri().join("project1/project2/file.ts").unwrap()], + "arguments": [[], temp_dir.url().join("project1/project2/file.ts").unwrap()], }), ); let res = client.write_request( "textDocument/definition", json!({ "textDocument": { - "uri": temp_dir.uri().join("project1/project2/file.ts").unwrap(), + "uri": temp_dir.url().join("project1/project2/file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -14326,7 +14330,7 @@ fn lsp_deno_json_workspace_jsr_resolution() { client.initialize_default(); client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import \"jsr:@org/project1@^1.0.0\";\n", @@ -14336,7 +14340,7 @@ fn lsp_deno_json_workspace_jsr_resolution() { "textDocument/hover", json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), }, "position": { "line": 0, "character": 7 }, }), @@ -14348,7 +14352,7 @@ fn lsp_deno_json_workspace_jsr_resolution() { "kind": "markdown", "value": format!( "**Resolved Dependency**\n\n**Code**: file​://{}\n", - temp_dir.uri().join("project1/mod.ts").unwrap().path(), + temp_dir.url().join("project1/mod.ts").unwrap().path(), ), }, "range": { @@ -14409,7 +14413,7 @@ fn lsp_npm_workspace() { client.initialize_default(); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("packages/subtract/index.ts").unwrap(), + "uri": temp_dir.url().join("packages/subtract/index.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "import { add } from 'add';\nexport function subtract(a: number, b: number): number { return add(a, -b); }", @@ -14420,7 +14424,7 @@ fn lsp_npm_workspace() { "textDocument/definition", json!({ "textDocument": { - "uri": temp_dir.uri().join("packages/subtract/index.ts").unwrap(), + "uri": temp_dir.url().join("packages/subtract/index.ts").unwrap(), }, "position": { "line": 0, "character": 9 }, }), @@ -14429,7 +14433,7 @@ fn lsp_npm_workspace() { assert_eq!( res, json!([{ - "targetUri": temp_dir.uri().join("packages/add/index.ts").unwrap(), + "targetUri": temp_dir.url().join("packages/add/index.ts").unwrap(), "targetRange": { "start": { "line": 0, @@ -14463,7 +14467,7 @@ fn lsp_import_unstable_bare_node_builtins_auto_discovered() { let contents = r#"import path from "path";"#; temp_dir.write("main.ts", contents); temp_dir.write("deno.json", r#"{ "unstable": ["bare-node-builtins"] }"#); - let main_script = temp_dir.uri().join("main.ts").unwrap(); + let main_script = temp_dir.url().join("main.ts").unwrap(); let mut client = context.new_lsp_command().capture_stderr().build(); client.initialize_default(); @@ -14559,7 +14563,7 @@ fn lsp_jupyter_byonm_diagnostics() { context.run_npm("install"); let mut client = context.new_lsp_command().build(); client.initialize_default(); - let notebook_specifier = temp_dir.join("notebook.ipynb").uri_file(); + let notebook_specifier = temp_dir.join("notebook.ipynb").url_file(); let notebook_specifier = format!( "{}#abc", notebook_specifier @@ -14621,7 +14625,7 @@ fn lsp_deno_future_env_byonm() { client.initialize_default(); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("file.ts").unwrap(), + "uri": temp_dir.url().join("file.ts").unwrap(), "languageId": "typescript", "version": 1, "text": r#" @@ -14670,11 +14674,11 @@ fn lsp_sloppy_imports() { temp_dir.join("c.d.ts").write("export class C {}"); let mut client = context.new_lsp_command().build(); client.initialize(|builder| { - builder.set_root_uri(temp_dir.uri_dir()); + builder.set_root_uri(temp_dir.url_dir()); }); client.did_open(json!({ "textDocument": { - "uri": temp_dir.join("b.ts").uri_file(), + "uri": temp_dir.join("b.ts").url_file(), "languageId": "typescript", "version": 1, "text": "export class B {}", @@ -14682,7 +14686,7 @@ fn lsp_sloppy_imports() { })); client.did_open(json!({ "textDocument": { - "uri": temp_dir.join("c.js").uri_file(), + "uri": temp_dir.join("c.js").url_file(), "languageId": "typescript", "version": 1, "text": "export class C {}", @@ -14690,7 +14694,7 @@ fn lsp_sloppy_imports() { })); client.did_open(json!({ "textDocument": { - "uri": temp_dir.join("c.d.ts").uri_file(), + "uri": temp_dir.join("c.d.ts").url_file(), "languageId": "typescript", "version": 1, "text": "export class C {}", @@ -14698,7 +14702,7 @@ fn lsp_sloppy_imports() { })); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.join("file.ts").uri_file(), + "uri": temp_dir.join("file.ts").url_file(), "languageId": "typescript", "version": 1, "text": concat!( @@ -14830,7 +14834,7 @@ fn lsp_sloppy_imports_prefers_dts() { ); let diagnostics = client.did_open_file(&a_dts); - assert_eq!(json!(diagnostics.for_file(&a_dts.uri())), json!([])); + assert_eq!(json!(diagnostics.for_file(&a_dts.url())), json!([])); let response = client.write_request( "textDocument/references", @@ -14846,12 +14850,12 @@ fn lsp_sloppy_imports_prefers_dts() { response, json!([ { - "uri": file.uri(), + "uri": file.url(), // the import "range": file.range_of("foo"), }, { - "uri": file.uri(), + "uri": file.url(), // the usage "range": file.range_of_nth(1, "foo"), } @@ -14871,11 +14875,11 @@ fn sloppy_imports_not_enabled() { temp_dir.join("a.ts").write("export class A {}"); let mut client = context.new_lsp_command().build(); client.initialize(|builder| { - builder.set_root_uri(temp_dir.uri_dir()); + builder.set_root_uri(temp_dir.url_dir()); }); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.join("file.ts").uri_file(), + "uri": temp_dir.join("file.ts").url_file(), "languageId": "typescript", "version": 1, "text": "import * as a from './a';\nconsole.log(a)\n", @@ -14901,11 +14905,11 @@ fn sloppy_imports_not_enabled() { source: Some("deno".to_string()), message: format!( "Unable to load a local module: {}\nMaybe add a '.ts' extension.", - temp_dir.join("a").uri_file(), + temp_dir.join("a").url_file(), ), data: Some(json!({ - "specifier": temp_dir.join("a").uri_file(), - "to": temp_dir.join("a.ts").uri_file(), + "specifier": temp_dir.join("a").url_file(), + "to": temp_dir.join("a.ts").url_file(), "message": "Add a '.ts' extension.", })), ..Default::default() @@ -14917,7 +14921,7 @@ fn sloppy_imports_not_enabled() { "textDocument/codeAction", json!({ "textDocument": { - "uri": temp_dir.join("file.ts").uri_file() + "uri": temp_dir.join("file.ts").url_file() }, "range": { "start": { "line": 0, "character": 19 }, @@ -14934,11 +14938,11 @@ fn sloppy_imports_not_enabled() { "source": "deno", "message": format!( "Unable to load a local module: {}\nMaybe add a '.ts' extension.", - temp_dir.join("a").uri_file(), + temp_dir.join("a").url_file(), ), "data": { - "specifier": temp_dir.join("a").uri_file(), - "to": temp_dir.join("a.ts").uri_file(), + "specifier": temp_dir.join("a").url_file(), + "to": temp_dir.join("a.ts").url_file(), "message": "Add a '.ts' extension.", }, }], @@ -14961,17 +14965,17 @@ fn sloppy_imports_not_enabled() { "source": "deno", "message": format!( "Unable to load a local module: {}\nMaybe add a '.ts' extension.", - temp_dir.join("a").uri_file(), + temp_dir.join("a").url_file(), ), "data": { - "specifier": temp_dir.join("a").uri_file(), - "to": temp_dir.join("a.ts").uri_file(), + "specifier": temp_dir.join("a").url_file(), + "to": temp_dir.join("a.ts").url_file(), "message": "Add a '.ts' extension.", }, }], "edit": { "changes": { - temp_dir.join("file.ts").uri_file(): [{ + temp_dir.join("file.ts").url_file(): [{ "range": { "start": { "line": 0, "character": 19 }, "end": { "line": 0, "character": 24 } @@ -15015,7 +15019,7 @@ fn lsp_byonm_js_import_resolves_to_dts() { client.initialize_default(); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": temp_dir.uri().join("node_modules/postcss/lib/comment.d.ts").unwrap(), + "uri": temp_dir.url().join("node_modules/postcss/lib/comment.d.ts").unwrap(), "languageId": "typescript", "version": 1, "text": temp_dir.path().join("node_modules/postcss/lib/comment.d.ts").read_to_string(), @@ -15034,7 +15038,7 @@ fn decorators_tc39() { let mut client = context.new_lsp_command().build(); client.initialize_default(); - let uri = temp_dir.uri().join("main.ts").unwrap(); + let uri = temp_dir.url().join("main.ts").unwrap(); let diagnostics = client .did_open(json!({ @@ -15085,7 +15089,7 @@ fn decorators_ts() { let mut client = context.new_lsp_command().build(); client.initialize_default(); - let uri = temp_dir.uri().join("main.ts").unwrap(); + let uri = temp_dir.url().join("main.ts").unwrap(); let diagnostics = client .did_open(json!({ @@ -15189,13 +15193,13 @@ fn lsp_cjs_internal_types_default_export() { ); client.did_open(json!({ "textDocument": { - "uri": node_modules_index_d_ts.uri_file(), + "uri": node_modules_index_d_ts.url_file(), "languageId": "typescript", "version": 1, "text": node_modules_index_d_ts.read_to_string(), } })); - let main_url = temp_dir.path().join("main.ts").uri_file(); + let main_url = temp_dir.path().join("main.ts").url_file(); let diagnostics = client.did_open( json!({ "textDocument": { @@ -15232,7 +15236,7 @@ fn lsp_cjs_import_dual() { let mut client = context.new_lsp_command().build(); client.initialize_default(); - let main_url = temp_dir.path().join("main.ts").uri_file(); + let main_url = temp_dir.path().join("main.ts").url_file(); let diagnostics = client.did_open( json!({ "textDocument": { @@ -15271,7 +15275,7 @@ fn lsp_ts_code_fix_any_param() { let param_def = range_of("param", src); - let main_url = temp_dir.path().join("main.ts").uri_file(); + let main_url = temp_dir.path().join("main.ts").url_file(); let diagnostics = client.did_open(json!({ "textDocument": { "uri": main_url, diff --git a/tests/integration/npm_tests.rs b/tests/integration/npm_tests.rs index 86db962f43..9e4eb7efe8 100644 --- a/tests/integration/npm_tests.rs +++ b/tests/integration/npm_tests.rs @@ -2090,7 +2090,7 @@ fn top_level_install_package_json_explicit_opt_in() { rm_created_files(); let mut client = test_context.new_lsp_command().build(); client.initialize_default(); - let file_uri = temp_dir.uri().join("file.ts").unwrap(); + let file_uri = temp_dir.url().join("file.ts").unwrap(); client.did_open(json!({ "textDocument": { "uri": file_uri, diff --git a/tests/util/server/src/fs.rs b/tests/util/server/src/fs.rs index fc27e44859..47d0d61fa1 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 85879d9d82..1c70978b68 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 = 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) -> &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() }