Skip to content
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
8 changes: 6 additions & 2 deletions packages/python/lsprotocol/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,16 +691,20 @@ def _symbol_list_hook(
assert isinstance(object_, list)
if len(object_) == 0:
return []
if "location" in object_[0]:
if "deprecated" in object_[0]:
return [
converter.structure(item, lsp_types.SymbolInformation)
for item in object_
]
else:
elif ("data" in object_[0]) or ("range" not in object_[0]["location"]):
return [
converter.structure(item, lsp_types.WorkspaceSymbol) for item in object_
]

return [
converter.structure(item, lsp_types.SymbolInformation) for item in object_
]

def _notebook_sync_registration_option_selector_hook(
object_: Any, _: type
) -> Union[
Expand Down
90 changes: 90 additions & 0 deletions tests/python/requests/test_workspace_symbols_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import hamcrest
import pytest
from cattrs import ClassValidationError
from lsprotocol import converters as cv
from lsprotocol import types as lsp

TEST_DATA = [
{
"id": 1,
"result": [{"name": "test", "kind": 1, "location": {"uri": "test"}}],
"jsonrpc": "2.0",
},
{
"id": 1,
"result": [
{
"name": "test",
"kind": 1,
"location": {
"uri": "test",
"range": {
"start": {"line": 1, "character": 1},
"end": {"line": 1, "character": 1},
},
},
}
],
"jsonrpc": "2.0",
},
{
"id": 1,
"result": [{"name": "test", "kind": 1, "location": {"uri": "test"}, "data": 1}],
"jsonrpc": "2.0",
},
{
"id": 1,
"result": [
{
"name": "test",
"kind": 1,
"location": {
"uri": "test",
"range": {
"start": {"line": 1, "character": 1},
"end": {"line": 1, "character": 1},
},
},
"deprecated": True,
}
],
"jsonrpc": "2.0",
},
]

BAD_TEST_DATA = [
{
"id": 1,
"result": [
{
"name": "test",
"kind": 1,
"location": {"uri": "test"},
"deprecated": True,
}
],
"jsonrpc": "2.0",
},
]


@pytest.mark.parametrize("data", TEST_DATA)
def test_workspace_symbols(data):
converter = cv.get_converter()
obj = converter.structure(data, lsp.WorkspaceSymbolResponse)
hamcrest.assert_that(obj, hamcrest.instance_of(lsp.WorkspaceSymbolResponse))
hamcrest.assert_that(
converter.unstructure(obj, lsp.WorkspaceSymbolResponse),
hamcrest.is_(data),
)


@pytest.mark.parametrize("data", BAD_TEST_DATA)
def test_workspace_symbols_bad(data):
converter = cv.get_converter()
with pytest.raises(ClassValidationError):
obj = converter.structure(data, lsp.WorkspaceSymbolResponse)
hamcrest.assert_that(obj, hamcrest.instance_of(lsp.WorkspaceSymbolResponse))