Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat: lint the Source Control commit message box (#3729)

Dmytro Soroka3f07e1610cda
diff --git a/harper-ls/src/backend.rs b/harper-ls/src/backend.rs
index 33c86511c..e797544e8 100644
--- a/harper-ls/src/backend.rs
+++ b/harper-ls/src/backend.rs
@@ -361,7 +361,9 @@ impl Backend {
Some(Box::new(ts_parser))
}
}
- "git-commit" | "gitcommit" | "octo" => Some(Box::new(GitCommitParser::default())),
+ "git-commit" | "gitcommit" | "octo" | "scminput" => {
+ Some(Box::new(GitCommitParser::default()))
+ }
"html" => Some(Box::new(HtmlParser::default())),
"asciidoc" => Some(Box::new(AsciidocParser::default())),
"ink" => Some(Box::new(InkParser::default())),
diff --git a/packages/vscode-plugin/package.json b/packages/vscode-plugin/package.json
index fc4e0fe72..923e39f41 100644
--- a/packages/vscode-plugin/package.json
+++ b/packages/vscode-plugin/package.json
@@ -62,6 +62,7 @@
"onLanguage:ruby",
"onLanguage:rust",
"onLanguage:scala",
+ "onLanguage:scminput",
"onLanguage:shellscript",
"onLanguage:solidity",
"onLanguage:swift",
diff --git a/packages/vscode-plugin/src/extension.ts b/packages/vscode-plugin/src/extension.ts
index 8501f016c..5968495d6 100644
--- a/packages/vscode-plugin/src/extension.ts
+++ b/packages/vscode-plugin/src/extension.ts
@@ -70,6 +70,14 @@ export async function activate(context: ExtensionContext): Promise<void> {
.filter((e) => e.startsWith('onLanguage:'))
.flatMap((e) => {
const language = e.split(':')[1];
+
+ // The Source Control commit message box is a document with the
+ // `scminput` language id. It is not backed by a file on disk, so it is
+ // matched by language alone rather than by scheme.
+ if (language === 'scminput') {
+ return [{ language: 'scminput' }];
+ }
+
return [
{ language, scheme: 'file' },
{ language, scheme: 'untitled' },
diff --git a/packages/vscode-plugin/src/tests/suite/integration.test.ts b/packages/vscode-plugin/src/tests/suite/integration.test.ts
index f3fb11bc7..7584add28 100644
--- a/packages/vscode-plugin/src/tests/suite/integration.test.ts
+++ b/packages/vscode-plugin/src/tests/suite/integration.test.ts
@@ -108,6 +108,26 @@ describe('Integration >', () => {
);
});
+ it('gives correct diagnostics for the Source Control commit message box', async () => {
+ // The Source Control commit box uses the `scminput` language id. Harper
+ // should lint it like a git commit message, so the subject line is checked
+ // while lines starting with `#` (comments) are ignored.
+ const untitledUri = await openUntitled('Errorz\n# Errorz');
+
+ compareActualVsExpectedDiagnostics(
+ await waitForDiagnosticsChange(
+ untitledUri,
+ async () => await setTextDocumentLanguage(untitledUri, 'scminput'),
+ ),
+ createExpectedDiagnostics({
+ message: 'Did you mean to spell `Errorz` this way?',
+ range: createRange(0, 0, 0, 6),
+ source: 'Harper',
+ code: 'SpellCheck',
+ }),
+ );
+ });
+
it('updates diagnostics on configuration change', async () => {
const config = workspace.getConfiguration('harper.linters');