fixied the clangd example
This commit is contained in:
parent
a6286c15e1
commit
f80128ad6b
@ -1,10 +1,24 @@
|
|||||||
import pylspclient
|
import pylspclient
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import threading
|
||||||
|
|
||||||
|
|
||||||
|
class ReadPipe(threading.Thread):
|
||||||
|
def __init__(self, pipe):
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
self.pipe = pipe
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
line = self.pipe.readline()
|
||||||
|
while line:
|
||||||
|
print(line)
|
||||||
|
line = self.pipe.readline()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
clangd_path = "/usr/bin/clangd-6.0"
|
clangd_path = "/usr/bin/clangd-6.0"
|
||||||
p = subprocess.Popen(clangd_path, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
p = subprocess.Popen(clangd_path, 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)
|
json_rpc_endpoint = pylspclient.JsonRpcEndpoint(p.stdin, p.stdout)
|
||||||
# To work with socket: sock_fd = sock.makefile()
|
# To work with socket: sock_fd = sock.makefile()
|
||||||
lsp_endpoint = pylspclient.LspEndpoint(json_rpc_endpoint)
|
lsp_endpoint = pylspclient.LspEndpoint(json_rpc_endpoint)
|
||||||
@ -122,21 +136,22 @@ if __name__ == "__main__":
|
|||||||
25,
|
25,
|
||||||
26]}},'workspaceEdit': {'documentChanges': True},
|
26]}},'workspaceEdit': {'documentChanges': True},
|
||||||
'workspaceFolders': True}}
|
'workspaceFolders': True}}
|
||||||
workspace_folders = [{'name': 'python-lsp', 'uri': 'file:///path/to/dir'}]
|
root_uri = 'file:///home/osboxes/projects/ctest'
|
||||||
root_uri = 'file:///path/to/dir'
|
workspace_folders = [{'name': 'python-lsp', 'uri': root_uri}]
|
||||||
print(lsp_client.initialize(p.pid, None, root_uri, None, capabilities, "off", workspace_folders))
|
print(lsp_client.initialize(p.pid, None, root_uri, None, capabilities, "off", workspace_folders))
|
||||||
print(lsp_client.initialized())
|
print(lsp_client.initialized())
|
||||||
|
|
||||||
file_path = "/path/to/dir/file.c"
|
file_path = "/home/osboxes/projects/ctest/test.c"
|
||||||
uri = "file://" + file_path
|
uri = "file://" + file_path
|
||||||
text = open(file_path, "r").read()
|
text = open(file_path, "r").read()
|
||||||
languageId = pylspclient.lsp_structs.LANGUAGE_IDENTIFIER.C
|
languageId = pylspclient.lsp_structs.LANGUAGE_IDENTIFIER.C
|
||||||
version = 1
|
version = 1
|
||||||
lsp_client.didOpen(pylspclient.lsp_structs.TextDocumentItem(uri, languageId, version, text))
|
lsp_client.didOpen(pylspclient.lsp_structs.TextDocumentItem(uri, languageId, version, text))
|
||||||
lsp_client.documentSymbol(pylspclient.lsp_structs.TextDocumentIdentifier(uri))
|
# documentSymbol is supported from version 8.
|
||||||
|
#lsp_client.documentSymbol(pylspclient.lsp_structs.TextDocumentIdentifier(uri))
|
||||||
|
|
||||||
lsp_client.definition(pylspclient.lsp_structs.TextDocumentIdentifier(uri), pylspclient.lsp_structs.Position(15, 4))
|
lsp_client.definition(pylspclient.lsp_structs.TextDocumentIdentifier(uri), pylspclient.lsp_structs.Position(15, 4))
|
||||||
lsp_client.signatureHelp(pylspclient.lsp_structs.TextDocumentIdentifier(uri), pylspclient.lsp_structs.Position(15, 4))
|
lsp_client.signatureHelp(pylspclient.lsp_structs.TextDocumentIdentifier(uri), pylspclient.lsp_structs.Position(15, 4))
|
||||||
|
lsp_client.completion(pylspclient.lsp_structs.TextDocumentIdentifier(uri), pylspclient.lsp_structs.Position(15, 4), pylspclient.lsp_structs.CompletionContext(pylspclient.lsp_structs.CompletionTriggerKind.Invoked))
|
||||||
lsp_client.shutdown()
|
lsp_client.shutdown()
|
||||||
lsp_client.exit()
|
lsp_client.exit()
|
||||||
|
Loading…
Reference in New Issue
Block a user