diff --git a/modules/cmp.nix b/modules/cmp.nix index 7678c0f..1ed78ae 100644 --- a/modules/cmp.nix +++ b/modules/cmp.nix @@ -1,3 +1,8 @@ +{ config, ... }: + +let + cmpWinHeight = config.opts.pumheight; +in { extraConfigLuaPre = /* lua */ '' local luasnip = require('luasnip') @@ -9,24 +14,36 @@ end ''; - extraConfigLua = /* lua */ '' - vim.api.nvim_create_autocmd({ 'TextChangedI' }, { - callback = function() - if has_words_before() then - cmp.complete() - end - end, - }) - ''; - plugins = { cmp = { enable = true; autoEnableSources = true; - settings = { - completion.autocomplete = false; + # https://github.com/hrsh7th/cmp-cmdline?tab=readme-ov-file#setup + # https://github.com/nix-community/nixvim/blob/a5e9dbdef1530a76056db12387d489a68eea6f80/plugins/completion/cmp/options/default.nix#L53-L71 + cmdline = { + "/" = { + mapping.__raw = "cmp.mapping.preset.cmdline()"; + sources = [ { name = "buffer"; } ]; + }; + ":" = { + mapping.__raw = "cmp.mapping.preset.cmdline()"; + sources = [ + { name = "path"; } + { + name = "cmdline"; + option = { + ignore_cmds = [ + "Man" + "!" + ]; + }; + } + ]; + }; + }; + settings = { # https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings mapping = { "" = /* lua */ '' @@ -98,9 +115,9 @@ "" = /* lua */ '' cmp.mapping(function(fallback) if cmp.visible() then - cmp.select_prev_item({ count = 5 }) - elseif luasnip.locally_jumpable(-5) then - luasnip.jump(-5) + cmp.select_prev_item({ count = ${toString cmpWinHeight} }) + elseif luasnip.locally_jumpable(${toString (cmpWinHeight * -1)}) then + luasnip.jump(${toString (cmpWinHeight * -1)}) else fallback() end @@ -109,9 +126,9 @@ "" = /* lua */ '' cmp.mapping(function(fallback) if cmp.visible() then - cmp.select_next_item({ count = 5 }) - elseif luasnip.locally_jumpable(5) then - luasnip.jump(5) + cmp.select_next_item({ count = ${toString cmpWinHeight} }) + elseif luasnip.locally_jumpable(${toString cmpWinHeight}) then + luasnip.jump(${toString cmpWinHeight}) else fallback() end @@ -129,13 +146,13 @@ sources = map (name: { inherit name; }) [ "crates" "nvim_lsp" + "treesitter" "luasnip" - #"treesitter" "path" - "buffer" #"calc" - "cmdline" - ]; + ] ++ [ { + name = "buffer"; keyword_length = 3; + } ]; }; }; diff --git a/modules/lsp.nix b/modules/lsp.nix index 63c9563..980d85a 100644 --- a/modules/lsp.nix +++ b/modules/lsp.nix @@ -21,18 +21,12 @@ in ''}" ]; lintersByFt = { - css = [ "eslint_d" ]; - scss = [ "eslint_d" ]; go = [ "golangcilint" ]; - javascript = [ "eslint_d" ]; - javascriptreact = [ "eslint_d" ]; json = [ "jsonlint" ]; markdownlint = [ "markdownlint-cli2" ]; nix = [ "deadnix" "nix" "statix" ]; python = [ "ruff" ]; sh = [ "shellcheck" ]; - typescript = [ "eslint_d" ]; - typescriptreact = [ "eslint_d" ]; yaml = [ "yamllint" ]; }; # Trigger linting more aggressively, not only after writing a buffer @@ -48,27 +42,7 @@ in cssls.enable = true; docker-compose-language-service.enable = true; dockerls.enable = true; - eslint = { - enable = true; - # https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/eslint.lua#L35-L48 - # https://eslint.org/docs/v8.x/use/configure/configuration-files - rootDir = '' - require('lspconfig').util.root_pattern( - '.eslintrc', - '.eslintrc.js', - '.eslintrc.cjs', - '.eslintrc.yaml', - '.eslintrc.yml', - '.eslintrc.json', - 'eslint.config.js', - 'eslint.config.mjs', - 'eslint.config.cjs', - 'eslint.config.ts', - 'eslint.config.mts', - 'eslint.config.cts' - ) - ''; - }; + eslint.enable = true; gopls = { enable = true; settings.gopls = {