From bd3f24056e3913545e1bb82f74fe3394cf4dfd6f Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 23 Oct 2024 22:34:35 +0100 Subject: [PATCH] modify nixvim - add config for nixd - fix luasnip call func in cmp - enable autocomplete in cmp- cmdline - add cmp-cmdline mapping --- home/common/core/nixvim/plugins/cmp.nix | 22 ++++++---------------- home/common/core/nixvim/plugins/lsp.nix | 12 +++++++++++- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/home/common/core/nixvim/plugins/cmp.nix b/home/common/core/nixvim/plugins/cmp.nix index 44475cb..90b764b 100644 --- a/home/common/core/nixvim/plugins/cmp.nix +++ b/home/common/core/nixvim/plugins/cmp.nix @@ -3,6 +3,7 @@ cmp-emoji = { enable = true; }; cmp = { enable = true; + cmdline = {}; settings = { autoEnableSources = true; experimental = { ghost_text = true; }; @@ -11,7 +12,7 @@ fetchingTimeout = 200; maxViewEntries = 30; }; - snippet = { expand = "luasnip"; }; + snippet = { expand = "function(args) require('luasnip').lsp_expand(args.body) end"; }; formatting = { fields = [ "kind" "abbr" "menu" ]; format = '' @@ -43,14 +44,10 @@ }; mapping = { "" = "cmp.mapping(cmp.mapping.select_next_item(), {'i', 's'})"; - "" = "cmp.mapping.select_next_item()"; - "" = "cmp.mapping.select_prev_item()"; - "" = "cmp.mapping.abort()"; + "" = "cmp.mapping.select_prev_item()"; "" = "cmp.mapping.scroll_docs(-4)"; "" = "cmp.mapping.scroll_docs(4)"; - "" = "cmp.mapping.complete()"; "" = "cmp.mapping.confirm({ select = true })"; - "" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })"; }; }; }; @@ -58,7 +55,7 @@ cmp-buffer = { enable = true; }; cmp-path = { enable = true; }; # file system paths cmp_luasnip = { enable = true; }; # snippets - cmp-cmdline = { enable = false; }; # autocomplete for cmdline + cmp-cmdline = { enable = true; }; # autocomplete for cmdline }; programs.nixvim.extraConfigLua = '' luasnip = require("luasnip") @@ -94,22 +91,15 @@ -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline({'/', "?" }, { + mapping = cmp.mapping.preset.cmdline(), sources = { { name = 'buffer' } } }) - -- Set configuration for specific filetype. - cmp.setup.filetype('gitcommit', { - sources = cmp.config.sources({ - { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. - }, { - { name = 'buffer' }, - }) - }) - -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = 'path' } }, { diff --git a/home/common/core/nixvim/plugins/lsp.nix b/home/common/core/nixvim/plugins/lsp.nix index 9aeb99e..702b482 100644 --- a/home/common/core/nixvim/plugins/lsp.nix +++ b/home/common/core/nixvim/plugins/lsp.nix @@ -4,7 +4,17 @@ enable = true; servers = { lua-ls = {enable = true;}; - nixd = {enable = true;}; + nixd = { + enable = true; + cmd = ["nixd"]; + settings = { + nixpkgs.expr = "import { }"; + options = { + nixos.expr = "(builtins.getFlake ('git+file://' + toString ./.)).nixosConfigurations.k-on.options"; + home_manager.expr = "(builtins.getFlake ('git+file://' + toString ./.)).homeConfigurations.'ruixi@k-on'.options"; + }; + }; + }; bashls = {enable = true;}; pyright = {enable = true;}; html = {enable = true;};