Skip to content

Commit ca7b93e

Browse files
committed
fix(md051): index cross-file links independently of frontmatter config
The workspace index holds one entry per file while `check_frontmatter` and `ignore_front_matter_fields` resolve per file, so filtering at index time made the contents of the index depend on whichever file happened to build it. A file under a config that checks frontmatter got no diagnostics when the index was built by a file whose config did not, and a file that had opted out got them when it was. Cross-file links are now recorded wherever they were written, carrying a `LinkOrigin` that distinguishes a body link from a frontmatter one and names the field owning the value. Each reader applies its own settings when it reads the index, which is the only arrangement that can be right when two files resolving different configs reference the same target. `LinkOrigin::FrontMatter` keeps `field: None` distinct from `Body`, so a value whose owning key is not determinable (a top-level YAML sequence item) is still recognized as frontmatter and still suppressed by `check-frontmatter = false`. Bumps the cache format version: postcard is not self-describing, so a version 8 cache would decode the following field's bytes as the new one.
1 parent b1908a0 commit ca7b93e

6 files changed

Lines changed: 316 additions & 48 deletions

File tree

‎benches/perf_audit.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rumdl_lib::rules::{
1919
MD021NoMultipleSpaceClosedAtx, MD027MultipleSpacesBlockquote, MD032BlanksAroundLists, MD033NoInlineHtml,
2020
MD052ReferenceLinkImages, MD057Config, MD057ExistingRelativeLinks,
2121
};
22-
use rumdl_lib::workspace_index::{CrossFileLinkIndex, FileIndex, WorkspaceIndex};
22+
use rumdl_lib::workspace_index::{CrossFileLinkIndex, FileIndex, LinkOrigin, WorkspaceIndex};
2323
use std::hint::black_box;
2424
use std::path::Path;
2525

@@ -320,6 +320,7 @@ fn bench_workspace_build(c: &mut Criterion) {
320320
fragment: String::new(),
321321
line: k,
322322
column: 1,
323+
origin: LinkOrigin::Body,
323324
});
324325
}
325326
idx.update_file(Path::new(&format!("doc{i}.md")), fi);

‎src/lsp/tests.rs‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4721,7 +4721,7 @@ async fn test_goto_definition_cursor_not_on_link() {
47214721

47224722
#[tokio::test]
47234723
async fn test_find_references_heading_with_incoming_links() {
4724-
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, HeadingIndex};
4724+
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, HeadingIndex, LinkOrigin};
47254725

47264726
let server = create_test_server();
47274727

@@ -4765,6 +4765,7 @@ async fn test_find_references_heading_with_incoming_links() {
47654765
fragment: "installation".to_string(),
47664766
line: 5,
47674767
column: 10,
4768+
origin: LinkOrigin::Body,
47684769
});
47694770
index.insert_file(source_file_a.clone(), source_a_fi);
47704771

@@ -4775,6 +4776,7 @@ async fn test_find_references_heading_with_incoming_links() {
47754776
fragment: "installation".to_string(),
47764777
line: 3,
47774778
column: 15,
4779+
origin: LinkOrigin::Body,
47784780
});
47794781
index.insert_file(source_file_b.clone(), source_b_fi);
47804782
}
@@ -4815,7 +4817,7 @@ async fn test_find_references_heading_with_incoming_links() {
48154817

48164818
#[tokio::test]
48174819
async fn test_find_references_finds_root_relative_links() {
4818-
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, HeadingIndex};
4820+
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, HeadingIndex, LinkOrigin};
48194821
use std::fs;
48204822
use tempfile::tempdir;
48214823

@@ -4862,6 +4864,7 @@ async fn test_find_references_finds_root_relative_links() {
48624864
fragment: "installation".to_string(),
48634865
line: 1,
48644866
column: 15,
4867+
origin: LinkOrigin::Body,
48654868
});
48664869
index.insert_file(source_file.clone(), source_fi);
48674870
}
@@ -5024,7 +5027,7 @@ async fn test_goto_definition_anchor_not_found_falls_back_to_line_zero() {
50245027

50255028
#[tokio::test]
50265029
async fn test_find_references_from_link_position() {
5027-
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, HeadingIndex};
5030+
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, HeadingIndex, LinkOrigin};
50285031

50295032
let server = create_test_server();
50305033

@@ -5066,6 +5069,7 @@ async fn test_find_references_from_link_position() {
50665069
fragment: "".to_string(),
50675070
line: 3,
50685071
column: 12,
5072+
origin: LinkOrigin::Body,
50695073
});
50705074
index.insert_file(current_file.clone(), current_fi);
50715075

@@ -5076,6 +5080,7 @@ async fn test_find_references_from_link_position() {
50765080
fragment: "".to_string(),
50775081
line: 7,
50785082
column: 5,
5083+
origin: LinkOrigin::Body,
50795084
});
50805085
index.insert_file(other_file.clone(), other_fi);
50815086
}
@@ -5096,7 +5101,7 @@ async fn test_find_references_from_link_position() {
50965101

50975102
#[tokio::test]
50985103
async fn test_find_references_from_target_file_without_selecting_link() {
5099-
use crate::workspace_index::{CrossFileLinkIndex, FileIndex};
5104+
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, LinkOrigin};
51005105

51015106
let server = create_test_server();
51025107

@@ -5127,6 +5132,7 @@ async fn test_find_references_from_target_file_without_selecting_link() {
51275132
fragment: "".to_string(),
51285133
line: 5,
51295134
column: 24,
5135+
origin: LinkOrigin::Body,
51305136
});
51315137
index.insert_file(source_file.clone(), source_fi);
51325138
}
@@ -6035,7 +6041,7 @@ async fn test_lint_document_embedded_markdown_md_alias() {
60356041
/// find-references should return all cross-file links pointing to that file.
60366042
#[tokio::test]
60376043
async fn test_find_references_fallback_to_file_links() {
6038-
use crate::workspace_index::{CrossFileLinkIndex, FileIndex};
6044+
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, LinkOrigin};
60396045

60406046
let server = create_test_server();
60416047

@@ -6071,6 +6077,7 @@ async fn test_find_references_fallback_to_file_links() {
60716077
fragment: "".to_string(),
60726078
line: 5,
60736079
column: 22,
6080+
origin: LinkOrigin::Body,
60746081
});
60756082
index.insert_file(source_file.clone(), source_fi);
60766083
}
@@ -6126,7 +6133,7 @@ async fn test_find_references_fallback_no_references() {
61266133
/// When multiple files link to the same target, the fallback should return all of them.
61276134
#[tokio::test]
61286135
async fn test_find_references_fallback_multiple_sources() {
6129-
use crate::workspace_index::{CrossFileLinkIndex, FileIndex};
6136+
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, LinkOrigin};
61306137

61316138
let server = create_test_server();
61326139

@@ -6162,6 +6169,7 @@ async fn test_find_references_fallback_multiple_sources() {
61626169
fragment: fragment.to_string(),
61636170
line,
61646171
column: 1,
6172+
origin: LinkOrigin::Body,
61656173
});
61666174
index.insert_file(source.clone(), fi);
61676175
}
@@ -6190,7 +6198,7 @@ async fn test_find_references_fallback_multiple_sources() {
61906198
/// the file-level fallback (ensuring the heading path still works correctly).
61916199
#[tokio::test]
61926200
async fn test_find_references_heading_takes_priority_over_fallback() {
6193-
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, HeadingIndex};
6201+
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, HeadingIndex, LinkOrigin};
61946202

61956203
let server = create_test_server();
61966204

@@ -6231,6 +6239,7 @@ async fn test_find_references_heading_takes_priority_over_fallback() {
62316239
fragment: "installation".to_string(),
62326240
line: 3,
62336241
column: 5,
6242+
origin: LinkOrigin::Body,
62346243
});
62356244
index.insert_file(source_with_anchor.clone(), fi_a);
62366245

@@ -6241,6 +6250,7 @@ async fn test_find_references_heading_takes_priority_over_fallback() {
62416250
fragment: "".to_string(),
62426251
line: 7,
62436252
column: 10,
6253+
origin: LinkOrigin::Body,
62446254
});
62456255
index.insert_file(source_without_anchor.clone(), fi_b);
62466256
}
@@ -7547,7 +7557,7 @@ async fn test_rename_heading_with_custom_anchor_only_changes_text() {
75477557

75487558
#[tokio::test]
75497559
async fn test_rename_heading_updates_cross_file_links() {
7550-
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, HeadingIndex};
7560+
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, HeadingIndex, LinkOrigin};
75517561

75527562
let server = create_test_server();
75537563
let docs_dir = test_temp_path("rumdl-rename-test6/docs");
@@ -7596,6 +7606,7 @@ async fn test_rename_heading_updates_cross_file_links() {
75967606
fragment: "api-reference".to_string(),
75977607
line: 1,
75987608
column: 11, // byte column of "guide.md" in the link
7609+
origin: LinkOrigin::Body,
75997610
});
76007611
index.insert_file(source_file.clone(), source_fi);
76017612
}
@@ -7805,7 +7816,7 @@ async fn test_rename_updates_same_file_ref_definitions() {
78057816

78067817
#[tokio::test]
78077818
async fn test_rename_cross_file_multiple_links_same_line() {
7808-
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, HeadingIndex};
7819+
use crate::workspace_index::{CrossFileLinkIndex, FileIndex, HeadingIndex, LinkOrigin};
78097820

78107821
let server = create_test_server();
78117822
let docs_dir = test_temp_path("rumdl-rename-test11/docs");
@@ -7856,12 +7867,14 @@ async fn test_rename_cross_file_multiple_links_same_line() {
78567867
fragment: "getting-started".to_string(),
78577868
line: 1,
78587869
column: 9,
7870+
origin: LinkOrigin::Body,
78597871
});
78607872
source_fi.add_cross_file_link(CrossFileLinkIndex {
78617873
target_path: "guide.md".to_string(),
78627874
fragment: "getting-started".to_string(),
78637875
line: 1,
78647876
column: 43,
7877+
origin: LinkOrigin::Body,
78657878
});
78667879
index.insert_file(source_file.clone(), source_fi);
78677880
}

0 commit comments

Comments
 (0)