Skip to content

Commit

Permalink
fix(lsp): panic on url_to_uri() (denoland#25238)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn authored Aug 28, 2024
1 parent efcabce commit 97d1635
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 251 deletions.
4 changes: 2 additions & 2 deletions cli/lsp/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ impl CodeActionCollection {
.as_ref()
.and_then(|d| serde_json::from_value::<Vec<DataQuickFix>>(d.clone()).ok())
{
let uri = url_to_uri(specifier);
let uri = url_to_uri(specifier)?;
for quick_fix in data_quick_fixes {
let mut changes = HashMap::new();
changes.insert(
Expand Down Expand Up @@ -797,7 +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 uri = url_to_uri(specifier)?;
let code = diagnostic
.code
.as_ref()
Expand Down
9 changes: 3 additions & 6 deletions cli/lsp/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use deno_core::anyhow::bail;
use deno_core::error::AnyError;
use deno_core::serde_json::json;
use deno_core::unsync::spawn;
use lsp_types::Uri;
use tower_lsp::lsp_types as lsp;
use tower_lsp::lsp_types::ConfigurationItem;

Expand All @@ -17,7 +18,6 @@ use super::config::WorkspaceSettings;
use super::config::SETTINGS_SECTION;
use super::lsp_custom;
use super::testing::lsp_custom as testing_lsp_custom;
use super::urls::LspClientUrl;

#[derive(Debug)]
pub enum TestingNotification {
Expand Down Expand Up @@ -52,14 +52,11 @@ impl Client {

pub async fn publish_diagnostics(
&self,
uri: LspClientUrl,
uri: Uri,
diags: Vec<lsp::Diagnostic>,
version: Option<i32>,
) {
self
.0
.publish_diagnostics(uri.to_uri(), diags, version)
.await;
self.0.publish_diagnostics(uri, diags, version).await;
}

pub fn send_registry_state_notification(
Expand Down
2 changes: 1 addition & 1 deletion cli/lsp/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ impl Config {
let mut config = Self::default();
let mut folders = vec![];
for root_url in root_urls {
let root_uri = url_to_uri(&root_url);
let root_uri = url_to_uri(&root_url).unwrap();
let name = root_url.path_segments().and_then(|s| s.last());
let name = name.unwrap_or_default().to_string();
folders.push((
Expand Down
39 changes: 18 additions & 21 deletions cli/lsp/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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;

use crate::graph_util;
Expand Down Expand Up @@ -164,15 +163,14 @@ impl DiagnosticsPublisher {
.state
.update(&record.specifier, version, &all_specifier_diagnostics);
let file_referrer = documents.get_file_referrer(&record.specifier);
let Ok(uri) =
url_map.specifier_to_uri(&record.specifier, file_referrer.as_deref())
else {
continue;
};
self
.client
.publish_diagnostics(
url_map
.normalize_specifier(&record.specifier, file_referrer.as_deref())
.unwrap_or(LspClientUrl::new(record.specifier)),
all_specifier_diagnostics,
version,
)
.publish_diagnostics(uri, all_specifier_diagnostics, version)
.await;
messages_sent += 1;
}
Expand All @@ -195,15 +193,14 @@ impl DiagnosticsPublisher {
// clear out any diagnostics for this specifier
self.state.update(specifier, removed_value.version, &[]);
let file_referrer = documents.get_file_referrer(specifier);
let Ok(uri) =
url_map.specifier_to_uri(specifier, file_referrer.as_deref())
else {
continue;
};
self
.client
.publish_diagnostics(
url_map
.normalize_specifier(specifier, file_referrer.as_deref())
.unwrap_or_else(|_| LspClientUrl::new(specifier.clone())),
Vec::new(),
removed_value.version,
)
.publish_diagnostics(uri, Vec::new(), removed_value.version)
.await;
messages_sent += 1;
}
Expand Down Expand Up @@ -1074,7 +1071,7 @@ impl DenoDiagnostic {
diagnostics: Some(vec![diagnostic.clone()]),
edit: Some(lsp::WorkspaceEdit {
changes: Some(HashMap::from([(
url_to_uri(specifier),
url_to_uri(specifier)?,
vec![lsp::TextEdit {
new_text: format!("\"{to}\""),
range: diagnostic.range,
Expand All @@ -1091,7 +1088,7 @@ impl DenoDiagnostic {
diagnostics: Some(vec![diagnostic.clone()]),
edit: Some(lsp::WorkspaceEdit {
changes: Some(HashMap::from([(
url_to_uri(specifier),
url_to_uri(specifier)?,
vec![lsp::TextEdit {
new_text: " with { type: \"json\" }".to_string(),
range: lsp::Range {
Expand Down Expand Up @@ -1142,7 +1139,7 @@ impl DenoDiagnostic {
diagnostics: Some(vec![diagnostic.clone()]),
edit: Some(lsp::WorkspaceEdit {
changes: Some(HashMap::from([(
url_to_uri(specifier),
url_to_uri(specifier)?,
vec![lsp::TextEdit {
new_text: format!(
"\"{}\"",
Expand All @@ -1168,7 +1165,7 @@ impl DenoDiagnostic {
diagnostics: Some(vec![diagnostic.clone()]),
edit: Some(lsp::WorkspaceEdit {
changes: Some(HashMap::from([(
url_to_uri(specifier),
url_to_uri(specifier)?,
vec![lsp::TextEdit {
new_text: format!(
"\"{}\"",
Expand All @@ -1194,7 +1191,7 @@ impl DenoDiagnostic {
diagnostics: Some(vec![diagnostic.clone()]),
edit: Some(lsp::WorkspaceEdit {
changes: Some(HashMap::from([(
url_to_uri(specifier),
url_to_uri(specifier)?,
vec![lsp::TextEdit {
new_text: format!("\"node:{}\"", data.specifier),
range: diagnostic.range,
Expand Down Expand Up @@ -1642,7 +1639,7 @@ mod tests {

fn mock_config() -> Config {
let root_url = resolve_url("file:///").unwrap();
let root_uri = url_to_uri(&root_url);
let root_uri = url_to_uri(&root_url).unwrap();
Config {
settings: Arc::new(Settings {
unscoped: Arc::new(WorkspaceSettings {
Expand Down
Loading

0 comments on commit 97d1635

Please sign in to comment.