mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-09 02:09:12 +00:00
fix lsp diagnostic accurancy
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user