The cross-spawn-spawner module has been moved from src/effect/ to src/ to simplify the core package structure. The src/types.d.ts file which contained unused type declarations has also been removed. All imports throughout the codebase have been updated to reflect the new location. This change reduces the package's internal complexity by flattening the module hierarchy and removing dead code, making future maintenance easier.
110 lines
3.1 KiB
TypeScript
110 lines
3.1 KiB
TypeScript
import { describe, expect, spyOn } from "bun:test"
|
|
import path from "path"
|
|
import { Effect, Layer } from "effect"
|
|
import { LSP } from "../../src/lsp"
|
|
import { LSPServer } from "../../src/lsp"
|
|
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
|
import { provideTmpdirInstance } from "../fixture/fixture"
|
|
import { testEffect } from "../lib/effect"
|
|
|
|
const it = testEffect(Layer.mergeAll(LSP.defaultLayer, CrossSpawnSpawner.defaultLayer))
|
|
|
|
describe("lsp.spawn", () => {
|
|
it.live("does not spawn builtin LSP for files outside instance", () =>
|
|
provideTmpdirInstance(
|
|
(dir) =>
|
|
LSP.Service.use((lsp) =>
|
|
Effect.gen(function* () {
|
|
const spy = spyOn(LSPServer.Typescript, "spawn").mockResolvedValue(undefined)
|
|
|
|
try {
|
|
yield* lsp.touchFile(path.join(dir, "..", "outside.ts"))
|
|
yield* lsp.hover({
|
|
file: path.join(dir, "..", "hover.ts"),
|
|
line: 0,
|
|
character: 0,
|
|
})
|
|
expect(spy).toHaveBeenCalledTimes(0)
|
|
} finally {
|
|
spy.mockRestore()
|
|
}
|
|
}),
|
|
),
|
|
{ config: { lsp: true } },
|
|
),
|
|
)
|
|
|
|
it.live("does not spawn builtin LSP for files inside instance when LSP is unset", () =>
|
|
provideTmpdirInstance((dir) =>
|
|
LSP.Service.use((lsp) =>
|
|
Effect.gen(function* () {
|
|
const spy = spyOn(LSPServer.Typescript, "spawn").mockResolvedValue(undefined)
|
|
|
|
try {
|
|
yield* lsp.hover({
|
|
file: path.join(dir, "src", "inside.ts"),
|
|
line: 0,
|
|
character: 0,
|
|
})
|
|
expect(spy).toHaveBeenCalledTimes(0)
|
|
} finally {
|
|
spy.mockRestore()
|
|
}
|
|
}),
|
|
),
|
|
),
|
|
)
|
|
|
|
it.live("would spawn builtin LSP for files inside instance when lsp is true", () =>
|
|
provideTmpdirInstance(
|
|
(dir) =>
|
|
LSP.Service.use((lsp) =>
|
|
Effect.gen(function* () {
|
|
const spy = spyOn(LSPServer.Typescript, "spawn").mockResolvedValue(undefined)
|
|
|
|
try {
|
|
yield* lsp.hover({
|
|
file: path.join(dir, "src", "inside.ts"),
|
|
line: 0,
|
|
character: 0,
|
|
})
|
|
expect(spy).toHaveBeenCalledTimes(1)
|
|
} finally {
|
|
spy.mockRestore()
|
|
}
|
|
}),
|
|
),
|
|
{ config: { lsp: true } },
|
|
),
|
|
)
|
|
|
|
it.live("would spawn builtin LSP for files inside instance when config object is provided", () =>
|
|
provideTmpdirInstance(
|
|
(dir) =>
|
|
LSP.Service.use((lsp) =>
|
|
Effect.gen(function* () {
|
|
const spy = spyOn(LSPServer.Typescript, "spawn").mockResolvedValue(undefined)
|
|
|
|
try {
|
|
yield* lsp.hover({
|
|
file: path.join(dir, "src", "inside.ts"),
|
|
line: 0,
|
|
character: 0,
|
|
})
|
|
expect(spy).toHaveBeenCalledTimes(1)
|
|
} finally {
|
|
spy.mockRestore()
|
|
}
|
|
}),
|
|
),
|
|
{
|
|
config: {
|
|
lsp: {
|
|
eslint: { disabled: true },
|
|
},
|
|
},
|
|
},
|
|
),
|
|
)
|
|
})
|