Skip to content

Commit 67faaf3

Browse files
committed
Write a little (mocked) test
1 parent f3cd385 commit 67faaf3

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

apps/vscode/src/lsp/client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,11 @@ function isWithinYamlComment(doc: TextDocument, pos: Position) {
348348
/**
349349
* Creates a diagnostic handler middleware that filters out diagnostics from virtual documents
350350
*
351-
* @param enabled Whether filtering is enabled
352351
* @returns A handler function for the middleware
353352
*/
354-
function createDiagnosticFilter() {
353+
export function createDiagnosticFilter() {
355354
return (uri: Uri, diagnostics: Diagnostic[], next: HandleDiagnosticsSignature) => {
356-
// If filtering is disabled or this is not a virtual document, pass through all diagnostics
355+
// If this is not a virtual document, pass through all diagnostics
357356
if (!isVirtualDoc(uri)) {
358357
next(uri, diagnostics);
359358
return;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as vscode from "vscode";
2+
import * as assert from "assert";
3+
import { createDiagnosticFilter } from "../lsp/client";
4+
5+
suite("Diagnostic Filtering", function () {
6+
7+
test("Diagnostic filter removes diagnostics for virtual documents", async function () {
8+
// Create mocks
9+
const virtualDocUri = vscode.Uri.file("/tmp/.vdoc.12345678-1234-1234-1234-123456789abc.py");
10+
const regularDocUri = vscode.Uri.file("/tmp/regular-file.py");
11+
12+
// Create some test diagnostics
13+
const testDiagnostics = [
14+
new vscode.Diagnostic(
15+
new vscode.Range(0, 0, 0, 10),
16+
"Test diagnostic message",
17+
vscode.DiagnosticSeverity.Error
18+
)
19+
];
20+
21+
// Create a mock diagnostics handler function to verify behavior
22+
let capturedUri: vscode.Uri | undefined;
23+
let capturedDiagnostics: vscode.Diagnostic[] | undefined;
24+
25+
const mockHandler = (uri: vscode.Uri, diagnostics: vscode.Diagnostic[]) => {
26+
capturedUri = uri;
27+
capturedDiagnostics = diagnostics;
28+
};
29+
30+
// Create the filter function
31+
const diagnosticFilter = createDiagnosticFilter();
32+
33+
// Test with a virtual document
34+
diagnosticFilter(virtualDocUri, testDiagnostics, mockHandler);
35+
36+
// Verify diagnostics were filtered (empty array)
37+
assert.strictEqual(capturedUri, virtualDocUri, "URI should be passed through");
38+
assert.strictEqual(capturedDiagnostics!.length, 0, "Diagnostics should be empty for virtual documents");
39+
40+
// Reset captured values
41+
capturedUri = undefined;
42+
capturedDiagnostics = undefined;
43+
44+
// Test with a regular document
45+
diagnosticFilter(regularDocUri, testDiagnostics, mockHandler);
46+
47+
// Verify diagnostics were not filtered
48+
assert.strictEqual(capturedUri, regularDocUri, "URI should be passed through");
49+
assert.strictEqual(capturedDiagnostics!.length, testDiagnostics.length, "Diagnostics should not be filtered for regular documents");
50+
assert.deepStrictEqual(capturedDiagnostics!, testDiagnostics, "Original diagnostics should be passed through unchanged");
51+
});
52+
53+
});

0 commit comments

Comments
 (0)