فهرست منبع

wip: symbols for lsp

Dax Raad 7 ماه پیش
والد
کامیت
c810b6d206
1فایلهای تغییر یافته به همراه25 افزوده شده و 1 حذف شده
  1. 25 1
      packages/opencode/src/lsp/index.ts

+ 25 - 1
packages/opencode/src/lsp/index.ts

@@ -4,10 +4,34 @@ import { LSPClient } from "./client"
 import path from "path"
 import path from "path"
 import { LSPServer } from "./server"
 import { LSPServer } from "./server"
 import { Ripgrep } from "../file/ripgrep"
 import { Ripgrep } from "../file/ripgrep"
+import { z } from "zod"
 
 
 export namespace LSP {
 export namespace LSP {
   const log = Log.create({ service: "lsp" })
   const log = Log.create({ service: "lsp" })
 
 
+  export const Symbol = z
+    .object({
+      name: z.string(),
+      kind: z.number(),
+      location: z.object({
+        uri: z.string(),
+        range: z.object({
+          start: z.object({
+            line: z.number(),
+            character: z.number(),
+          }),
+          end: z.object({
+            line: z.number(),
+            character: z.number(),
+          }),
+        }),
+      }),
+    })
+    .openapi({
+      ref: "LSP.Symbol",
+    })
+  export type Symbol = z.infer<typeof Symbol>
+
   const state = App.state(
   const state = App.state(
     "lsp",
     "lsp",
     async (app) => {
     async (app) => {
@@ -96,7 +120,7 @@ export namespace LSP {
       client.connection.sendRequest("workspace/symbol", {
       client.connection.sendRequest("workspace/symbol", {
         query,
         query,
       }),
       }),
-    )
+    ).then((result) => result.flat() as LSP.Symbol[])
   }
   }
 
 
   async function run<T>(
   async function run<T>(