Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions marimo/_server/lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from marimo._messaging.ops import Alert
from marimo._server.utils import find_free_port
from marimo._tracer import server_tracer
from marimo._types.ids import CellId_t
from marimo._utils.formatter import DefaultFormatter, FormatError
from marimo._utils.paths import marimo_package_path

LOGGER = _loggers.marimo_logger()
Expand Down Expand Up @@ -295,3 +297,27 @@ def any_lsp_server_running(config: MarimoConfig) -> bool:
for server in language_servers.values()
)
return (copilot_enabled is not False) or language_servers_enabled


if DependencyManager.pylsp.has():
from pylsp import hookimpl

formatter = DefaultFormatter(line_length=88)

def format_signature(signature: str) -> str:
try:
signature_as_func = f"def {signature.strip()}:\n pass"
dummy_cell_id = cast(CellId_t, "")
reformatted = formatter.format({dummy_cell_id: signature_as_func})[
dummy_cell_id
]
signature = reformatted.removeprefix("def ").removesuffix(
":\n pass"
)
except (ModuleNotFoundError, FormatError):
pass
return "```python\n" + signature + "\n```\n"

@hookimpl
def pylsp_signatures_to_markdown(signatures: list[str]) -> str:
return format_signature("\n".join(signatures))
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ homepage = "https://github.com/marimo-team/marimo"
[project.entry-points."docstring_to_markdown"]
marimo_converter = "marimo._utils.docs:MarimoConverter"

[project.entry-points."pylsp"]
marimo_plugin = "marimo._server.lsp"

[project.optional-dependencies]
sql = [
"duckdb>=1.0.0",
Expand Down Expand Up @@ -192,6 +195,7 @@ dependencies = [
"sqlglot>=23.4",
"sqlalchemy>=2.0.40",
"loro>=1.5.0",
"python-lsp-server>=1.12.1",
"pandas-stubs>=1.5.3.230321",
"pyiceberg>=0.9.0",
"types-Pillow~=10.2.0.20240520",
Expand Down Expand Up @@ -470,6 +474,11 @@ exclude = [
]
warn_unused_ignores = false

[[tool.mypy.overrides]]
module = "pylsp"
# until https://github.com/python-lsp/python-lsp-server/pull/641 is released
follow_untyped_imports = true

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -q -v --ignore tests/_cli/ipynb_data --ignore tests/_ast/codegen_data --ignore tests/_ast/app_data"
Expand Down
Loading