diff --git a/flake.nix b/flake.nix index 986809e11..71746587f 100644 --- a/flake.nix +++ b/flake.nix @@ -52,6 +52,15 @@ pkgs.nixpkgs-fmt (import ./nixd/docs/editors/nvim-lsp.nix { inherit pkgs; }) ]; + shellHook = '' + echo -e "\033[1;34mEntering the nvim test environment...\033[0m" + mkdir -p /tmp/NixOS_Home-Manager + cp -r ./nixd/docs/examples/NixOS_Home-Manager/* /tmp/NixOS_Home-Manager/ + cd /tmp/NixOS_Home-Manager + echo -e "\033[1;32mNow, you can edit the nix file by running the following command:\033[0m" + echo -e "\033[1;33m'nvim-lsp flake.nix'\033[0m" + echo -e "\033[1;34mEnvironment setup complete.\033[0m" + ''; }; devShells.vscodium = pkgs.mkShell { nativeBuildInputs = [ diff --git a/nixd/docs/editors/editors.md b/nixd/docs/editors/editors.md index f26592070..0b014c494 100644 --- a/nixd/docs/editors/editors.md +++ b/nixd/docs/editors/editors.md @@ -2,7 +2,7 @@ ### VSCodium -We provide a test environment with the *vscode-nix-ide* plugin, and the repository has some [configuration examples](/nixd/docs/examples) that you can try. +We provide a test environment with the _vscode-nix-ide_ plugin, and the repository has some [configuration examples](/nixd/docs/examples) that you can try. Start up the test environment: @@ -14,20 +14,8 @@ $ codium-test ### Neovim -You can run the following command to edit a *.nix file - ```console $ nix develop github:nix-community/nixd#nvim -$ nvim-lsp /tmp/test/default.nix - -``` - -tip: If you want to configure lsp itself, see [configuration](/nixd/docs/user-guide.md#configuration), and the following tree-like directory - -```console -# tree -a /tmp/test -/tmp/test/ -├── default.nix -└── .nixd.json +$ nvim-lsp flake.nix ``` diff --git a/nixd/docs/editors/nvim-lsp.nix b/nixd/docs/editors/nvim-lsp.nix index 4d361837d..933c671b6 100644 --- a/nixd/docs/editors/nvim-lsp.nix +++ b/nixd/docs/editors/nvim-lsp.nix @@ -11,7 +11,6 @@ let packages.myPlugins.start = with pkgs.vimPlugins; [ (nvim-treesitter.withPlugins (parsers: [ parsers.nix - parsers.json ])) friendly-snippets luasnip @@ -20,8 +19,14 @@ let cmp-buffer cmp_luasnip cmp-path - null-ls-nvim + cmp-cmdline + none-ls-nvim nvim-lspconfig + nord-nvim + noice-nvim + lualine-nvim + bufferline-nvim + lspsaga-nvim ]; }; }; @@ -59,6 +64,62 @@ let vim.opt[k] = v end + ---------------- + -- nord theme -- + ---------------- + vim.g.nord_contrast = false + vim.g.nord_borders = true + vim.g.nord_disable_background = false + vim.g.nord_italic = true + vim.g.nord_uniform_diff_background = true + vim.g.nord_enable_sidebar_background = true + vim.g.nord_bold = true + vim.g.nord_cursorline_transparent = false + require("nord").set() + + ----------------- + -- About noice -- + ----------------- + require("noice").setup({ + routes = { + { + filter = { + event = "msg_show", + any = { + { find = "%d+L, %d+B" }, + { find = "; after #%d+" }, + { find = "; before #%d+" }, + { find = "%d fewer lines" }, + { find = "%d more lines" }, + }, + }, + opts = { skip = true }, + }, + }, + }) + + ------------------- + -- About lualine -- + ------------------- + require("lualine").setup({ + options = { + theme = "auto", + globalstatus = true, + }, + }) + + ---------------------- + -- About bufferline -- + ---------------------- + local highlights + highlights = require("nord").bufferline.highlights({ + italic = true, + bold = true, + }) + require("bufferline").setup({ + highlights = highlights, + }) + ---------------------- -- About treesitter -- ---------------------- @@ -181,9 +242,17 @@ let native_menu = false, }, }) + cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" }, + }, { + { name = "cmdline" }, + }), + }) ------------------- - -- About null-ls -- + -- About none-ls -- ------------------- -- format(async) local async_formatting = function(bufnr) @@ -291,48 +360,113 @@ let }) end nvim_lsp.nixd.setup({ - on_attach = on_attach(), - capabilities = capabilities, + on_attach = on_attach(), + capabilities = capabilities, + settings = { + nixd = { + nixpkgs = { + expr = "import { }", + }, + formatting = { + command = { "nixpkgs-fmt" }, + }, + options = { + nixos = { + expr = '(builtins.getFlake "/tmp/NixOS_Home-Manager").nixosConfigurations.hostname.options', + }, + home_manager = { + expr = '(builtins.getFlake "/tmp/NixOS_Home-Manager").homeConfigurations."user@hostname".options', + }, + }, + }, + }, }) - -- Global mappings. - -- See `:help vim.diagnostic.*` for documentation on any of the below functions - vim.keymap.set("n", "e", vim.diagnostic.open_float) - vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) - vim.keymap.set("n", "]d", vim.diagnostic.goto_next) - vim.keymap.set("n", "q", vim.diagnostic.setloclist) - - -- Use LspAttach autocommand to only map the following keys - -- after the language server attaches to the current buffer - vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup("UserLspConfig", {}), - callback = function(ev) - -- Manual, triggered completion is provided by Nvim's builtin omnifunc. For autocompletion, a general purpose autocompletion plugin(.i.e nvim-cmp) is required - -- Enable completion triggered by - vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" - - -- Buffer local mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - local opts = { buffer = ev.buf } - vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) - vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) - vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) - vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) - vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, opts) - vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, opts) - vim.keymap.set("n", "wl", function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, opts) - vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) - vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) - vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) - vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) - vim.keymap.set("n", "f", function() - vim.lsp.buf.format({ async = true }) - end, opts) - end, + ------------------- + -- About lspsaga -- + ------------------- + local colors, kind + colors = { normal_bg = "#3b4252" } + require("lspsaga").setup({ + ui = { + colors = colors, + kind = kind, + border = "single", + }, + outline = { + win_width = 25, + }, }) + vim.cmd([[ colorscheme nord ]]) + + local keymap = vim.keymap.set + + -- Lsp finder + -- Find the symbol definition, implementation, reference. + -- If there is no implementation, it will hide. + -- When you use action in finder like open, vsplit, then you can use to jump back. + keymap("n", "gh", "Lspsaga lsp_finder", { silent = true, desc = "Lsp finder" }) + + -- Code action + keymap("n", "ca", "Lspsaga code_action", { silent = true, desc = "Code action" }) + keymap("v", "ca", "Lspsaga code_action", { silent = true, desc = "Code action" }) + + -- Rename + keymap("n", "gr", "Lspsaga rename", { silent = true, desc = "Rename" }) + -- Rename word in whole project + keymap("n", "gr", "Lspsaga rename ++project", { silent = true, desc = "Rename in project" }) + + -- Peek definition + keymap("n", "gD", "Lspsaga peek_definition", { silent = true, desc = "Peek definition" }) + + -- Go to definition + keymap("n", "gd", "Lspsaga goto_definition", { silent = true, desc = "Go to definition" }) + + -- Show line diagnostics + keymap("n", "sl", "Lspsaga show_line_diagnostics", { silent = true, desc = "Show line diagnostics" }) + + -- Show cursor diagnostics + keymap( + "n", + "sc", + "Lspsaga show_cursor_diagnostics", + { silent = true, desc = "Show cursor diagnostic" } + ) + + -- Show buffer diagnostics + keymap("n", "sb", "Lspsaga show_buf_diagnostics", { silent = true, desc = "Show buffer diagnostic" }) + + -- Diagnostic jump prev + keymap("n", "[e", "Lspsaga diagnostic_jump_prev", { silent = true, desc = "Diagnostic jump prev" }) + + -- Diagnostic jump next + keymap("n", "]e", "Lspsaga diagnostic_jump_next", { silent = true, desc = "Diagnostic jump next" }) + + -- Goto prev error + keymap("n", "[E", function() + require("lspsaga.diagnostic"):goto_prev({ severity = vim.diagnostic.severity.ERROR }) + end, { silent = true, desc = "Goto prev error" }) + + -- Goto next error + keymap("n", "]E", function() + require("lspsaga.diagnostic"):goto_next({ severity = vim.diagnostic.severity.ERROR }) + end, { silent = true, desc = "Goto next error" }) + + -- Toggle outline + keymap("n", "ss", "Lspsaga outline", { silent = true, desc = "Toggle outline" }) + + -- Hover doc + keymap("n", "K", "Lspsaga hover_doc ++keep", { silent = true, desc = "Hover doc" }) + + -- Incoming calls + keymap("n", "ci", "Lspsaga incoming_calls", { silent = true, desc = "Incoming calls" }) + + -- Outgoing calls + keymap("n", "co", "Lspsaga outgoing_calls", { silent = true, desc = "Outgoing calls" }) + + -- Float terminal + keymap("n", "", "Lspsaga term_toggle", { silent = true, desc = "Float terminal" }) + keymap("t", "", "Lspsaga term_toggle", { silent = true, desc = "Float terminal" }) ''; in diff --git a/nixd/docs/examples/NixOS_Home-Manager/flake.lock b/nixd/docs/examples/NixOS_Home-Manager/flake.lock new file mode 100644 index 000000000..837818ca9 --- /dev/null +++ b/nixd/docs/examples/NixOS_Home-Manager/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1713818326, + "narHash": "sha256-aw3xbVPJauLk/bbrlakIYxKpeuMWzA2feGrkIpIuXd8=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "67de98ae6eed5ad6f91b1142356d71a87ba97f21", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1713714899, + "narHash": "sha256-+z/XjO3QJs5rLE5UOf015gdVauVRQd2vZtsFkaXBq2Y=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6143fc5eeb9c4f00163267708e26191d1e918932", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nixd/docs/examples/NixOS_Home-Manager/flake.nix b/nixd/docs/examples/NixOS_Home-Manager/flake.nix new file mode 100644 index 000000000..216472e88 --- /dev/null +++ b/nixd/docs/examples/NixOS_Home-Manager/flake.nix @@ -0,0 +1,44 @@ +{ + description = "A simple flake for NixOS and Home Manager"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, home-manager, ... }: + { + nixosConfigurations = { + hostname = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ({ pkgs, ... }: { + networking.hostName = "hostname"; + environment.systemPackages = with pkgs; [ + nixd + ]; + }) + ]; + }; + }; + + homeConfigurations = { + "user@hostname" = home-manager.lib.homeManagerConfiguration { + pkgs = nixpkgs.legacyPackages.x86_64-linux; + modules = [ + { + home.stateVersion = "24.05"; + home.username = "user"; + home.homeDirectory = "/home/user"; + } + ({ pkgs, ... }: { + wayland.windowManager.hyprland.enable = true; + }) + ]; + }; + }; + }; +}