Skip to content

Add reminder to update lsp-extensions.md #6226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions docs/dev/lsp-extensions.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<!---
lsp_ext.rs hash: 286f8bbac885531a

If you need to change the above hash to make the test pass, please check if you
need to adjust this doc as well and ping this issue:

https://github.com/rust-analyzer/rust-analyzer/issues/4604

--->

# LSP Extensions

This document describes LSP extensions used by rust-analyzer.
Expand Down
45 changes: 45 additions & 0 deletions xtask/tests/tidy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,41 @@ fn smoke_test_docs_generation() {
codegen::generate_feature_docs(Mode::Overwrite).unwrap();
}

#[test]
fn check_lsp_extensions_docs() {
let expected_hash = {
let lsp_ext_rs =
fs2::read_to_string(project_root().join("crates/rust-analyzer/src/lsp_ext.rs"))
.unwrap();
stable_hash(lsp_ext_rs.as_str())
};

let actual_hash = {
let lsp_extensions_md =
fs2::read_to_string(project_root().join("docs/dev/lsp-extensions.md")).unwrap();
let text = lsp_extensions_md
.lines()
.find_map(|line| line.strip_prefix("lsp_ext.rs hash:"))
.unwrap()
.trim();
u64::from_str_radix(text, 16).unwrap()
};

if actual_hash != expected_hash {
panic!(
"
lsp_ext.rs was changed without touching lsp-extensions.md.

Expected hash: {:x}
Actual hash: {:x}

Please adjust docs/dev/lsp-extensions.md.
",
expected_hash, actual_hash
)
}
}

#[test]
fn rust_files_are_tidy() {
let mut tidy_docs = TidyDocs::default();
Expand Down Expand Up @@ -280,3 +315,13 @@ fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool {
.filter_map(|it| it.as_os_str().to_str())
.any(|it| dirs_to_exclude.contains(&it))
}

#[allow(deprecated)]
fn stable_hash(text: &str) -> u64 {
use std::hash::{Hash, Hasher, SipHasher};

let text = text.replace('\r', "");
let mut hasher = SipHasher::default();
text.hash(&mut hasher);
hasher.finish()
}