fix(vscode): skip non-file URIs in ImportDefinitionsService parser lookup (#7239)

VS Code output panel URIs (e.g. output:tasks) were being passed to
getParserForFile, causing TypeError when tree-sitter Parser failed to
load. Add early-return for non-file URI schemes and a defensive null
check on the Parser export.
This commit is contained in:
Marius
2026-03-18 09:58:23 -03:00
committed by GitHub
parent a19f4c5092
commit 7853e65503
2 changed files with 9 additions and 0 deletions
@@ -33,6 +33,12 @@ export class ImportDefinitionsService {
return null
}
// Skip non-file URIs (e.g. output:tasks, vscode:, untitled:) — these are
// VS Code virtual documents that have no parseable source.
if (/^[a-zA-Z][\w+.-]*:/.test(filepath) && !filepath.startsWith("file:") && !filepath.startsWith("/")) {
return null
}
const parser = await getParserForFile(filepath)
if (!parser) {
return {
@@ -126,6 +126,9 @@ export async function getParserForFile(filepath: string) {
try {
// Dynamically import Parser to avoid issues with WASM loading
const { Parser } = require("web-tree-sitter")
if (!Parser) {
return undefined
}
await Parser.init()
const parser = new Parser()