11import { describe , expect , spyOn } from "bun:test"
22import path from "path"
3- import { Effect , Layer } from "effect"
3+ import { Deferred , Effect , Layer } from "effect"
4+ import { Bus } from "@/bus"
45import { Config } from "@/config/config"
56import { RuntimeFlags } from "@/effect/runtime-flags"
67import { LSP } from "@/lsp/lsp"
78import * as LSPServer from "@/lsp/server"
89import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
910import { provideTmpdirInstance } from "../fixture/fixture"
10- import { testEffect } from "../lib/effect"
11+ import { awaitWithTimeout , testEffect } from "../lib/effect"
1112
1213const it = testEffect ( Layer . mergeAll ( LSP . defaultLayer , CrossSpawnSpawner . defaultLayer ) )
1314const experimentalTyIt = testEffect (
@@ -16,6 +17,7 @@ const experimentalTyIt = testEffect(
1617 CrossSpawnSpawner . defaultLayer ,
1718 ) ,
1819)
20+ const fakeServerPath = path . join ( __dirname , "../fixture/lsp/fake-lsp-server.js" )
1921const disabledDownloadIt = testEffect (
2022 Layer . mergeAll (
2123 LSP . layer . pipe ( Layer . provide ( Config . defaultLayer ) , Layer . provide ( RuntimeFlags . layer ( { disableLspDownload : true } ) ) ) ,
@@ -92,6 +94,35 @@ describe("lsp.spawn", () => {
9294 ) ,
9395 )
9496
97+ it . live ( "publishes lsp.updated after custom LSP initialization" , ( ) =>
98+ provideTmpdirInstance (
99+ ( dir ) =>
100+ Effect . gen ( function * ( ) {
101+ const lsp = yield * LSP . Service
102+ const updated = yield * Deferred . make < void > ( )
103+ const unsubscribe = Bus . subscribe ( LSP . Event . Updated , ( ) =>
104+ Effect . runSync ( Deferred . succeed ( updated , undefined ) ) ,
105+ )
106+ yield * Effect . addFinalizer ( ( ) => Effect . sync ( unsubscribe ) )
107+
108+ const file = path . join ( dir , "sample.repro" )
109+ yield * Effect . promise ( ( ) => Bun . write ( file , "sample\n" ) )
110+ yield * lsp . touchFile ( file )
111+ yield * awaitWithTimeout ( Deferred . await ( updated ) , "lsp.updated event was not published" )
112+ } ) ,
113+ {
114+ config : {
115+ lsp : {
116+ fake : {
117+ command : [ process . execPath , fakeServerPath ] ,
118+ extensions : [ ".repro" ] ,
119+ } ,
120+ } ,
121+ } ,
122+ } ,
123+ ) ,
124+ )
125+
95126 it . live ( "would spawn builtin LSP for files inside instance when config object is provided" , ( ) =>
96127 provideTmpdirInstance (
97128 ( dir ) =>
0 commit comments