From bd2c54e04cf5560826f1aa9eaea6691fd6ef6d45 Mon Sep 17 00:00:00 2001 From: Oliver Mannion <125105+tekumara@users.noreply.github.com> Date: Mon, 8 Apr 2024 21:11:20 +1000 Subject: [PATCH 1/2] refactor: extract Ignores into typos.rs --- crates/typos-lsp/src/lsp.rs | 35 +++-------------------------------- crates/typos-lsp/src/typos.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/crates/typos-lsp/src/lsp.rs b/crates/typos-lsp/src/lsp.rs index c0d81b7..a2203e4 100644 --- a/crates/typos-lsp/src/lsp.rs +++ b/crates/typos-lsp/src/lsp.rs @@ -12,7 +12,7 @@ use tower_lsp::{Client, LanguageServer}; use typos_cli::policy; use crate::state::{url_path_sanitised, BackendState}; -use crate::typos::AccumulatePosition; +use crate::typos::{AccumulatePosition, Ignores}; pub struct Backend<'s, 'p> { client: Client, state: Mutex>, @@ -228,34 +228,6 @@ impl LanguageServer for Backend<'static, 'static> { } } -// copied from https://github.com/crate-ci/typos/blob/c15b28fff9a814f9c12bd24cb1cfc114037e9187/crates/typos-cli/src/file.rs#L741 -#[derive(Clone, Debug)] -struct Ignores { - blocks: Vec>, -} - -impl Ignores { - fn new(content: &[u8], ignores: &[regex::Regex]) -> Self { - let mut blocks = Vec::new(); - if let Ok(content) = std::str::from_utf8(content) { - for ignore in ignores { - for mat in ignore.find_iter(content) { - blocks.push(mat.range()); - } - } - } - Self { blocks } - } - - fn is_ignored(&self, span: std::ops::Range) -> bool { - let start = span.start; - let end = span.end.saturating_sub(1); - self.blocks - .iter() - .any(|block| block.contains(&start) || block.contains(&end)) - } -} - impl<'s, 'p> Backend<'s, 'p> { pub fn new(client: Client) -> Self { Self { @@ -273,6 +245,8 @@ impl<'s, 'p> Backend<'s, 'p> { } // mimics typos_cli::file::FileChecker::check_file + // see https://github.com/crate-ci/typos/blob/c15b28fff9a814f9c12bd24cb1cfc114037e9187/crates/typos-cli/src/file.rs#L43 + // but using check_str instead of check_bytes fn check_text(&self, buffer: &str, uri: &Url) -> Vec { let state = self.state.lock().unwrap(); @@ -327,9 +301,6 @@ impl<'s, 'p> Backend<'s, 'p> { let mut accum = AccumulatePosition::new(); - // mimics https://github.com/crate-ci/typos/blob/c15b28fff9a814f9c12bd24cb1cfc114037e9187/crates/typos-cli/src/file.rs#L43 - // but using check_str instead of check_bytes - let mut ignores: Option = None; typos::check_str(buffer, tokenizer, dict) diff --git a/crates/typos-lsp/src/typos.rs b/crates/typos-lsp/src/typos.rs index b3446b2..5ac4758 100644 --- a/crates/typos-lsp/src/typos.rs +++ b/crates/typos-lsp/src/typos.rs @@ -52,6 +52,35 @@ impl Instance<'_> { } } + +// copied from https://github.com/crate-ci/typos/blob/c15b28fff9a814f9c12bd24cb1cfc114037e9187/crates/typos-cli/src/file.rs#L741 +#[derive(Clone, Debug)] +pub(crate) struct Ignores { + blocks: Vec>, +} + +impl Ignores { + pub(crate) fn new(content: &[u8], ignores: &[regex::Regex]) -> Self { + let mut blocks = Vec::new(); + if let Ok(content) = std::str::from_utf8(content) { + for ignore in ignores { + for mat in ignore.find_iter(content) { + blocks.push(mat.range()); + } + } + } + Self { blocks } + } + + pub(crate) fn is_ignored(&self, span: std::ops::Range) -> bool { + let start = span.start; + let end = span.end.saturating_sub(1); + self.blocks + .iter() + .any(|block| block.contains(&start) || block.contains(&end)) + } +} + pub struct AccumulatePosition { line_num: usize, line_pos: usize, From 40728f7964249b80b0e08e66a9a20597eddd12a0 Mon Sep 17 00:00:00 2001 From: "potatobot-prime[bot]" <132267321+potatobot-prime[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 11:14:17 +0000 Subject: [PATCH 2/2] chore(main): release 0.1.17 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 15 +++++++++++++++ Cargo.lock | 2 +- crates/typos-lsp/Cargo.toml | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 8d8a2b5..88efc87 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.16" + ".": "0.1.17" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d05f3d..f2e848d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## [0.1.17](https://github.com/tekumara/typos-lsp/compare/v0.1.16...v0.1.17) (2024-04-08) + + +### Features + +* check vscode source control commit messages ([53d3bf5](https://github.com/tekumara/typos-lsp/commit/53d3bf5651015d6f4bd2b7c9088dc5845c1884d3)), closes [#59](https://github.com/tekumara/typos-lsp/issues/59) +* support extend-ignore-re config field ([1a03b6f](https://github.com/tekumara/typos-lsp/commit/1a03b6ff84d6cb2e85ddb8eb925445446b3bff8a)), closes [#55](https://github.com/tekumara/typos-lsp/issues/55) +* typos 1.20.4 Mar 2024 dictionary ([4a559ff](https://github.com/tekumara/typos-lsp/commit/4a559fffce361fca5e68aa822764d85ba3f8bebd)) + + +### Chores + +* **deps-dev:** bump the vscode group with 4 updates ([#57](https://github.com/tekumara/typos-lsp/issues/57)) ([c1b26fe](https://github.com/tekumara/typos-lsp/commit/c1b26fe85067d239cdb80ed864bd1b5a6c154109)) +* **deps:** bump the lsp group with 1 update ([#56](https://github.com/tekumara/typos-lsp/issues/56)) ([40190c6](https://github.com/tekumara/typos-lsp/commit/40190c6db6c9bf2b8d482e141431d3bf7b1e1c2a)) + ## [0.1.16](https://github.com/tekumara/typos-lsp/compare/v0.1.15...v0.1.16) (2024-03-26) diff --git a/Cargo.lock b/Cargo.lock index aa11704..0d668b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1517,7 +1517,7 @@ dependencies = [ [[package]] name = "typos-lsp" -version = "0.1.16" +version = "0.1.17" dependencies = [ "anyhow", "bstr 1.9.1", diff --git a/crates/typos-lsp/Cargo.toml b/crates/typos-lsp/Cargo.toml index d5aa709..3ffec3a 100644 --- a/crates/typos-lsp/Cargo.toml +++ b/crates/typos-lsp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "typos-lsp" -version = "0.1.16" +version = "0.1.17" edition = "2021" [dependencies] diff --git a/package-lock.json b/package-lock.json index 18cbb14..cd7d689 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "typos-vscode", - "version": "0.1.16", + "version": "0.1.17", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "typos-vscode", - "version": "0.1.16", + "version": "0.1.17", "license": "MIT", "dependencies": { "vscode-languageclient": "^9.0.1" diff --git a/package.json b/package.json index eacba05..11dba5e 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Typos spell checker", "description": "Low false-positive source code spell checker", "publisher": "tekumara", - "version": "0.1.16", + "version": "0.1.17", "private": true, "icon": "images/typos.png", "repository": {