Skip to content

Commit 60a8ba2

Browse files
authored
Fix bug with WorkspaceSymbol structuring hook (#312)
Closes #308
1 parent 4d9d780 commit 60a8ba2

File tree

3 files changed

+98
-2
lines changed

3 files changed

+98
-2
lines changed

.github/workflows/pr-check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ jobs:
205205
with:
206206
repository: openlawlibrary/pygls
207207
path: smoke_tests
208+
ref: 'v1.1.2'
208209

209210
- name: Use Python ${{ matrix.python }}
210211
uses: actions/setup-python@v4

packages/python/lsprotocol/_hooks.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,16 +689,20 @@ def _symbol_list_hook(
689689
assert isinstance(object_, list)
690690
if len(object_) == 0:
691691
return []
692-
if "location" in object_[0]:
692+
if "deprecated" in object_[0]:
693693
return [
694694
converter.structure(item, lsp_types.SymbolInformation)
695695
for item in object_
696696
]
697-
else:
697+
elif ("data" in object_[0]) or ("range" not in object_[0]["location"]):
698698
return [
699699
converter.structure(item, lsp_types.WorkspaceSymbol) for item in object_
700700
]
701701

702+
return [
703+
converter.structure(item, lsp_types.SymbolInformation) for item in object_
704+
]
705+
702706
def _notebook_sync_registration_option_selector_hook(
703707
object_: Any, _: type
704708
) -> Union[
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import hamcrest
5+
import pytest
6+
from cattrs import ClassValidationError
7+
8+
from lsprotocol import converters as cv
9+
from lsprotocol import types as lsp
10+
11+
TEST_DATA = [
12+
{
13+
"id": 1,
14+
"result": [{"name": "test", "kind": 1, "location": {"uri": "test"}}],
15+
"jsonrpc": "2.0",
16+
},
17+
{
18+
"id": 1,
19+
"result": [
20+
{
21+
"name": "test",
22+
"kind": 1,
23+
"location": {
24+
"uri": "test",
25+
"range": {
26+
"start": {"line": 1, "character": 1},
27+
"end": {"line": 1, "character": 1},
28+
},
29+
},
30+
}
31+
],
32+
"jsonrpc": "2.0",
33+
},
34+
{
35+
"id": 1,
36+
"result": [{"name": "test", "kind": 1, "location": {"uri": "test"}, "data": 1}],
37+
"jsonrpc": "2.0",
38+
},
39+
{
40+
"id": 1,
41+
"result": [
42+
{
43+
"name": "test",
44+
"kind": 1,
45+
"location": {
46+
"uri": "test",
47+
"range": {
48+
"start": {"line": 1, "character": 1},
49+
"end": {"line": 1, "character": 1},
50+
},
51+
},
52+
"deprecated": True,
53+
}
54+
],
55+
"jsonrpc": "2.0",
56+
},
57+
]
58+
59+
BAD_TEST_DATA = [
60+
{
61+
"id": 1,
62+
"result": [
63+
{
64+
"name": "test",
65+
"kind": 1,
66+
"location": {"uri": "test"},
67+
"deprecated": True,
68+
}
69+
],
70+
"jsonrpc": "2.0",
71+
},
72+
]
73+
74+
75+
@pytest.mark.parametrize("data", TEST_DATA)
76+
def test_workspace_symbols(data):
77+
converter = cv.get_converter()
78+
obj = converter.structure(data, lsp.WorkspaceSymbolResponse)
79+
hamcrest.assert_that(obj, hamcrest.instance_of(lsp.WorkspaceSymbolResponse))
80+
hamcrest.assert_that(
81+
converter.unstructure(obj, lsp.WorkspaceSymbolResponse),
82+
hamcrest.is_(data),
83+
)
84+
85+
86+
@pytest.mark.parametrize("data", BAD_TEST_DATA)
87+
def test_workspace_symbols_bad(data):
88+
converter = cv.get_converter()
89+
with pytest.raises(ClassValidationError):
90+
obj = converter.structure(data, lsp.WorkspaceSymbolResponse)
91+
hamcrest.assert_that(obj, hamcrest.instance_of(lsp.WorkspaceSymbolResponse))

0 commit comments

Comments
 (0)