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