How to implement async code runner? (building a LSP client)
Hi! I'm trying to build a rought implementation of LSP client for Textmate 2.
Though bundle system for Textmate 2 feels extremely powerful, there are some
aspects I can't figure out.
What is the propper approach for bundles to run code in background?
Imagine the following command:
i = 0
while i < 10:
print('Hello %i' % i)
i += 1
If I run this code as a command, Textmate will hang unit script finishes,
captures ALL output and inserts to current document. it seems, building LSP
client requires to start inifinite Event listener in background and response
to events, comming from LSP server. Something like this:
msg = socket.read()
if not msg:
if msg == 'COMPLETIONS':
show_suggestions() # exec TM_DIALOG
elif msg == 'GOTO_DEFINITION':
open_document() # exec mate <file>
elif msg == 'DIAGNOSTICS':
highlight_errors_in_document() # Don't know how to implement
If bundles in Textmate run always synchronously, this approach can't work.
Thought right now I tested only print in a while loop (and it doesn't work),
I'd like to figure out the proper way to send commands to TM in backgroud.
How to highlight arbitrary symbols in current document?
This is related to diagnostic messages. Is there a way to tell TM "highlight
with red line symbols from 5:35 till 5:42" to mark it as error?
Is there a callback for open-document?
I need to notify LSP server about opening/saving/closing files in project. I
found in TM code callbacks for did/will-save and did/will-open. Is there a
way to run a command on file opening?