Skip to content

modules/lsp: add onAttach option #3280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2025

Conversation

MattSturgeon
Copy link
Member

@MattSturgeon MattSturgeon commented May 3, 2025

Similar to plugins.lsp.onAttach, implement a "global" equivalent to the per-server on_attach callback.

The implementation is simpler than plugins.lsp.onAttach, by using a LspAttach autocmd. The old impl was to propagate the global onAttach lines into each server's on_attach callback.

The old impl should be able to migrate to using the new option under the hood, or even become an alias of it.

Alternatively, we might decide we don't want this at all? Although it seems convenient.

Perhaps in future it'd be nice to have a similar per-server onAttach option? When the per-server onAttach option is defined, settings.on_attach would be derived from it, using it as the function body.

@MattSturgeon MattSturgeon requested a review from a team May 3, 2025 22:45
Copy link
Member

@GaetanLepage GaetanLepage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good to me.
However, I agree about assessing the relevance of such a feature first.
We could maybe poll our users in the Matrix chat?

Copy link
Contributor

@jfly jfly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would make my work in #3289 simpler!

@MattSturgeon MattSturgeon requested a review from a team May 5, 2025 20:47
Similar to `plugins.lsp.onAttach`, implement a "global" equivalent to
the per-server `on_attach` callback.

This is implemented using a `LspAttach` autoCmd.
@MattSturgeon
Copy link
Member Author

I've added a second commit which refactors #3289 to make use of the new option.

Hopefully this demonstrates the usefulness of it?

@MattSturgeon MattSturgeon requested a review from jfly May 6, 2025 12:20
Copy link
Member

@GaetanLepage GaetanLepage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MattSturgeon

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

@MattSturgeon MattSturgeon merged commit c26f5c2 into nix-community:main May 6, 2025
3 of 4 checks passed
@MattSturgeon MattSturgeon deleted the lsp-on-attach branch May 6, 2025 13:09
Copy link
Contributor

@jfly jfly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants