Skip to content

Commit

Permalink
Support willSave option of TextDocumentSyncOptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Nov 4, 2024
1 parent 9b5c2b9 commit 6f08095
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions core/lspserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def __init__(self, message_queue, project_path, server_info, server_name, enable
self.workspace_symbol_provider = False
self.inlay_hint_provider = False
self.semantic_tokens_provider = False
self.save_file_provider = False

self.work_done_progress_title = ""

Expand Down Expand Up @@ -538,21 +539,22 @@ def send_did_rename_files_notification(self, old_filepath, new_filepath):
})

def send_did_save_notification(self, filepath, buffer_name):
args = {
"textDocument": {
"uri": path_to_uri(filepath)
}
}

# Fetch buffer whole content to LSP server if server capability 'includeText' is True.
if self.save_include_text:
args = merge(args, {
if self.save_file_provider:
args = {
"textDocument": {
"text": get_buffer_content(filepath, buffer_name)
"uri": path_to_uri(filepath)
}
})
}

# Fetch buffer whole content to LSP server if server capability 'includeText' is True.
if self.save_include_text:
args = merge(args, {
"textDocument": {
"text": get_buffer_content(filepath, buffer_name)
}
})

self.sender.send_notification("textDocument/didSave", args)
self.sender.send_notification("textDocument/didSave", args)

def send_workspace_did_change_watched_files(self, filepath, change_type):
self.sender.send_notification("workspace/didChangeWatchedFiles", {
Expand Down Expand Up @@ -758,7 +760,8 @@ def save_attribute_from_message(self, message):
]),
("save_include_text", ["result", "capabilities", "textDocumentSync", "save", "includeText"]),
("text_document_sync", ["result", "capabilities", "textDocumentSync"]),
("semantic_tokens_provider", ["result", "capabilities", "semanticTokensProvider"])]
("semantic_tokens_provider", ["result", "capabilities", "semanticTokensProvider"]),
("save_file_provider", ["result", "capabilities", "textDocumentSync", "willSave"])]

for attr, path in attributes_to_set:
self.set_attribute_from_message(message, attr, path)
Expand Down

0 comments on commit 6f08095

Please sign in to comment.