forked from tkh44/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance.ts
More file actions
27 lines (25 loc) · 853 Bytes
/
instance.ts
File metadata and controls
27 lines (25 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Context } from "../util/context"
import { Project } from "./project"
import { State } from "./state"
const context = Context.create<{ directory: string; worktree: string; project: Project.Info }>("path")
export const Instance = {
async provide<R>(directory: string, cb: () => R): Promise<R> {
const project = await Project.fromDirectory(directory)
return context.provide({ directory, worktree: project.worktree, project }, cb)
},
get directory() {
return context.use().directory
},
get worktree() {
return context.use().worktree
},
get project() {
return context.use().project
},
state<S>(init: () => S, dispose?: (state: Awaited<S>) => Promise<void>): () => S {
return State.create(() => Instance.directory, init, dispose)
},
async dispose() {
await State.dispose(Instance.directory)
},
}