Skip to content

Commit

Permalink
Try to implement first version of workspace/symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
niilohlin committed Jun 1, 2024
1 parent 4c0e99b commit 9c6c327
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pylsp/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@
"default": true,
"description": "If True includes symbols imported from other libraries."
},
"pylsp.plugins.jedi_workspace_symbols": {
"type": "boolean",
"default": true,
"description": "If True includes workspace symbols."
},
"pylsp.plugins.mccabe.enabled": {
"type": "boolean",
"default": true,
Expand Down
5 changes: 5 additions & 0 deletions pylsp/hookspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def pylsp_execute_command(config, workspace, command, arguments):
pass


@hookspec
def pylsp_workspace_symbol(config, workspace, document, query):
pass


@hookspec
def pylsp_experimental_capabilities(config, workspace):
pass
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions pylsp/plugins/workspace_symbol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2017-2020 Palantir Technologies, Inc.
# Copyright 2021- Python Language Server Contributors.

import logging
from pathlib import Path

from pylsp import hookimpl
from pylsp.lsp import SymbolKind

log = logging.getLogger(__name__)


@hookimpl
def pylsp_workspace_symbol(config, workspace, document, query):
log.debug("pylsp_workspace_symbol is called!")
return [
{
"name": "test",
"kind": SymbolKind.File,
"location": {
"uri": "file:/tmp/test.py",
"range": {
"start": {"line": 0, "character": 0},
"end": {"line": 0, "character": 0},
},
},
]

9 changes: 9 additions & 0 deletions pylsp/python_lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def capabilities(self):
"workspaceFolders": {"supported": True, "changeNotifications": True}
},
"experimental": merge(self._hook("pylsp_experimental_capabilities")),
"workspaceSymbolProvider": True,
}
log.info("Server capabilities: %s", server_capabilities)
return server_capabilities
Expand Down Expand Up @@ -433,6 +434,11 @@ def highlight(self, doc_uri, position):
or None
)

def workspace_symbol(self, query):
hook = self._hook("pylsp_workspace_symbol", query=query)
log.debug("Workspace symbol hook returned: %s", hook)
return hook

def hover(self, doc_uri, position):
return self._hook("pylsp_hover", doc_uri, position=position) or {"contents": ""}

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

def m_workspace__symbol(self, textDocument=None, **_kwargs):
return self.workspace_symbol(_kwargs["query"])

def m_text_document__formatting(self, textDocument=None, options=None, **_kwargs):
return self.format_document(textDocument["uri"], options)

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ jedi_highlight = "pylsp.plugins.highlight"
jedi_references = "pylsp.plugins.references"
jedi_rename = "pylsp.plugins.jedi_rename"
jedi_signature_help = "pylsp.plugins.signature"
jedi_symbols = "pylsp.plugins.symbols"
jedi_symbols = "pylsp.plugins.document_symbols"
jedi_workspace_symbol = "pylsp.plugins.workspace_symbol"
mccabe = "pylsp.plugins.mccabe_lint"
preload = "pylsp.plugins.preload_imports"
pycodestyle = "pylsp.plugins.pycodestyle_lint"
Expand Down
3 changes: 2 additions & 1 deletion test/plugins/test_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

from pylsp import uris
from pylsp.lsp import SymbolKind
from pylsp.plugins.symbols import pylsp_document_symbols
from pylsp.plugins.document_symbols import pylsp_document_symbols
from pylsp.plugins.workspace_symbol import pylsp_workspace_symbol
from pylsp.workspace import Document

PY2 = sys.version[0] == "2"
Expand Down

0 comments on commit 9c6c327

Please sign in to comment.