Skip to content

python: Register LSP adapters directly to the LanguageRegistry#50662

Merged
Veykril merged 2 commits intozed-industries:mainfrom
lingyaochu:python_lsp
Mar 4, 2026
Merged

python: Register LSP adapters directly to the LanguageRegistry#50662
Veykril merged 2 commits intozed-industries:mainfrom
lingyaochu:python_lsp

Conversation

@lingyaochu
Copy link
Copy Markdown
Contributor

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:

"Python": {
"code_actions_on_format": {
"source.organizeImports.ruff": true,
},
"formatter": {
"language_server": {
"name": "ruff",
},
},
"debuggers": ["Debugpy"],
"language_servers": ["basedpyright", "ruff", "!ty", "!pyrefly", "!pyright", "!pylsp", "..."],
},

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)
  • Done a self-review taking into account security and performance aspects
  • Aligned any UI changes with the UI checklist

Release Notes:

  • N/A or Added/Fixed/Improved ...

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 4, 2026
@github-actions github-actions bot added the community champion Issues filed by our amazing community champions! 🫶 label Mar 4, 2026
@lingyaochu lingyaochu changed the title Python: register lsp adapters directly to the LanguageRegistry python: Register LSP adapters directly to the LanguageRegistry Mar 4, 2026
@Veykril
Copy link
Copy Markdown
Member

Veykril commented Mar 4, 2026

Thanks!

@Veykril Veykril enabled auto-merge (squash) March 4, 2026 07:28
@Veykril Veykril merged commit cdb34c3 into zed-industries:main Mar 4, 2026
31 checks passed
@lingyaochu lingyaochu deleted the python_lsp branch March 4, 2026 07:36
tahayvr pushed a commit to tahayvr/zed that referenced this pull request Mar 4, 2026
…ndustries#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 ...
wzulfikar pushed a commit to wzulfikar/zed that referenced this pull request Mar 4, 2026
…ndustries#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 ...
Veykril pushed a commit that referenced this pull request Mar 6, 2026
…ent (#50697)

Closes #47917

Currently, during remote development, Zed uses the first available local
LSP adapter to handle all label computing. This isn't ideal and causes
bugs because different adapters may expect different label formats. By
leveraging the `all_capable_for_proto_request` method, we can now
retrieve the specific language server name and use it as a key to find
the correct LSP adapter for label population. Even if this lookup fails,
we can still fall back to the first adapter, so this PR should provide
more accurate label population than before.

This addresses the root cause of #47917, which stems from two main
issues. For example, in remote Python development, the `basedpyright`
adapter might incorrectly handle labels even when the remote server is
actually `ty`. The completion items returned by `ty` are slightly
different from `basedpyright`: `ty` stores labels in
`labelDetails.detail`, while basedpyright uses
`labelDetails.description`. By matching the correct adapter, we ensure
labels are populated properly for completion items.
```json
// RPC message returned by `ty`, label is in `labelDetails.detail`
{
  ...
  "labelDetails": { "detail": " (import pathlib)" },
  ...
}

// RPC message returned by `basedpyright`, label is in `labelDetails.description`
{
  ...
  "labelDetails": { "description": "pathlib" },
  ...
}
```
Additionally, adapters registered via `register_available_lsp_adapter`
are lazy-loaded into the `LanguageRegistry` (which is the case for `ty`
before). In remote scenarios, the adapter might be loaded on the remote
server but not on the local host, making it hard to find in
`lsp_adapters`. This is partially resolved in #50662, and combined with
this PR, we can fully address #47917.

There is still more to do, however. In some cases, we still can't find
the correct local LSP adapter if the local host lacks the registry that
the remote server has; this typically happens when the adapter is
registered via `register_available_lsp_adapter`. I've opened a feature
discussion #49178 to track this. If it's decided that this needs further
refinement, I'm happy to continue working on it.


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
- [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:

- Fixed missing labels for `ty` completion items in remote development.
dapovoa pushed a commit to dapovoa/zed that referenced this pull request Mar 7, 2026
…ent (zed-industries#50697)

Closes zed-industries#47917

Currently, during remote development, Zed uses the first available local
LSP adapter to handle all label computing. This isn't ideal and causes
bugs because different adapters may expect different label formats. By
leveraging the `all_capable_for_proto_request` method, we can now
retrieve the specific language server name and use it as a key to find
the correct LSP adapter for label population. Even if this lookup fails,
we can still fall back to the first adapter, so this PR should provide
more accurate label population than before.

This addresses the root cause of zed-industries#47917, which stems from two main
issues. For example, in remote Python development, the `basedpyright`
adapter might incorrectly handle labels even when the remote server is
actually `ty`. The completion items returned by `ty` are slightly
different from `basedpyright`: `ty` stores labels in
`labelDetails.detail`, while basedpyright uses
`labelDetails.description`. By matching the correct adapter, we ensure
labels are populated properly for completion items.
```json
// RPC message returned by `ty`, label is in `labelDetails.detail`
{
  ...
  "labelDetails": { "detail": " (import pathlib)" },
  ...
}

// RPC message returned by `basedpyright`, label is in `labelDetails.description`
{
  ...
  "labelDetails": { "description": "pathlib" },
  ...
}
```
Additionally, adapters registered via `register_available_lsp_adapter`
are lazy-loaded into the `LanguageRegistry` (which is the case for `ty`
before). In remote scenarios, the adapter might be loaded on the remote
server but not on the local host, making it hard to find in
`lsp_adapters`. This is partially resolved in zed-industries#50662, and combined with
this PR, we can fully address zed-industries#47917.

There is still more to do, however. In some cases, we still can't find
the correct local LSP adapter if the local host lacks the registry that
the remote server has; this typically happens when the adapter is
registered via `register_available_lsp_adapter`. I've opened a feature
discussion zed-industries#49178 to track this. If it's decided that this needs further
refinement, I'm happy to continue working on it.


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
- [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:

- Fixed missing labels for `ty` completion items in remote development.
@zelenenka zelenenka added the guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions label Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement community champion Issues filed by our amazing community champions! 🫶 guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants