Rust: adapt extractor to rust-analyzer 0.0.328 API changes

This commit is contained in:
Taus
2026-04-15 13:26:54 +00:00
parent 5f76c946de
commit ce360c4f17
4 changed files with 36 additions and 15 deletions

View File

@@ -14,7 +14,7 @@ use ra_ap_ide_db::FxHashMap;
use ra_ap_intern::Symbol;
use ra_ap_load_cargo::{LoadCargoConfig, ProcMacroServerChoice};
use ra_ap_paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
use ra_ap_project_model::{CargoConfig, CargoFeatures, CfgOverrides, RustLibSource, Sysroot};
use ra_ap_project_model::{CargoConfig, CargoFeatures, CfgOverrides, RustLibSource, Sysroot, TargetDirectoryConfig};
use rust_extractor_macros::extractor_cli_config;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
@@ -171,12 +171,12 @@ impl Config {
.iter()
.map(|p| join_path_buf(dir, p))
.collect(),
target_dir: Utf8PathBuf::from_path_buf(
target_dir_config: Utf8PathBuf::from_path_buf(
self.cargo_target_dir
.clone()
.unwrap_or_else(|| self.scratch_dir.join("target")),
)
.ok(),
.map_or(TargetDirectoryConfig::None, TargetDirectoryConfig::Directory),
features: self.cargo_features(),
target: self.cargo_target.clone(),
cfg_overrides: to_cfg_overrides(&self.cargo_cfg_overrides),
@@ -192,6 +192,8 @@ impl Config {
load_out_dirs_from_check: true,
with_proc_macro_server: self.proc_macro_server_choice(dir),
prefill_caches: false,
num_worker_threads: 0,
proc_macro_processes: 0,
},
)
}

View File

@@ -1,7 +1,7 @@
use crate::{generated, trap};
use itertools::Itertools;
use ra_ap_base_db::{Crate, RootQueryDb};
use ra_ap_base_db::Crate;
use ra_ap_cfg::CfgAtom;
use ra_ap_ide_db::RootDatabase;
use ra_ap_vfs::{Vfs, VfsPath};
@@ -12,7 +12,7 @@ use std::{cmp::Ordering, collections::HashMap, path::PathBuf};
use tracing::error;
pub fn extract_crate_graph(trap_provider: &trap::TrapFileProvider, db: &RootDatabase, vfs: &Vfs) {
let crate_graph = db.all_crates();
let crate_graph = ra_ap_base_db::all_crates(db);
// According to the documentation of `CrateGraph`:
// Each crate is defined by the `FileId` of its root module, the set of enabled

View File

@@ -1,6 +1,6 @@
use crate::trap;
use itertools::Itertools;
use ra_ap_base_db::{EditionedFileId, FileText, RootQueryDb, SourceDatabase};
use ra_ap_base_db::{EditionedFileId, FileText, SourceDatabase};
use ra_ap_hir::Semantics;
use ra_ap_ide_db::RootDatabase;
use ra_ap_load_cargo::{LoadCargoConfig, load_workspace_at};
@@ -115,7 +115,7 @@ impl<'a> RustAnalyzer<'a> {
"no text available for the file in the project",
)),
)?;
let editioned_file_id = semantics.attach_first_edition(file_id).ok_or(
let editioned_file_id = semantics.attach_first_edition_opt(file_id).ok_or(
RustAnalyzerNoSemantics::warning("failed to determine rust edition"),
)?;
Ok((semantics, editioned_file_id, input))
@@ -127,9 +127,8 @@ impl<'a> RustAnalyzer<'a> {
match self.get_file_data(path) {
Ok((semantics, file_id, input)) => {
let source_file = semantics.parse(file_id);
let errors = semantics
.db
.parse_errors(file_id)
let errors = file_id
.parse_errors(semantics.db)
.into_iter()
.flat_map(|x| x.to_vec())
.collect();

View File

@@ -465,9 +465,27 @@ impl<'a> Translator<'a> {
pub(crate) fn should_be_excluded(&self, item: &impl ast::HasAttrs) -> bool {
self.semantics.is_some_and(|sema| {
item.attrs().any(|attr| {
attr.as_simple_call().is_some_and(|(name, tokens)| {
name == "cfg" && sema.check_cfg_attr(&tokens) == Some(false)
})
let meta = match attr.meta() {
Some(meta) => meta,
None => return false,
};
let cfg_meta = match ast::CfgMeta::cast(meta.syntax().clone()) {
Some(cfg_meta) => cfg_meta,
None => return false,
};
let cfg_predicate = match cfg_meta.cfg_predicate() {
Some(pred) => pred,
None => return false,
};
let cfg_expr = ra_ap_cfg::CfgExpr::parse_from_ast(cfg_predicate);
let file_id = sema.hir_file_for(item.syntax());
let krate = match file_id.file_id().and_then(|fid| {
sema.file_to_module_defs(fid.file_id(sema.db)).next()
}) {
Some(module) => module.krate(sema.db),
None => return false,
};
krate.cfg(sema.db).check(&cfg_expr) == Some(false)
})
})
}
@@ -551,9 +569,9 @@ impl<'a> Translator<'a> {
is_const: false,
is_gen: false,
is_move: false,
is_try: false,
is_unsafe: false,
stmt_list: Some(stmt_list),
try_block_modifier: None,
});
self.emit_location(label, node);
self.emit_tokens(node, label.into(), node.syntax().children_with_tokens());
@@ -695,7 +713,9 @@ impl<'a> Translator<'a> {
let node: ast::Adt = node.clone().into();
let expansions = node
.attrs()
.filter_map(|attr| semantics.expand_derive_macro(&attr))
.filter_map(|attr| attr.meta())
.filter_map(|meta| semantics.expand_derive_macro(&meta))
.flatten()
.flatten()
.filter_map(|expanded| self.process_item_macro_expansion(&node, expanded))
.collect::<Vec<_>>();