From a10ed5327bbbc9d3321a3fb5260c0c6dba0d21b7 Mon Sep 17 00:00:00 2001 From: smathot Date: Tue, 22 Dec 2020 13:49:04 +0100 Subject: [PATCH 1/2] Minor fixes - Add CompletionItemKind - Don't require containerName in SumbolInformation --- pylspclient/lsp_structs.py | 62 +++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/pylspclient/lsp_structs.py b/pylspclient/lsp_structs.py index 05ebe93..2681e96 100644 --- a/pylspclient/lsp_structs.py +++ b/pylspclient/lsp_structs.py @@ -176,8 +176,8 @@ def __init__(self, uri, version): open notification before) the server can send `null` to indicate that the version is known and the content on disk is the truth (as speced with document content ownership). - The version number of a document will increase after each change, including - undo/redo. The number doesn't need to be consecutive. + The version number of a document will increase after each change, including + undo/redo. The number doesn't need to be consecutive. """ super(VersionedTextDocumentIdentifier, self).__init__(uri) self.version = version @@ -301,7 +301,7 @@ class SymbolInformation(object): """ Represents information about programming constructs like variables, classes, interfaces etc. """ - def __init__(self, name, kind, location, containerName, deprecated=False): + def __init__(self, name, kind, location, containerName=None, deprecated=False): """ Constructs a new SymbolInformation instance. @@ -481,6 +481,34 @@ def __init__(self, label, kind=None, detail=None, documentation=None, deprecated self.score = score +class CompletionItemKind(enum.Enum): + Text = 1 + Method = 2 + Function = 3 + Constructor = 4 + Field = 5 + Variable = 6 + Class = 7 + Interface = 8 + Module = 9 + Property = 10 + Unit = 11 + Value = 12 + Enum = 13 + Keyword = 14 + Snippet = 15 + Color = 16 + File = 17 + Reference = 18 + Folder = 19 + EnumMember = 20 + Constant = 21 + Struct = 22 + Event = 23 + Operator = 24 + TypeParameter = 25 + + class CompletionList(object): """ Represents a collection of [completion items](#CompletionItem) to be presented in the editor. @@ -496,20 +524,20 @@ def __init__(self, isIncomplete, items): self.items = [to_type(i, CompletionItem) for i in items] class ErrorCodes(enum.Enum): - # Defined by JSON RPC - ParseError = -32700 - InvalidRequest = -32600 - MethodNotFound = -32601 - InvalidParams = -32602 - InternalError = -32603 - serverErrorStart = -32099 - serverErrorEnd = -32000 - ServerNotInitialized = -32002 - UnknownErrorCode = -32001 - - # Defined by the protocol. - RequestCancelled = -32800 - ContentModified = -32801 + # Defined by JSON RPC + ParseError = -32700 + InvalidRequest = -32600 + MethodNotFound = -32601 + InvalidParams = -32602 + InternalError = -32603 + serverErrorStart = -32099 + serverErrorEnd = -32000 + ServerNotInitialized = -32002 + UnknownErrorCode = -32001 + + # Defined by the protocol. + RequestCancelled = -32800 + ContentModified = -32801 class ResponseError(Exception): def __init__(self, code, message, data = None): From d2572c9f3836f8734ec37c5e5f59bb466a713882 Mon Sep 17 00:00:00 2001 From: smathot Date: Wed, 23 Dec 2020 11:42:36 +0100 Subject: [PATCH 2/2] LspEndpoint: add timeout --- pylspclient/lsp_endpoint.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pylspclient/lsp_endpoint.py b/pylspclient/lsp_endpoint.py index 8364d6f..28b1a2c 100644 --- a/pylspclient/lsp_endpoint.py +++ b/pylspclient/lsp_endpoint.py @@ -5,7 +5,7 @@ class LspEndpoint(threading.Thread): - def __init__(self, json_rpc_endpoint, method_callbacks={}, notify_callbacks={}): + def __init__(self, json_rpc_endpoint, method_callbacks={}, notify_callbacks={}, timeout=2): threading.Thread.__init__(self) self.json_rpc_endpoint = json_rpc_endpoint self.notify_callbacks = notify_callbacks @@ -13,6 +13,7 @@ def __init__(self, json_rpc_endpoint, method_callbacks={}, notify_callbacks={}): self.event_dict = {} self.response_dict = {} self.next_id = 0 + self._timeout = timeout self.shutdown_flag = False @@ -93,7 +94,8 @@ def call_method(self, method_name, **kwargs): if self.shutdown_flag: return None - cond.wait() + if not cond.wait(timeout=self._timeout): + raise TimeoutError() cond.release() self.event_dict.pop(current_id)