mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Fix edition used for include macro parsing
This commit is contained in:
parent
f4199f786e
commit
92f5e806f1
@ -18,7 +18,7 @@ use crate::{
|
|||||||
name, quote,
|
name, quote,
|
||||||
quote::dollar_crate,
|
quote::dollar_crate,
|
||||||
tt::{self, DelimSpan},
|
tt::{self, DelimSpan},
|
||||||
ExpandError, ExpandResult, HirFileIdExt, MacroCallId, MacroFileIdExt,
|
ExpandError, ExpandResult, HirFileIdExt, Lookup as _, MacroCallId,
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! register_builtin {
|
macro_rules! register_builtin {
|
||||||
@ -687,8 +687,8 @@ fn relative_file(
|
|||||||
path_str: &str,
|
path_str: &str,
|
||||||
allow_recursion: bool,
|
allow_recursion: bool,
|
||||||
) -> Result<EditionedFileId, ExpandError> {
|
) -> Result<EditionedFileId, ExpandError> {
|
||||||
let call_site =
|
let lookup = call_id.lookup(db);
|
||||||
call_id.as_macro_file().parent(db).original_file_respecting_includes(db).file_id();
|
let call_site = lookup.kind.file_id().original_file_respecting_includes(db).file_id();
|
||||||
let path = AnchoredPath { anchor: call_site, path: path_str };
|
let path = AnchoredPath { anchor: call_site, path: path_str };
|
||||||
let res = db
|
let res = db
|
||||||
.resolve_path(path)
|
.resolve_path(path)
|
||||||
@ -697,7 +697,7 @@ fn relative_file(
|
|||||||
if res == call_site && !allow_recursion {
|
if res == call_site && !allow_recursion {
|
||||||
Err(ExpandError::other(format!("recursive inclusion of `{path_str}`")))
|
Err(ExpandError::other(format!("recursive inclusion of `{path_str}`")))
|
||||||
} else {
|
} else {
|
||||||
Ok(EditionedFileId::new(res, Edition::CURRENT_FIXME))
|
Ok(EditionedFileId::new(res, db.crate_graph()[lookup.krate].edition))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ static PARSER_STEP_LIMIT: Limit = Limit::new(15_000_000);
|
|||||||
|
|
||||||
impl<'t> Parser<'t> {
|
impl<'t> Parser<'t> {
|
||||||
pub(super) fn new(inp: &'t Input, edition: Edition) -> 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> {
|
pub(crate) fn finish(self) -> Vec<Event> {
|
||||||
|
@ -5,8 +5,8 @@ use project_model::{CargoConfig, RustLibSource};
|
|||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
use hir::{db::HirDatabase, Crate, HirFileIdExt, Module};
|
use hir::{db::HirDatabase, Crate, HirFileIdExt, Module};
|
||||||
use ide::{AnalysisHost, AssistResolveStrategy, DiagnosticsConfig, Severity};
|
use ide::{AnalysisHost, AssistResolveStrategy, Diagnostic, DiagnosticsConfig, Severity};
|
||||||
use ide_db::base_db::SourceDatabaseExt;
|
use ide_db::{base_db::SourceDatabaseExt, LineIndexDatabase};
|
||||||
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
|
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
|
||||||
|
|
||||||
use crate::cli::flags;
|
use crate::cli::flags;
|
||||||
@ -74,7 +74,11 @@ impl flags::Diagnostics {
|
|||||||
found_error = true;
|
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);
|
visited_files.insert(file_id);
|
||||||
|
@ -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>) {
|
pub(crate) fn parse_text(text: &str, edition: parser::Edition) -> (GreenNode, Vec<SyntaxError>) {
|
||||||
let _p = tracing::info_span!("parse_text").entered();
|
let _p = tracing::info_span!("parse_text").entered();
|
||||||
let lexed = parser::LexedStr::new(edition, text);
|
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 parser_output = parser::TopEntryPoint::SourceFile.parse(&parser_input, edition);
|
||||||
let (node, errors, _eof) = build_tree(lexed, parser_output);
|
let (node, errors, _eof) = build_tree(lexed, parser_output);
|
||||||
(node, errors)
|
(node, errors)
|
||||||
@ -25,7 +25,7 @@ pub(crate) fn parse_text_at(
|
|||||||
) -> (GreenNode, Vec<SyntaxError>) {
|
) -> (GreenNode, Vec<SyntaxError>) {
|
||||||
let _p = tracing::info_span!("parse_text_at").entered();
|
let _p = tracing::info_span!("parse_text_at").entered();
|
||||||
let lexed = parser::LexedStr::new(edition, text);
|
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 parser_output = entry.parse(&parser_input, edition);
|
||||||
let (node, errors, _eof) = build_tree(lexed, parser_output);
|
let (node, errors, _eof) = build_tree(lexed, parser_output);
|
||||||
(node, errors)
|
(node, errors)
|
||||||
|
@ -92,7 +92,7 @@ fn reparse_block(
|
|||||||
let text = get_text_after_edit(node.clone().into(), edit);
|
let text = get_text_after_edit(node.clone().into(), edit);
|
||||||
|
|
||||||
let lexed = parser::LexedStr::new(edition, text.as_str());
|
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) {
|
if !is_balanced(&lexed) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ use std::{
|
|||||||
time::{Instant, SystemTime, UNIX_EPOCH},
|
time::{Instant, SystemTime, UNIX_EPOCH},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{bail, format_err};
|
use anyhow::format_err;
|
||||||
use xshell::{cmd, Shell};
|
use xshell::{cmd, Shell};
|
||||||
|
|
||||||
use crate::flags::{self, MeasurementType};
|
use crate::flags::{self, MeasurementType};
|
||||||
@ -193,7 +193,7 @@ impl Metrics {
|
|||||||
impl Host {
|
impl Host {
|
||||||
fn new(sh: &Shell) -> anyhow::Result<Host> {
|
fn new(sh: &Shell) -> anyhow::Result<Host> {
|
||||||
if cfg!(not(target_os = "linux")) {
|
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();
|
let os = read_field(sh, "/etc/os-release", "PRETTY_NAME=")?.trim_matches('"').to_owned();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user