Skip to content

Commit 6a93a72

Browse files
authored
Merge branch 'main' into force-save-before-switch
2 parents e92e07d + 6ac1612 commit 6a93a72

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

apps/vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fixed an issue where attribute values containing '='s could be truncated in some scenarios (<https://github.com/quarto-dev/quarto/pull/814>).
66
- Fixed an issue where a loading spinner for qmd previews wasn't dismissed on preview errors (<https://github.com/quarto-dev/quarto/pull/823>).
7+
- Diagnostics are no longer reported for internal temporary virtual document files (<https://github.com/quarto-dev/quarto/pull/832>).
78
- Fixed switching to visual mode for untitled documents in Positron (<https://github.com/quarto-dev/quarto/pull/831>).
89

910
## 1.124.0 (Release on 2025-08-20)

apps/vscode/src/lsp/client.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
LocationLink,
2424
Definition,
2525
LogOutputChannel,
26-
Uri
26+
Uri,
27+
Diagnostic
2728
} from "vscode";
2829
import {
2930
LanguageClient,
@@ -46,6 +47,7 @@ import {
4647
ProvideHoverSignature,
4748
ProvideSignatureHelpSignature,
4849
State,
50+
HandleDiagnosticsSignature
4951
} from "vscode-languageclient";
5052
import { MarkdownEngine } from "../markdown/engine";
5153
import {
@@ -54,6 +56,7 @@ import {
5456
virtualDoc,
5557
withVirtualDocUri,
5658
} from "../vdoc/vdoc";
59+
import { isVirtualDoc } from "../vdoc/vdoc-tempfile";
5760
import { activateVirtualDocEmbeddedContent } from "../vdoc/vdoc-content";
5861
import { vdocCompletions } from "../vdoc/vdoc-completion";
5962

@@ -99,6 +102,7 @@ export async function activateLsp(
99102
const config = workspace.getConfiguration("quarto");
100103
activateVirtualDocEmbeddedContent();
101104
const middleware: Middleware = {
105+
handleDiagnostics: createDiagnosticFilter(),
102106
provideCompletionItem: embeddedCodeCompletionProvider(engine),
103107
provideDefinition: embeddedGoToDefinitionProvider(engine),
104108
provideDocumentFormattingEdits: embeddedDocumentFormattingProvider(engine),
@@ -338,3 +342,21 @@ function isWithinYamlComment(doc: TextDocument, pos: Position) {
338342
const line = doc.lineAt(pos.line).text;
339343
return !!line.match(/^\s*#\s*\| /);
340344
}
345+
346+
/**
347+
* Creates a diagnostic handler middleware that filters out diagnostics from virtual documents
348+
*
349+
* @returns A handler function for the middleware
350+
*/
351+
export function createDiagnosticFilter() {
352+
return (uri: Uri, diagnostics: Diagnostic[], next: HandleDiagnosticsSignature) => {
353+
// If this is not a virtual document, pass through all diagnostics
354+
if (!isVirtualDoc(uri)) {
355+
next(uri, diagnostics);
356+
return;
357+
}
358+
359+
// For virtual documents, filter out all diagnostics
360+
next(uri, []);
361+
};
362+
}
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+
});

apps/vscode/src/vdoc/vdoc-tempfile.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,14 @@ function createVirtualDoc(filepath: string, content: string): void {
150150
function generateVirtualDocFilepath(directory: string, extension: string): string {
151151
return path.join(directory, ".vdoc." + uuid.v4() + "." + extension);
152152
}
153+
154+
export function isVirtualDoc(uri: Uri): boolean {
155+
// Check for tempfile virtual docs
156+
if (uri.scheme === "file") {
157+
const filename = path.basename(uri.fsPath);
158+
// Virtual docs have a specific filename pattern .vdoc.[uuid].[extension]
159+
return filename.startsWith(".vdoc.") && filename.split(".").length > 3;
160+
}
161+
162+
return false;
163+
}

0 commit comments

Comments
 (0)