Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
e752116
fix(preproc): separate macro definition ranges
hongjr03 Jun 6, 2026
c86a0f5
feat(preproc): add expansion provenance model skeleton
hongjr03 Jun 6, 2026
34a946f
feat(preproc): build resolved provenance model
hongjr03 Jun 6, 2026
de5de1a
feat(preproc): query macro visibility from state timeline
hongjr03 Jun 6, 2026
e505df9
refactor(preproc): expose mapped provenance results
hongjr03 Jun 6, 2026
39dc63e
feat(preproc): map virtual preprocessor sources
hongjr03 Jun 6, 2026
159629d
refactor(preproc): remove replay-backed semantic queries
hongjr03 Jun 6, 2026
53f0189
feat(preproc): ingest emitted token provenance
hongjr03 Jun 6, 2026
6fde833
fix(slang): map nested macro call ranges to written source
hongjr03 Jun 6, 2026
746e04f
feat(preproc): build macro expansion graph
hongjr03 Jun 6, 2026
f879a65
feat(hir): expose macro expansion queries
hongjr03 Jun 6, 2026
d0d8c32
feat(hir): bridge expansion provenance to source maps
hongjr03 Jun 6, 2026
bde6ad9
feat(hir): bridge preproc provenance through source maps
hongjr03 Jun 6, 2026
afccca4
fix(ide): surface contextual preproc navigation results
hongjr03 Jun 6, 2026
af923e9
feat(hir): link macro parameters through preproc facts
hongjr03 Jun 6, 2026
33fcc25
chore: clippy
hongjr03 Jun 6, 2026
dbc8722
fix(ide): resolve macro argument source tokens
hongjr03 Jun 6, 2026
07da17e
feat(hir): link manifest predefines to source ranges
hongjr03 Jun 6, 2026
cc51fa2
feat(hir): link manifest predefines to source ranges (#238)
hongjr03 Jun 6, 2026
f78c18c
feat(ide): explain macro expansion steps in hover
hongjr03 Jun 6, 2026
8ac0b60
fix(ci): restore syntax-only diagnostics
hongjr03 Jun 6, 2026
1b607fd
fix(preproc): use half-open provenance hit testing
hongjr03 Jun 7, 2026
90870b5
fix(ide): avoid publishing diagnostics to synthetic virtual files
hongjr03 Jun 7, 2026
89d5614
feat(slang): expose direct macro provenance identity
hongjr03 Jun 7, 2026
01bc796
feat(preproc): consume direct macro provenance identity
hongjr03 Jun 7, 2026
6d06724
fix(ide): select preproc tokens by provenance identity
hongjr03 Jun 7, 2026
447a029
fix(hir): report ambiguous macro diagnostic provenance
hongjr03 Jun 7, 2026
a0f5a06
fix(hir): scope single-offset preproc queries to relevant contexts
hongjr03 Jun 7, 2026
545d62e
test(project-model): lock manifest semantic participation
hongjr03 Jun 7, 2026
4aba1c8
fix(hir): validate configured predefine source mapping
hongjr03 Jun 7, 2026
b0a444d
fix(hir): separate expansion display text from virtual source
hongjr03 Jun 7, 2026
4ab3e2c
fix(preproc): trace runtime macro usages
hongjr03 Jun 7, 2026
eb1e671
fix(hir): preserve ambiguous macro expansion contexts
hongjr03 Jun 7, 2026
4e86f7f
feat(ide): compact macro expansion hover
hongjr03 Jun 7, 2026
98522ce
chore: resolve provenance clippy lints
hongjr03 Jun 7, 2026
dccb04f
chore: remove redundant validate
hongjr03 Jun 7, 2026
3261469
refactor(preproc): modularize source provenance code
hongjr03 Jun 7, 2026
a2c0b61
refactor(preproc): simplify provenance plumbing
hongjr03 Jun 7, 2026
96e7b8a
refactor: hir::src::preproc
hongjr03 Jun 7, 2026
eb4f0c6
feat(hover): make macro hover more compact
hongjr03 Jun 7, 2026
179cb0e
fix(preproc): preserve nested argument macro provenance
hongjr03 Jun 7, 2026
e44b40f
feat(ide): highlight preproc macro references
hongjr03 Jun 7, 2026
a7e163b
refactor(slang): add parse-path preprocessor trace recorder
hongjr03 Jun 7, 2026
ef72f6a
feat(slang): expose parse-derived preprocessor trace
hongjr03 Jun 7, 2026
b188939
refactor(hir): share parse-derived preprocessor trace
hongjr03 Jun 7, 2026
fe4dd7d
refactor(slang): remove static preprocessor trace path
hongjr03 Jun 7, 2026
70cf6e0
refactor(hir): lazily resolve preproc contexts
hongjr03 Jun 7, 2026
b397301
perf(hir): index preproc reference ranges
hongjr03 Jun 7, 2026
af46fd6
perf(preproc): memoize recursive expansion tokens
hongjr03 Jun 7, 2026
9dea282
perf(ide): reuse macro hover reference lookup
hongjr03 Jun 7, 2026
5e64fcc
fix(preproc): bound macro state to include scope
hongjr03 Jun 7, 2026
f23e7d8
fix(hir): prefer including contexts for header queries
hongjr03 Jun 7, 2026
f25be9b
fix(hir): decode manifest predefine source tokens
hongjr03 Jun 7, 2026
220d510
fix(ide): preserve partial macro reference status
hongjr03 Jun 7, 2026
6c7427b
fix(preproc): satisfy include scope clippy lint
hongjr03 Jun 8, 2026
7d9a7a8
perf(ide): gate macro provenance token lookup
hongjr03 Jun 8, 2026
f621ee4
perf(hir): index preproc contexts by profile
hongjr03 Jun 8, 2026
ce01c93
fix(hir): preserve partial preproc context status
hongjr03 Jun 8, 2026
8cfb480
fix(preproc): keep macro body references per call
hongjr03 Jun 8, 2026
7d206b2
fix(hir): map duplicate predefine sources
hongjr03 Jun 8, 2026
7cd6c05
fix(preproc): expose builtin token provenance
hongjr03 Jun 8, 2026
06a2f2e
fix(hir): scope include-only preproc contexts
hongjr03 Jun 8, 2026
0e15fa6
fix(preproc): connect builtin expansion provenance
hongjr03 Jun 8, 2026
e45bb83
fix(preproc): keep zero-token macro expansions available
hongjr03 Jun 8, 2026
7bd4afa
test(hir): accept structured diagnostic provenance unavailability
hongjr03 Jun 8, 2026
e34b029
fix(preproc): track macro operation provenance
hongjr03 Jun 8, 2026
a1792e5
feat(ide): add macro argument inlay hints
hongjr03 Jun 8, 2026
01f469e
test(vscode): cover macro argument inlay setting
hongjr03 Jun 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/hir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ salsa.workspace = true
smallvec.workspace = true
smol_str.workspace = true
syntax.workspace = true
toml.workspace = true
tracing.workspace = true
triomphe.workspace = true
utils.workspace = true
Expand Down
74 changes: 51 additions & 23 deletions crates/hir/src/base_db/compilation_plan.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use preproc::source::{MacroIncludeTarget, SourcePreprocModel};
use preproc::source::{MacroIncludeTarget, SourcePreprocError, SourcePreprocModel};
use rustc_hash::FxHashSet;
use syntax::{SyntaxTree, SyntaxTreeBuffer, SyntaxTreeOptions};
use utils::{
Expand All @@ -24,6 +24,19 @@ pub struct CompilationPlan {
pub include_dirs: Vec<AbsPathBuf>,
pub top_modules: Vec<String>,
pub predefines: Vec<String>,
pub include_scan_issues: Vec<IncludeScanIssue>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IncludeScanIssue {
pub file_id: FileId,
pub reason: IncludeScanIssueReason,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum IncludeScanIssueReason {
TraceUnavailable,
Model(SourcePreprocError),
}

impl CompilationPlan {
Expand Down Expand Up @@ -59,10 +72,18 @@ impl CompilationPlan {
include_dirs: Vec<AbsPathBuf>,
predefines: Vec<String>,
) -> Self {
let include_only =
let (include_only, include_scan_issues) =
include_targets_for_source_roots(db, &source_roots, &include_dirs, &predefines);
let roots = compile_roots_for_source_roots(db, &source_roots, &include_only);
CompilationPlan { source_roots, roots, include_only, include_dirs, top_modules, predefines }
CompilationPlan {
source_roots,
roots,
include_only,
include_dirs,
top_modules,
predefines,
include_scan_issues,
}
}
}

Expand Down Expand Up @@ -140,17 +161,13 @@ fn profile_inputs(
profile.source_roots.clone(),
profile.top_modules.clone(),
profile.preprocess.include_dirs.clone(),
profile.preprocess.predefines.clone(),
profile.preprocess.predefine_strings(),
);
}

let preprocess = project_config.preprocess_for_profile(profile_id);
(
root_scoped_source_root.into_iter().collect(),
Vec::new(),
preprocess.include_dirs,
preprocess.predefines,
)
let predefines = preprocess.predefine_strings();
(root_scoped_source_root.into_iter().collect(), Vec::new(), preprocess.include_dirs, predefines)
}

fn all_non_ignored_roots(db: &dyn SourceRootDb) -> Vec<SourceRootId> {
Expand Down Expand Up @@ -216,9 +233,10 @@ fn include_targets_for_source_roots(
roots: &[SourceRootId],
include_dirs: &[AbsPathBuf],
predefines: &[String],
) -> FxHashSet<FileId> {
) -> (FxHashSet<FileId>, Vec<IncludeScanIssue>) {
let path_file_ids = path_file_ids(db);
let mut included = FxHashSet::default();
let mut issues = Vec::new();
let mut scanned = FxHashSet::default();
let mut pending = Vec::new();
for root_id in roots {
Expand All @@ -243,7 +261,14 @@ fn include_targets_for_source_roots(
continue;
};

for include in literal_include_targets(db, file_id, predefines) {
let include_targets = match literal_include_targets(db, file_id, predefines) {
Ok(targets) => targets,
Err(issue) => {
issues.push(issue);
continue;
}
};
for include in include_targets {
let MacroIncludeTarget::Literal { path, .. } = &include.target else {
continue;
};
Expand All @@ -256,19 +281,19 @@ fn include_targets_for_source_roots(
}
}

included
(included, issues)
}

fn literal_include_targets(
db: &dyn SourceRootDb,
file_id: FileId,
predefines: &[String],
) -> Vec<preproc::source::SourceMacroInclude> {
) -> Result<Vec<preproc::source::SourceMacroInclude>, IncludeScanIssue> {
if !matches!(
db.file_kind(file_id),
SourceFileKind::SystemVerilog | SourceFileKind::IncludeHeader
) {
return Vec::new();
return Ok(Vec::new());
}

let path = db.file_path(file_id).map(|path| path.to_string()).unwrap_or_default();
Expand All @@ -277,15 +302,18 @@ fn literal_include_targets(
predefines: predefines.to_vec(),
..SyntaxTreeOptions::without_include_expansion()
};
let Some(trace) =
SyntaxTree::preprocessor_trace(&db.file_text(file_id), &name, &path, &options)
else {
return Vec::new();
};
let Ok(model) = SourcePreprocModel::from_trace(trace) else {
return Vec::new();
let parsed = SyntaxTree::from_text_with_options_and_trace(
&db.file_text(file_id),
&name,
&path,
&options,
);
let Some(trace) = parsed.preprocessor_trace else {
return Err(IncludeScanIssue { file_id, reason: IncludeScanIssueReason::TraceUnavailable });
};
model.includes().to_vec()
let model = SourcePreprocModel::from_trace(trace)
.map_err(|err| IncludeScanIssue { file_id, reason: IncludeScanIssueReason::Model(err) })?;
Ok(model.includes().to_vec())
}

fn resolve_include_target(
Expand Down
56 changes: 54 additions & 2 deletions crates/hir/src/base_db/project.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use triomphe::Arc;
use utils::paths::AbsPathBuf;
use utils::{line_index::TextRange, paths::AbsPathBuf};

use crate::base_db::source_root::SourceRootId;

Expand All @@ -8,14 +8,66 @@ pub struct CompilationProfileId(pub u32);

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct PreprocessConfig {
pub predefines: Vec<String>,
pub predefines: Vec<Predefine>,
pub include_dirs: Vec<AbsPathBuf>,
}

impl PreprocessConfig {
pub fn with_predefine_strings(
predefines: impl IntoIterator<Item = impl Into<String>>,
include_dirs: Vec<AbsPathBuf>,
) -> Self {
Self {
predefines: predefines.into_iter().map(|predefine| Predefine::new(predefine)).collect(),
include_dirs,
}
}

pub fn include_dir_strings(&self) -> Vec<String> {
self.include_dirs.iter().map(ToString::to_string).collect()
}

pub fn predefine_strings(&self) -> Vec<String> {
self.predefines.iter().map(|predefine| predefine.definition.clone()).collect()
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Predefine {
pub definition: String,
pub source: Option<PredefineSource>,
}

impl Predefine {
pub fn new(definition: impl Into<String>) -> Self {
Self { definition: definition.into(), source: None }
}

pub fn with_source(definition: impl Into<String>, source: PredefineSource) -> Self {
Self { definition: definition.into(), source: Some(source) }
}

pub fn as_str(&self) -> &str {
self.definition.as_str()
}
}

impl From<String> for Predefine {
fn from(value: String) -> Self {
Predefine::new(value)
}
}

impl From<&str> for Predefine {
fn from(value: &str) -> Self {
Predefine::new(value)
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PredefineSource {
pub path: AbsPathBuf,
pub range: TextRange,
}

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
Loading
Loading