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

Work around broken language servers for textDocument/rename #1178

Merged
merged 2 commits into from
Jul 8, 2020
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
10 changes: 6 additions & 4 deletions plugin/core/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

def parse_workspace_edit(workspace_edit: Dict[str, Any]) -> Dict[str, List[TextEdit]]:
changes = {} # type: Dict[str, List[TextEdit]]
if 'changes' in workspace_edit:
for uri, file_changes in workspace_edit.get('changes', {}).items():
raw_changes = workspace_edit.get('changes')
if isinstance(raw_changes, dict):
for uri, file_changes in raw_changes.items():
changes[uri_to_filename(uri)] = list(parse_text_edit(change) for change in file_changes)
if 'documentChanges' in workspace_edit:
for document_change in workspace_edit.get('documentChanges', []):
document_changes = workspace_edit.get('documentChanges')
if isinstance(document_changes, list):
for document_change in document_changes:
if 'kind' in document_change:
debug('Ignoring unsupported "resourceOperations" edit type')
continue
Expand Down
15 changes: 15 additions & 0 deletions tests/test_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
}]
}

LSP_EDIT_DOCUMENT_CHANGES_2 = {
'changes': None,
'documentChanges': [{
'textDocument': {'uri': URI},
'edits': [LSP_TEXT_EDIT]
}]
}


class TextEditTests(unittest.TestCase):

Expand Down Expand Up @@ -53,6 +61,13 @@ def test_parse_document_changes_from_lsp(self):
self.assertEqual(len(edit), 1)
self.assertEqual(len(edit[FILENAME]), 1)

def test_protocol_violation(self):
# This should ignore the None in 'changes'
edit = parse_workspace_edit(LSP_EDIT_DOCUMENT_CHANGES_2)
self.assertIn(FILENAME, edit)
self.assertEqual(len(edit), 1)
self.assertEqual(len(edit[FILENAME]), 1)


class SortByApplicationOrderTests(unittest.TestCase):

Expand Down