mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
extract area to a crate
This commit is contained in:
parent
821fa7a50a
commit
291d578938
9 changed files with 142 additions and 94 deletions
|
@ -350,7 +350,7 @@ fn on_notification(
|
|||
.write()
|
||||
.add_file_overlay(&path, params.text_document.text)
|
||||
{
|
||||
subs.add_sub(FileId(file_id.0));
|
||||
subs.add_sub(FileId(file_id.0.into()));
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ fn on_notification(
|
|||
.to_file_path()
|
||||
.map_err(|()| format_err!("invalid uri: {}", uri))?;
|
||||
if let Some(file_id) = state.vfs.write().remove_file_overlay(path.as_path()) {
|
||||
subs.remove_sub(FileId(file_id.0));
|
||||
subs.remove_sub(FileId(file_id.0.into()));
|
||||
}
|
||||
let params = req::PublishDiagnosticsParams {
|
||||
uri,
|
||||
|
|
|
@ -337,7 +337,10 @@ pub fn handle_runnables(
|
|||
None => return Ok(None),
|
||||
};
|
||||
let file_id = world.analysis().crate_root(crate_id)?;
|
||||
let path = world.vfs.read().file2path(ra_vfs::VfsFile(file_id.0));
|
||||
let path = world
|
||||
.vfs
|
||||
.read()
|
||||
.file2path(ra_vfs::VfsFile(file_id.0.into()));
|
||||
let res = world.workspaces.iter().find_map(|ws| {
|
||||
let tgt = ws.target_by_root(&path)?;
|
||||
let res = CargoTargetSpec {
|
||||
|
|
|
@ -49,7 +49,7 @@ impl ServerWorldState {
|
|||
let (mut vfs, roots) = Vfs::new(roots);
|
||||
for r in roots {
|
||||
let is_local = vfs.root2path(r).starts_with(&root);
|
||||
change.add_root(SourceRootId(r.0), is_local);
|
||||
change.add_root(SourceRootId(r.0.into()), is_local);
|
||||
}
|
||||
|
||||
let mut crate_graph = CrateGraph::default();
|
||||
|
@ -60,7 +60,7 @@ impl ServerWorldState {
|
|||
for tgt in pkg.targets(ws) {
|
||||
let root = tgt.root(ws);
|
||||
if let Some(file_id) = vfs.load(root) {
|
||||
let file_id = FileId(file_id.0);
|
||||
let file_id = FileId(file_id.0.into());
|
||||
let crate_id = crate_graph.add_crate_root(file_id);
|
||||
if tgt.kind(ws) == TargetKind::Lib {
|
||||
pkg_to_lib_crate.insert(pkg, crate_id);
|
||||
|
@ -113,14 +113,19 @@ impl ServerWorldState {
|
|||
if root_path.starts_with(&self.root) {
|
||||
self.roots_to_scan -= 1;
|
||||
for (file, path, text) in files {
|
||||
change.add_file(SourceRootId(root.0), FileId(file.0), path, text);
|
||||
change.add_file(
|
||||
SourceRootId(root.0.into()),
|
||||
FileId(file.0.into()),
|
||||
path,
|
||||
text,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
let files = files
|
||||
.into_iter()
|
||||
.map(|(vfsfile, path, text)| (FileId(vfsfile.0), path, text))
|
||||
.map(|(vfsfile, path, text)| (FileId(vfsfile.0.into()), path, text))
|
||||
.collect();
|
||||
libs.push((SourceRootId(root.0), files));
|
||||
libs.push((SourceRootId(root.0.into()), files));
|
||||
}
|
||||
}
|
||||
VfsChange::AddFile {
|
||||
|
@ -129,13 +134,18 @@ impl ServerWorldState {
|
|||
path,
|
||||
text,
|
||||
} => {
|
||||
change.add_file(SourceRootId(root.0), FileId(file.0), path, text);
|
||||
change.add_file(
|
||||
SourceRootId(root.0.into()),
|
||||
FileId(file.0.into()),
|
||||
path,
|
||||
text,
|
||||
);
|
||||
}
|
||||
VfsChange::RemoveFile { root, file, path } => {
|
||||
change.remove_file(SourceRootId(root.0), FileId(file.0), path)
|
||||
change.remove_file(SourceRootId(root.0.into()), FileId(file.0.into()), path)
|
||||
}
|
||||
VfsChange::ChangeFile { file, text } => {
|
||||
change.change_file(FileId(file.0), text);
|
||||
change.change_file(FileId(file.0.into()), text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -173,18 +183,18 @@ impl ServerWorld {
|
|||
.read()
|
||||
.path2file(&path)
|
||||
.ok_or_else(|| format_err!("unknown file: {}", path.display()))?;
|
||||
Ok(FileId(file.0))
|
||||
Ok(FileId(file.0.into()))
|
||||
}
|
||||
|
||||
pub fn file_id_to_uri(&self, id: FileId) -> Result<Url> {
|
||||
let path = self.vfs.read().file2path(VfsFile(id.0));
|
||||
let path = self.vfs.read().file2path(VfsFile(id.0.into()));
|
||||
let url = Url::from_file_path(&path)
|
||||
.map_err(|_| format_err!("can't convert path to url: {}", path.display()))?;
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
pub fn path_to_uri(&self, root: SourceRootId, path: &RelativePathBuf) -> Result<Url> {
|
||||
let base = self.vfs.read().root2path(VfsRoot(root.0));
|
||||
let base = self.vfs.read().root2path(VfsRoot(root.0.into()));
|
||||
let path = path.to_path(base);
|
||||
let url = Url::from_file_path(&path)
|
||||
.map_err(|_| format_err!("can't convert path to url: {}", path.display()))?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue