Skip to content

Commit 012ed6e

Browse files
Use upstream signature formatting code for pylsp (#5214)
## 📝 Summary This is a follow-up to #4864 since the signature-formatting capability was incorporated directly into `python-lsp-server` ## 🔍 Description of Changes Removed custom plugin and typechecking dependency on `python-lsp-server`, added configuration to prefer `ruff` if enabled over `black` (default in `python-lsp-server`). This should remain in draft pending a new release of `python-lsp-server`. ## 📋 Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [ ] I have added tests for the changes made. - [ ] I have run the code and verified that it works as expected. ## 📜 Reviewers mscolnick --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 0828063 commit 012ed6e

File tree

3 files changed

+5
-36
lines changed

3 files changed

+5
-36
lines changed

frontend/src/core/codemirror/language/languages/python.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ const lspClient = once((lspConfig: LSPConfig) => {
133133
...ignoredRuffRules,
134134
],
135135
},
136+
signature: {
137+
formatter: config?.enable_ruff ? "ruff" : "black",
138+
line_length: 88,
139+
},
136140
},
137141
},
138142
};

marimo/_server/lsp.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
from marimo._messaging.ops import Alert
1515
from marimo._server.utils import find_free_port
1616
from marimo._tracer import server_tracer
17-
from marimo._types.ids import CellId_t
18-
from marimo._utils.formatter import DefaultFormatter, FormatError
1917
from marimo._utils.paths import marimo_package_path
2018

2119
LOGGER = _loggers.marimo_logger()
@@ -312,27 +310,3 @@ def any_lsp_server_running(config: MarimoConfig) -> bool:
312310
for server in language_servers.values()
313311
)
314312
return (copilot_enabled is not False) or language_servers_enabled
315-
316-
317-
if DependencyManager.pylsp.has():
318-
from pylsp import hookimpl
319-
320-
formatter = DefaultFormatter(line_length=88)
321-
322-
def format_signature(signature: str) -> str:
323-
try:
324-
signature_as_func = f"def {signature.strip()}:\n pass"
325-
dummy_cell_id = cast(CellId_t, "")
326-
reformatted = formatter.format({dummy_cell_id: signature_as_func})[
327-
dummy_cell_id
328-
]
329-
signature = reformatted.removeprefix("def ").removesuffix(
330-
":\n pass"
331-
)
332-
except (ModuleNotFoundError, FormatError):
333-
pass
334-
return "```python\n" + signature + "\n```\n"
335-
336-
@hookimpl
337-
def pylsp_signatures_to_markdown(signatures: list[str]) -> str:
338-
return format_signature("\n".join(signatures))

pyproject.toml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ homepage = "https://github.com/marimo-team/marimo"
7878
[project.entry-points."docstring_to_markdown"]
7979
marimo_converter = "marimo._utils.docs:MarimoConverter"
8080

81-
[project.entry-points."pylsp"]
82-
marimo_plugin = "marimo._server.lsp"
83-
8481
[project.optional-dependencies]
8582
sql = [
8683
"duckdb>=1.0.0",
@@ -117,7 +114,7 @@ dev = [
117114
]
118115

119116
lsp = [
120-
"python-lsp-server>=1.10.0",
117+
"python-lsp-server>=1.13.0",
121118
"python-lsp-ruff>=2.0.0",
122119
]
123120

@@ -195,7 +192,6 @@ dependencies = [
195192
"sqlglot>=23.4",
196193
"sqlalchemy>=2.0.40",
197194
"loro>=1.5.0",
198-
"python-lsp-server>=1.12.1",
199195
"pandas-stubs>=1.5.3.230321",
200196
"pyiceberg>=0.9.0",
201197
"litellm>=1.70.0",
@@ -485,11 +481,6 @@ exclude = [
485481
]
486482
warn_unused_ignores = false
487483

488-
[[tool.mypy.overrides]]
489-
module = "pylsp"
490-
# until https://github.com/python-lsp/python-lsp-server/pull/641 is released
491-
follow_untyped_imports = true
492-
493484
[tool.pytest.ini_options]
494485
minversion = "6.0"
495486
addopts = "-ra -q -v --ignore tests/_cli/ipynb_data --ignore tests/_ast/codegen_data --ignore tests/_ast/app_data"

0 commit comments

Comments
 (0)