Skip to content

Commit a1bbd40

Browse files
lgeigergatesn
authored andcommitted
Jedi symbols: Add all_scopes config option (#140)
* Jedi symbols: Add all_scopes config setting * Jedi symbols: Test all_scopes option * Jedi symbols: Enable `all_scopes` per default
1 parent 2d502da commit a1bbd40

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

pyls/plugins/symbols.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88

99
@hookimpl
10-
def pyls_document_symbols(document):
11-
definitions = document.jedi_names()
10+
def pyls_document_symbols(config, document):
11+
all_scopes = config.plugin_settings('jedi_symbols').get('all_scopes', True)
12+
definitions = document.jedi_names(all_scopes=all_scopes)
1213
return [{
1314
'name': d.name,
1415
'kind': _kind(d),

test/plugins/test_symbols.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@
99
1010
a = 'hello'
1111
12-
class B(object):
13-
pass
12+
class B:
13+
def __init__():
14+
pass
1415
1516
def main():
1617
pass
1718
"""
1819

1920

20-
def test_symbols():
21+
def test_symbols(config):
2122
doc = Document(DOC_URI, DOC)
22-
symbols = pyls_document_symbols(doc)
23+
config.update({'plugins': {'jedi_symbols': {'all_scopes': False}}})
24+
symbols = pyls_document_symbols(config, doc)
2325

2426
# All four symbols (import sys, a, B, main)
2527
assert len(symbols) == 4
@@ -35,3 +37,24 @@ def sym(name):
3537

3638
# Not going to get too in-depth here else we're just testing Jedi
3739
assert sym('a')['location']['range']['start'] == {'line': 2, 'character': 0}
40+
41+
42+
def test_symbols_alls_scopes(config):
43+
doc = Document(DOC_URI, DOC)
44+
symbols = pyls_document_symbols(config, doc)
45+
46+
# All five symbols (import sys, a, B, __init__, main)
47+
assert len(symbols) == 5
48+
49+
def sym(name):
50+
return [s for s in symbols if s['name'] == name][0]
51+
52+
# Check we have some sane mappings to VSCode constants
53+
assert sym('sys')['kind'] == SymbolKind.Module
54+
assert sym('a')['kind'] == SymbolKind.Variable
55+
assert sym('B')['kind'] == SymbolKind.Class
56+
assert sym('__init__')['kind'] == SymbolKind.Function
57+
assert sym('main')['kind'] == SymbolKind.Function
58+
59+
# Not going to get too in-depth here else we're just testing Jedi
60+
assert sym('a')['location']['range']['start'] == {'line': 2, 'character': 0}

vscode-client/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
"default": true,
5151
"description": "Enable or disable the plugin."
5252
},
53+
"pyls.plugins.jedi_symbols.all_scopes": {
54+
"type": "boolean",
55+
"default": true,
56+
"description": "If True lists the names of all scopes instead of only the module namespace."
57+
},
5358
"pyls.plugins.mccabe.enabled": {
5459
"type": "boolean",
5560
"default": true,

0 commit comments

Comments
 (0)