mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-11-03 21:25:25 +00:00 
			
		
		
		
	Register virtual workspace Cargo.toml files in the VFS
This commit is contained in:
		
							parent
							
								
									7f1f85ac16
								
							
						
					
					
						commit
						d4dc3ca83b
					
				
					 15 changed files with 77 additions and 37 deletions
				
			
		| 
						 | 
					@ -162,7 +162,11 @@ xshell = "0.2.5"
 | 
				
			||||||
dashmap = { version = "=5.5.3", features = ["raw-api"] }
 | 
					dashmap = { version = "=5.5.3", features = ["raw-api"] }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[workspace.lints.rust]
 | 
					[workspace.lints.rust]
 | 
				
			||||||
rust_2018_idioms = "warn"
 | 
					bare_trait_objects = "warn"
 | 
				
			||||||
 | 
					elided_lifetimes_in_paths = "warn"
 | 
				
			||||||
 | 
					ellipsis_inclusive_range_patterns = "warn"
 | 
				
			||||||
 | 
					explicit_outlives_requirements = "warn"
 | 
				
			||||||
 | 
					unused_extern_crates = "warn"
 | 
				
			||||||
unused_lifetimes = "warn"
 | 
					unused_lifetimes = "warn"
 | 
				
			||||||
unreachable_pub = "warn"
 | 
					unreachable_pub = "warn"
 | 
				
			||||||
semicolon_in_expressions_from_macros = "warn"
 | 
					semicolon_in_expressions_from_macros = "warn"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -246,6 +246,7 @@ impl TyBuilder<()> {
 | 
				
			||||||
    /// - yield type of coroutine ([`Coroutine::Yield`](std::ops::Coroutine::Yield))
 | 
					    /// - yield type of coroutine ([`Coroutine::Yield`](std::ops::Coroutine::Yield))
 | 
				
			||||||
    /// - return type of coroutine ([`Coroutine::Return`](std::ops::Coroutine::Return))
 | 
					    /// - return type of coroutine ([`Coroutine::Return`](std::ops::Coroutine::Return))
 | 
				
			||||||
    /// - generic parameters in scope on `parent`
 | 
					    /// - generic parameters in scope on `parent`
 | 
				
			||||||
 | 
					    ///
 | 
				
			||||||
    /// in this order.
 | 
					    /// in this order.
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// This method prepopulates the builder with placeholder substitution of `parent`, so you
 | 
					    /// This method prepopulates the builder with placeholder substitution of `parent`, so you
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -898,20 +898,19 @@ pub enum Rvalue {
 | 
				
			||||||
    Cast(CastKind, Operand, Ty),
 | 
					    Cast(CastKind, Operand, Ty),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // FIXME link to `pointer::offset` when it hits stable.
 | 
					    // FIXME link to `pointer::offset` when it hits stable.
 | 
				
			||||||
    /// * `Offset` has the same semantics as `pointer::offset`, except that the second
 | 
					    // /// * `Offset` has the same semantics as `pointer::offset`, except that the second
 | 
				
			||||||
    ///   parameter may be a `usize` as well.
 | 
					    // ///   parameter may be a `usize` as well.
 | 
				
			||||||
    /// * The comparison operations accept `bool`s, `char`s, signed or unsigned integers, floats,
 | 
					    // /// * The comparison operations accept `bool`s, `char`s, signed or unsigned integers, floats,
 | 
				
			||||||
    ///   raw pointers, or function pointers and return a `bool`. The types of the operands must be
 | 
					    // ///   raw pointers, or function pointers and return a `bool`. The types of the operands must be
 | 
				
			||||||
    ///   matching, up to the usual caveat of the lifetimes in function pointers.
 | 
					    // ///   matching, up to the usual caveat of the lifetimes in function pointers.
 | 
				
			||||||
    /// * Left and right shift operations accept signed or unsigned integers not necessarily of the
 | 
					    // /// * Left and right shift operations accept signed or unsigned integers not necessarily of the
 | 
				
			||||||
    ///   same type and return a value of the same type as their LHS. Like in Rust, the RHS is
 | 
					    // ///   same type and return a value of the same type as their LHS. Like in Rust, the RHS is
 | 
				
			||||||
    ///   truncated as needed.
 | 
					    // ///   truncated as needed.
 | 
				
			||||||
    /// * The `Bit*` operations accept signed integers, unsigned integers, or bools with matching
 | 
					    // /// * The `Bit*` operations accept signed integers, unsigned integers, or bools with matching
 | 
				
			||||||
    ///   types and return a value of that type.
 | 
					    // ///   types and return a value of that type.
 | 
				
			||||||
    /// * The remaining operations accept signed integers, unsigned integers, or floats with
 | 
					    // /// * The remaining operations accept signed integers, unsigned integers, or floats with
 | 
				
			||||||
    ///   matching types and return a value of that type.
 | 
					    // ///   matching types and return a value of that type.
 | 
				
			||||||
    //BinaryOp(BinOp, Box<(Operand, Operand)>),
 | 
					    //BinaryOp(BinOp, Box<(Operand, Operand)>),
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /// Same as `BinaryOp`, but yields `(T, bool)` with a `bool` indicating an error condition.
 | 
					    /// Same as `BinaryOp`, but yields `(T, bool)` with a `bool` indicating an error condition.
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// When overflow checking is disabled and we are generating run-time code, the error condition
 | 
					    /// When overflow checking is disabled and we are generating run-time code, the error condition
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@
 | 
				
			||||||
//! * `defs` - Set of items in scope at term search target location
 | 
					//! * `defs` - Set of items in scope at term search target location
 | 
				
			||||||
//! * `lookup` - Lookup table for types
 | 
					//! * `lookup` - Lookup table for types
 | 
				
			||||||
//! * `should_continue` - Function that indicates when to stop iterating
 | 
					//! * `should_continue` - Function that indicates when to stop iterating
 | 
				
			||||||
 | 
					//!
 | 
				
			||||||
//! And they return iterator that yields type trees that unify with the `goal` type.
 | 
					//! And they return iterator that yields type trees that unify with the `goal` type.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use std::iter;
 | 
					use std::iter;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -368,7 +368,7 @@ fn inline(
 | 
				
			||||||
                    _ => None,
 | 
					                    _ => None,
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
                .for_each(|usage| {
 | 
					                .for_each(|usage| {
 | 
				
			||||||
                    ted::replace(usage, &this());
 | 
					                    ted::replace(usage, this());
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -483,7 +483,7 @@ fn inline(
 | 
				
			||||||
                cov_mark::hit!(inline_call_inline_direct_field);
 | 
					                cov_mark::hit!(inline_call_inline_direct_field);
 | 
				
			||||||
                field.replace_expr(replacement.clone_for_update());
 | 
					                field.replace_expr(replacement.clone_for_update());
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                ted::replace(usage.syntax(), &replacement.syntax().clone_for_update());
 | 
					                ted::replace(usage.syntax(), replacement.syntax().clone_for_update());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -452,6 +452,7 @@ pub(crate) struct CompletionContext<'a> {
 | 
				
			||||||
    /// - crate-root
 | 
					    /// - crate-root
 | 
				
			||||||
    ///  - mod foo
 | 
					    ///  - mod foo
 | 
				
			||||||
    ///   - mod bar
 | 
					    ///   - mod bar
 | 
				
			||||||
 | 
					    ///
 | 
				
			||||||
    /// Here depth will be 2
 | 
					    /// Here depth will be 2
 | 
				
			||||||
    pub(crate) depth_from_crate_root: usize,
 | 
					    pub(crate) depth_from_crate_root: usize,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,7 @@ use ide_db::{
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use itertools::Itertools;
 | 
					use itertools::Itertools;
 | 
				
			||||||
use proc_macro_api::{MacroDylib, ProcMacroServer};
 | 
					use proc_macro_api::{MacroDylib, ProcMacroServer};
 | 
				
			||||||
use project_model::{CargoConfig, PackageRoot, ProjectManifest, ProjectWorkspace};
 | 
					use project_model::{CargoConfig, ManifestPath, PackageRoot, ProjectManifest, ProjectWorkspace};
 | 
				
			||||||
use span::Span;
 | 
					use span::Span;
 | 
				
			||||||
use tracing::instrument;
 | 
					use tracing::instrument;
 | 
				
			||||||
use vfs::{file_set::FileSetConfig, loader::Handle, AbsPath, AbsPathBuf, VfsPath};
 | 
					use vfs::{file_set::FileSetConfig, loader::Handle, AbsPath, AbsPathBuf, VfsPath};
 | 
				
			||||||
| 
						 | 
					@ -238,6 +238,19 @@ impl ProjectFolders {
 | 
				
			||||||
            fsc.add_file_set(file_set_roots)
 | 
					            fsc.add_file_set(file_set_roots)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // register the workspace manifest as well, note that this currently causes duplicates for
 | 
				
			||||||
 | 
					        // non-virtual cargo workspaces! We ought to fix that
 | 
				
			||||||
 | 
					        for manifest in workspaces.iter().filter_map(|ws| ws.manifest().map(ManifestPath::as_ref)) {
 | 
				
			||||||
 | 
					            let file_set_roots: Vec<VfsPath> = vec![VfsPath::from(manifest.to_owned())];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            let entry = vfs::loader::Entry::Files(vec![manifest.to_owned()]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            res.watch.push(res.load.len());
 | 
				
			||||||
 | 
					            res.load.push(entry);
 | 
				
			||||||
 | 
					            local_filesets.push(fsc.len() as u64);
 | 
				
			||||||
 | 
					            fsc.add_file_set(file_set_roots)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let fsc = fsc.build();
 | 
					        let fsc = fsc.build();
 | 
				
			||||||
        res.source_root_config = SourceRootConfig { fsc, local_filesets };
 | 
					        res.source_root_config = SourceRootConfig { fsc, local_filesets };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -93,6 +93,7 @@ fn read_section<'a>(dylib_binary: &'a [u8], section_name: &str) -> io::Result<&'
 | 
				
			||||||
///   means bytes from here(including this sequence) are compressed in
 | 
					///   means bytes from here(including this sequence) are compressed in
 | 
				
			||||||
///   snappy compression format. Version info is inside here, so decompress
 | 
					///   snappy compression format. Version info is inside here, so decompress
 | 
				
			||||||
///   this.
 | 
					///   this.
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
/// The bytes you get after decompressing the snappy format portion has
 | 
					/// The bytes you get after decompressing the snappy format portion has
 | 
				
			||||||
/// following layout:
 | 
					/// following layout:
 | 
				
			||||||
/// * [b'r',b'u',b's',b't',0,0,0,5] is the first 8 bytes(again)
 | 
					/// * [b'r',b'u',b's',b't',0,0,0,5] is the first 8 bytes(again)
 | 
				
			||||||
| 
						 | 
					@ -102,6 +103,7 @@ fn read_section<'a>(dylib_binary: &'a [u8], section_name: &str) -> io::Result<&'
 | 
				
			||||||
///   for the version string's utf8 bytes
 | 
					///   for the version string's utf8 bytes
 | 
				
			||||||
/// * [version string bytes encoded in utf8] <- GET THIS BOI
 | 
					/// * [version string bytes encoded in utf8] <- GET THIS BOI
 | 
				
			||||||
/// * [some more bytes that we don't really care but about still there] :-)
 | 
					/// * [some more bytes that we don't really care but about still there] :-)
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
/// Check this issue for more about the bytes layout:
 | 
					/// Check this issue for more about the bytes layout:
 | 
				
			||||||
/// <https://github.com/rust-lang/rust-analyzer/issues/6174>
 | 
					/// <https://github.com/rust-lang/rust-analyzer/issues/6174>
 | 
				
			||||||
pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
 | 
					pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -167,6 +167,11 @@ impl ProjectJson {
 | 
				
			||||||
        &self.project_root
 | 
					        &self.project_root
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Returns the path to the project's manifest file, if it exists.
 | 
				
			||||||
 | 
					    pub fn manifest(&self) -> Option<&ManifestPath> {
 | 
				
			||||||
 | 
					        self.manifest.as_ref()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Returns the path to the project's manifest or root folder, if no manifest exists.
 | 
					    /// Returns the path to the project's manifest or root folder, if no manifest exists.
 | 
				
			||||||
    pub fn manifest_or_root(&self) -> &AbsPath {
 | 
					    pub fn manifest_or_root(&self) -> &AbsPath {
 | 
				
			||||||
        self.manifest.as_ref().map_or(&self.project_root, |manifest| manifest.as_ref())
 | 
					        self.manifest.as_ref().map_or(&self.project_root, |manifest| manifest.as_ref())
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -527,6 +527,16 @@ impl ProjectWorkspace {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn manifest(&self) -> Option<&ManifestPath> {
 | 
				
			||||||
 | 
					        match &self.kind {
 | 
				
			||||||
 | 
					            ProjectWorkspaceKind::Cargo { cargo, .. } => Some(cargo.manifest_path()),
 | 
				
			||||||
 | 
					            ProjectWorkspaceKind::Json(project) => project.manifest(),
 | 
				
			||||||
 | 
					            ProjectWorkspaceKind::DetachedFile { cargo, .. } => {
 | 
				
			||||||
 | 
					                Some(cargo.as_ref()?.0.manifest_path())
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn find_sysroot_proc_macro_srv(&self) -> anyhow::Result<AbsPathBuf> {
 | 
					    pub fn find_sysroot_proc_macro_srv(&self) -> anyhow::Result<AbsPathBuf> {
 | 
				
			||||||
        self.sysroot.discover_proc_macro_srv()
 | 
					        self.sysroot.discover_proc_macro_srv()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -122,7 +122,7 @@ impl DiagnosticCollection {
 | 
				
			||||||
        &self,
 | 
					        &self,
 | 
				
			||||||
        file_id: FileId,
 | 
					        file_id: FileId,
 | 
				
			||||||
    ) -> impl Iterator<Item = &lsp_types::Diagnostic> {
 | 
					    ) -> impl Iterator<Item = &lsp_types::Diagnostic> {
 | 
				
			||||||
        let native = self.native.get(&file_id).into_iter().map(|(_, d)| d).flatten();
 | 
					        let native = self.native.get(&file_id).into_iter().flat_map(|(_, d)| d);
 | 
				
			||||||
        let check = self.check.values().filter_map(move |it| it.get(&file_id)).flatten();
 | 
					        let check = self.check.values().filter_map(move |it| it.get(&file_id)).flatten();
 | 
				
			||||||
        native.chain(check)
 | 
					        native.chain(check)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -440,15 +440,19 @@ impl GlobalState {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if let FilesWatcher::Client = self.config.files().watcher {
 | 
					        if let FilesWatcher::Client = self.config.files().watcher {
 | 
				
			||||||
            let filter =
 | 
					            let filter = self
 | 
				
			||||||
                self.workspaces.iter().flat_map(|ws| ws.to_roots()).filter(|it| it.is_local);
 | 
					                .workspaces
 | 
				
			||||||
 | 
					                .iter()
 | 
				
			||||||
 | 
					                .flat_map(|ws| ws.to_roots())
 | 
				
			||||||
 | 
					                .filter(|it| it.is_local)
 | 
				
			||||||
 | 
					                .map(|it| it.include);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            let mut watchers: Vec<FileSystemWatcher> =
 | 
					            let mut watchers: Vec<FileSystemWatcher> =
 | 
				
			||||||
                if self.config.did_change_watched_files_relative_pattern_support() {
 | 
					                if self.config.did_change_watched_files_relative_pattern_support() {
 | 
				
			||||||
                    // When relative patterns are supported by the client, prefer using them
 | 
					                    // When relative patterns are supported by the client, prefer using them
 | 
				
			||||||
                    filter
 | 
					                    filter
 | 
				
			||||||
                        .flat_map(|root| {
 | 
					                        .flat_map(|include| {
 | 
				
			||||||
                            root.include.into_iter().flat_map(|base| {
 | 
					                            include.into_iter().flat_map(|base| {
 | 
				
			||||||
                                [
 | 
					                                [
 | 
				
			||||||
                                    (base.clone(), "**/*.rs"),
 | 
					                                    (base.clone(), "**/*.rs"),
 | 
				
			||||||
                                    (base.clone(), "**/Cargo.{lock,toml}"),
 | 
					                                    (base.clone(), "**/Cargo.{lock,toml}"),
 | 
				
			||||||
| 
						 | 
					@ -471,8 +475,8 @@ impl GlobalState {
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    // When they're not, integrate the base to make them into absolute patterns
 | 
					                    // When they're not, integrate the base to make them into absolute patterns
 | 
				
			||||||
                    filter
 | 
					                    filter
 | 
				
			||||||
                        .flat_map(|root| {
 | 
					                        .flat_map(|include| {
 | 
				
			||||||
                            root.include.into_iter().flat_map(|base| {
 | 
					                            include.into_iter().flat_map(|base| {
 | 
				
			||||||
                                [
 | 
					                                [
 | 
				
			||||||
                                    format!("{base}/**/*.rs"),
 | 
					                                    format!("{base}/**/*.rs"),
 | 
				
			||||||
                                    format!("{base}/**/Cargo.{{toml,lock}}"),
 | 
					                                    format!("{base}/**/Cargo.{{toml,lock}}"),
 | 
				
			||||||
| 
						 | 
					@ -488,13 +492,14 @@ impl GlobalState {
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            watchers.extend(
 | 
					            watchers.extend(
 | 
				
			||||||
                iter::once(self.config.user_config_path().to_string())
 | 
					                iter::once(self.config.user_config_path().as_path())
 | 
				
			||||||
                    .chain(iter::once(self.config.root_ratoml_path().to_string()))
 | 
					                    .chain(iter::once(self.config.root_ratoml_path().as_path()))
 | 
				
			||||||
 | 
					                    .chain(self.workspaces.iter().map(|ws| ws.manifest().map(ManifestPath::as_ref)))
 | 
				
			||||||
 | 
					                    .flatten()
 | 
				
			||||||
                    .map(|glob_pattern| lsp_types::FileSystemWatcher {
 | 
					                    .map(|glob_pattern| lsp_types::FileSystemWatcher {
 | 
				
			||||||
                        glob_pattern: lsp_types::GlobPattern::String(glob_pattern),
 | 
					                        glob_pattern: lsp_types::GlobPattern::String(glob_pattern.to_string()),
 | 
				
			||||||
                        kind: None,
 | 
					                        kind: None,
 | 
				
			||||||
                    })
 | 
					                    }),
 | 
				
			||||||
                    .collect::<Vec<FileSystemWatcher>>(),
 | 
					 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            let registration_options =
 | 
					            let registration_options =
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -384,8 +384,7 @@ impl VirtualPath {
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// # Returns
 | 
					    /// # Returns
 | 
				
			||||||
    /// - `None` if `self` ends with `"//"`.
 | 
					    /// - `None` if `self` ends with `"//"`.
 | 
				
			||||||
    /// - `Some((name, None))` if `self`'s base contains no `.`, or only one `.` at
 | 
					    /// - `Some((name, None))` if `self`'s base contains no `.`, or only one `.` at the start.
 | 
				
			||||||
    /// the start.
 | 
					 | 
				
			||||||
    /// - `Some((name, Some(extension))` else.
 | 
					    /// - `Some((name, Some(extension))` else.
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// # Note
 | 
					    /// # Note
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue