Class: Pikuri::Lsp::ServerProgress
- Inherits:
-
Data
- Object
- Data
- Pikuri::Lsp::ServerProgress
- Includes:
- Agent::Event::Transient
- Defined in:
- lib/pikuri/lsp/server_progress.rb
Overview
One language server's indexing progress, shaped as a domain event a host can draw. Two states matter — a task under way, and the same task over:
progress = ServerProgress.new(server_id: 'java', title: 'Initialize Workspace',
message: 'Importing gradle project', percentage: 40)
progress.to_s # => "java: Initialize Workspace — 40% — Importing gradle project"
progress.with(message: nil, percentage: nil, done: true).to_s
# => "java: Initialize Workspace — done"
It is a Agent::Event::Transient, so a chrome that can rewrite a line replaces the previous update rather than logging it — a cold import emits hundreds.
It exists because pikuri removed the clock: the first call blocks until the server is ready — 7s warm, 78s for a cold jdtls import — and a silent three-minute stall is indistinguishable from a hang for whoever is watching.
Maps 1:1 onto LSP's WorkDoneProgress begin / report / end, one
variant covering the whole lifecycle.
Instance Attribute Summary collapse
-
#done ⇒ Boolean
readonly
The task is over and its bar should go away.
-
#message ⇒ String?
readonly
The finer detail a
reportcarries, e.g. -
#percentage ⇒ Integer?
readonly
0..100, or
nil— which is common enough that a consumer needs an indeterminate spinner and not only a bar. -
#server_id ⇒ String
readonly
The registry entry's
id, e.g. -
#title ⇒ String
readonly
The server's own name for the task, e.g.
Instance Method Summary collapse
-
#initialize(server_id:, title:, message: nil, percentage: nil, done: false) ⇒ ServerProgress
constructor
A new instance of ServerProgress.
-
#to_s ⇒ String
One line, server first — two servers index at once, so whoever reads it needs to know whose bar moved.
Constructor Details
#initialize(server_id:, title:, message: nil, percentage: nil, done: false) ⇒ ServerProgress
Returns a new instance of ServerProgress.
45 46 47 |
# File 'lib/pikuri/lsp/server_progress.rb', line 45 def initialize(server_id:, title:, message: nil, percentage: nil, done: false) super end |
Instance Attribute Details
#done ⇒ Boolean (readonly)
Returns the task is over and its bar should go away. Defaults
to false.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pikuri/lsp/server_progress.rb', line 42 ServerProgress = Data.define(:server_id, :title, :message, :percentage, :done) do include Pikuri::Agent::Event::Transient def initialize(server_id:, title:, message: nil, percentage: nil, done: false) super end # @return [String] one line, server first — two servers index at once, so # whoever reads it needs to know whose bar moved. def to_s detail = [percentage && "#{percentage}%", , (done ? 'done' : nil)].compact "#{server_id}: #{([title] + detail).join(' — ')}" end end |
#message ⇒ String? (readonly)
Returns the finer detail a report carries, e.g.
"3200/4096 files"; nil when the server sent none.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pikuri/lsp/server_progress.rb', line 42 ServerProgress = Data.define(:server_id, :title, :message, :percentage, :done) do include Pikuri::Agent::Event::Transient def initialize(server_id:, title:, message: nil, percentage: nil, done: false) super end # @return [String] one line, server first — two servers index at once, so # whoever reads it needs to know whose bar moved. def to_s detail = [percentage && "#{percentage}%", , (done ? 'done' : nil)].compact "#{server_id}: #{([title] + detail).join(' — ')}" end end |
#percentage ⇒ Integer? (readonly)
Returns 0..100, or nil — which is common enough that a
consumer needs an indeterminate spinner and not only a bar.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pikuri/lsp/server_progress.rb', line 42 ServerProgress = Data.define(:server_id, :title, :message, :percentage, :done) do include Pikuri::Agent::Event::Transient def initialize(server_id:, title:, message: nil, percentage: nil, done: false) super end # @return [String] one line, server first — two servers index at once, so # whoever reads it needs to know whose bar moved. def to_s detail = [percentage && "#{percentage}%", , (done ? 'done' : nil)].compact "#{server_id}: #{([title] + detail).join(' — ')}" end end |
#server_id ⇒ String (readonly)
Returns the registry entry's id, e.g. "ruby" or "java".
Two servers index concurrently at boot, so a bar is keyed by this.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pikuri/lsp/server_progress.rb', line 42 ServerProgress = Data.define(:server_id, :title, :message, :percentage, :done) do include Pikuri::Agent::Event::Transient def initialize(server_id:, title:, message: nil, percentage: nil, done: false) super end # @return [String] one line, server first — two servers index at once, so # whoever reads it needs to know whose bar moved. def to_s detail = [percentage && "#{percentage}%", , (done ? 'done' : nil)].compact "#{server_id}: #{([title] + detail).join(' — ')}" end end |
#title ⇒ String (readonly)
Returns the server's own name for the task, e.g.
"Initialize Workspace". Server-supplied text bound for a terminal,
so whoever renders it defangs it via Sanitizer.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pikuri/lsp/server_progress.rb', line 42 ServerProgress = Data.define(:server_id, :title, :message, :percentage, :done) do include Pikuri::Agent::Event::Transient def initialize(server_id:, title:, message: nil, percentage: nil, done: false) super end # @return [String] one line, server first — two servers index at once, so # whoever reads it needs to know whose bar moved. def to_s detail = [percentage && "#{percentage}%", , (done ? 'done' : nil)].compact "#{server_id}: #{([title] + detail).join(' — ')}" end end |
Instance Method Details
#to_s ⇒ String
Returns one line, server first — two servers index at once, so whoever reads it needs to know whose bar moved.
51 52 53 54 |
# File 'lib/pikuri/lsp/server_progress.rb', line 51 def to_s detail = [percentage && "#{percentage}%", , (done ? 'done' : nil)].compact "#{server_id}: #{([title] + detail).join(' — ')}" end |