File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 14
14
from marimo ._messaging .ops import Alert
15
15
from marimo ._server .utils import find_free_port
16
16
from marimo ._tracer import server_tracer
17
+ from marimo ._types .ids import CellId_t
18
+ from marimo ._utils .formatter import DefaultFormatter , FormatError
17
19
from marimo ._utils .paths import marimo_package_path
18
20
19
21
LOGGER = _loggers .marimo_logger ()
@@ -295,3 +297,27 @@ def any_lsp_server_running(config: MarimoConfig) -> bool:
295
297
for server in language_servers .values ()
296
298
)
297
299
return (copilot_enabled is not False ) or language_servers_enabled
300
+
301
+
302
+ if DependencyManager .pylsp .has ():
303
+ from pylsp import hookimpl
304
+
305
+ formatter = DefaultFormatter (line_length = 88 )
306
+
307
+ def format_signature (signature : str ) -> str :
308
+ try :
309
+ signature_as_func = f"def { signature .strip ()} :\n pass"
310
+ dummy_cell_id = cast (CellId_t , "" )
311
+ reformatted = formatter .format ({dummy_cell_id : signature_as_func })[
312
+ dummy_cell_id
313
+ ]
314
+ signature = reformatted .removeprefix ("def " ).removesuffix (
315
+ ":\n pass"
316
+ )
317
+ except (ModuleNotFoundError , FormatError ):
318
+ pass
319
+ return "```python\n " + signature + "\n ```\n "
320
+
321
+ @hookimpl
322
+ def pylsp_signatures_to_markdown (signatures : list [str ]) -> str :
323
+ return format_signature ("\n " .join (signatures ))
Original file line number Diff line number Diff line change @@ -78,6 +78,9 @@ homepage = "https://github.com/marimo-team/marimo"
78
78
[project .entry-points ."docstring_to_markdown" ]
79
79
marimo_converter = " marimo._utils.docs:MarimoConverter"
80
80
81
+ [project .entry-points ."pylsp" ]
82
+ marimo_plugin = " marimo._server.lsp"
83
+
81
84
[project .optional-dependencies ]
82
85
sql = [
83
86
" duckdb>=1.0.0" ,
@@ -192,6 +195,7 @@ dependencies = [
192
195
" sqlglot>=23.4" ,
193
196
" sqlalchemy>=2.0.40" ,
194
197
" loro>=1.5.0" ,
198
+ " python-lsp-server>=1.12.1" ,
195
199
" pandas-stubs>=1.5.3.230321" ,
196
200
" pyiceberg>=0.9.0" ,
197
201
" types-Pillow~=10.2.0.20240520" ,
@@ -470,6 +474,11 @@ exclude = [
470
474
]
471
475
warn_unused_ignores = false
472
476
477
+ [[tool .mypy .overrides ]]
478
+ module = " pylsp"
479
+ # until https://github.com/python-lsp/python-lsp-server/pull/641 is released
480
+ follow_untyped_imports = true
481
+
473
482
[tool .pytest .ini_options ]
474
483
minversion = " 6.0"
475
484
addopts = " -ra -q -v --ignore tests/_cli/ipynb_data --ignore tests/_ast/codegen_data --ignore tests/_ast/app_data"
You can’t perform that action at this time.
0 commit comments