Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat(ls): configurable max length (#1335)
Steve Kurch57141a09153f
diff --git a/harper-ls/src/backend.rs b/harper-ls/src/backend.rsindex cf860c82b..9785894fc 100644--- a/harper-ls/src/backend.rs+++ b/harper-ls/src/backend.rs@@ -206,13 +206,14 @@ impl Backend {self.pull_config().await;// Copy necessary configuration to avoid holding lock.- let (lint_config, markdown_options, isolate_english, dialect) = {+ let (lint_config, markdown_options, isolate_english, dialect, max_file_length) = {let config = self.config.read().await;(config.lint_config.clone(),config.markdown_options,config.isolate_english,config.dialect,+ config.max_file_length,)};@@ -343,10 +344,14 @@ impl Backend {parser = Box::new(IsolateEnglish::new(parser, doc_state.dict.clone()));}- // Don't lint on large documents.- // This should eventually be configurable, but that isn't necessary yet.- if text.len() < 120_000 {+ // Don't lint on documents larger than the configured maximum length.+ if text.len() <= max_file_length {doc_state.document = Document::new(text, &parser, &doc_state.dict);+ } else {+ // Ensures that existing lints are cleared when we stop linting the file.+ // Otherwise, prior lints will remain, and they will quickly fall out of sync+ // with the document when it is edited.+ doc_state.document = Document::default();}}}diff --git a/harper-ls/src/config.rs b/harper-ls/src/config.rsindex 23eb32485..1c0b717d0 100644--- a/harper-ls/src/config.rs+++ b/harper-ls/src/config.rs@@ -73,6 +73,9 @@ pub struct Config {pub isolate_english: bool,pub markdown_options: MarkdownOptions,pub dialect: Dialect,+ /// Maximum length (in bytes) a file can have before it's skipped.+ /// Above this limit, the file will not be linted.+ pub max_file_length: usize,}impl Config {@@ -152,6 +155,10 @@ impl Config {}}+ if let Some(v) = value.get("maxFileLength") {+ base.max_file_length = serde_json::from_value(v.clone())?;+ }+if let Some(v) = value.get("markdown") {if let Some(v) = v.get("IgnoreLinkTitle") {base.markdown_options.ignore_link_title = serde_json::from_value(v.clone())?;@@ -177,6 +184,7 @@ impl Default for Config {isolate_english: false,markdown_options: MarkdownOptions::default(),dialect: Dialect::American,+ max_file_length: 120_000,}}}diff --git a/packages/vscode-plugin/package.json b/packages/vscode-plugin/package.jsonindex 270701552..cc1a69f86 100644--- a/packages/vscode-plugin/package.json+++ b/packages/vscode-plugin/package.json@@ -118,6 +118,12 @@"default": false,"description": "Skip linting link titles."},+ "harper.maxFileLength": {+ "scope": "resource",+ "type": "number",+ "default": 120000,+ "description": "Maximum length of file to be linted (in bytes). If a file is larger than this, it will not be linted."+ },"harper.userDictPath": {"scope": "resource","type": "string",diff --git a/packages/web/src/routes/docs/integrations/emacs/+page.md b/packages/web/src/routes/docs/integrations/emacs/+page.mdindex 525e34503..b93007494 100644--- a/packages/web/src/routes/docs/integrations/emacs/+page.md+++ b/packages/web/src/routes/docs/integrations/emacs/+page.md@@ -59,7 +59,8 @@ Additionally, you can also configure things like which linters to use or how you:markdown (:IgnoreLinkTitle :json-false):diagnosticSeverity "hint":isolateEnglish :json-false- :dialect "American")))+ :dialect "American"+ :maxFileLength 120000)))```:::notediff --git a/packages/web/src/routes/docs/integrations/helix/+page.md b/packages/web/src/routes/docs/integrations/helix/+page.mdindex 8b2628799..7de7bfdd0 100644--- a/packages/web/src/routes/docs/integrations/helix/+page.md+++ b/packages/web/src/routes/docs/integrations/helix/+page.md@@ -45,6 +45,7 @@ fileDictPath = ""diagnosticSeverity = "hint"isolateEnglish = falsedialect = "American"+maxFileLength = 120000[language-server.harper-ls.config.harper-ls.linters]SpellCheck = truediff --git a/packages/web/src/routes/docs/integrations/language-server/+page.md b/packages/web/src/routes/docs/integrations/language-server/+page.mdindex b2cb314e7..56b02f33d 100644--- a/packages/web/src/routes/docs/integrations/language-server/+page.md+++ b/packages/web/src/routes/docs/integrations/language-server/+page.md@@ -163,7 +163,7 @@ In the above example, "spellcheckd", "this this", and other spelling or grammar}```-## Directories+### Directories| Config | Type | Default Value | Description || -------------- | -------- | ------------- | --------------------------------------------------------------- |@@ -250,6 +250,7 @@ These configs are under the `markdown` key:| `diagnosticSeverity` | `"error"`, `"hint"`, `"information"`, `"warning"` | `"hint"` | Configures how severe diagnostics appear in your editor || `isolateEnglish` | `boolean` | `false` | In documents that are a mixture of English and another language, only lint English text. This feature is incredibly new and unstable. Do not expect it to work perfectly. || `dialect` | `"American"`, `"British"`, `"Australian"`, `"Canadian"` | `"American"` | Set the dialect of English Harper should expect. |+| `maxFileLength` | `number` | `120000` | Maximum length of file to be linted (in bytes). If a file is larger/longer than this, it will not be linted. |## Supported Languagesdiff --git a/packages/web/src/routes/docs/integrations/neovim/+page.md b/packages/web/src/routes/docs/integrations/neovim/+page.mdindex 751c371a4..86b982695 100644--- a/packages/web/src/routes/docs/integrations/neovim/+page.md+++ b/packages/web/src/routes/docs/integrations/neovim/+page.md@@ -47,7 +47,8 @@ require('lspconfig').harper_ls.setup {},diagnosticSeverity = "hint",isolateEnglish = false,- dialect = "American"+ dialect = "American",+ maxFileLength = 120000}}}