|
| 1 | +import { describe, expect, spyOn, test } from "bun:test" |
| 2 | +import path from "path" |
| 3 | +import * as Lsp from "../../src/lsp/index" |
| 4 | +import { LSPServer } from "../../src/lsp/server" |
| 5 | +import { Instance } from "../../src/project/instance" |
| 6 | +import { tmpdir } from "../fixture/fixture" |
| 7 | + |
| 8 | +describe("lsp.spawn", () => { |
| 9 | + test("does not spawn builtin LSP for files outside instance", async () => { |
| 10 | + await using tmp = await tmpdir() |
| 11 | + const spy = spyOn(LSPServer.Typescript, "spawn").mockResolvedValue(undefined) |
| 12 | + |
| 13 | + try { |
| 14 | + await Instance.provide({ |
| 15 | + directory: tmp.path, |
| 16 | + fn: async () => { |
| 17 | + await Lsp.LSP.touchFile(path.join(tmp.path, "..", "outside.ts")) |
| 18 | + await Lsp.LSP.hover({ |
| 19 | + file: path.join(tmp.path, "..", "hover.ts"), |
| 20 | + line: 0, |
| 21 | + character: 0, |
| 22 | + }) |
| 23 | + }, |
| 24 | + }) |
| 25 | + |
| 26 | + expect(spy).toHaveBeenCalledTimes(0) |
| 27 | + } finally { |
| 28 | + spy.mockRestore() |
| 29 | + await Instance.disposeAll() |
| 30 | + } |
| 31 | + }) |
| 32 | + |
| 33 | + test("would spawn builtin LSP for files inside instance", async () => { |
| 34 | + await using tmp = await tmpdir() |
| 35 | + const spy = spyOn(LSPServer.Typescript, "spawn").mockResolvedValue(undefined) |
| 36 | + |
| 37 | + try { |
| 38 | + await Instance.provide({ |
| 39 | + directory: tmp.path, |
| 40 | + fn: async () => { |
| 41 | + await Lsp.LSP.hover({ |
| 42 | + file: path.join(tmp.path, "src", "inside.ts"), |
| 43 | + line: 0, |
| 44 | + character: 0, |
| 45 | + }) |
| 46 | + }, |
| 47 | + }) |
| 48 | + |
| 49 | + expect(spy).toHaveBeenCalledTimes(1) |
| 50 | + } finally { |
| 51 | + spy.mockRestore() |
| 52 | + await Instance.disposeAll() |
| 53 | + } |
| 54 | + }) |
| 55 | +}) |
0 commit comments