48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
# Python imports
|
|
import subprocess
|
|
import threading
|
|
|
|
# Lib imports
|
|
import pylspclient
|
|
|
|
# Application imports
|
|
from .capabilities import Capabilities
|
|
|
|
|
|
|
|
# In order to run this example, you need to have python-language-server module installed.
|
|
# See more information on the project page: https://github.com/palantir/python-language-server
|
|
|
|
|
|
|
|
class ReadPipe(threading.Thread):
|
|
def __init__(self, pipe):
|
|
threading.Thread.__init__(self)
|
|
self.pipe = pipe
|
|
|
|
def run(self):
|
|
line = self.pipe.readline().decode('utf-8')
|
|
while line:
|
|
line = self.pipe.readline().decode('utf-8')
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pyls_cmd = ["python", "-m", "pyls"]
|
|
|
|
p = subprocess.Popen(pyls_cmd, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
|
|
read_pipe = ReadPipe(p.stderr)
|
|
read_pipe.start()
|
|
|
|
json_rpc_endpoint = pylspclient.JsonRpcEndpoint(p.stdin, p.stdout)
|
|
# To work with socket: sock_fd = sock.makefile()
|
|
lsp_endpoint = pylspclient.LspEndpoint(json_rpc_endpoint)
|
|
lsp_client = pylspclient.LspClient(lsp_endpoint)
|
|
root_uri = 'file:///path/to/python/project'
|
|
workspace_folders = [{'name': 'python-lsp', 'uri': root_uri}]
|
|
|
|
print(lsp_client.initialize(p.pid, None, root_uri, None, Capabilities.data, "off", workspace_folders))
|
|
print(lsp_client.initialized())
|
|
|
|
lsp_client.shutdown()
|
|
lsp_client.exit() |