[TxMt Plugins] How to implement async code runner? (building a LSP client)

f1nnix ilya at rusanen.co.uk
Thu Nov 14 09:23:33 UTC 2019


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:

    #!/usr/local/bin/python3
    import time

    i = 0
    while i < 10:
        print('Hello %i' % i)
        i += 1
    
        time.sleep(3)


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:
    
    while True:
        msg = socket.read()
        if not msg:
            continue
        
        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
yet...
            
            
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?



--
Sent from: http://textmate.1073791.n5.nabble.com/textmate-plugins-f25277.html


More information about the textmate-plugins mailing list