Skip to content

Commit

Permalink
Jedi symbols: Add all_scopes config option (#140)
Browse files Browse the repository at this point in the history
* Jedi symbols: Add all_scopes config setting

* Jedi symbols: Test all_scopes option

* Jedi symbols: Enable `all_scopes` per default
  • Loading branch information
lgeiger authored and gatesn committed Sep 27, 2017
1 parent 2d502da commit a1bbd40
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pyls/plugins/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@


@hookimpl
def pyls_document_symbols(document):
definitions = document.jedi_names()
def pyls_document_symbols(config, document):
all_scopes = config.plugin_settings('jedi_symbols').get('all_scopes', True)
definitions = document.jedi_names(all_scopes=all_scopes)
return [{
'name': d.name,
'kind': _kind(d),
Expand Down
31 changes: 27 additions & 4 deletions test/plugins/test_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
a = 'hello'
class B(object):
pass
class B:
def __init__():
pass
def main():
pass
"""


def test_symbols():
def test_symbols(config):
doc = Document(DOC_URI, DOC)
symbols = pyls_document_symbols(doc)
config.update({'plugins': {'jedi_symbols': {'all_scopes': False}}})
symbols = pyls_document_symbols(config, doc)

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

# Not going to get too in-depth here else we're just testing Jedi
assert sym('a')['location']['range']['start'] == {'line': 2, 'character': 0}


def test_symbols_alls_scopes(config):
doc = Document(DOC_URI, DOC)
symbols = pyls_document_symbols(config, doc)

# All five symbols (import sys, a, B, __init__, main)
assert len(symbols) == 5

def sym(name):
return [s for s in symbols if s['name'] == name][0]

# Check we have some sane mappings to VSCode constants
assert sym('sys')['kind'] == SymbolKind.Module
assert sym('a')['kind'] == SymbolKind.Variable
assert sym('B')['kind'] == SymbolKind.Class
assert sym('__init__')['kind'] == SymbolKind.Function
assert sym('main')['kind'] == SymbolKind.Function

# Not going to get too in-depth here else we're just testing Jedi
assert sym('a')['location']['range']['start'] == {'line': 2, 'character': 0}
5 changes: 5 additions & 0 deletions vscode-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"default": true,
"description": "Enable or disable the plugin."
},
"pyls.plugins.jedi_symbols.all_scopes": {
"type": "boolean",
"default": true,
"description": "If True lists the names of all scopes instead of only the module namespace."
},
"pyls.plugins.mccabe.enabled": {
"type": "boolean",
"default": true,
Expand Down

0 comments on commit a1bbd40

Please sign in to comment.