Skip to content

Commit b03ce39

Browse files
committed
Apply suggested changes
1 parent c83d8cf commit b03ce39

File tree

19 files changed

+1920
-296
lines changed

19 files changed

+1920
-296
lines changed

Cargo.lock

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ide/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,17 @@ impl Analysis {
273273
self.with_db(|db| status::status(db, file_id))
274274
}
275275

276-
pub fn source_root(&self, file_id: FileId) -> Cancellable<SourceRootId> {
276+
pub fn source_root_id(&self, file_id: FileId) -> Cancellable<SourceRootId> {
277277
self.with_db(|db| db.file_source_root(file_id))
278278
}
279279

280+
pub fn is_local_source_root(&self, source_root_id: SourceRootId) -> Cancellable<bool> {
281+
self.with_db(|db| {
282+
let sr = db.source_root(source_root_id);
283+
!sr.is_library
284+
})
285+
}
286+
280287
pub fn parallel_prime_caches<F>(&self, num_worker_threads: u8, cb: F) -> Cancellable<()>
281288
where
282289
F: Fn(ParallelPrimeCachesProgress) + Sync + std::panic::UnwindSafe,

crates/paths/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,24 @@ impl AbsPathBuf {
135135
pub fn pop(&mut self) -> bool {
136136
self.0.pop()
137137
}
138+
139+
/// Equivalent of [`PathBuf::push`] for `AbsPathBuf`.
140+
///
141+
/// Extends `self` with `path`.
142+
///
143+
/// If `path` is absolute, it replaces the current path.
144+
///
145+
/// On Windows:
146+
///
147+
/// * if `path` has a root but no prefix (e.g., `\windows`), it
148+
/// replaces everything except for the prefix (if any) of `self`.
149+
/// * if `path` has a prefix but no root, it replaces `self`.
150+
/// * if `self` has a verbatim prefix (e.g. `\\?\C:\windows`)
151+
/// and `path` is not empty, the new path is normalized: all references
152+
/// to `.` and `..` are removed.
153+
pub fn push(&mut self, suffix: &str) {
154+
self.0.push(suffix)
155+
}
138156
}
139157

140158
impl fmt::Display for AbsPathBuf {

crates/rust-analyzer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ path = "src/bin/main.rs"
2121
[dependencies]
2222
anyhow.workspace = true
2323
crossbeam-channel = "0.5.5"
24+
dirs = "5.0.1"
2425
dissimilar.workspace = true
2526
itertools.workspace = true
2627
scip = "0.3.3"

crates/rust-analyzer/src/bin/main.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ use std::{env, fs, path::PathBuf, process::ExitCode, sync::Arc};
1515

1616
use anyhow::Context;
1717
use lsp_server::Connection;
18-
use rust_analyzer::{cli::flags, config::Config, from_json};
18+
use rust_analyzer::{
19+
cli::flags,
20+
config::{Config, ConfigChange, ConfigError},
21+
from_json,
22+
};
1923
use semver::Version;
2024
use tracing_subscriber::fmt::writer::BoxMakeWriter;
2125
use vfs::AbsPathBuf;
@@ -220,16 +224,20 @@ fn run_server() -> anyhow::Result<()> {
220224
.filter(|workspaces| !workspaces.is_empty())
221225
.unwrap_or_else(|| vec![root_path.clone()]);
222226
let mut config =
223-
Config::new(root_path, capabilities, workspace_roots, visual_studio_code_version);
227+
Config::new(root_path, capabilities, workspace_roots, visual_studio_code_version, None);
224228
if let Some(json) = initialization_options {
225-
if let Err(e) = config.update(json) {
229+
let mut change = ConfigChange::default();
230+
change.change_client_config(json);
231+
let mut error_sink = ConfigError::default();
232+
config = config.apply_change(change, &mut error_sink);
233+
if !error_sink.is_empty() {
226234
use lsp_types::{
227235
notification::{Notification, ShowMessage},
228236
MessageType, ShowMessageParams,
229237
};
230238
let not = lsp_server::Notification::new(
231239
ShowMessage::METHOD.to_owned(),
232-
ShowMessageParams { typ: MessageType::WARNING, message: e.to_string() },
240+
ShowMessageParams { typ: MessageType::WARNING, message: error_sink.to_string() },
233241
);
234242
connection.sender.send(lsp_server::Message::Notification(not)).unwrap();
235243
}

crates/rust-analyzer/src/cli/scip.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ use ide_db::LineIndexDatabase;
1010
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
1111
use rustc_hash::{FxHashMap, FxHashSet};
1212
use scip::types as scip_types;
13+
use tracing::error;
1314

1415
use crate::{
1516
cli::flags,
17+
config::{ConfigChange, ConfigError},
1618
line_index::{LineEndings, LineIndex, PositionEncoding},
1719
};
1820

@@ -35,12 +37,18 @@ impl flags::Scip {
3537
lsp_types::ClientCapabilities::default(),
3638
vec![],
3739
None,
40+
None,
3841
);
3942

4043
if let Some(p) = self.config_path {
4144
let mut file = std::io::BufReader::new(std::fs::File::open(p)?);
4245
let json = serde_json::from_reader(&mut file)?;
43-
config.update(json)?;
46+
let mut change = ConfigChange::default();
47+
change.change_client_config(json);
48+
let mut error_sink = ConfigError::default();
49+
config = config.apply_change(change, &mut error_sink);
50+
// FIXME @alibektas : What happens to errors without logging?
51+
error!(?error_sink, "Config Error(s)");
4452
}
4553
let cargo_config = config.cargo();
4654
let (db, vfs, _) = load_workspace_at(

0 commit comments

Comments
 (0)