Class: Pikuri::Lsp::Extension
- Inherits:
-
Object
- Object
- Pikuri::Lsp::Extension
- Includes:
- Agent::Extension
- Defined in:
- lib/pikuri/lsp/extension.rb
Overview
Wires the lsp tool onto an agent: builds the Servers runtime from a
Registry, arms its teardown, and hands the tool an event emitter so a host
can draw a bar while a cold index runs.
registry = Pikuri::Lsp::Registry.from_h(config['lsp_servers'])
Pikuri::Agent.new(transport: ..., system_prompt: ...) do |c|
c.add_extension Pikuri::Lsp::Extension.new(registry: registry, filesystem: filesystem)
end
An empty Registry makes the whole extension a no-op — no tool, no teardown — so a host that ships the gem without config costs the model nothing.
Implementation details
There is deliberately no trifecta_contribution: the legs belong to the
tool, which holds the filesystem that answers them, and a second declaration
here would only put the extension's name on the report row.
Instance Attribute Summary collapse
-
#servers ⇒ Servers?
readonly
The runtime built in
configure, ornilwhen the registry was empty.
Instance Method Summary collapse
-
#bind(ctx) ⇒ void
Point the tool's progress callback at the agent's event stream.
-
#configure(c) ⇒ void
Build the Servers runtime, arm its teardown, register the tool — in that order, so
closeis armed before any call can spawn a child. -
#initialize(filesystem:, registry: Registry::EMPTY) ⇒ Extension
constructor
A new instance of Extension.
Constructor Details
Instance Attribute Details
#servers ⇒ Servers? (readonly)
Returns the runtime built in configure, or nil when the
registry was empty.
40 41 42 |
# File 'lib/pikuri/lsp/extension.rb', line 40 def servers @servers end |
Instance Method Details
#bind(ctx) ⇒ void
This method returns an undefined value.
Point the tool's progress callback at the agent's event stream.
The tool emits on the thread that is blocked waiting for an index — the agent's own — which is what makes Agent::ExtensionContext#emit_event legal from there.
67 68 69 70 71 72 |
# File 'lib/pikuri/lsp/extension.rb', line 67 def bind(ctx) return if @tool.nil? @tool.on_progress = ->(progress) { ctx.emit_event(progress) } nil end |
#configure(c) ⇒ void
This method returns an undefined value.
Build the Servers runtime, arm its teardown, register the tool — in that
order, so close is armed before any call can spawn a child.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pikuri/lsp/extension.rb', line 47 def configure(c) return if @registry.empty? @servers = Servers.new(registry: @registry, root: @filesystem.project_root, cancellable: c.cancellable) c.on_close { @servers.close } @tool = LspTool.new(servers: @servers, filesystem: @filesystem, cancellable: c.cancellable) c.add_tool @tool nil end |