Skip to content

Commit f3cd385

Browse files
committed
Hide diagnostics from virtual documents
1 parent 012d457 commit f3cd385

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

apps/vscode/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,13 @@
10451045
"default": true,
10461046
"markdownDescription": "Use reticulate to execute Python cells within Knitr engine documents."
10471047
},
1048+
"quarto.vdoc.hideDiagnostics": {
1049+
"order": 26,
1050+
"scope": "window",
1051+
"type": "boolean",
1052+
"default": true,
1053+
"markdownDescription": "Hide diagnostics (problems) reported for internal virtual document files. These are temporary files used to provide language features in code blocks."
1054+
},
10481055
"quarto.mathjax.scale": {
10491056
"order": 15,
10501057
"scope": "window",

apps/vscode/src/lsp/client.ts

Lines changed: 26 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,13 +47,15 @@ import {
4647
ProvideHoverSignature,
4748
ProvideSignatureHelpSignature,
4849
State,
50+
HandleDiagnosticsSignature
4951
} from "vscode-languageclient";
5052
import { MarkdownEngine } from "../markdown/engine";
5153
import {
5254
adjustedPosition,
5355
unadjustedRange,
5456
virtualDoc,
5557
withVirtualDocUri,
58+
isVirtualDoc,
5659
} from "../vdoc/vdoc";
5760
import { activateVirtualDocEmbeddedContent } from "../vdoc/vdoc-content";
5861
import { vdocCompletions } from "../vdoc/vdoc-completion";
@@ -112,6 +115,9 @@ export async function activateLsp(
112115
if (config.get("cells.signatureHelp.enabled", true)) {
113116
middleware.provideSignatureHelp = embeddedSignatureHelpProvider(engine);
114117
}
118+
if (config.get("vdoc.hideDiagnostics", true)) {
119+
middleware.handleDiagnostics = createDiagnosticFilter();
120+
}
115121
extensionHost().registerStatementRangeProvider(engine);
116122
extensionHost().registerHelpTopicProvider(engine);
117123

@@ -338,3 +344,22 @@ function isWithinYamlComment(doc: TextDocument, pos: Position) {
338344
const line = doc.lineAt(pos.line).text;
339345
return !!line.match(/^\s*#\s*\| /);
340346
}
347+
348+
/**
349+
* Creates a diagnostic handler middleware that filters out diagnostics from virtual documents
350+
*
351+
* @param enabled Whether filtering is enabled
352+
* @returns A handler function for the middleware
353+
*/
354+
function createDiagnosticFilter() {
355+
return (uri: Uri, diagnostics: Diagnostic[], next: HandleDiagnosticsSignature) => {
356+
// If filtering is disabled or this is not a virtual document, pass through all diagnostics
357+
if (!isVirtualDoc(uri)) {
358+
next(uri, diagnostics);
359+
return;
360+
}
361+
362+
// For virtual documents, filter out all diagnostics
363+
next(uri, []);
364+
};
365+
}

apps/vscode/src/vdoc/vdoc.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import { Position, TextDocument, Uri, Range } from "vscode";
1717
import { Token, isExecutableLanguageBlock, languageBlockAtPosition, languageNameFromBlock } from "quarto-core";
18+
import * as path from "path";
1819

1920
import { isQuartoDoc } from "../core/doc";
2021
import { MarkdownEngine } from "../markdown/engine";
@@ -53,6 +54,17 @@ export async function virtualDoc(
5354
}
5455
}
5556

57+
export function isVirtualDoc(uri: Uri): boolean {
58+
// Check for tempfile virtual docs
59+
if (uri.scheme === "file") {
60+
const filename = path.basename(uri.fsPath);
61+
// Virtual docs have a specific filename pattern .vdoc.[uuid].[extension]
62+
return filename.startsWith(".vdoc.") && filename.split(".").length > 3;
63+
}
64+
65+
return false;
66+
}
67+
5668
export function virtualDocForBlock(document: TextDocument, block: Token, language: EmbeddedLanguage) {
5769
const lines = linesForLanguage(document, language);
5870
fillLinesFromBlock(lines, document, block);

0 commit comments

Comments
 (0)