Skip to content

modules/lsp: feat add ansiblels back and add defaults for ansiblels cmd#4211

Open
dtvillafana wants to merge 1 commit intonix-community:mainfrom
dtvillafana:main
Open

modules/lsp: feat add ansiblels back and add defaults for ansiblels cmd#4211
dtvillafana wants to merge 1 commit intonix-community:mainfrom
dtvillafana:main

Conversation

@dtvillafana
Copy link
Copy Markdown

@dtvillafana dtvillafana commented Mar 3, 2026

This might not be the best way to do this, but I figured out a way to add back in ansiblels and set the cmd.

did this because I added ansible-language-server to upstream nixpkgs so that I could use it in nixvim, so I figured I'd open a PR here.

@dtvillafana dtvillafana changed the title feat: add defaults for ansiblels modules/lsp: feat add ansiblels back and add defaults for ansiblels cmd Mar 3, 2026
@dtvillafana
Copy link
Copy Markdown
Author

nixpkgs needs to be updated so that ansible-language-server is available, but updating it also causes build failures.
Fixing all those is beyond my time and expertise currently.
If this isn't helpful, please leave some advice before closing the PR.

Copy link
Copy Markdown
Member

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

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

Some feedback on the approach taken and some comments on how this highlights issues with Nixvim's existing architecture.

Thanks for opening the PR!

nixpkgs needs to be updated so that ansible-language-server is available

I think this is resolved now on main?

@@ -0,0 +1,8 @@
{ lib, config, ... }:
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
{
{
options.config = lib.mkOption {
// Use option declaration merging to set defaultText
type = with lib.types; attrsOf anything;
defaultText = lib.literalExpression ''
[
(lib.getExe config.${options.package})
"--stdio"
]
'';
};

That'll render the default in docs as something like:

[
  (lib.getExe config.lsp.servers.ansiblels.package)
  "--stdio"
]

However, we don't need this if we drop the below config definition.

{
# cmd depends on evaluated config.package, so set via module config
config.config.cmd = lib.mkIf (config.package != null) [
(lib.getExe config.package)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we really need getExe here? The lsp module installs config.package onto the neovim PATH. Most (all?) servers run the LSP via the path rather than an absolute path-in-store.

Suggested change
(lib.getExe config.package)
"ansible-language-server"

(if so, we can drop this entire file)

{ lib, config, ... }:
{
# cmd depends on evaluated config.package, so set via module config
config.config.cmd = lib.mkIf (config.package != null) [
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This sets config and config.cmd at the defaultOverridePriority (100). That's bad because it is the same override priority typically used by end-users, so their cmd definition will be merged with this one into a single list.

Ideally, we want mkOptionDefault as that is the override priority used by mkOption's default. mkDefault is also acceptable, as is mkOverride 1499 (1 less than mkOptionDefault).

https://github.com/NixOS/nixpkgs/blob/e3b13232390e3c72d8d6fe1214bd406cded4d9d0/lib/modules.nix#L1577-L1581

In this case, I don't think we need this definition at all. The default you passed into config = mkOption already specifies [ "ansible-language-server" "--stdio" ] and the lsp module ensures that config.package is on neovim's PATH.

@@ -195,6 +190,15 @@
aiken = "aiken";
air = "air-formatter";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file is currently supposed to be a simple mapping of lsp->package. Having a mixture of plain package values and default config values complicates it, and complicates our usage in modules/lsp/servers/default.nix and tests.


We can simplify by doing this throughout the file:

Suggested change
air = "air-formatter";
air.package = "air-formatter";

But this has a bunch of follow-up implications:

E.g. renaming packages to something like configs, modules, args, etc. Maybe rename the file to something like known-servers.nix or servers/known.nix (requires treewide updates).

...and we could also simplify unpackaged = [ "foo" ] to foo = null and filter out nulls in modules/lsp/servers/default.nix. Maybe.

Therefore, we'd want to isolate such a refactor to a separate PR, though. Especially as it'll require treewide updates everywhere the file is imported.

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.

2 participants