mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +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"] }
|
||||
|
||||
[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"
|
||||
unreachable_pub = "warn"
|
||||
semicolon_in_expressions_from_macros = "warn"
|
||||
|
|
|
@ -246,6 +246,7 @@ impl TyBuilder<()> {
|
|||
/// - yield type of coroutine ([`Coroutine::Yield`](std::ops::Coroutine::Yield))
|
||||
/// - return type of coroutine ([`Coroutine::Return`](std::ops::Coroutine::Return))
|
||||
/// - generic parameters in scope on `parent`
|
||||
///
|
||||
/// in this order.
|
||||
///
|
||||
/// This method prepopulates the builder with placeholder substitution of `parent`, so you
|
||||
|
|
|
@ -898,20 +898,19 @@ pub enum Rvalue {
|
|||
Cast(CastKind, Operand, Ty),
|
||||
|
||||
// FIXME link to `pointer::offset` when it hits stable.
|
||||
/// * `Offset` has the same semantics as `pointer::offset`, except that the second
|
||||
/// parameter may be a `usize` as well.
|
||||
/// * 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
|
||||
/// 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
|
||||
/// same type and return a value of the same type as their LHS. Like in Rust, the RHS is
|
||||
/// truncated as needed.
|
||||
/// * The `Bit*` operations accept signed integers, unsigned integers, or bools with matching
|
||||
/// types and return a value of that type.
|
||||
/// * The remaining operations accept signed integers, unsigned integers, or floats with
|
||||
/// matching types and return a value of that type.
|
||||
// /// * `Offset` has the same semantics as `pointer::offset`, except that the second
|
||||
// /// parameter may be a `usize` as well.
|
||||
// /// * 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
|
||||
// /// 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
|
||||
// /// same type and return a value of the same type as their LHS. Like in Rust, the RHS is
|
||||
// /// truncated as needed.
|
||||
// /// * The `Bit*` operations accept signed integers, unsigned integers, or bools with matching
|
||||
// /// types and return a value of that type.
|
||||
// /// * The remaining operations accept signed integers, unsigned integers, or floats with
|
||||
// /// matching types and return a value of that type.
|
||||
//BinaryOp(BinOp, Box<(Operand, Operand)>),
|
||||
|
||||
/// 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
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
//! * `defs` - Set of items in scope at term search target location
|
||||
//! * `lookup` - Lookup table for types
|
||||
//! * `should_continue` - Function that indicates when to stop iterating
|
||||
//!
|
||||
//! And they return iterator that yields type trees that unify with the `goal` type.
|
||||
|
||||
use std::iter;
|
||||
|
|
|
@ -393,9 +393,9 @@ impl FunctionBuilder {
|
|||
/// The rule for whether we focus a return type or not (and thus focus the function body),
|
||||
/// is rather simple:
|
||||
/// * If we could *not* infer what the return type should be, focus it (so the user can fill-in
|
||||
/// the correct return type).
|
||||
/// the correct return type).
|
||||
/// * If we could infer the return type, don't focus it (and thus focus the function body) so the
|
||||
/// user can change the `todo!` function body.
|
||||
/// user can change the `todo!` function body.
|
||||
fn make_return_type(
|
||||
ctx: &AssistContext<'_>,
|
||||
expr: &ast::Expr,
|
||||
|
@ -918,9 +918,9 @@ fn filter_generic_params(ctx: &AssistContext<'_>, node: SyntaxNode) -> Option<hi
|
|||
/// Say we have a trait bound `Struct<T>: Trait<U>`. Given `necessary_params`, when is it relevant
|
||||
/// and when not? Some observations:
|
||||
/// - When `necessary_params` contains `T`, it's likely that we want this bound, but now we have
|
||||
/// an extra param to consider: `U`.
|
||||
/// an extra param to consider: `U`.
|
||||
/// - On the other hand, when `necessary_params` contains `U` (but not `T`), then it's unlikely
|
||||
/// that we want this bound because it doesn't really constrain `U`.
|
||||
/// that we want this bound because it doesn't really constrain `U`.
|
||||
///
|
||||
/// (FIXME?: The latter clause might be overstating. We may want to include the bound if the self
|
||||
/// type does *not* include generic params at all - like `Option<i32>: From<U>`)
|
||||
|
@ -928,7 +928,7 @@ fn filter_generic_params(ctx: &AssistContext<'_>, node: SyntaxNode) -> Option<hi
|
|||
/// Can we make this a bit more formal? Let's define "dependency" between generic parameters and
|
||||
/// trait bounds:
|
||||
/// - A generic parameter `T` depends on a trait bound if `T` appears in the self type (i.e. left
|
||||
/// part) of the bound.
|
||||
/// part) of the bound.
|
||||
/// - A trait bound depends on a generic parameter `T` if `T` appears in the bound.
|
||||
///
|
||||
/// Using the notion, what we want is all the bounds that params in `necessary_params`
|
||||
|
|
|
@ -368,7 +368,7 @@ fn inline(
|
|||
_ => None,
|
||||
})
|
||||
.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);
|
||||
field.replace_expr(replacement.clone_for_update());
|
||||
} 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
|
||||
/// - mod foo
|
||||
/// - mod bar
|
||||
///
|
||||
/// Here depth will be 2
|
||||
pub(crate) depth_from_crate_root: usize,
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ use ide_db::{
|
|||
};
|
||||
use itertools::Itertools;
|
||||
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 tracing::instrument;
|
||||
use vfs::{file_set::FileSetConfig, loader::Handle, AbsPath, AbsPathBuf, VfsPath};
|
||||
|
@ -238,6 +238,19 @@ impl ProjectFolders {
|
|||
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();
|
||||
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
|
||||
/// snappy compression format. Version info is inside here, so decompress
|
||||
/// this.
|
||||
///
|
||||
/// The bytes you get after decompressing the snappy format portion has
|
||||
/// following layout:
|
||||
/// * [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
|
||||
/// * [version string bytes encoded in utf8] <- GET THIS BOI
|
||||
/// * [some more bytes that we don't really care but about still there] :-)
|
||||
///
|
||||
/// Check this issue for more about the bytes layout:
|
||||
/// <https://github.com/rust-lang/rust-analyzer/issues/6174>
|
||||
pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
|
||||
|
|
|
@ -167,6 +167,11 @@ impl ProjectJson {
|
|||
&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.
|
||||
pub fn manifest_or_root(&self) -> &AbsPath {
|
||||
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> {
|
||||
self.sysroot.discover_proc_macro_srv()
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ impl DiagnosticCollection {
|
|||
&self,
|
||||
file_id: FileId,
|
||||
) -> 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();
|
||||
native.chain(check)
|
||||
}
|
||||
|
|
|
@ -440,15 +440,19 @@ impl GlobalState {
|
|||
}
|
||||
|
||||
if let FilesWatcher::Client = self.config.files().watcher {
|
||||
let filter =
|
||||
self.workspaces.iter().flat_map(|ws| ws.to_roots()).filter(|it| it.is_local);
|
||||
let filter = self
|
||||
.workspaces
|
||||
.iter()
|
||||
.flat_map(|ws| ws.to_roots())
|
||||
.filter(|it| it.is_local)
|
||||
.map(|it| it.include);
|
||||
|
||||
let mut watchers: Vec<FileSystemWatcher> =
|
||||
if self.config.did_change_watched_files_relative_pattern_support() {
|
||||
// When relative patterns are supported by the client, prefer using them
|
||||
filter
|
||||
.flat_map(|root| {
|
||||
root.include.into_iter().flat_map(|base| {
|
||||
.flat_map(|include| {
|
||||
include.into_iter().flat_map(|base| {
|
||||
[
|
||||
(base.clone(), "**/*.rs"),
|
||||
(base.clone(), "**/Cargo.{lock,toml}"),
|
||||
|
@ -471,8 +475,8 @@ impl GlobalState {
|
|||
} else {
|
||||
// When they're not, integrate the base to make them into absolute patterns
|
||||
filter
|
||||
.flat_map(|root| {
|
||||
root.include.into_iter().flat_map(|base| {
|
||||
.flat_map(|include| {
|
||||
include.into_iter().flat_map(|base| {
|
||||
[
|
||||
format!("{base}/**/*.rs"),
|
||||
format!("{base}/**/Cargo.{{toml,lock}}"),
|
||||
|
@ -488,13 +492,14 @@ impl GlobalState {
|
|||
};
|
||||
|
||||
watchers.extend(
|
||||
iter::once(self.config.user_config_path().to_string())
|
||||
.chain(iter::once(self.config.root_ratoml_path().to_string()))
|
||||
iter::once(self.config.user_config_path().as_path())
|
||||
.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 {
|
||||
glob_pattern: lsp_types::GlobPattern::String(glob_pattern),
|
||||
glob_pattern: lsp_types::GlobPattern::String(glob_pattern.to_string()),
|
||||
kind: None,
|
||||
})
|
||||
.collect::<Vec<FileSystemWatcher>>(),
|
||||
}),
|
||||
);
|
||||
|
||||
let registration_options =
|
||||
|
|
|
@ -282,7 +282,7 @@ impl Vfs {
|
|||
/// Returns the id associated with `path`
|
||||
///
|
||||
/// - If `path` does not exists in the `Vfs`, allocate a new id for it, associated with a
|
||||
/// deleted file;
|
||||
/// deleted file;
|
||||
/// - Else, returns `path`'s id.
|
||||
///
|
||||
/// Does not record a change.
|
||||
|
|
|
@ -384,8 +384,7 @@ impl VirtualPath {
|
|||
///
|
||||
/// # Returns
|
||||
/// - `None` if `self` ends with `"//"`.
|
||||
/// - `Some((name, None))` if `self`'s base contains no `.`, or only one `.` at
|
||||
/// the start.
|
||||
/// - `Some((name, None))` if `self`'s base contains no `.`, or only one `.` at the start.
|
||||
/// - `Some((name, Some(extension))` else.
|
||||
///
|
||||
/// # Note
|
||||
|
|
Loading…
Reference in a new issue