Class: PlatformosCheck::LanguageServer::Bridge
- Inherits:
-
Object
- Object
- PlatformosCheck::LanguageServer::Bridge
- Defined in:
- lib/platformos_check/language_server/bridge.rb
Instance Attribute Summary collapse
-
#supports_work_done_progress ⇒ Object
writeonly
Sets the attribute supports_work_done_progress.
Instance Method Summary collapse
-
#initialize(messenger) ⇒ Bridge
constructor
A new instance of Bridge.
- #log(message) ⇒ Object
- #read_message ⇒ Object
- #receive_response(id, result) ⇒ Object
- #send_create_work_done_progress_request ⇒ Object
- #send_internal_error(id, e) ⇒ Object
- #send_message(message_hash) ⇒ Object
- #send_notification(method, params) ⇒ Object
- #send_progress(token, value) ⇒ Object
- #send_request(method, params = nil) ⇒ Object
- #send_response(id, result = nil, error = nil) ⇒ Object
- #send_work_done_progress_begin(token, title) ⇒ Object
- #send_work_done_progress_end(token, message) ⇒ Object
- #send_work_done_progress_report(token, message, percentage) ⇒ Object
- #supports_work_done_progress? ⇒ Boolean
Constructor Details
#initialize(messenger) ⇒ Bridge
Returns a new instance of Bridge.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/platformos_check/language_server/bridge.rb', line 27 def initialize(messenger) # The messenger is responsible for IO. # Could be STDIO or WebSockets or Mock. @messenger = messenger # Whether the client supports work done progress notifications @supports_work_done_progress = false @work_done_progress_mutex = Mutex.new @work_done_progress_token = 1 end |
Instance Attribute Details
#supports_work_done_progress=(value) ⇒ Object (writeonly)
Sets the attribute supports_work_done_progress
25 26 27 |
# File 'lib/platformos_check/language_server/bridge.rb', line 25 def supports_work_done_progress=(value) @supports_work_done_progress = value end |
Instance Method Details
#log(message) ⇒ Object
39 40 41 |
# File 'lib/platformos_check/language_server/bridge.rb', line 39 def log() @messenger.log() end |
#read_message ⇒ Object
43 44 45 46 47 48 |
# File 'lib/platformos_check/language_server/bridge.rb', line 43 def = @messenger. = JSON.parse(, symbolize_names: true) @messenger.log(JSON.pretty_generate()) if PlatformosCheck.debug? end |
#receive_response(id, result) ⇒ Object
69 70 71 |
# File 'lib/platformos_check/language_server/bridge.rb', line 69 def receive_response(id, result) Channel.by_id(id) << result end |
#send_create_work_done_progress_request ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/platformos_check/language_server/bridge.rb', line 116 def send_create_work_done_progress_request # This isn't necessary, but it kind of is to make it obvious # that this variable is not thread safe. Don't try to refactor # this with @work_done_progress_token because you're going to # have a hard time. token = @work_done_progress_mutex.synchronize do @work_done_progress_token += 1 end return token unless supports_work_done_progress? # We're going to wait for a response here... send_request("window/workDoneProgress/create", { token: }) token end |
#send_internal_error(id, e) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/platformos_check/language_server/bridge.rb', line 85 def send_internal_error(id, e) # For a reason I can't comprehend, sometimes # e.full_message _hangs_ and brings your CPU to 100%. # It's wrapped in here because it prints anyway... # This shit is weird, yo. Timeout.timeout(1) do warn e. end ensure send_response(id, nil, { code: ErrorCodes::INTERNAL_ERROR, message: "A platformos-check-language-server has occured, inspect OUTPUT logs for details." }) end |
#send_message(message_hash) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/platformos_check/language_server/bridge.rb', line 50 def () [:jsonrpc] = '2.0' = JSON.dump() @messenger.log(JSON.pretty_generate()) if PlatformosCheck.debug? @messenger.() end |
#send_notification(method, params) ⇒ Object
101 102 103 104 105 |
# File 'lib/platformos_check/language_server/bridge.rb', line 101 def send_notification(method, params) = { method: } [:params] = params () end |
#send_progress(token, value) ⇒ Object
108 109 110 |
# File 'lib/platformos_check/language_server/bridge.rb', line 108 def send_progress(token, value) send_notification("$/progress", token:, value:) end |
#send_request(method, params = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/platformos_check/language_server/bridge.rb', line 58 def send_request(method, params = nil) channel = Channel.create = { id: channel.id } [:method] = method [:params] = params if params () channel.pop ensure channel.close end |
#send_response(id, result = nil, error = nil) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/platformos_check/language_server/bridge.rb', line 74 def send_response(id, result = nil, error = nil) = { id: } if error [:error] = error else [:result] = result end () end |
#send_work_done_progress_begin(token, title) ⇒ Object
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/platformos_check/language_server/bridge.rb', line 135 def send_work_done_progress_begin(token, title) return unless supports_work_done_progress? send_progress(token, { kind: 'begin', title:, cancellable: false, percentage: 0 }) end |
#send_work_done_progress_end(token, message) ⇒ Object
157 158 159 160 161 162 163 164 |
# File 'lib/platformos_check/language_server/bridge.rb', line 157 def send_work_done_progress_end(token, ) return unless supports_work_done_progress? send_progress(token, { kind: 'end', message: }) end |
#send_work_done_progress_report(token, message, percentage) ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/platformos_check/language_server/bridge.rb', line 146 def send_work_done_progress_report(token, , percentage) return unless supports_work_done_progress? send_progress(token, { kind: 'report', message:, cancellable: false, percentage: }) end |
#supports_work_done_progress? ⇒ Boolean
112 113 114 |
# File 'lib/platformos_check/language_server/bridge.rb', line 112 def supports_work_done_progress? @supports_work_done_progress end |