Fix edition used for include macro parsing

This commit is contained in:
Lukas Wirth 2024-07-19 20:04:38 +02:00
parent f4199f786e
commit 92f5e806f1
6 changed files with 17 additions and 13 deletions

View file

@ -18,7 +18,7 @@ use crate::{
name, quote,
quote::dollar_crate,
tt::{self, DelimSpan},
ExpandError, ExpandResult, HirFileIdExt, MacroCallId, MacroFileIdExt,
ExpandError, ExpandResult, HirFileIdExt, Lookup as _, MacroCallId,
};
macro_rules! register_builtin {
@ -687,8 +687,8 @@ fn relative_file(
path_str: &str,
allow_recursion: bool,
) -> Result<EditionedFileId, ExpandError> {
let call_site =
call_id.as_macro_file().parent(db).original_file_respecting_includes(db).file_id();
let lookup = call_id.lookup(db);
let call_site = lookup.kind.file_id().original_file_respecting_includes(db).file_id();
let path = AnchoredPath { anchor: call_site, path: path_str };
let res = db
.resolve_path(path)
@ -697,7 +697,7 @@ fn relative_file(
if res == call_site && !allow_recursion {
Err(ExpandError::other(format!("recursive inclusion of `{path_str}`")))
} else {
Ok(EditionedFileId::new(res, Edition::CURRENT_FIXME))
Ok(EditionedFileId::new(res, db.crate_graph()[lookup.krate].edition))
}
}

View file

@ -34,7 +34,7 @@ static PARSER_STEP_LIMIT: Limit = Limit::new(15_000_000);
impl<'t> Parser<'t> {
pub(super) fn new(inp: &'t Input, edition: Edition) -> Parser<'t> {
Parser { inp, pos: 0, events: Vec::new(), steps: Cell::new(0), edition: edition }
Parser { inp, pos: 0, events: Vec::new(), steps: Cell::new(0), edition }
}
pub(crate) fn finish(self) -> Vec<Event> {

View file

@ -5,8 +5,8 @@ use project_model::{CargoConfig, RustLibSource};
use rustc_hash::FxHashSet;
use hir::{db::HirDatabase, Crate, HirFileIdExt, Module};
use ide::{AnalysisHost, AssistResolveStrategy, DiagnosticsConfig, Severity};
use ide_db::base_db::SourceDatabaseExt;
use ide::{AnalysisHost, AssistResolveStrategy, Diagnostic, DiagnosticsConfig, Severity};
use ide_db::{base_db::SourceDatabaseExt, LineIndexDatabase};
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
use crate::cli::flags;
@ -74,7 +74,11 @@ impl flags::Diagnostics {
found_error = true;
}
println!("{diagnostic:?}");
let Diagnostic { code, message, range, severity, .. } = diagnostic;
let line_index = db.line_index(range.file_id);
let start = line_index.line_col(range.range.start());
let end = line_index.line_col(range.range.end());
println!("{severity:?} {code:?} from {start:?} to {end:?}: {message}");
}
visited_files.insert(file_id);

View file

@ -12,7 +12,7 @@ pub(crate) use crate::parsing::reparsing::incremental_reparse;
pub(crate) fn parse_text(text: &str, edition: parser::Edition) -> (GreenNode, Vec<SyntaxError>) {
let _p = tracing::info_span!("parse_text").entered();
let lexed = parser::LexedStr::new(edition, text);
let parser_input = lexed.to_input();
let parser_input = lexed.to_input(edition);
let parser_output = parser::TopEntryPoint::SourceFile.parse(&parser_input, edition);
let (node, errors, _eof) = build_tree(lexed, parser_output);
(node, errors)
@ -25,7 +25,7 @@ pub(crate) fn parse_text_at(
) -> (GreenNode, Vec<SyntaxError>) {
let _p = tracing::info_span!("parse_text_at").entered();
let lexed = parser::LexedStr::new(edition, text);
let parser_input = lexed.to_input();
let parser_input = lexed.to_input(edition);
let parser_output = entry.parse(&parser_input, edition);
let (node, errors, _eof) = build_tree(lexed, parser_output);
(node, errors)

View file

@ -92,7 +92,7 @@ fn reparse_block(
let text = get_text_after_edit(node.clone().into(), edit);
let lexed = parser::LexedStr::new(edition, text.as_str());
let parser_input = lexed.to_input();
let parser_input = lexed.to_input(edition);
if !is_balanced(&lexed) {
return None;
}

View file

@ -6,7 +6,7 @@ use std::{
time::{Instant, SystemTime, UNIX_EPOCH},
};
use anyhow::{bail, format_err};
use anyhow::format_err;
use xshell::{cmd, Shell};
use crate::flags::{self, MeasurementType};
@ -193,7 +193,7 @@ impl Metrics {
impl Host {
fn new(sh: &Shell) -> anyhow::Result<Host> {
if cfg!(not(target_os = "linux")) {
bail!("can only collect metrics on Linux ");
return Ok(Host { os: "unknown".into(), cpu: "unknown".into(), mem: "unknown".into() });
}
let os = read_field(sh, "/etc/os-release", "PRETTY_NAME=")?.trim_matches('"').to_owned();