26bab00dab
publish / publish (push) Has been cancelled
all old sessions and share links. we'll be more backwards compatible in the future once we're more stable.
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import { z } from "zod"
|
|
import { Tool } from "./tool"
|
|
import path from "path"
|
|
import { LSP } from "../lsp"
|
|
import { App } from "../app/app"
|
|
import DESCRIPTION from "./lsp-hover.txt"
|
|
|
|
export const LspHoverTool = Tool.define({
|
|
id: "lsp_hover",
|
|
description: DESCRIPTION,
|
|
parameters: z.object({
|
|
file: z.string().describe("The path to the file to get diagnostics."),
|
|
line: z.number().describe("The line number to get diagnostics."),
|
|
character: z.number().describe("The character number to get diagnostics."),
|
|
}),
|
|
execute: async (args) => {
|
|
const app = App.info()
|
|
const file = path.isAbsolute(args.file)
|
|
? args.file
|
|
: path.join(app.path.cwd, args.file)
|
|
await LSP.touchFile(file, true)
|
|
const result = await LSP.hover({
|
|
...args,
|
|
file,
|
|
})
|
|
|
|
return {
|
|
metadata: {
|
|
result,
|
|
title:
|
|
path.relative(app.path.root, file) +
|
|
":" +
|
|
args.line +
|
|
":" +
|
|
args.character,
|
|
},
|
|
output: JSON.stringify(result, null, 2),
|
|
}
|
|
},
|
|
})
|