summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-08-24 01:21:21 +0100
committerGitHub <noreply@github.com>2024-08-24 01:21:21 +0100
commit2ab4afc6b8e90f1315e0727c9b9c714c3667dc45 (patch)
tree05f07ba22d5d4a5f5120ab988320ad88ea20d542 /cli
parentbbd3a7e637b0223647405adf76b23092ab957157 (diff)
refactor(lsp): changes for lsp_types 0.97.0 (#25169)
Diffstat (limited to 'cli')
-rw-r--r--cli/bench/lsp.rs9
-rw-r--r--cli/clippy.toml3
-rw-r--r--cli/lsp/analysis.rs11
-rw-r--r--cli/lsp/capabilities.rs2
-rw-r--r--cli/lsp/client.rs16
-rw-r--r--cli/lsp/completions.rs4
-rw-r--r--cli/lsp/config.rs13
-rw-r--r--cli/lsp/diagnostics.rs34
-rw-r--r--cli/lsp/documents.rs12
-rw-r--r--cli/lsp/language_server.rs113
-rw-r--r--cli/lsp/lsp_custom.rs6
-rw-r--r--cli/lsp/repl.rs19
-rw-r--r--cli/lsp/testing/definitions.rs3
-rw-r--r--cli/lsp/testing/execution.rs34
-rw-r--r--cli/lsp/testing/server.rs7
-rw-r--r--cli/lsp/tsc.rs65
-rw-r--r--cli/lsp/urls.rs47
-rw-r--r--cli/resolver.rs24
-rw-r--r--cli/tools/registry/api.rs2
-rw-r--r--cli/tools/registry/diagnostics.rs2
-rw-r--r--cli/tools/registry/graph.rs2
-rw-r--r--cli/tools/registry/mod.rs2
-rw-r--r--cli/tools/registry/unfurl.rs2
-rw-r--r--cli/tsc/mod.rs2
24 files changed, 243 insertions, 191 deletions
diff --git a/cli/bench/lsp.rs b/cli/bench/lsp.rs
index f2070eb21..b088865c6 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 c4afef17c..e20c56c47 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 9f2c7ffc8..bea626841 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::<Vec<DataQuickFix>>(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 650fea571..e93d3b7c2 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 719ce53f6..6ed0c0430 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<Option<lsp::Url>>,
+ scopes: Vec<Option<lsp::Uri>>,
) -> Result<Vec<WorkspaceSettings>, 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<lsp::Diagnostic>,
version: Option<i32>,
);
@@ -182,7 +182,7 @@ trait ClientTrait: Send + Sync {
);
async fn workspace_configuration(
&self,
- scopes: Vec<Option<lsp::Url>>,
+ scopes: Vec<Option<lsp::Uri>>,
) -> Result<Vec<WorkspaceSettings>, 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<lsp::Diagnostic>,
version: Option<i32>,
) {
@@ -276,7 +276,7 @@ impl ClientTrait for TowerClient {
async fn workspace_configuration(
&self,
- scopes: Vec<Option<lsp::Url>>,
+ scopes: Vec<Option<lsp::Uri>>,
) -> Result<Vec<WorkspaceSettings>, 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<lsp::Diagnostic>,
_version: Option<i32>,
) {
@@ -383,7 +383,7 @@ impl ClientTrait for ReplClient {
async fn workspace_configuration(
&self,
- scopes: Vec<Option<lsp::Url>>,
+ scopes: Vec<Option<lsp::Uri>>,
) -> Result<Vec<WorkspaceSettings>, AnyError> {
Ok(vec![get_repl_workspace_settings(); scopes.len()])
}
diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs
index ab2d8000c..1e5504d75 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 f99f1fa10..4a279a7c4 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<Item = Url>) -> Self {
+ pub fn new_with_roots(root_urls: impl IntoIterator<Item = Url>) -> 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 5054aa931..d871ffbe4 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 e91cfe0ac..a8ddc8fd7 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 04863c251..86277ab41 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", &params);
- 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(&params.text_document.uri))
- .then(|| params.text_document.uri.clone());
+ let file_referrer = Some(uri_to_url(&params.text_document.uri))
+ .filter(|s| self.documents.is_valid_file_referrer(s));
let specifier = self
.url_map
.normalize_url(&params.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", &params);
- self.diagnostics_state.clear(&params.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(&params.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<Option<Vec<TextEdit>>> {
- let file_referrer = (self
- .documents
- .is_valid_file_referrer(&params.text_document.uri))
- .then(|| params.text_document.uri.clone());
+ let file_referrer = Some(uri_to_url(&params.text_document.uri))
+ .filter(|s| self.documents.is_valid_file_referrer(s));
let mut specifier = self
.url_map
.normalize_url(&params.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(&params.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 637a88bda..5f485db7a 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 2db7b1f72..ada30f837 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 43a07c2e3..69baf053e 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 14196baa3..aec91b3e7 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) = &params.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 &params.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<usize, LspTestDescription>,
) -> 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 ff59e1033..0c34ea7bc 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 3ac25507c..566c61977 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<StateSnapshot>, 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 594c223b4..4a960d366 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 a62828b6e..bd88ecd9a 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 c382aa9ac..2f27cb2fe 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 69434f1ea..c53a39683 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 bdcb27aa1..d14e4cd84 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 ee3204dc7..24b3051e4 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 2babedb36..0f5b9fdd3 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<deno_ast::TextChange>,
diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs
index ac7fc48e3..cf7a55d8c 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;