-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Don't send not specified properties #124
Comments
Important notions from the LSP spec:
|
There's also a This library needs to distinguish between optional keys with typed values and mandatory keys. |
I haven't tested this but this might work as serializer: def default_serializer(o):
"""JSON serializer for complex objects."""
if isinstance(o, enum.Enum):
return o.value
d = {}
for k, v in o.__dict__.items():
if not k.startswith('_') and v is not None:
d[k] = v
return d |
You should also account for cases where a
|
Another example where this breaks an editor is for textDocument/rename. We do a check here to see if we're dealing with new-style 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():
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', []):
if 'kind' in document_change:
debug('Ignoring unsupported "resourceOperations" edit type')
continue
uri = document_change.get('textDocument').get('uri')
version = document_change.get('textDocument').get('version')
text_edit = list(parse_text_edit(change, version) for change in document_change.get('edits'))
changes[uri_to_filename(uri)] = text_edit
return changes However, the payload from this framework is
|
@rwols Because both 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():
+ _changes = workspace_edit.get('changes')
+ if _changes:
+ for uri, file_changes in _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', []):
+ _changes = workspace_edit.get('documentChanges')
+ if _changes:
+ for document_change in _changes:
if 'kind' in document_change:
debug('Ignoring unsupported "resourceOperations" edit type')
continue |
@danixeee Another option is to have a library-specific value for an optionally undefined attribute: UNDEFINED = object() In the serializer, you can do an identity def default_serializer(o):
"""JSON serializer for complex objects."""
if isinstance(o, enum.Enum):
return o.value
d = {}
for k, v in o.__dict__.items():
if v is not UNDEFINED:
d[k] = v
return d The above will still allow I was drawn to this conversation by the following issue: pappasam/jedi-language-server#38 (comment) Here's a mypy-friendly way of achieving the above: https://www.python.org/dev/peps/pep-0484/#support-for-singleton-types-in-unions |
Solved with #139. |
E.g.
will result in sending all other attributes along with label:
The text was updated successfully, but these errors were encountered: