Skip to content

Commit c6740a5

Browse files
committed
Try to implement first version of workspace/symbol
1 parent 4c0e99b commit c6740a5

File tree

7 files changed

+51
-2
lines changed

7 files changed

+51
-2
lines changed

pylsp/config/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@
257257
"default": true,
258258
"description": "If True includes symbols imported from other libraries."
259259
},
260+
"pylsp.plugins.jedi_workspace_symbols": {
261+
"type": "boolean",
262+
"default": true,
263+
"description": "If True includes workspace symbols."
264+
},
260265
"pylsp.plugins.mccabe.enabled": {
261266
"type": "boolean",
262267
"default": true,

pylsp/hookspecs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def pylsp_execute_command(config, workspace, command, arguments):
6868
pass
6969

7070

71+
@hookspec
72+
def pylsp_workspace_symbol(config, workspace, document, query):
73+
pass
74+
75+
7176
@hookspec
7277
def pylsp_experimental_capabilities(config, workspace):
7378
pass
File renamed without changes.

pylsp/plugins/workspace_symbol.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2017-2020 Palantir Technologies, Inc.
2+
# Copyright 2021- Python Language Server Contributors.
3+
4+
import logging
5+
from pathlib import Path
6+
7+
from pylsp import hookimpl
8+
from pylsp.lsp import SymbolKind
9+
10+
log = logging.getLogger(__name__)
11+
12+
13+
@hookimpl
14+
def pylsp_workspace_symbol(config, workspace, document, query):
15+
log.debug("pylsp_workspace_symbol is called!")
16+
return [
17+
{
18+
"name": "test",
19+
"kind": SymbolKind.File,
20+
"location": {
21+
"uri": "file:/tmp/test.py",
22+
"range": {
23+
"start": {"line": 0, "character": 0},
24+
"end": {"line": 0, "character": 0},
25+
},
26+
},
27+
]
28+

pylsp/python_lsp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ def capabilities(self):
298298
"workspaceFolders": {"supported": True, "changeNotifications": True}
299299
},
300300
"experimental": merge(self._hook("pylsp_experimental_capabilities")),
301+
"workspaceSymbolProvider": True,
301302
}
302303
log.info("Server capabilities: %s", server_capabilities)
303304
return server_capabilities
@@ -433,6 +434,11 @@ def highlight(self, doc_uri, position):
433434
or None
434435
)
435436

437+
def workspace_symbol(self, query):
438+
response = self._hook("pylsp_workspace_symbol", query=query)
439+
log.debug("Workspace symbol hook returned: %s", response)
440+
return flatten(response)
441+
436442
def hover(self, doc_uri, position):
437443
return self._hook("pylsp_hover", doc_uri, position=position) or {"contents": ""}
438444

@@ -767,6 +773,9 @@ def m_text_document__hover(self, textDocument=None, position=None, **_kwargs):
767773
def m_text_document__document_symbol(self, textDocument=None, **_kwargs):
768774
return self.document_symbols(textDocument["uri"])
769775

776+
def m_workspace__symbol(self, textDocument=None, **_kwargs):
777+
return self.workspace_symbol(_kwargs["query"])
778+
770779
def m_text_document__formatting(self, textDocument=None, options=None, **_kwargs):
771780
return self.format_document(textDocument["uri"], options)
772781

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ jedi_highlight = "pylsp.plugins.highlight"
7171
jedi_references = "pylsp.plugins.references"
7272
jedi_rename = "pylsp.plugins.jedi_rename"
7373
jedi_signature_help = "pylsp.plugins.signature"
74-
jedi_symbols = "pylsp.plugins.symbols"
74+
jedi_symbols = "pylsp.plugins.document_symbols"
75+
jedi_workspace_symbol = "pylsp.plugins.workspace_symbol"
7576
mccabe = "pylsp.plugins.mccabe_lint"
7677
preload = "pylsp.plugins.preload_imports"
7778
pycodestyle = "pylsp.plugins.pycodestyle_lint"

test/plugins/test_symbols.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
from pylsp import uris
1010
from pylsp.lsp import SymbolKind
11-
from pylsp.plugins.symbols import pylsp_document_symbols
11+
from pylsp.plugins.document_symbols import pylsp_document_symbols
12+
from pylsp.plugins.workspace_symbol import pylsp_workspace_symbol
1213
from pylsp.workspace import Document
1314

1415
PY2 = sys.version[0] == "2"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy