Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two minor fixes #17

Merged
merged 2 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pylspclient/lsp_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@


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
self.method_callbacks = method_callbacks
self.event_dict = {}
self.response_dict = {}
self.next_id = 0
self._timeout = timeout
self.shutdown_flag = False


Expand Down Expand Up @@ -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)
Expand Down
62 changes: 45 additions & 17 deletions pylspclient/lsp_structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand All @@ -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):
Expand Down