Skip to content

Commit 44a1094

Browse files
committed
fix: check if the uri is a folder before trying to open it as a document
1 parent 7bef4f0 commit 44a1094

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/integrations/diagnostics/index.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export async function diagnosticsToProblemsString(
7878
const documents = new Map<vscode.Uri, vscode.TextDocument>()
7979
let result = ""
8080
for (const [uri, fileDiagnostics] of diagnostics) {
81-
const problems = fileDiagnostics.filter((d) => severities.includes(d.severity))
81+
const problems = fileDiagnostics
82+
.filter((d) => severities.includes(d.severity))
83+
.sort((a, b) => a.range.start.line - b.range.start.line)
8284
if (problems.length > 0) {
8385
result += `\n\n${path.relative(cwd, uri.fsPath).toPosix()}`
8486
for (const diagnostic of problems) {
@@ -101,10 +103,19 @@ export async function diagnosticsToProblemsString(
101103
}
102104
const line = diagnostic.range.start.line + 1 // VSCode lines are 0-indexed
103105
const source = diagnostic.source ? `${diagnostic.source} ` : ""
104-
const document = documents.get(uri) || (await vscode.workspace.openTextDocument(uri))
105-
documents.set(uri, document)
106-
const lineContent = document.lineAt(diagnostic.range.start.line).text
107-
result += `\n- [${source}${label}] ${line} | ${lineContent} : ${diagnostic.message}`
106+
try {
107+
const fileStat = await vscode.workspace.fs.stat(uri)
108+
if (fileStat.type === vscode.FileType.File) {
109+
const document = documents.get(uri) || (await vscode.workspace.openTextDocument(uri))
110+
documents.set(uri, document)
111+
const lineContent = document.lineAt(diagnostic.range.start.line).text
112+
result += `\n- [${source}${label}] ${line} | ${lineContent} : ${diagnostic.message}`
113+
} else {
114+
result += `\n- [${source}${label}] 1 | (directory) : ${diagnostic.message}`
115+
}
116+
} catch {
117+
result += `\n- [${source}${label}] ${line} | (unavailable) : ${diagnostic.message}`
118+
}
108119
}
109120
}
110121
}

0 commit comments

Comments
 (0)