Skip to content

Commit d852189

Browse files
committed
Add reminder to update lsp-extensions.md
1 parent b62f48f commit d852189

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

docs/dev/lsp-extensions.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<!---
2+
lsp_ext.rs hash: 286f8bbac885531a
3+
4+
If you need to change the above hash to make the test pass, please check if you
5+
need to adjust this doc as well and ping this issue:
6+
7+
https://github.com/rust-analyzer/rust-analyzer/issues/4604
8+
9+
--->
10+
111
# LSP Extensions
212

313
This document describes LSP extensions used by rust-analyzer.

xtask/tests/tidy.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,41 @@ fn smoke_test_docs_generation() {
4444
codegen::generate_feature_docs(Mode::Overwrite).unwrap();
4545
}
4646

47+
#[test]
48+
fn check_lsp_extensions_docs() {
49+
let expected_hash = {
50+
let lsp_ext_rs =
51+
fs2::read_to_string(project_root().join("crates/rust-analyzer/src/lsp_ext.rs"))
52+
.unwrap();
53+
stable_hash(lsp_ext_rs.as_str())
54+
};
55+
56+
let actual_hash = {
57+
let lsp_extensions_md =
58+
fs2::read_to_string(project_root().join("docs/dev/lsp-extensions.md")).unwrap();
59+
let text = lsp_extensions_md
60+
.lines()
61+
.find_map(|line| line.strip_prefix("lsp_ext.rs hash:"))
62+
.unwrap()
63+
.trim();
64+
u64::from_str_radix(text, 16).unwrap()
65+
};
66+
67+
if actual_hash != expected_hash {
68+
panic!(
69+
"
70+
lsp_ext.rs was changed without touching lsp-extensions.md.
71+
72+
Expected hash: {:x}
73+
Actual hash: {:x}
74+
75+
Please adjust docs/dev/lsp-extensions.md.
76+
",
77+
expected_hash, actual_hash
78+
)
79+
}
80+
}
81+
4782
#[test]
4883
fn rust_files_are_tidy() {
4984
let mut tidy_docs = TidyDocs::default();
@@ -280,3 +315,13 @@ fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool {
280315
.filter_map(|it| it.as_os_str().to_str())
281316
.any(|it| dirs_to_exclude.contains(&it))
282317
}
318+
319+
#[allow(deprecated)]
320+
fn stable_hash(text: &str) -> u64 {
321+
use std::hash::{Hash, Hasher, SipHasher};
322+
323+
let text = text.replace('\r', "");
324+
let mut hasher = SipHasher::default();
325+
text.hash(&mut hasher);
326+
hasher.finish()
327+
}

0 commit comments

Comments
 (0)