Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cmp #34

Merged
merged 6 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 39 additions & 22 deletions modules/cmp.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{ config, ... }:

let
cmpWinHeight = config.opts.pumheight;
in
{
extraConfigLuaPre = /* lua */ ''
local luasnip = require('luasnip')
Expand All @@ -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 = {
"<CR>" = /* lua */ ''
Expand Down Expand Up @@ -98,9 +115,9 @@
"<PageUp>" = /* 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
Expand All @@ -109,9 +126,9 @@
"<PageDown>" = /* 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
Expand All @@ -129,13 +146,13 @@
sources = map (name: { inherit name; }) [
"crates"
"nvim_lsp"
"treesitter"
"luasnip"
#"treesitter"
"path"
"buffer"
#"calc"
"cmdline"
];
] ++ [ {
name = "buffer"; keyword_length = 3;
} ];
};
};

Expand Down
28 changes: 1 addition & 27 deletions modules/lsp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down