From d852189e56056c1c1742ad56a09c4a3e4a75b170 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 14 Oct 2020 13:30:06 +0200 Subject: Add reminder to update lsp-extensions.md --- docs/dev/lsp-extensions.md | 10 ++++++++++ xtask/tests/tidy.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md index 3f861f3e0..43a69d6ce 100644 --- a/docs/dev/lsp-extensions.md +++ b/docs/dev/lsp-extensions.md @@ -1,3 +1,13 @@ + + # LSP Extensions This document describes LSP extensions used by rust-analyzer. diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index 0c233f87d..b3bb9d543 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs @@ -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(); @@ -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() +} -- cgit v1.2.3