Skip to content

Commit

Permalink
Refactor code.
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Nov 4, 2023
1 parent 41a1c4e commit 61a857b
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions core/lspserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,27 @@ def handle_error_message(self, message):
else:
message_emacs(error_message)

def handle_publish_diagnostics(self, message):
if "method" in message and message["method"] == "textDocument/publishDiagnostics":
filepath = uri_to_path(message["params"]["uri"])
if self.enable_diagnostics and is_in_path_dict(self.files, filepath):
get_from_path_dict(self.files, filepath).record_diagnostics(message["params"]["diagnostics"], self.server_info["name"])

def handle_dart_publish_closing_labels(self, message):
if "method" in message and message["method"] == "dart/textDocument/publishClosingLabels":
filepath = uri_to_path(message["params"]["uri"])
if is_in_path_dict(self.files, filepath):
get_from_path_dict(self.files, filepath).record_dart_closing_lables(message["params"]["labels"])

def handle_log_message(self, message):
# Notice user if got error message from lsp server.
if "method" in message and message["method"] == "window/logMessage":
try:
if "error" in message["params"]["message"].lower():
message_emacs("{} ({}): {}".format(self.project_name, self.server_info["name"], message["params"]["message"]))
except:
pass

def handle_recv_message(self, message: dict):
if "error" in message:
self.handle_error_message(message)
Expand All @@ -564,23 +585,11 @@ def handle_recv_message(self, message: dict):
# others
log_time("Recv message {} from '{}' for project {}".format(message, self.server_info["name"], self.project_name))

if "method" in message and message["method"] == "textDocument/publishDiagnostics":
filepath = uri_to_path(message["params"]["uri"])
if self.enable_diagnostics and is_in_path_dict(self.files, filepath):
get_from_path_dict(self.files, filepath).record_diagnostics(message["params"]["diagnostics"], self.server_info["name"])
self.handle_publish_diagnostics(message)

if "method" in message and message["method"] == "dart/textDocument/publishClosingLabels":
filepath = uri_to_path(message["params"]["uri"])
if is_in_path_dict(self.files, filepath):
get_from_path_dict(self.files, filepath).record_dart_closing_lables(message["params"]["labels"])
self.handle_dart_publish_closing_labels(message)

# Notice user if got error message from lsp server.
if "method" in message and message["method"] == "window/logMessage":
try:
if "error" in message["params"]["message"].lower():
message_emacs("{} ({}): {}".format(self.project_name, self.server_info["name"], message["params"]["message"]))
except:
pass
self.handle_log_message(message)

logger.debug(json.dumps(message, indent=3))

Expand Down

0 comments on commit 61a857b

Please sign in to comment.