1- import { Plugin } from "../plugin"
21import { Format } from "../format"
32import { LSP } from "@/lsp/lsp"
43import { File } from "../file"
@@ -7,6 +6,7 @@ import * as Project from "./project"
76import * as Vcs from "./vcs"
87import { Bus } from "../bus"
98import { Command } from "../command"
9+ import { Plugin } from "../plugin"
1010import { InstanceState } from "@/effect/instance-state"
1111import { FileWatcher } from "@/file/watcher"
1212import { ShareNext } from "@/share/share-next"
@@ -17,6 +17,21 @@ export interface Interface {
1717 readonly run : Effect . Effect < void >
1818}
1919
20+ const ConfigWithPluginPriority = Layer . effect (
21+ Config . Service ,
22+ Effect . gen ( function * ( ) {
23+ const config = yield * Config . Service
24+ const plugin = yield * Plugin . Service
25+
26+ return {
27+ ...config ,
28+ get : ( ) => Effect . andThen ( plugin . init ( ) , config . get ) ,
29+ getGlobal : ( ) => Effect . andThen ( plugin . init ( ) , config . getGlobal ) ,
30+ getConsoleState : ( ) => Effect . andThen ( plugin . init ( ) , config . getConsoleState ) ,
31+ }
32+ } ) ,
33+ ) . pipe ( Layer . provide ( Layer . merge ( Plugin . defaultLayer , Config . defaultLayer ) ) )
34+
2035export class Service extends Context . Service < Service , Interface > ( ) ( "@opencode/InstanceBootstrap" ) { }
2136
2237export const layer = Layer . effect (
@@ -31,7 +46,6 @@ export const layer = Layer.effect(
3146 const fileWatcher = yield * FileWatcher . Service
3247 const format = yield * Format . Service
3348 const lsp = yield * LSP . Service
34- const plugin = yield * Plugin . Service
3549 const shareNext = yield * ShareNext . Service
3650 const snapshot = yield * Snapshot . Service
3751 const vcs = yield * Vcs . Service
@@ -41,8 +55,6 @@ export const layer = Layer.effect(
4155 yield * Effect . logInfo ( "bootstrapping" , { directory : ctx . directory } )
4256 // everything depends on config so eager load it for nice traces
4357 yield * config . get ( )
44- // Plugin can mutate config so it has to be initialized before anything else.
45- yield * plugin . init ( )
4658 yield * Effect . all (
4759 [ lsp , shareNext , format , file , fileWatcher , vcs , snapshot ] . map ( ( s ) => Effect . forkDetach ( s . init ( ) ) ) ,
4860 ) . pipe ( Effect . withSpan ( "InstanceBootstrap.init" ) )
@@ -62,12 +74,11 @@ export const layer = Layer.effect(
6274export const defaultLayer : Layer . Layer < Service > = layer . pipe (
6375 Layer . provide ( [
6476 Bus . layer ,
65- Config . defaultLayer ,
77+ ConfigWithPluginPriority ,
6678 File . defaultLayer ,
6779 FileWatcher . defaultLayer ,
6880 Format . defaultLayer ,
6981 LSP . defaultLayer ,
70- Plugin . defaultLayer ,
7182 Project . defaultLayer ,
7283 ShareNext . defaultLayer ,
7384 Snapshot . defaultLayer ,
0 commit comments