diff --git a/pyls/plugins/symbols.py b/pyls/plugins/symbols.py index 82af34a4..6b9a951d 100644 --- a/pyls/plugins/symbols.py +++ b/pyls/plugins/symbols.py @@ -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), diff --git a/test/plugins/test_symbols.py b/test/plugins/test_symbols.py index 3d8d47dd..54cd8a2f 100644 --- a/test/plugins/test_symbols.py +++ b/test/plugins/test_symbols.py @@ -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 @@ -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} diff --git a/vscode-client/package.json b/vscode-client/package.json index 4dba8f64..b75ce259 100644 --- a/vscode-client/package.json +++ b/vscode-client/package.json @@ -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,