mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
feat(plugin): add reference editor lookup
This commit is contained in:
committed by
GitHub
Unverified
parent
2b87169cc1
commit
efefd90443
@@ -397,6 +397,7 @@ export const make = Effect.fn("PluginHost.make")(function* (
|
||||
add: (name, source) => editor.add(name, Schema.decodeUnknownSync(Reference.Source)(source)),
|
||||
remove: editor.remove,
|
||||
list: editor.list,
|
||||
get: editor.get,
|
||||
})
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -32,6 +32,7 @@ type Editor = {
|
||||
add(name: string, source: Source): void
|
||||
remove(name: string): void
|
||||
list(): readonly [string, Source][]
|
||||
get(name: string): Source | undefined
|
||||
}
|
||||
|
||||
export interface Interface extends State.Transformable<Editor> {
|
||||
@@ -98,6 +99,7 @@ const layer = Layer.effect(
|
||||
add: (name, source) => editor.sources.set(name, source),
|
||||
remove: (name) => editor.sources.delete(name),
|
||||
list: () => Array.from(editor.sources),
|
||||
get: (name) => editor.sources.get(name),
|
||||
}),
|
||||
notify: () =>
|
||||
Effect.gen(function* () {
|
||||
|
||||
@@ -19,6 +19,26 @@ const referenceLayer = AppNodeBuilder.build(LayerNode.group([Reference.node, Bus
|
||||
])
|
||||
|
||||
describe("Reference", () => {
|
||||
it.effect("reads the current editor source by name", () =>
|
||||
Effect.gen(function* () {
|
||||
const references = yield* Reference.Service
|
||||
const source = Reference.LocalSource.make({ type: "local", path: AbsolutePath.make("/docs") })
|
||||
yield* references.transform((editor) => editor.add("docs", source))
|
||||
yield* references.transform((editor) => {
|
||||
expect(editor.get("docs")).toBe(editor.list()[0]?.[1])
|
||||
expect(editor.get("docs")).toEqual(source)
|
||||
expect(editor.get("missing")).toBeUndefined()
|
||||
const replacement = Reference.GitSource.make({ type: "git", repository: "owner/repo" })
|
||||
editor.add("docs", replacement)
|
||||
expect(editor.get("docs")).toBe(replacement)
|
||||
editor.remove("docs")
|
||||
expect(editor.get("docs")).toBeUndefined()
|
||||
})
|
||||
|
||||
expect(yield* references.list()).toEqual([])
|
||||
}).pipe(Effect.provide(referenceLayer)),
|
||||
)
|
||||
|
||||
it.effect("reads batched references before cache work and update events", () => {
|
||||
const operations: RepositoryCache.EnsureInput[] = []
|
||||
const started = Deferred.makeUnsafe<void>()
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface ReferenceEditor {
|
||||
add(name: string, source: ReferenceLocalSource | ReferenceGitSource): void
|
||||
remove(name: string): void
|
||||
list(): readonly (readonly [string, ReferenceLocalSource | ReferenceGitSource])[]
|
||||
get(name: string): ReferenceLocalSource | ReferenceGitSource | undefined
|
||||
}
|
||||
|
||||
export interface ReferenceDomain extends ReferenceApi<unknown> {
|
||||
|
||||
@@ -6,6 +6,7 @@ export interface ReferenceEditor {
|
||||
add(name: string, source: ReferenceLocalSource | ReferenceGitSource): void
|
||||
remove(name: string): void
|
||||
list(): readonly (readonly [string, ReferenceLocalSource | ReferenceGitSource])[]
|
||||
get(name: string): ReferenceLocalSource | ReferenceGitSource | undefined
|
||||
}
|
||||
|
||||
export interface ReferenceDomain extends ReferenceApi {
|
||||
|
||||
@@ -644,7 +644,8 @@ effect: (ctx) =>
|
||||
}),
|
||||
```
|
||||
|
||||
Add or remove local and Git references, then reload after external state changes.
|
||||
Add or remove local and Git references, then reload after external state changes. `get(name)` returns the current configured
|
||||
source, or `undefined` when the name is absent.
|
||||
|
||||
```ts
|
||||
effect: (ctx) =>
|
||||
@@ -653,6 +654,7 @@ effect: (ctx) =>
|
||||
yield* reference.transform((editor) => {
|
||||
editor.add("handbook", { type: "local", path: "/workspace/docs/handbook" })
|
||||
editor.add("standards", { type: "git", repository: "https://github.com/acme/standards", branch: "main" })
|
||||
const handbook = editor.get("handbook")
|
||||
editor.remove("legacy")
|
||||
})
|
||||
yield* reference.reload()
|
||||
@@ -667,6 +669,7 @@ interface ReferenceEditor {
|
||||
add(name: string, source: ReferenceLocalSource | ReferenceGitSource): void
|
||||
remove(name: string): void
|
||||
list(): readonly (readonly [string, ReferenceLocalSource | ReferenceGitSource])[]
|
||||
get(name: string): ReferenceLocalSource | ReferenceGitSource | undefined
|
||||
}
|
||||
|
||||
interface ReferenceDomain extends ReferenceApi<unknown> {
|
||||
|
||||
@@ -596,13 +596,15 @@ Read the references available at a location.
|
||||
const references = await ctx.reference.list()
|
||||
```
|
||||
|
||||
Register a transform to inspect, add, or remove local and Git references.
|
||||
Register a transform to inspect, add, or remove local and Git references. `get(name)` returns the current configured source,
|
||||
or `undefined` when the name is absent.
|
||||
|
||||
```ts
|
||||
await ctx.reference.transform((editor) => {
|
||||
const references = editor.list()
|
||||
editor.add("handbook", { type: "local", path: "/workspace/docs/handbook" })
|
||||
editor.add("standards", { type: "git", repository: "https://github.com/acme/standards", branch: "main" })
|
||||
const handbook = editor.get("handbook")
|
||||
editor.remove("legacy")
|
||||
})
|
||||
```
|
||||
@@ -627,6 +629,7 @@ interface ReferenceContext {
|
||||
|
||||
interface ReferenceEditor {
|
||||
list(): readonly (readonly [string, ReferenceLocalSource | ReferenceGitSource])[]
|
||||
get(name: string): ReferenceLocalSource | ReferenceGitSource | undefined
|
||||
add(name: string, source: ReferenceLocalSource | ReferenceGitSource): void
|
||||
remove(name: string): void
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user