2020-02-18 05:25:26 -06:00
|
|
|
//! The context or environment in which the language server functions. In our
|
|
|
|
//! server implementation this is know as the `WorldState`.
|
2019-12-21 14:27:38 -06:00
|
|
|
//!
|
|
|
|
//! Each tick provides an immutable snapshot of the state as `WorldSnapshot`.
|
2019-09-30 03:58:53 -05:00
|
|
|
|
2018-08-17 11:54:08 -05:00
|
|
|
use std::{
|
2019-04-13 12:45:21 -05:00
|
|
|
path::{Path, PathBuf},
|
2018-09-02 06:46:15 -05:00
|
|
|
sync::Arc,
|
2018-08-17 11:54:08 -05:00
|
|
|
};
|
|
|
|
|
2019-08-25 05:04:56 -05:00
|
|
|
use crossbeam_channel::{unbounded, Receiver};
|
2019-01-14 04:55:56 -06:00
|
|
|
use lsp_types::Url;
|
2019-07-04 15:05:17 -05:00
|
|
|
use parking_lot::RwLock;
|
2020-01-31 12:23:25 -06:00
|
|
|
use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher};
|
2019-11-27 12:32:33 -06:00
|
|
|
use ra_ide::{
|
2020-03-12 11:38:48 -05:00
|
|
|
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsOptions, LibraryData,
|
2020-03-10 13:21:56 -05:00
|
|
|
SourceRootId,
|
2018-10-31 15:41:43 -05:00
|
|
|
};
|
2020-03-18 07:56:46 -05:00
|
|
|
use ra_project_model::{get_rustc_cfg_options, ProcMacroClient, ProjectWorkspace};
|
2019-09-06 08:25:24 -05:00
|
|
|
use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch};
|
2019-03-19 08:14:16 -05:00
|
|
|
use relative_path::RelativePathBuf;
|
2020-03-28 05:08:19 -05:00
|
|
|
use stdx::format_to;
|
2018-08-17 11:54:08 -05:00
|
|
|
|
2018-10-15 12:15:53 -05:00
|
|
|
use crate::{
|
2020-01-31 12:23:25 -06:00
|
|
|
diagnostics::{CheckFixes, DiagnosticCollection},
|
2020-03-10 12:56:15 -05:00
|
|
|
feature_flags::FeatureFlags,
|
2019-12-25 12:10:45 -06:00
|
|
|
main_loop::pending_requests::{CompletedRequest, LatestRequests},
|
2020-02-17 12:07:30 -06:00
|
|
|
vfs_glob::{Glob, RustPackageFilterBuilder},
|
2019-07-04 15:05:17 -05:00
|
|
|
LspError, Result,
|
2018-08-17 11:54:08 -05:00
|
|
|
};
|
2020-03-10 09:00:58 -05:00
|
|
|
use ra_db::ExternSourceId;
|
|
|
|
use rustc_hash::{FxHashMap, FxHashSet};
|
2018-08-17 11:54:08 -05:00
|
|
|
|
2019-07-08 06:09:38 -05:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Options {
|
|
|
|
pub publish_decorations: bool,
|
|
|
|
pub supports_location_link: bool,
|
2019-10-20 18:04:55 -05:00
|
|
|
pub line_folding_only: bool,
|
2020-03-12 11:38:48 -05:00
|
|
|
pub inlay_hints: InlayHintsOptions,
|
2020-02-17 02:44:58 -06:00
|
|
|
pub rustfmt_args: Vec<String>,
|
2019-12-27 04:10:07 -06:00
|
|
|
pub cargo_watch: CheckOptions,
|
2020-03-12 16:31:47 -05:00
|
|
|
pub vscode_lldb: bool,
|
2019-07-08 06:09:38 -05:00
|
|
|
}
|
|
|
|
|
2019-06-01 02:31:40 -05:00
|
|
|
/// `WorldState` is the primary mutable state of the language server
|
|
|
|
///
|
|
|
|
/// The most interesting components are `vfs`, which stores a consistent
|
|
|
|
/// snapshot of the file systems, and `analysis_host`, which stores our
|
|
|
|
/// incremental salsa database.
|
2018-12-19 06:04:15 -06:00
|
|
|
#[derive(Debug)]
|
2019-06-01 02:31:40 -05:00
|
|
|
pub struct WorldState {
|
2019-07-08 06:09:38 -05:00
|
|
|
pub options: Options,
|
2020-03-10 12:56:15 -05:00
|
|
|
pub feature_flags: Arc<FeatureFlags>,
|
2019-04-11 01:08:19 -05:00
|
|
|
pub roots: Vec<PathBuf>,
|
2019-01-10 11:13:08 -06:00
|
|
|
pub workspaces: Arc<Vec<ProjectWorkspace>>,
|
2018-08-30 04:51:46 -05:00
|
|
|
pub analysis_host: AnalysisHost,
|
2018-12-19 06:04:15 -06:00
|
|
|
pub vfs: Arc<RwLock<Vfs>>,
|
2019-08-25 05:04:56 -05:00
|
|
|
pub task_receiver: Receiver<VfsTask>,
|
2019-05-31 12:14:54 -05:00
|
|
|
pub latest_requests: Arc<RwLock<LatestRequests>>,
|
2020-03-30 04:46:04 -05:00
|
|
|
pub check_watcher: Option<CheckWatcher>,
|
2020-01-31 12:23:25 -06:00
|
|
|
pub diagnostics: DiagnosticCollection,
|
2018-08-17 11:54:08 -05:00
|
|
|
}
|
|
|
|
|
2019-06-01 02:31:40 -05:00
|
|
|
/// An immutable snapshot of the world's state at a point in time.
|
|
|
|
pub struct WorldSnapshot {
|
2019-07-08 06:09:38 -05:00
|
|
|
pub options: Options,
|
2020-03-10 12:56:15 -05:00
|
|
|
pub feature_flags: Arc<FeatureFlags>,
|
2019-01-10 11:13:08 -06:00
|
|
|
pub workspaces: Arc<Vec<ProjectWorkspace>>,
|
2018-08-29 10:03:14 -05:00
|
|
|
pub analysis: Analysis,
|
2019-05-31 12:14:54 -05:00
|
|
|
pub latest_requests: Arc<RwLock<LatestRequests>>,
|
2020-01-31 12:23:25 -06:00
|
|
|
pub check_fixes: CheckFixes,
|
2020-01-16 04:58:31 -06:00
|
|
|
vfs: Arc<RwLock<Vfs>>,
|
2018-08-17 11:54:08 -05:00
|
|
|
}
|
|
|
|
|
2019-06-01 02:31:40 -05:00
|
|
|
impl WorldState {
|
2019-06-07 12:49:29 -05:00
|
|
|
pub fn new(
|
|
|
|
folder_roots: Vec<PathBuf>,
|
|
|
|
workspaces: Vec<ProjectWorkspace>,
|
|
|
|
lru_capacity: Option<usize>,
|
2019-08-06 06:34:28 -05:00
|
|
|
exclude_globs: &[Glob],
|
2019-09-06 08:25:24 -05:00
|
|
|
watch: Watch,
|
2020-01-11 14:37:01 -06:00
|
|
|
options: Options,
|
2019-08-22 06:44:16 -05:00
|
|
|
feature_flags: FeatureFlags,
|
2019-06-07 12:49:29 -05:00
|
|
|
) -> WorldState {
|
2018-10-25 02:57:55 -05:00
|
|
|
let mut change = AnalysisChange::new();
|
2018-08-17 11:54:08 -05:00
|
|
|
|
2018-12-19 06:04:15 -06:00
|
|
|
let mut roots = Vec::new();
|
2019-08-06 06:00:37 -05:00
|
|
|
roots.extend(folder_roots.iter().map(|path| {
|
2019-08-06 06:34:28 -05:00
|
|
|
let mut filter = RustPackageFilterBuilder::default().set_member(true);
|
|
|
|
for glob in exclude_globs.iter() {
|
|
|
|
filter = filter.exclude(glob.clone());
|
|
|
|
}
|
|
|
|
RootEntry::new(path.clone(), filter.into_vfs_filter())
|
2019-08-06 06:00:37 -05:00
|
|
|
}));
|
2018-12-19 06:04:15 -06:00
|
|
|
for ws in workspaces.iter() {
|
2019-08-06 06:00:37 -05:00
|
|
|
roots.extend(ws.to_roots().into_iter().map(|pkg_root| {
|
2019-08-06 06:34:28 -05:00
|
|
|
let mut filter =
|
|
|
|
RustPackageFilterBuilder::default().set_member(pkg_root.is_member());
|
|
|
|
for glob in exclude_globs.iter() {
|
|
|
|
filter = filter.exclude(glob.clone());
|
|
|
|
}
|
|
|
|
RootEntry::new(pkg_root.path().clone(), filter.into_vfs_filter())
|
2019-08-06 06:00:37 -05:00
|
|
|
}));
|
2018-09-04 03:40:45 -05:00
|
|
|
}
|
2020-03-10 09:00:58 -05:00
|
|
|
|
2020-03-16 08:10:13 -05:00
|
|
|
let mut extern_dirs = FxHashSet::default();
|
2020-03-16 07:43:29 -05:00
|
|
|
for ws in workspaces.iter() {
|
|
|
|
extern_dirs.extend(ws.out_dirs());
|
|
|
|
}
|
|
|
|
|
2020-03-10 09:00:58 -05:00
|
|
|
let mut extern_source_roots = FxHashMap::default();
|
|
|
|
|
2020-03-16 07:43:29 -05:00
|
|
|
roots.extend(extern_dirs.iter().map(|path| {
|
2020-03-10 09:00:58 -05:00
|
|
|
let mut filter = RustPackageFilterBuilder::default().set_member(false);
|
|
|
|
for glob in exclude_globs.iter() {
|
|
|
|
filter = filter.exclude(glob.clone());
|
|
|
|
}
|
|
|
|
RootEntry::new(PathBuf::from(&path), filter.into_vfs_filter())
|
|
|
|
}));
|
|
|
|
|
2019-08-25 05:04:56 -05:00
|
|
|
let (task_sender, task_receiver) = unbounded();
|
|
|
|
let task_sender = Box::new(move |t| task_sender.send(t).unwrap());
|
2019-09-06 08:25:24 -05:00
|
|
|
let (mut vfs, vfs_roots) = Vfs::new(roots, task_sender, watch);
|
2020-03-28 17:33:16 -05:00
|
|
|
|
2019-04-11 01:08:19 -05:00
|
|
|
for r in vfs_roots {
|
|
|
|
let vfs_root_path = vfs.root2path(r);
|
|
|
|
let is_local = folder_roots.iter().any(|it| vfs_root_path.starts_with(it));
|
2019-06-03 09:21:08 -05:00
|
|
|
change.add_root(SourceRootId(r.0), is_local);
|
2019-09-08 01:48:45 -05:00
|
|
|
change.set_debug_root_path(SourceRootId(r.0), vfs_root_path.display().to_string());
|
2020-03-10 09:00:58 -05:00
|
|
|
|
|
|
|
// FIXME: add path2root in vfs to simpily this logic
|
|
|
|
if extern_dirs.contains(&vfs_root_path) {
|
|
|
|
extern_source_roots.insert(vfs_root_path, ExternSourceId(r.0));
|
|
|
|
}
|
2018-09-04 03:40:45 -05:00
|
|
|
}
|
2018-08-17 11:54:08 -05:00
|
|
|
|
2019-10-02 13:02:53 -05:00
|
|
|
// FIXME: Read default cfgs from config
|
2019-10-08 06:22:49 -05:00
|
|
|
let default_cfg_options = {
|
|
|
|
let mut opts = get_rustc_cfg_options();
|
|
|
|
opts.insert_atom("test".into());
|
|
|
|
opts.insert_atom("debug_assertion".into());
|
|
|
|
opts
|
|
|
|
};
|
2019-10-02 13:02:53 -05:00
|
|
|
|
2019-02-06 15:54:33 -06:00
|
|
|
// Create crate graph from all the workspaces
|
2018-11-27 18:25:20 -06:00
|
|
|
let mut crate_graph = CrateGraph::default();
|
2019-02-09 04:08:24 -06:00
|
|
|
let mut load = |path: &std::path::Path| {
|
|
|
|
let vfs_file = vfs.load(path);
|
2019-06-03 09:21:08 -05:00
|
|
|
vfs_file.map(|f| FileId(f.0))
|
2019-02-09 04:08:24 -06:00
|
|
|
};
|
2020-03-08 08:26:57 -05:00
|
|
|
|
2020-03-18 07:56:46 -05:00
|
|
|
let proc_macro_client =
|
|
|
|
ProcMacroClient::extern_process(std::path::Path::new("ra_proc_macro_srv"));
|
|
|
|
|
2020-03-10 09:00:58 -05:00
|
|
|
workspaces
|
|
|
|
.iter()
|
2020-03-18 07:56:46 -05:00
|
|
|
.map(|ws| {
|
|
|
|
ws.to_crate_graph(
|
|
|
|
&default_cfg_options,
|
|
|
|
&extern_source_roots,
|
|
|
|
&proc_macro_client,
|
|
|
|
&mut load,
|
|
|
|
)
|
|
|
|
})
|
2020-03-10 09:00:58 -05:00
|
|
|
.for_each(|graph| {
|
2020-03-08 08:26:57 -05:00
|
|
|
crate_graph.extend(graph);
|
2020-03-10 09:00:58 -05:00
|
|
|
});
|
2018-10-25 02:57:55 -05:00
|
|
|
change.set_crate_graph(crate_graph);
|
2018-12-19 06:04:15 -06:00
|
|
|
|
2019-12-25 05:21:38 -06:00
|
|
|
// FIXME: Figure out the multi-workspace situation
|
2020-01-11 14:32:40 -06:00
|
|
|
let check_watcher = workspaces
|
|
|
|
.iter()
|
|
|
|
.find_map(|w| match w {
|
|
|
|
ProjectWorkspace::Cargo { cargo, .. } => Some(cargo),
|
|
|
|
ProjectWorkspace::Json { .. } => None,
|
|
|
|
})
|
|
|
|
.map(|cargo| {
|
|
|
|
let cargo_project_root = cargo.workspace_root().to_path_buf();
|
2020-03-30 04:46:04 -05:00
|
|
|
Some(CheckWatcher::new(&options.cargo_watch, cargo_project_root))
|
2020-01-11 14:32:40 -06:00
|
|
|
})
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
|
2020-03-30 04:46:04 -05:00
|
|
|
None
|
2020-01-11 14:32:40 -06:00
|
|
|
});
|
2019-12-25 05:21:38 -06:00
|
|
|
|
2020-03-10 12:56:15 -05:00
|
|
|
let mut analysis_host = AnalysisHost::new(lru_capacity);
|
2018-12-19 06:04:15 -06:00
|
|
|
analysis_host.apply_change(change);
|
2019-06-01 02:31:40 -05:00
|
|
|
WorldState {
|
2019-07-08 06:09:38 -05:00
|
|
|
options,
|
2020-03-10 12:56:15 -05:00
|
|
|
feature_flags: Arc::new(feature_flags),
|
2019-04-11 01:08:19 -05:00
|
|
|
roots: folder_roots,
|
2018-12-19 06:04:15 -06:00
|
|
|
workspaces: Arc::new(workspaces),
|
|
|
|
analysis_host,
|
|
|
|
vfs: Arc::new(RwLock::new(vfs)),
|
2019-08-25 05:04:56 -05:00
|
|
|
task_receiver,
|
2019-05-31 12:14:54 -05:00
|
|
|
latest_requests: Default::default(),
|
2019-12-25 05:21:38 -06:00
|
|
|
check_watcher,
|
2020-01-31 12:23:25 -06:00
|
|
|
diagnostics: Default::default(),
|
2018-12-19 06:04:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a vec of libraries
|
|
|
|
/// FIXME: better API here
|
|
|
|
pub fn process_changes(
|
|
|
|
&mut self,
|
2020-03-29 13:39:03 -05:00
|
|
|
roots_scanned: &mut usize,
|
2019-12-22 06:56:19 -06:00
|
|
|
) -> Option<Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc<String>)>)>> {
|
2018-12-19 06:40:42 -06:00
|
|
|
let changes = self.vfs.write().commit_changes();
|
|
|
|
if changes.is_empty() {
|
2019-12-22 06:56:19 -06:00
|
|
|
return None;
|
2018-12-19 06:40:42 -06:00
|
|
|
}
|
2018-12-19 06:04:15 -06:00
|
|
|
let mut libs = Vec::new();
|
|
|
|
let mut change = AnalysisChange::new();
|
2018-12-19 06:40:42 -06:00
|
|
|
for c in changes {
|
2018-12-19 06:04:15 -06:00
|
|
|
match c {
|
|
|
|
VfsChange::AddRoot { root, files } => {
|
2018-12-19 06:40:42 -06:00
|
|
|
let root_path = self.vfs.read().root2path(root);
|
2019-04-11 01:08:19 -05:00
|
|
|
let is_local = self.roots.iter().any(|r| root_path.starts_with(r));
|
|
|
|
if is_local {
|
2020-03-29 13:39:03 -05:00
|
|
|
*roots_scanned += 1;
|
2018-12-19 06:40:42 -06:00
|
|
|
for (file, path, text) in files {
|
2019-06-03 09:21:08 -05:00
|
|
|
change.add_file(SourceRootId(root.0), FileId(file.0), path, text);
|
2018-12-19 06:40:42 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let files = files
|
|
|
|
.into_iter()
|
2019-06-03 09:21:08 -05:00
|
|
|
.map(|(vfsfile, path, text)| (FileId(vfsfile.0), path, text))
|
2018-12-19 06:40:42 -06:00
|
|
|
.collect();
|
2019-06-03 09:21:08 -05:00
|
|
|
libs.push((SourceRootId(root.0), files));
|
2018-12-19 06:40:42 -06:00
|
|
|
}
|
2018-12-19 06:04:15 -06:00
|
|
|
}
|
2019-02-08 05:49:43 -06:00
|
|
|
VfsChange::AddFile { root, file, path, text } => {
|
2019-06-03 09:21:08 -05:00
|
|
|
change.add_file(SourceRootId(root.0), FileId(file.0), path, text);
|
2018-12-19 06:04:15 -06:00
|
|
|
}
|
|
|
|
VfsChange::RemoveFile { root, file, path } => {
|
2019-06-03 09:21:08 -05:00
|
|
|
change.remove_file(SourceRootId(root.0), FileId(file.0), path)
|
2018-12-19 06:04:15 -06:00
|
|
|
}
|
|
|
|
VfsChange::ChangeFile { file, text } => {
|
2019-06-03 09:21:08 -05:00
|
|
|
change.change_file(FileId(file.0), text);
|
2018-12-19 06:04:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-25 02:57:55 -05:00
|
|
|
self.analysis_host.apply_change(change);
|
2019-12-22 06:56:19 -06:00
|
|
|
Some(libs)
|
2018-09-02 06:46:15 -05:00
|
|
|
}
|
2018-12-19 06:04:15 -06:00
|
|
|
|
|
|
|
pub fn add_lib(&mut self, data: LibraryData) {
|
|
|
|
let mut change = AnalysisChange::new();
|
|
|
|
change.add_library(data);
|
|
|
|
self.analysis_host.apply_change(change);
|
|
|
|
}
|
|
|
|
|
2019-06-01 02:31:40 -05:00
|
|
|
pub fn snapshot(&self) -> WorldSnapshot {
|
|
|
|
WorldSnapshot {
|
2019-07-08 06:09:38 -05:00
|
|
|
options: self.options.clone(),
|
2020-03-10 12:56:15 -05:00
|
|
|
feature_flags: Arc::clone(&self.feature_flags),
|
2018-09-02 06:46:15 -05:00
|
|
|
workspaces: Arc::clone(&self.workspaces),
|
2018-09-10 04:57:40 -05:00
|
|
|
analysis: self.analysis_host.analysis(),
|
2018-12-19 06:04:15 -06:00
|
|
|
vfs: Arc::clone(&self.vfs),
|
2019-05-31 12:14:54 -05:00
|
|
|
latest_requests: Arc::clone(&self.latest_requests),
|
2020-01-31 12:23:25 -06:00
|
|
|
check_fixes: Arc::clone(&self.diagnostics.check_fixes),
|
2018-08-17 11:54:08 -05:00
|
|
|
}
|
|
|
|
}
|
2019-01-25 10:11:58 -06:00
|
|
|
|
2019-01-26 11:33:33 -06:00
|
|
|
pub fn maybe_collect_garbage(&mut self) {
|
|
|
|
self.analysis_host.maybe_collect_garbage()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn collect_garbage(&mut self) {
|
2019-01-25 10:11:58 -06:00
|
|
|
self.analysis_host.collect_garbage()
|
|
|
|
}
|
2019-05-29 07:42:14 -05:00
|
|
|
|
|
|
|
pub fn complete_request(&mut self, request: CompletedRequest) {
|
2019-05-31 12:14:54 -05:00
|
|
|
self.latest_requests.write().record(request)
|
2019-05-29 07:42:14 -05:00
|
|
|
}
|
2018-08-17 11:54:08 -05:00
|
|
|
}
|
|
|
|
|
2019-06-01 02:31:40 -05:00
|
|
|
impl WorldSnapshot {
|
2018-08-29 10:03:14 -05:00
|
|
|
pub fn analysis(&self) -> &Analysis {
|
2018-08-17 11:54:08 -05:00
|
|
|
&self.analysis
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn uri_to_file_id(&self, uri: &Url) -> Result<FileId> {
|
2019-06-14 15:42:56 -05:00
|
|
|
let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?;
|
2019-04-06 12:20:33 -05:00
|
|
|
let file = self.vfs.read().path2file(&path).ok_or_else(|| {
|
2019-04-07 05:26:02 -05:00
|
|
|
// Show warning as this file is outside current workspace
|
2020-03-09 04:54:14 -05:00
|
|
|
// FIXME: just handle such files, and remove `LspError::UNKNOWN_FILE`.
|
2019-06-14 15:42:56 -05:00
|
|
|
LspError {
|
2020-03-09 04:54:14 -05:00
|
|
|
code: LspError::UNKNOWN_FILE,
|
2019-04-07 05:26:02 -05:00
|
|
|
message: "Rust file outside current workspace is not supported yet.".to_string(),
|
2019-06-14 15:42:56 -05:00
|
|
|
}
|
2019-04-06 12:20:33 -05:00
|
|
|
})?;
|
2019-06-03 09:21:08 -05:00
|
|
|
Ok(FileId(file.0))
|
2018-08-17 11:54:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn file_id_to_uri(&self, id: FileId) -> Result<Url> {
|
2019-06-03 09:21:08 -05:00
|
|
|
let path = self.vfs.read().file2path(VfsFile(id.0));
|
2019-12-15 09:46:00 -06:00
|
|
|
let url = url_from_path_with_drive_lowercasing(path)?;
|
2019-12-15 08:51:57 -06:00
|
|
|
|
2018-08-17 11:54:08 -05:00
|
|
|
Ok(url)
|
|
|
|
}
|
2018-12-21 03:18:14 -06:00
|
|
|
|
2020-01-16 04:58:31 -06:00
|
|
|
pub fn file_id_to_path(&self, id: FileId) -> PathBuf {
|
|
|
|
self.vfs.read().file2path(VfsFile(id.0))
|
|
|
|
}
|
|
|
|
|
2019-08-20 10:53:59 -05:00
|
|
|
pub fn file_line_endings(&self, id: FileId) -> LineEndings {
|
|
|
|
self.vfs.read().file_line_endings(VfsFile(id.0))
|
|
|
|
}
|
|
|
|
|
2018-12-21 03:18:14 -06:00
|
|
|
pub fn path_to_uri(&self, root: SourceRootId, path: &RelativePathBuf) -> Result<Url> {
|
2019-06-03 09:21:08 -05:00
|
|
|
let base = self.vfs.read().root2path(VfsRoot(root.0));
|
2018-12-21 03:18:14 -06:00
|
|
|
let path = path.to_path(base);
|
|
|
|
let url = Url::from_file_path(&path)
|
2019-06-14 15:42:56 -05:00
|
|
|
.map_err(|_| format!("can't convert path to url: {}", path.display()))?;
|
2018-12-21 03:18:14 -06:00
|
|
|
Ok(url)
|
|
|
|
}
|
2019-01-22 15:15:03 -06:00
|
|
|
|
|
|
|
pub fn status(&self) -> String {
|
2020-03-28 05:08:19 -05:00
|
|
|
let mut buf = String::new();
|
2019-01-22 15:15:03 -06:00
|
|
|
if self.workspaces.is_empty() {
|
2020-03-28 05:08:19 -05:00
|
|
|
buf.push_str("no workspaces\n")
|
2019-01-22 15:15:03 -06:00
|
|
|
} else {
|
2020-03-28 05:08:19 -05:00
|
|
|
buf.push_str("workspaces:\n");
|
2019-01-22 15:15:03 -06:00
|
|
|
for w in self.workspaces.iter() {
|
2020-03-28 05:08:19 -05:00
|
|
|
format_to!(buf, "{} packages loaded\n", w.n_packages());
|
2019-01-22 15:15:03 -06:00
|
|
|
}
|
|
|
|
}
|
2020-03-28 05:08:19 -05:00
|
|
|
buf.push_str("\nanalysis:\n");
|
|
|
|
buf.push_str(
|
2019-07-25 12:22:41 -05:00
|
|
|
&self
|
|
|
|
.analysis
|
|
|
|
.status()
|
|
|
|
.unwrap_or_else(|_| "Analysis retrieval was cancelled".to_owned()),
|
|
|
|
);
|
2020-03-28 05:08:19 -05:00
|
|
|
buf
|
2019-01-22 15:15:03 -06:00
|
|
|
}
|
2019-04-13 12:45:21 -05:00
|
|
|
|
|
|
|
pub fn workspace_root_for(&self, file_id: FileId) -> Option<&Path> {
|
2019-06-03 09:21:08 -05:00
|
|
|
let path = self.vfs.read().file2path(VfsFile(file_id.0));
|
2019-04-13 12:45:21 -05:00
|
|
|
self.workspaces.iter().find_map(|ws| ws.workspace_root_for(&path))
|
|
|
|
}
|
2018-08-17 11:54:08 -05:00
|
|
|
}
|