fix lsp diagnostic accurancy

This commit is contained in:
Dax Raad
2025-06-30 22:46:42 -04:00
parent fea56d8de6
commit de15e67834
8 changed files with 299 additions and 104 deletions

View File

@@ -1,5 +1,8 @@
import { z } from "zod"
import { Bus } from "../bus"
import { $ } from "bun"
import { createPatch } from "diff"
import path from "path"
export namespace File {
export const Event = {
@@ -10,4 +13,26 @@ export namespace File {
}),
),
}
export async function read(file: string) {
const content = await Bun.file(file).text()
const gitDiff = await $`git diff HEAD -- ${file}`
.cwd(path.dirname(file))
.quiet()
.nothrow()
.text()
if (gitDiff.trim()) {
const relativePath = path.relative(process.cwd(), file)
const originalContent = await $`git show HEAD:./${relativePath}`
.cwd(process.cwd())
.quiet()
.nothrow()
.text()
if (originalContent.trim()) {
const patch = createPatch(file, originalContent, content)
return patch
}
}
return content.trim()
}
}