Skip to content

Commit a6dc68b

Browse files
committed
clean up test
1 parent e4ec937 commit a6dc68b

File tree

4 files changed

+39
-68
lines changed

4 files changed

+39
-68
lines changed

pylsp/hookspecs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def pylsp_execute_command(config, workspace, command, arguments):
6969

7070

7171
@hookspec
72-
def pylsp_workspace_symbol(config, workspace, query):
72+
def pylsp_workspace_symbol(workspace, query):
7373
pass
7474

7575

pylsp/plugins/workspace_symbol.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Copyright 2021- Python Language Server Contributors.
33

44
import logging
5-
from pathlib import Path
65

76
from pylsp import hookimpl
87
from pylsp.lsp import SymbolKind
@@ -11,11 +10,14 @@
1110

1211

1312
@hookimpl
14-
def pylsp_workspace_symbol(config, workspace, query):
13+
def pylsp_workspace_symbol(workspace, query):
1514
if not query or not workspace:
1615
return []
1716

18-
return [_jedi_name_to_symbol(jedi_name) for jedi_name in workspace.search(query)]
17+
return [
18+
_jedi_name_to_symbol(jedi_name)
19+
for jedi_name in workspace.complete_search(query)
20+
]
1921

2022

2123
def _jedi_name_to_symbol(jedi_name):
@@ -33,18 +35,8 @@ def _jedi_name_to_symbol(jedi_name):
3335

3436

3537
def _jedi_type_to_symbol_kind(jedi_type):
36-
if jedi_type == "module":
37-
return SymbolKind.Module
38-
if jedi_type == "class":
39-
return SymbolKind.Class
40-
if jedi_type == "function":
41-
return SymbolKind.Function
42-
if jedi_type == "instance":
43-
return SymbolKind.Variable
44-
if jedi_type == "statement":
45-
return SymbolKind.Variable
46-
if jedi_type == "param":
47-
return SymbolKind.Variable
48-
if jedi_type == "path":
49-
return SymbolKind.File
50-
return SymbolKind.Variable
38+
return {
39+
"module": SymbolKind.Module,
40+
"class": SymbolKind.Class,
41+
"function": SymbolKind.Function,
42+
}.get(jedi_type, SymbolKind.Variable)

pylsp/workspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def root_path(self):
100100
def root_uri(self):
101101
return self._root_uri
102102

103-
def search(self, query):
103+
def complete_search(self, query):
104104
project = self.jedi_project()
105105
return project.complete_search(query)
106106

test/plugins/test_workspace_symbols.py

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,49 @@
77
import pytest
88

99
from pylsp import uris
10-
from pylsp.lsp import SymbolKind
1110
from pylsp.plugins.workspace_symbol import pylsp_workspace_symbol
12-
from pylsp.workspace import Workspace
1311

1412
PY2 = sys.version[0] == "2"
1513
LINUX = sys.platform.startswith("linux")
1614
CI = os.environ.get("CI")
1715
DOC_URI = uris.from_fs_path(__file__)
18-
DOC = """import sys
1916

20-
a = 'hello'
2117

22-
class B:
23-
def __init__(self):
24-
x = 2
25-
self.y = x
26-
27-
def main(x):
28-
y = 2 * x
29-
return y
18+
DOC1_NAME = "file1.py"
19+
DOC2_NAME = "file2.py"
3020

21+
DOC1 = """class Test1():
22+
pass
3123
"""
3224

25+
DOC2 = """from file1 import Test1
3326
34-
def test_symbols_empty_query(config, workspace):
35-
config.update({"plugins": {"jedi_workspace_symbols": {"enabled": True}}})
36-
symbols = pylsp_workspace_symbol(config, workspace, "")
27+
try:
28+
Test1()
29+
except UnicodeError:
30+
pass
31+
"""
3732

38-
assert len(symbols) == 0
3933

34+
@pytest.fixture
35+
def tmp_workspace(temp_workspace_factory):
36+
return temp_workspace_factory(
37+
{
38+
DOC1_NAME: DOC1,
39+
DOC2_NAME: DOC2,
40+
}
41+
)
4042

41-
def test_symbols_nonempty_query(config, workspace):
42-
config.update({"plugins": {"jedi_workspace_symbols": {"enabled": True}}})
43-
symbols = pylsp_workspace_symbol(config, workspace, "main")
43+
44+
def test_symbols_empty_query(tmp_workspace):
45+
symbols = pylsp_workspace_symbol(tmp_workspace, "")
4446

4547
assert len(symbols) == 0
4648

4749

48-
#
49-
# def test_symbols_all_scopes(config, workspace):
50-
# doc = Document(DOC_URI, workspace, DOC)
51-
# symbols = pylsp_document_symbols(config, doc)
52-
# helper_check_symbols_all_scope(symbols)
53-
#
54-
#
55-
# def test_symbols_non_existing_file(config, workspace, tmpdir):
56-
# path = tmpdir.join("foo.py")
57-
# # Check pre-condition: file must not exist
58-
# assert not path.check(exists=1)
59-
#
60-
# doc = Document(uris.from_fs_path(str(path)), workspace, DOC)
61-
# symbols = pylsp_document_symbols(config, doc)
62-
# helper_check_symbols_all_scope(symbols)
63-
#
64-
#
65-
# @pytest.mark.skipif(
66-
# PY2 or not LINUX or not CI, reason="tested on linux and python 3 only"
67-
# )
68-
# def test_symbols_all_scopes_with_jedi_environment(workspace):
69-
# doc = Document(DOC_URI, workspace, DOC)
70-
#
71-
# # Update config extra environment
72-
# env_path = "/tmp/pyenv/bin/python"
73-
# settings = {"pylsp": {"plugins": {"jedi": {"environment": env_path}}}}
74-
# doc.update_config(settings)
75-
# symbols = pylsp_document_symbols(doc._config, doc)
76-
# helper_check_symbols_all_scope(symbols)
50+
def test_symbols_nonempty_query(tmp_workspace):
51+
symbols = pylsp_workspace_symbol(tmp_workspace, "Test")
52+
53+
assert len(symbols) == 1
54+
assert symbols[0]["name"] == "Test1"
55+
assert symbols[0]["kind"] == 5 # Class

0 commit comments

Comments
 (0)