mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Auto merge of #13639 - Veykril:macro-diags, r=Veykril
fix: Fix proc-macro-srv search paths for Arch Linux Fixes https://github.com/rust-lang/rust-analyzer/issues/13616
This commit is contained in:
commit
ac60077ee5
7 changed files with 50 additions and 67 deletions
|
@ -5,10 +5,7 @@ use crate::{Diagnostic, DiagnosticsContext};
|
||||||
// This diagnostic is shown for macro expansion errors.
|
// This diagnostic is shown for macro expansion errors.
|
||||||
pub(crate) fn macro_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroError) -> Diagnostic {
|
pub(crate) fn macro_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroError) -> Diagnostic {
|
||||||
// Use more accurate position if available.
|
// Use more accurate position if available.
|
||||||
let display_range = d
|
let display_range = ctx.resolve_precise_location(&d.node, d.precise_location);
|
||||||
.precise_location
|
|
||||||
.unwrap_or_else(|| ctx.sema.diagnostics_display_range(d.node.clone()).range);
|
|
||||||
|
|
||||||
Diagnostic::new("macro-error", d.message.clone(), display_range).experimental()
|
Diagnostic::new("macro-error", d.message.clone(), display_range).experimental()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,7 @@ pub(crate) fn unresolved_macro_call(
|
||||||
d: &hir::UnresolvedMacroCall,
|
d: &hir::UnresolvedMacroCall,
|
||||||
) -> Diagnostic {
|
) -> Diagnostic {
|
||||||
// Use more accurate position if available.
|
// Use more accurate position if available.
|
||||||
let display_range = d
|
let display_range = ctx.resolve_precise_location(&d.macro_call, d.precise_location);
|
||||||
.precise_location
|
|
||||||
.unwrap_or_else(|| ctx.sema.diagnostics_display_range(d.macro_call.clone()).range);
|
|
||||||
|
|
||||||
let bang = if d.is_bang { "!" } else { "" };
|
let bang = if d.is_bang { "!" } else { "" };
|
||||||
Diagnostic::new(
|
Diagnostic::new(
|
||||||
"unresolved-macro-call",
|
"unresolved-macro-call",
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use hir::db::DefDatabase;
|
use hir::db::DefDatabase;
|
||||||
use syntax::NodeOrToken;
|
|
||||||
|
|
||||||
use crate::{Diagnostic, DiagnosticsContext, Severity};
|
use crate::{Diagnostic, DiagnosticsContext, Severity};
|
||||||
|
|
||||||
|
@ -19,16 +18,7 @@ pub(crate) fn unresolved_proc_macro(
|
||||||
proc_attr_macros_enabled: bool,
|
proc_attr_macros_enabled: bool,
|
||||||
) -> Diagnostic {
|
) -> Diagnostic {
|
||||||
// Use more accurate position if available.
|
// Use more accurate position if available.
|
||||||
let display_range = (|| {
|
let display_range = ctx.resolve_precise_location(&d.node, d.precise_location);
|
||||||
let precise_location = d.precise_location?;
|
|
||||||
let root = ctx.sema.parse_or_expand(d.node.file_id)?;
|
|
||||||
match root.covering_element(precise_location) {
|
|
||||||
NodeOrToken::Node(it) => Some(ctx.sema.original_range(&it)),
|
|
||||||
NodeOrToken::Token(it) => d.node.with_value(it).original_file_range_opt(ctx.sema.db),
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
.unwrap_or_else(|| ctx.sema.diagnostics_display_range(d.node.clone()))
|
|
||||||
.range;
|
|
||||||
|
|
||||||
let config_enabled = match d.kind {
|
let config_enabled = match d.kind {
|
||||||
hir::MacroKind::Attr => proc_macros_enabled && proc_attr_macros_enabled,
|
hir::MacroKind::Attr => proc_macros_enabled && proc_attr_macros_enabled,
|
||||||
|
|
|
@ -182,6 +182,28 @@ struct DiagnosticsContext<'a> {
|
||||||
resolve: &'a AssistResolveStrategy,
|
resolve: &'a AssistResolveStrategy,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> DiagnosticsContext<'a> {
|
||||||
|
fn resolve_precise_location(
|
||||||
|
&self,
|
||||||
|
node: &InFile<SyntaxNodePtr>,
|
||||||
|
precise_location: Option<TextRange>,
|
||||||
|
) -> TextRange {
|
||||||
|
let sema = &self.sema;
|
||||||
|
(|| {
|
||||||
|
let precise_location = precise_location?;
|
||||||
|
let root = sema.parse_or_expand(node.file_id)?;
|
||||||
|
match root.covering_element(precise_location) {
|
||||||
|
syntax::NodeOrToken::Node(it) => Some(sema.original_range(&it)),
|
||||||
|
syntax::NodeOrToken::Token(it) => {
|
||||||
|
node.with_value(it).original_file_range_opt(sema.db)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
.unwrap_or_else(|| sema.diagnostics_display_range(node.clone()))
|
||||||
|
.range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn diagnostics(
|
pub fn diagnostics(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
config: &DiagnosticsConfig,
|
config: &DiagnosticsConfig,
|
||||||
|
|
|
@ -377,6 +377,21 @@ impl ProjectWorkspace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_sysroot_proc_macro_srv(&self) -> Option<AbsPathBuf> {
|
||||||
|
match self {
|
||||||
|
ProjectWorkspace::Cargo { sysroot: Some(sysroot), .. }
|
||||||
|
| ProjectWorkspace::Json { sysroot: Some(sysroot), .. } => {
|
||||||
|
let standalone_server_name =
|
||||||
|
format!("rust-analyzer-proc-macro-srv{}", std::env::consts::EXE_SUFFIX);
|
||||||
|
["libexec", "lib"]
|
||||||
|
.into_iter()
|
||||||
|
.map(|segment| sysroot.root().join(segment).join(&standalone_server_name))
|
||||||
|
.find(|server_path| std::fs::metadata(&server_path).is_ok())
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the roots for the current `ProjectWorkspace`
|
/// Returns the roots for the current `ProjectWorkspace`
|
||||||
/// The return type contains the path and whether or not
|
/// The return type contains the path and whether or not
|
||||||
/// the root is a member of the current workspace
|
/// the root is a member of the current workspace
|
||||||
|
|
|
@ -60,24 +60,12 @@ pub fn load_workspace(
|
||||||
};
|
};
|
||||||
|
|
||||||
let proc_macro_client = if load_config.with_proc_macro {
|
let proc_macro_client = if load_config.with_proc_macro {
|
||||||
let mut path = AbsPathBuf::assert(std::env::current_exe()?);
|
let (server_path, args): (_, &[_]) = match ws.find_sysroot_proc_macro_srv() {
|
||||||
let mut args = vec!["proc-macro"];
|
Some(server_path) => (server_path, &[]),
|
||||||
|
None => (AbsPathBuf::assert(std::env::current_exe()?), &["proc-macro"]),
|
||||||
|
};
|
||||||
|
|
||||||
if let ProjectWorkspace::Cargo { sysroot, .. } | ProjectWorkspace::Json { sysroot, .. } =
|
ProcMacroServer::spawn(server_path, args).map_err(|e| e.to_string())
|
||||||
&ws
|
|
||||||
{
|
|
||||||
if let Some(sysroot) = sysroot.as_ref() {
|
|
||||||
let standalone_server_name =
|
|
||||||
format!("rust-analyzer-proc-macro-srv{}", std::env::consts::EXE_SUFFIX);
|
|
||||||
let server_path = sysroot.root().join("libexec").join(&standalone_server_name);
|
|
||||||
if std::fs::metadata(&server_path).is_ok() {
|
|
||||||
path = server_path;
|
|
||||||
args = vec![];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcMacroServer::spawn(path.clone(), args.clone()).map_err(|e| e.to_string())
|
|
||||||
} else {
|
} else {
|
||||||
Err("proc macro server disabled".to_owned())
|
Err("proc macro server disabled".to_owned())
|
||||||
};
|
};
|
||||||
|
|
|
@ -305,9 +305,6 @@ impl GlobalState {
|
||||||
let files_config = self.config.files();
|
let files_config = self.config.files();
|
||||||
let project_folders = ProjectFolders::new(&self.workspaces, &files_config.exclude);
|
let project_folders = ProjectFolders::new(&self.workspaces, &files_config.exclude);
|
||||||
|
|
||||||
let standalone_server_name =
|
|
||||||
format!("rust-analyzer-proc-macro-srv{}", std::env::consts::EXE_SUFFIX);
|
|
||||||
|
|
||||||
if self.proc_macro_clients.is_empty() {
|
if self.proc_macro_clients.is_empty() {
|
||||||
if let Some((path, path_manually_set)) = self.config.proc_macro_srv() {
|
if let Some((path, path_manually_set)) = self.config.proc_macro_srv() {
|
||||||
tracing::info!("Spawning proc-macro servers");
|
tracing::info!("Spawning proc-macro servers");
|
||||||
|
@ -315,40 +312,17 @@ impl GlobalState {
|
||||||
.workspaces
|
.workspaces
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ws| {
|
.map(|ws| {
|
||||||
let (path, args) = if path_manually_set {
|
let (path, args): (_, &[_]) = if path_manually_set {
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
"Pro-macro server path explicitly set: {}",
|
"Pro-macro server path explicitly set: {}",
|
||||||
path.display()
|
path.display()
|
||||||
);
|
);
|
||||||
(path.clone(), vec![])
|
(path.clone(), &[])
|
||||||
} else {
|
} else {
|
||||||
let mut sysroot_server = None;
|
match ws.find_sysroot_proc_macro_srv() {
|
||||||
if let ProjectWorkspace::Cargo { sysroot, .. }
|
Some(server_path) => (server_path, &[]),
|
||||||
| ProjectWorkspace::Json { sysroot, .. } = ws
|
None => (path.clone(), &["proc-macro"]),
|
||||||
{
|
|
||||||
if let Some(sysroot) = sysroot.as_ref() {
|
|
||||||
let server_path = sysroot
|
|
||||||
.root()
|
|
||||||
.join("libexec")
|
|
||||||
.join(&standalone_server_name);
|
|
||||||
if std::fs::metadata(&server_path).is_ok() {
|
|
||||||
tracing::debug!(
|
|
||||||
"Sysroot proc-macro server exists at {}",
|
|
||||||
server_path.display()
|
|
||||||
);
|
|
||||||
sysroot_server = Some(server_path);
|
|
||||||
} else {
|
|
||||||
tracing::debug!(
|
|
||||||
"Sysroot proc-macro server does not exist at {}",
|
|
||||||
server_path.display()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sysroot_server.map_or_else(
|
|
||||||
|| (path.clone(), vec!["proc-macro".to_owned()]),
|
|
||||||
|path| (path, vec![]),
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
tracing::info!(?args, "Using proc-macro server at {}", path.display(),);
|
tracing::info!(?args, "Using proc-macro server at {}", path.display(),);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue