Class: Pikuri::Lsp::Extension

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(filesystem:, registry: Registry::EMPTY) ⇒ Extension

Returns a new instance of Extension.

Parameters:

  • registry (Registry) (defaults to: Registry::EMPTY)

    configured language servers. Defaults to Registry::EMPTY, which makes this extension a no-op.

  • filesystem (Pikuri::Workspace::Filesystem)

    the project: the servers' root, path resolution, the denylist pass every walked result owes, and the private? answer the tool's legs inherit.



31
32
33
34
35
36
# File 'lib/pikuri/lsp/extension.rb', line 31

def initialize(filesystem:, registry: Registry::EMPTY)
  @registry = registry
  @filesystem = filesystem
  @servers = nil
  @tool = nil
end

Instance Attribute Details

#serversServers? (readonly)

Returns the runtime built in configure, or nil when the registry was empty.

Returns:

  • (Servers, nil)

    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.

Parameters:

  • ctx (Pikuri::Agent::ExtensionContext)


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.

Parameters:

  • c (Pikuri::Agent::Configurator)


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