From cdb34c30c921a1bd480180c9485d4cac28deede2 Mon Sep 17 00:00:00 2001 From: Xin Zhao Date: Wed, 4 Mar 2026 15:31:27 +0800 Subject: [PATCH] python: Register LSP adapters directly to the LanguageRegistry (#50662) The purpose of `register_available_lsp_adapter()` is to allow language servers to be reused across multiple languages. Since adapters like `ty`, `pylsp`, and `pyright` are specific to Python, there is no need to register them for other languages. Additionally, registering them directly to the global `LanguageRegistry` results in negligible resource consumption. We can then use the default settings to control the default language server for Python, as referenced here: https://github.com/zed-industries/zed/blob/9c9337a8021f74511625517c3f4fa021106609eb/assets/settings/default.json#L2119-L2130 Additionally, the documentation for Python has been updated to clarify that the `"..."` syntax does not mean "keep the rest at default," but rather "include all other available servers." Before you mark this PR as ready for review, make sure that you have: - [ ] Added a solid test coverage and/or screenshots from doing manual testing (no sure how to add test for this) - [x] Done a self-review taking into account security and performance aspects - [x] Aligned any UI changes with the [UI checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) Release Notes: - N/A *or* Added/Fixed/Improved ... --- crates/languages/src/lib.rs | 11 +++++++---- docs/src/languages/python.md | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/languages/src/lib.rs b/crates/languages/src/lib.rs index c31911f372261db47f689d29de9c60c0f9cad56e..4c291b86982a8cb1aa153aa0c036b3d169621339 100644 --- a/crates/languages/src/lib.rs +++ b/crates/languages/src/lib.rs @@ -179,7 +179,13 @@ pub fn init(languages: Arc, fs: Arc, node: NodeRuntime }, LanguageInfo { name: "python", - adapters: vec![basedpyright_lsp_adapter, ruff_lsp_adapter], + adapters: vec![ + basedpyright_lsp_adapter, + ruff_lsp_adapter, + ty_lsp_adapter, + py_lsp_adapter, + python_lsp_adapter, + ], context: Some(python_context_provider), toolchain: Some(python_toolchain_provider), manifest_name: Some(SharedString::new_static("pyproject.toml").into()), @@ -281,9 +287,6 @@ pub fn init(languages: Arc, fs: Arc, node: NodeRuntime typescript_lsp_adapter, ); - languages.register_available_lsp_adapter(python_lsp_adapter.name(), python_lsp_adapter); - languages.register_available_lsp_adapter(py_lsp_adapter.name(), py_lsp_adapter); - languages.register_available_lsp_adapter(ty_lsp_adapter.name(), ty_lsp_adapter); // Register Tailwind for the existing languages that should have it by default. // // This can be driven by the `language_servers` setting once we have a way for diff --git a/docs/src/languages/python.md b/docs/src/languages/python.md index d66f52c71cb9295fe9ca94e5890de48cd1275e57..fdeabec5069ed20a9b168ab19129dde0cc6280ba 100644 --- a/docs/src/languages/python.md +++ b/docs/src/languages/python.md @@ -89,8 +89,8 @@ Configure language servers in Settings ({#kb zed::OpenSettings}) under Languages "languages": { "Python": { "language_servers": [ - // Disable basedpyright and enable ty, and otherwise - // use the default configuration. + // Disable basedpyright and enable ty, and include all + // other registered language servers (ruff, pylsp, pyright). "ty", "!basedpyright", "..."