| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import { describe, expect, test, beforeEach } from "bun:test"
- import path from "path"
- import { LSPClient } from "../../src/lsp/client"
- import { LSPServer } from "../../src/lsp/server"
- import { Instance } from "../../src/project/instance"
- import { Log } from "../../src/util/log"
- // Minimal fake LSP server that speaks JSON-RPC over stdio
- function spawnFakeServer() {
- const { spawn } = require("child_process")
- const serverPath = path.join(__dirname, "../fixture/lsp/fake-lsp-server.js")
- return {
- process: spawn(process.execPath, [serverPath], {
- stdio: "pipe",
- }),
- }
- }
- describe("LSPClient interop", () => {
- beforeEach(async () => {
- await Log.init({ print: true })
- })
- test("handles workspace/workspaceFolders request", async () => {
- const handle = spawnFakeServer() as any
- const client = await Instance.provide({
- directory: process.cwd(),
- fn: () =>
- LSPClient.create({
- serverID: "fake",
- server: handle as unknown as LSPServer.Handle,
- root: process.cwd(),
- }),
- })
- await client.connection.sendNotification("test/trigger", {
- method: "workspace/workspaceFolders",
- })
- await new Promise((r) => setTimeout(r, 100))
- expect(client.connection).toBeDefined()
- await client.shutdown()
- })
- test("handles client/registerCapability request", async () => {
- const handle = spawnFakeServer() as any
- const client = await Instance.provide({
- directory: process.cwd(),
- fn: () =>
- LSPClient.create({
- serverID: "fake",
- server: handle as unknown as LSPServer.Handle,
- root: process.cwd(),
- }),
- })
- await client.connection.sendNotification("test/trigger", {
- method: "client/registerCapability",
- })
- await new Promise((r) => setTimeout(r, 100))
- expect(client.connection).toBeDefined()
- await client.shutdown()
- })
- test("handles client/unregisterCapability request", async () => {
- const handle = spawnFakeServer() as any
- const client = await Instance.provide({
- directory: process.cwd(),
- fn: () =>
- LSPClient.create({
- serverID: "fake",
- server: handle as unknown as LSPServer.Handle,
- root: process.cwd(),
- }),
- })
- await client.connection.sendNotification("test/trigger", {
- method: "client/unregisterCapability",
- })
- await new Promise((r) => setTimeout(r, 100))
- expect(client.connection).toBeDefined()
- await client.shutdown()
- })
- })
|