Skip to content

Commit

Permalink
fix: revert lsp related internal specifiers (denoland#17673)
Browse files Browse the repository at this point in the history
To fix reports of breakage from denoland#17655
  • Loading branch information
crowlKats authored Feb 6, 2023
1 parent 34bfa2c commit 7f23063
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
6 changes: 3 additions & 3 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ impl Inner {

async fn did_close(&mut self, params: DidCloseTextDocumentParams) {
let mark = self.performance.mark("did_close", Some(&params));
if params.text_document.uri.scheme() == "internal" {
if params.text_document.uri.scheme() == "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
Expand Down Expand Up @@ -2609,7 +2609,7 @@ impl tower_lsp::LanguageServer for LanguageServer {
}

async fn did_open(&self, params: DidOpenTextDocumentParams) {
if params.text_document.uri.scheme() == "internal" {
if params.text_document.uri.scheme() == "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
Expand Down Expand Up @@ -3121,7 +3121,7 @@ impl Inner {
.performance
.mark("virtual_text_document", Some(&params));
let specifier = self.url_map.normalize_url(&params.text_document.uri);
let contents = if specifier.as_str() == "internal:/status.md" {
let contents = if specifier.as_str() == "deno:/status.md" {
let mut contents = String::new();
let mut documents_specifiers = self
.documents
Expand Down
8 changes: 2 additions & 6 deletions cli/lsp/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,15 +1154,11 @@ impl ImplementationLocation {
language_server: &language_server::Inner,
) -> lsp::Location {
let specifier = normalize_specifier(&self.document_span.file_name)
.unwrap_or_else(|_| {
ModuleSpecifier::parse("internal://invalid").unwrap()
});
.unwrap_or_else(|_| ModuleSpecifier::parse("deno://invalid").unwrap());
let uri = language_server
.url_map
.normalize_specifier(&specifier)
.unwrap_or_else(|_| {
ModuleSpecifier::parse("internal://invalid").unwrap()
});
.unwrap_or_else(|_| ModuleSpecifier::parse("deno://invalid").unwrap());
lsp::Location {
uri,
range: self.document_span.text_span.to_range(line_index),
Expand Down
18 changes: 9 additions & 9 deletions cli/lsp/urls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::sync::Arc;
/// Used in situations where a default URL needs to be used where otherwise a
/// panic is undesired.
pub static INVALID_SPECIFIER: Lazy<ModuleSpecifier> =
Lazy::new(|| ModuleSpecifier::parse("internal://invalid").unwrap());
Lazy::new(|| ModuleSpecifier::parse("deno://invalid").unwrap());

/// Matches the `encodeURIComponent()` encoding from JavaScript, which matches
/// the component percent encoding set.
Expand Down Expand Up @@ -81,7 +81,7 @@ impl LspUrlMapInner {
}

/// A bi-directional map of URLs sent to the LSP client and internal module
/// specifiers. We need to map internal specifiers into `internal:` schema URLs
/// specifiers. We need to map internal specifiers into `deno:` schema URLs
/// to allow the Deno language server to manage these as virtual documents.
#[derive(Debug, Default, Clone)]
pub struct LspUrlMap(Arc<Mutex<LspUrlMapInner>>);
Expand All @@ -101,7 +101,7 @@ impl LspUrlMap {
specifier.clone()
} else {
let specifier_str = if specifier.scheme() == "asset" {
format!("internal:/asset{}", specifier.path())
format!("deno:/asset{}", specifier.path())
} else if specifier.scheme() == "data" {
let data_url = DataUrl::process(specifier.as_str())
.map_err(|e| uri_error(format!("{e:?}")))?;
Expand All @@ -114,7 +114,7 @@ impl LspUrlMap {
media_type.as_ts_extension()
};
format!(
"internal:/{}/data_url{}",
"deno:/{}/data_url{}",
hash_data_specifier(specifier),
extension
)
Expand All @@ -128,7 +128,7 @@ impl LspUrlMap {
})
.collect();
path.push_str(&parts.join("/"));
format!("internal:/{path}")
format!("deno:/{path}")
};
let url = Url::parse(&specifier_str)?;
inner.put(specifier.clone(), url.clone());
Expand All @@ -138,7 +138,7 @@ impl LspUrlMap {
}
}

/// Normalize URLs from the client, where "virtual" `internal:///` URLs are
/// Normalize URLs from the client, where "virtual" `deno:///` URLs are
/// converted into proper module specifiers, as well as handle situations
/// where the client encodes a file URL differently than Rust does by default
/// causing issues with string matching of URLs.
Expand Down Expand Up @@ -178,7 +178,7 @@ mod tests {
.normalize_specifier(&fixture)
.expect("could not handle specifier");
let expected_url =
Url::parse("internal:/https/deno.land/x/pkg%401.0.0/mod.ts").unwrap();
Url::parse("deno:/https/deno.land/x/pkg%401.0.0/mod.ts").unwrap();
assert_eq!(actual_url, expected_url);

let actual_specifier = map.normalize_url(&actual_url);
Expand All @@ -193,7 +193,7 @@ mod tests {
let actual_url = map
.normalize_specifier(&fixture)
.expect("could not handle specifier");
let expected_url = Url::parse("internal:/https/cdn.skypack.dev/-/postcss%40v8.2.9-E4SktPp9c0AtxrJHp8iV/dist%3Des2020%2Cmode%3Dtypes/lib/postcss.d.ts").unwrap();
let expected_url = Url::parse("deno:/https/cdn.skypack.dev/-/postcss%40v8.2.9-E4SktPp9c0AtxrJHp8iV/dist%3Des2020%2Cmode%3Dtypes/lib/postcss.d.ts").unwrap();
assert_eq!(actual_url, expected_url);

let actual_specifier = map.normalize_url(&actual_url);
Expand All @@ -207,7 +207,7 @@ mod tests {
let actual_url = map
.normalize_specifier(&fixture)
.expect("could not handle specifier");
let expected_url = Url::parse("internal:/c21c7fc382b2b0553dc0864aa81a3acacfb7b3d1285ab5ae76da6abec213fb37/data_url.ts").unwrap();
let expected_url = Url::parse("deno:/c21c7fc382b2b0553dc0864aa81a3acacfb7b3d1285ab5ae76da6abec213fb37/data_url.ts").unwrap();
assert_eq!(actual_url, expected_url);

let actual_specifier = map.normalize_url(&actual_url);
Expand Down
8 changes: 4 additions & 4 deletions cli/tests/integration/lsp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ fn lsp_hover_asset() {
"deno/virtualTextDocument",
json!({
"textDocument": {
"uri": "internal:/asset/lib.deno.shared_globals.d.ts"
"uri": "deno:/asset/lib.deno.shared_globals.d.ts"
}
}),
)
Expand All @@ -1084,7 +1084,7 @@ fn lsp_hover_asset() {
"textDocument/hover",
json!({
"textDocument": {
"uri": "internal:/asset/lib.es2015.symbol.wellknown.d.ts"
"uri": "deno:/asset/lib.es2015.symbol.wellknown.d.ts"
},
"position": {
"line": 109,
Expand Down Expand Up @@ -3103,7 +3103,7 @@ fn lsp_code_lens_non_doc_nav_tree() {
"deno/virtualTextDocument",
json!({
"textDocument": {
"uri": "internal:/asset/lib.deno.shared_globals.d.ts"
"uri": "deno:/asset/lib.deno.shared_globals.d.ts"
}
}),
)
Expand All @@ -3115,7 +3115,7 @@ fn lsp_code_lens_non_doc_nav_tree() {
"textDocument/codeLens",
json!({
"textDocument": {
"uri": "internal:/asset/lib.deno.shared_globals.d.ts"
"uri": "deno:/asset/lib.deno.shared_globals.d.ts"
}
}),
)
Expand Down

0 comments on commit 7f23063

Please sign in to comment.