robocorp / robotframework-lsp

Robocorp extensions for VS Code: Robocorp Code and RFW LSP
https://robocorp.com/docs/developer-tools/visual-studio-code
Apache License 2.0
202 stars 91 forks source link

Language server not handling TextDocumentContentChangeEvent correctly with text-only argument #78

Closed avaissi closed 4 years ago

avaissi commented 4 years ago

Detailed description of the bug or suggestion

LSP assumes to get all 3 arguments for the TextDocumentContentChangeEvent (range, rangeLength, text), but Jupyterlab extension https://github.com/krassowski/jupyterlab-lsp passes only the text argument.

lsp: 2020-05-29 16:41:10 UTC pid: 22084 - MainThread - EXCEPTION - robocode_ls_core.python_ls
Error updating document: {'uri': 'file:///c:/Users/avaissi/Documents/code/robocloud_bundles/project%202/tasks/robot.robot', 'version': 1} with changes: [{'text': '*** Settin gs ***\nDocumentation   An example robot.\nResource        ../resources/keywords.robot\n\n*** Tasks ***\nLog greeting for today\n    Process greeting for today\n\n'}]

Traceback (most recent call last):
  File "c:\users\avaissi\documents\code\projects\robotframework-lsp\robocode-python-ls-core\src\robocode_ls_core\python_ls.py", line 300, in m_text_document__did_change
    TextDocumentContentChangeEvent(**change),
TypeError: __init__() missing 2 required positional arguments: 'range' and 'rangeLength'

Extension logs (attach as a file)

robotframework_ls.log.lsp.21720.api.txt robotframework_ls.lsp.22084.log.txt

(Logs ran with the -vv argument)

Minimal example (if possible)

This temporary fix seemed to be enough to get TextDocumentContentChangeEvent working, but there's bound to be more elegant solution also:

def m_text_document__did_change(
        self, contentChanges=None, textDocument=None, **_kwargs
    ):
        from robocode_ls_core.lsp import TextDocumentItem
        from robocode_ls_core.lsp import TextDocumentContentChangeEvent

        if contentChanges:
            for change in contentChanges:
                try:
                    # TEMP FIX: handle missing range and rangeLength
                    change["range"] = change.get("range", None)
                    change["rangeLength"] = change.get("rangeLength", 0)
                    self.workspace.update_document(
                        TextDocumentItem(**textDocument),
                        TextDocumentContentChangeEvent(**change),
                    )
fabioz commented 4 years ago

It seems that there aren't actually special capabilities for this (so, the final code was very close to what was suggested).