From 5090767ba2dc87a98e81e70c519d8bb5e2d28f53 Mon Sep 17 00:00:00 2001 From: "Alexandre Cavalheiro S. Tiago da Silva" Date: Thu, 24 Apr 2025 22:44:12 -0300 Subject: [PATCH 1/2] fix(neovim): update roslyn.nvim to new spec Also finally call AstroLsp's `on_attach` function for `roslyn` and `rzls` lsp servers. --- modules/neovim/lua/plugins/roslyn-nvim.lua | 31 +++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/modules/neovim/lua/plugins/roslyn-nvim.lua b/modules/neovim/lua/plugins/roslyn-nvim.lua index 11607a2..9747d5a 100644 --- a/modules/neovim/lua/plugins/roslyn-nvim.lua +++ b/modules/neovim/lua/plugins/roslyn-nvim.lua @@ -7,9 +7,15 @@ return { dependencies = { { "tris203/rzls.nvim", + ---@return rzls.Config opts = function(_, opts) + local has_astrolsp, astrolsp = pcall(require, "astrolsp") + local has_blink, blink = pcall(require, "blink-cmp") + opts = { - capabilities = vim.lsp.protocol.make_client_capabilities(), + capabilities = has_blink and blink.get_lsp_capabilities({}, true) + or vim.lsp.protocol.make_client_capabilities(), + on_attach = has_astrolsp and astrolsp.on_attach or nil, path = vim.fn.get_nix_store "rzls" .. "/bin/rzls", } @@ -18,24 +24,25 @@ return { }, }, opts = function(_, opts) + local has_astrolsp, astrolsp = pcall(require, "astrolsp") local rzlspath = vim.fn.get_nix_store "rzls" - require("roslyn.config").get() opts = { - exe = "Microsoft.CodeAnalysis.LanguageServer", - args = { - "--stdio", - "--logLevel=Information", - "--extensionLogDirectory=" .. vim.fs.dirname(vim.lsp.get_log_path()), - "--razorSourceGenerator=" .. rzlspath .. "/lib/rzls/Microsoft.CodeAnalysis.Razor.Compiler.dll", - "--razorDesignTimePath=" - .. rzlspath - .. "/lib/rzls/Targets/Microsoft.NET.Sdk.Razor.DesignTime.targets", - }, ---@type vim.lsp.ClientConfig ---@diagnostic disable-next-line: missing-fields config = { + cmd = { + "Microsoft.CodeAnalysis.LanguageServer", + "--stdio", + "--logLevel=Information", + "--extensionLogDirectory=" .. vim.fs.dirname(vim.lsp.get_log_path()), + "--razorSourceGenerator=" .. rzlspath .. "/lib/rzls/Microsoft.CodeAnalysis.Razor.Compiler.dll", + "--razorDesignTimePath=" + .. rzlspath + .. "/lib/rzls/Targets/Microsoft.NET.Sdk.Razor.DesignTime.targets", + }, handlers = require "rzls.roslyn_handlers", + on_attach = has_astrolsp and astrolsp.on_attach or nil, settings = { ["csharp|inlay_hints"] = { csharp_enable_inlay_hints_for_implicit_object_creation = true, From 5b99eaffea8ba300ad34b20cf1a34e3944da75ef Mon Sep 17 00:00:00 2001 From: "Alexandre Cavalheiro S. Tiago da Silva" Date: Thu, 24 Apr 2025 23:27:56 -0300 Subject: [PATCH 2/2] feat(neovim)!: pull flake information from envvar This makes so we don't have to rely on writing an extra derivation just for the parsed lsp configuration. Thus, the `programs.neovim.nixd.hostname` settings has been dropped and you can migrate your `programs.neovim.nixd.location` to `programs.neovim.flakePath` if you do not set the `FLAKE` envvar anywhere. --- hosts/wizlap/home-manager.nix | 3 -- modules/neovim/README.md | 10 ++--- modules/neovim/default.nix | 39 +++++++------------ .../{lsp.lua => lua/plugins/astrolsp.lua} | 19 +++++++-- modules/template/home-manager.nix | 12 +----- 5 files changed, 34 insertions(+), 49 deletions(-) rename modules/neovim/{lsp.lua => lua/plugins/astrolsp.lua} (91%) diff --git a/hosts/wizlap/home-manager.nix b/hosts/wizlap/home-manager.nix index 157379c..12cf15e 100644 --- a/hosts/wizlap/home-manager.nix +++ b/hosts/wizlap/home-manager.nix @@ -112,9 +112,6 @@ # Enable ollama support ollama.enable = true; - - # Set the hostname for nixd in neovim - nixd.hostname = "wizlap"; }; # Add monitor configuration to hyprland diff --git a/modules/neovim/README.md b/modules/neovim/README.md index 4f90c70..6e917b5 100644 --- a/modules/neovim/README.md +++ b/modules/neovim/README.md @@ -4,16 +4,14 @@ The module extends `programs.neovim`. ## Module options -### programs.neovim.nixd.hostname - -By default [nixd] is enabled, you **need** to pass the current machine's -hostname that is used to generate your system. - -### programs.neovim.nixd.location +### programs.neovim.flakePath The location of your system's flake, [nixd] will execute an expression defined in the LSP's configuration that reads the flake's contents to evaluate [NixOS] and [Home Manager] options. +This setting is optional since other programs might force you to set the `FLAKE` environment variable; if this is not +set by the time you open [neovim] it will spout an error, impeding critical plugins from starting. + ### programs.neovim.ollama.enable Whether to add an [ollama] package to be used with [ollama.nvim](https://github.com/nomnivore/ollama.nvim). diff --git a/modules/neovim/default.nix b/modules/neovim/default.nix index 5fbbe2e..163fad1 100644 --- a/modules/neovim/default.nix +++ b/modules/neovim/default.nix @@ -25,20 +25,11 @@ let in { options.programs.neovim = { - nixd = { - hostname = mkOption { - default = "wizdesk"; - description = "Your NixOS hostname, needed for nixd lsp."; - example = "nixos"; - type = types.str; - }; - - location = mkOption { - default = "git+file:///home/wizardlink/.system"; - description = "Path to your flake location, prepend 'file:///' to it and 'git+' before that if using git."; - example = "git+file:///home/wizardlink/.system"; - type = types.str; - }; + flakePath = mkOption { + default = null; + description = "The path to your flake, this will be the value of the `FLAKE` environment variable."; + example = "~/.config/nix"; + type = types.nullOr types.str; }; ollama = { @@ -57,10 +48,14 @@ in }; config = { - home.sessionVariables = { - EDITOR = "nvim"; - MANPAGER = "nvim +Man!"; - }; + home.sessionVariables = + { + EDITOR = "nvim"; + MANPAGER = "nvim +Man!"; + } + // lib.optionalAttrs (config.programs.neovim.flakePath != null) { + FLAKE = config.programs.neovim.flakePath; + }; programs.neovim = { withNodeJs = true; @@ -157,14 +152,6 @@ in source = ./ftplugin; }; - xdg.configFile."nvim/lua/plugins/astrolsp.lua".source = pkgs.runCommand "astrolsp.lua" { } '' - cp ${./lsp.lua} $out - - substituteInPlace $out \ - --replace-fail "{hostname}" "${config.programs.neovim.nixd.hostname}" \ - --replace-fail "{location}" "${config.programs.neovim.nixd.location}" - ''; - xdg.dataFile."nvim/lazy/blink.cmp/target/release/libblink_cmp_fuzzy.so" = { recursive = true; source = "${blink-cmp.packages.${pkgs.system}.blink-fuzzy-lib}/lib/libblink_cmp_fuzzy.so"; diff --git a/modules/neovim/lsp.lua b/modules/neovim/lua/plugins/astrolsp.lua similarity index 91% rename from modules/neovim/lsp.lua rename to modules/neovim/lua/plugins/astrolsp.lua index 457db21..1a51e7a 100644 --- a/modules/neovim/lsp.lua +++ b/modules/neovim/lua/plugins/astrolsp.lua @@ -9,6 +9,9 @@ return { ---@param opts AstroLSPOpts ---@return AstroLSPOpts opts = function(_, opts) + local system_flake_path = vim.fn.getenv "FLAKE" or error "FLAKE environment variable must be set." + local hostname = vim.fn.hostname() + ---@type AstroLSPOpts local lsp_options = { -- Configuration table of features provided by AstroLSP @@ -84,15 +87,23 @@ return { settings = { nixd = { nixpkgs = { - expr = "import (builtins.getFlake ({location})).inputs.nixpkgs { }", + expr = "import (builtins.getFlake (" .. system_flake_path .. ")).inputs.nixpkgs { }", }, options = { nixos = { - expr = '(builtins.getFlake ("{location}")).nixosConfigurations.{hostname}.options', + expr = "(builtins.getFlake (" + .. system_flake_path + .. ")).nixosConfigurations." + .. hostname + .. ".options", }, home_manager = { - expr = - '(builtins.getFlake ("{location}")).nixosConfigurations.{hostname}.options.home-manager.users.type.getSubOptions []', + expr = "(builtins.getFlake (" + .. system_flake_path + .. ")).nixosConfigurations." + .. hostname + .. ".options" + .. ".home-manager.users.type.getSubOptions []", }, }, }, diff --git a/modules/template/home-manager.nix b/modules/template/home-manager.nix index 33d8b7c..9f6fabc 100644 --- a/modules/template/home-manager.nix +++ b/modules/template/home-manager.nix @@ -85,14 +85,6 @@ # Let Home Manager install and manage itself. programs.home-manager.enable = true; - programs.neovim = { - # Enable Neovim, pre-configured by `linuxware`. - enable = true; - - # Configure nixd - nixd = { - hostname = "your-hostname-here"; - location = "your-flake-location-here"; - }; - }; + # Enable Neovim, pre-configured by `linuxware`. + programs.neovim.enable = true; }