-
Notifications
You must be signed in to change notification settings - Fork 44
Hide diagnostics from virtual documents #832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import * as vscode from "vscode"; | ||
| import * as assert from "assert"; | ||
| import { createDiagnosticFilter } from "../lsp/client"; | ||
|
|
||
| suite("Diagnostic Filtering", function () { | ||
|
|
||
| test("Diagnostic filter removes diagnostics for virtual documents", async function () { | ||
| // Create mocks | ||
| const virtualDocUri = vscode.Uri.file("/tmp/.vdoc.12345678-1234-1234-1234-123456789abc.py"); | ||
| const regularDocUri = vscode.Uri.file("/tmp/regular-file.py"); | ||
|
|
||
| // Create some test diagnostics | ||
| const testDiagnostics = [ | ||
| new vscode.Diagnostic( | ||
| new vscode.Range(0, 0, 0, 10), | ||
| "Test diagnostic message", | ||
| vscode.DiagnosticSeverity.Error | ||
| ) | ||
| ]; | ||
|
|
||
| // Create a mock diagnostics handler function to verify behavior | ||
| let capturedUri: vscode.Uri | undefined; | ||
| let capturedDiagnostics: vscode.Diagnostic[] | undefined; | ||
|
|
||
| const mockHandler = (uri: vscode.Uri, diagnostics: vscode.Diagnostic[]) => { | ||
| capturedUri = uri; | ||
| capturedDiagnostics = diagnostics; | ||
| }; | ||
|
|
||
| // Create the filter function | ||
| const diagnosticFilter = createDiagnosticFilter(); | ||
|
|
||
| // Test with a virtual document | ||
| diagnosticFilter(virtualDocUri, testDiagnostics, mockHandler); | ||
|
|
||
| // Verify diagnostics were filtered (empty array) | ||
| assert.strictEqual(capturedUri, virtualDocUri, "URI should be passed through"); | ||
| assert.strictEqual(capturedDiagnostics!.length, 0, "Diagnostics should be empty for virtual documents"); | ||
|
|
||
| // Reset captured values | ||
| capturedUri = undefined; | ||
| capturedDiagnostics = undefined; | ||
|
|
||
| // Test with a regular document | ||
| diagnosticFilter(regularDocUri, testDiagnostics, mockHandler); | ||
|
|
||
| // Verify diagnostics were not filtered | ||
| assert.strictEqual(capturedUri, regularDocUri, "URI should be passed through"); | ||
| assert.strictEqual(capturedDiagnostics!.length, testDiagnostics.length, "Diagnostics should not be filtered for regular documents"); | ||
| assert.deepStrictEqual(capturedDiagnostics!, testDiagnostics, "Original diagnostics should be passed through unchanged"); | ||
| }); | ||
|
|
||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
|
|
||
| import { Position, TextDocument, Uri, Range } from "vscode"; | ||
| import { Token, isExecutableLanguageBlock, languageBlockAtPosition, languageNameFromBlock } from "quarto-core"; | ||
| import * as path from "path"; | ||
|
|
||
| import { isQuartoDoc } from "../core/doc"; | ||
| import { MarkdownEngine } from "../markdown/engine"; | ||
|
|
@@ -53,6 +54,17 @@ export async function virtualDoc( | |
| } | ||
| } | ||
|
|
||
| export function isVirtualDoc(uri: Uri): boolean { | ||
| // Check for tempfile virtual docs | ||
| if (uri.scheme === "file") { | ||
| const filename = path.basename(uri.fsPath); | ||
| // Virtual docs have a specific filename pattern .vdoc.[uuid].[extension] | ||
| return filename.startsWith(".vdoc.") && filename.split(".").length > 3; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
||
|
|
||
| export function virtualDocForBlock(document: TextDocument, block: Token, language: EmbeddedLanguage) { | ||
| const lines = linesForLanguage(document, language); | ||
| fillLinesFromBlock(lines, document, block); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I see any reason to have this option
In the long term I'd actually like if Quarto didn't generate virtual docs at all, which would render this option kind of useless anyways!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great point! If we're trying to deal with problems in this area, then we're just using a dev build anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for reviving a closed PR conversation, but @DavisVaughan do you have something in mind for replacing virtual docs?