Skip to content

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

fix(vscode-plugin): add a test to check when language is changed

Donny Kim50c24aeb490d
diff --git a/packages/vscode-plugin/src/tests/suite/helper.ts b/packages/vscode-plugin/src/tests/suite/helper.ts
index e4c079fc4..6f74a2da6 100644
--- a/packages/vscode-plugin/src/tests/suite/helper.ts
+++ b/packages/vscode-plugin/src/tests/suite/helper.ts
@@ -40,6 +40,11 @@ export async function openUntitled(text: string): Promise<Uri> {
return document.uri;
}
+export async function setTextDocumentLanguage(uri: Uri, languageId: string): Promise<void> {
+ const document = await workspace.openTextDocument(uri);
+ languages.setTextDocumentLanguage(document, languageId);
+}
+
export function getActualDiagnostics(resource: Uri): Diagnostic[] {
return languages.getDiagnostics(resource).filter((d) => d.source === 'Harper');
}
diff --git a/packages/vscode-plugin/src/tests/suite/integration.test.ts b/packages/vscode-plugin/src/tests/suite/integration.test.ts
index 1b0d020cc..4ededca13 100644
--- a/packages/vscode-plugin/src/tests/suite/integration.test.ts
+++ b/packages/vscode-plugin/src/tests/suite/integration.test.ts
@@ -11,6 +11,7 @@ import {
getActualDiagnostics,
openFile,
openUntitled,
+ setTextDocumentLanguage,
sleep,
} from './helper';
@@ -62,6 +63,41 @@ describe('Integration >', () => {
);
});
+ it('gives correct diagnostics when language is changed', async () => {
+ const untitledUri = await openUntitled('Errorz # Errorz');
+ await setTextDocumentLanguage(untitledUri, 'plaintext');
+
+ // Wait for `harper-ls` to send diagnostics
+ await sleep(500);
+
+ compareActualVsExpectedDiagnostics(
+ getActualDiagnostics(untitledUri),
+ createExpectedDiagnostics(
+ {
+ message: 'Did you mean to spell “Errorz” this way?',
+ range: createRange(0, 0, 0, 6),
+ },
+ {
+ message: 'Did you mean to spell “Errorz” this way?',
+ range: createRange(0, 9, 0, 15),
+ },
+ ),
+ );
+
+ await setTextDocumentLanguage(untitledUri, 'shellscript');
+
+ // Wait for `harper-ls` to send diagnostics
+ await sleep(500);
+
+ compareActualVsExpectedDiagnostics(
+ getActualDiagnostics(untitledUri),
+ createExpectedDiagnostics({
+ message: 'Did you mean to spell “Errorz” this way?',
+ range: createRange(0, 9, 0, 15),
+ }),
+ );
+ });
+
it('updates diagnostics on configuration change', async () => {
const config = workspace.getConfiguration('harper.linters');
await config.update('RepeatedWords', false, ConfigurationTarget.Workspace);