Skip to content

Commit

Permalink
LS: Consider empty strings in workspace/configuration as None
Browse files Browse the repository at this point in the history
It occurs that the `workspace/configuration`
request returns `Some("")` for the `cairo1.corelibPath`
field even if it is not set anywhere.
This fact blocked any logic that happened in the ` find_unmanaged_core `
function,
as it always assumed
that the user explicitly set the path in their config to `""`.
By nullifying empty configuration values, this change fixes
`find_unmanaged_core`.

commit-id:c5cd2e07
  • Loading branch information
mkaput committed Aug 21, 2024
1 parent 562bf3c commit 94e0ee7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/cairo-lang-language-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::VecDeque;
use std::path::PathBuf;

use anyhow::Context;
use serde_json::Value;
use tower_lsp::lsp_types::{ClientCapabilities, ConfigurationItem};
use tower_lsp::Client;
use tracing::{debug, error, warn};
Expand Down Expand Up @@ -64,8 +65,12 @@ impl Config {
// This conversion is O(1), and makes popping from front also O(1).
let mut response = VecDeque::from(response);

self.unmanaged_core_path =
response.pop_front().as_ref().and_then(|v| v.as_str()).map(Into::into);
self.unmanaged_core_path = response
.pop_front()
.as_ref()
.and_then(Value::as_str)
.filter(|s| !s.is_empty())
.map(Into::into);

debug!("reloaded configuration: {self:#?}");
}
Expand Down

0 comments on commit 94e0ee7

Please sign in to comment.