-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #510 from horriblename/feat-blink
completion/blink.cmp: add
- Loading branch information
Showing
20 changed files
with
485 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
rustPlatform, | ||
hostPlatform, | ||
vimUtils, | ||
git, | ||
src, | ||
version, | ||
}: let | ||
blink-fuzzy-lib = rustPlatform.buildRustPackage { | ||
pname = "blink-fuzzy-lib"; | ||
inherit version src; | ||
|
||
env = { | ||
# TODO: remove this if plugin stops using nightly rust | ||
RUSTC_BOOTSTRAP = true; | ||
}; | ||
nativeBuildInputs = [git]; | ||
cargoLock = { | ||
lockFile = "${src}/Cargo.lock"; | ||
allowBuiltinFetchGit = true; | ||
}; | ||
}; | ||
libExt = | ||
if hostPlatform.isDarwin | ||
then "dylib" | ||
else "so"; | ||
in | ||
vimUtils.buildVimPlugin { | ||
pname = "blink-cmp"; | ||
inherit version src; | ||
|
||
# blink references a repro.lua which is placed outside the lua/ directory | ||
doCheck = false; | ||
preInstall = '' | ||
mkdir -p target/release | ||
ln -s ${blink-fuzzy-lib}/lib/libblink_cmp_fuzzy.${libExt} target/release/libblink_cmp_fuzzy.${libExt} | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
{lib, ...}: let | ||
inherit (lib.options) mkEnableOption mkOption literalMD; | ||
inherit (lib.types) listOf str either attrsOf submodule enum anything int nullOr; | ||
inherit (lib.generators) mkLuaInline; | ||
inherit (lib.nvim.types) mkPluginSetupOption luaInline; | ||
inherit (lib.nvim.binds) mkMappingOption; | ||
inherit (lib.nvim.config) mkBool; | ||
|
||
keymapType = submodule { | ||
freeformType = attrsOf (listOf (either str luaInline)); | ||
options = { | ||
preset = mkOption { | ||
type = enum ["default" "none" "super-tab" "enter"]; | ||
default = "none"; | ||
description = "keymap presets"; | ||
}; | ||
}; | ||
}; | ||
|
||
providerType = submodule { | ||
freeformType = anything; | ||
options = { | ||
module = mkOption { | ||
type = str; | ||
description = "module of the provider"; | ||
}; | ||
}; | ||
}; | ||
in { | ||
options.vim.autocomplete.blink-cmp = { | ||
enable = mkEnableOption "blink.cmp"; | ||
setupOpts = mkPluginSetupOption "blink.cmp" { | ||
sources = { | ||
default = mkOption { | ||
type = listOf str; | ||
default = ["lsp" "path" "snippets" "buffer"]; | ||
description = "Default list of sources to enable for completion."; | ||
}; | ||
|
||
cmdline = mkOption { | ||
type = nullOr (listOf str); | ||
default = []; | ||
description = "List of sources to enable for cmdline. Null means use default source list."; | ||
}; | ||
|
||
providers = mkOption { | ||
type = attrsOf providerType; | ||
default = {}; | ||
description = "Settings for completion providers"; | ||
}; | ||
|
||
transform_items = mkOption { | ||
type = nullOr luaInline; | ||
default = mkLuaInline "function(_, items) return items end"; | ||
defaultText = '' | ||
Our default does nothing. If you want blink.cmp's default, which | ||
lowers the score for snippets, set this option to null. | ||
''; | ||
description = '' | ||
Function to use when transforming the items before they're returned | ||
for all providers. | ||
''; | ||
}; | ||
}; | ||
|
||
completion = { | ||
documentation = { | ||
auto_show = mkBool true "Show documentation whenever an item is selected"; | ||
auto_show_delay_ms = mkOption { | ||
type = int; | ||
default = 200; | ||
description = "Delay before auto show triggers"; | ||
}; | ||
}; | ||
}; | ||
|
||
keymap = mkOption { | ||
type = keymapType; | ||
default = {}; | ||
description = "blink.cmp keymap"; | ||
example = literalMD '' | ||
```nix | ||
vim.autocomplete.blink-cmp.setupOpts.keymap = { | ||
preset = "none"; | ||
"<Up>" = ["select_prev" "fallback"]; | ||
"<C-n>" = [ | ||
(lib.generators.mkLuaInline '''' | ||
function(cmp) | ||
if some_condition then return end -- runs the next command | ||
return true -- doesn't run the next command | ||
end, | ||
'''') | ||
"select_next" | ||
]; | ||
}; | ||
``` | ||
''; | ||
}; | ||
|
||
fuzzy = { | ||
prebuilt_binaries = { | ||
download = mkBool false '' | ||
Auto-downloads prebuilt binaries. Do not enable, it doesn't work on nix | ||
''; | ||
}; | ||
}; | ||
}; | ||
|
||
mappings = { | ||
complete = mkMappingOption "Complete [blink.cmp]" "<C-Space>"; | ||
confirm = mkMappingOption "Confirm [blink.cmp]" "<CR>"; | ||
next = mkMappingOption "Next item [blink.cmp]" "<Tab>"; | ||
previous = mkMappingOption "Previous item [blink.cmp]" "<S-Tab>"; | ||
close = mkMappingOption "Close [blink.cmp]" "<C-e>"; | ||
scrollDocsUp = mkMappingOption "Scroll docs up [blink.cmp]" "<C-d>"; | ||
scrollDocsDown = mkMappingOption "Scroll docs down [blink.cmp]" "<C-f>"; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{ | ||
lib, | ||
config, | ||
... | ||
}: let | ||
inherit (lib.modules) mkIf; | ||
inherit (lib.strings) optionalString; | ||
inherit (lib.generators) mkLuaInline; | ||
inherit (lib.nvim.lua) toLuaObject; | ||
inherit (builtins) concatStringsSep typeOf tryEval attrNames mapAttrs; | ||
|
||
cfg = config.vim.autocomplete.blink-cmp; | ||
cmpCfg = config.vim.autocomplete.nvim-cmp; | ||
inherit (cfg) mappings; | ||
|
||
getPluginName = plugin: | ||
if typeOf plugin == "string" | ||
then plugin | ||
else if (plugin ? pname && (tryEval plugin.pname).success) | ||
then plugin.pname | ||
else plugin.name; | ||
in { | ||
vim = mkIf cfg.enable { | ||
startPlugins = ["blink-compat"]; | ||
lazy.plugins = { | ||
blink-cmp = { | ||
package = "blink-cmp"; | ||
setupModule = "blink.cmp"; | ||
inherit (cfg) setupOpts; | ||
|
||
# TODO: lazy disabled until lspconfig is lazy loaded | ||
# | ||
# event = ["InsertEnter" "CmdlineEnter"]; | ||
|
||
after = '' | ||
${optionalString config.vim.lazy.enable | ||
(concatStringsSep "\n" (map | ||
(package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})") | ||
cmpCfg.sourcePlugins))} | ||
''; | ||
}; | ||
}; | ||
|
||
autocomplete = { | ||
enableSharedCmpSources = true; | ||
blink-cmp.setupOpts = { | ||
sources = { | ||
default = ["lsp" "path" "snippets" "buffer"] ++ (attrNames cmpCfg.sources); | ||
providers = | ||
mapAttrs (name: _: { | ||
inherit name; | ||
module = "blink.compat.source"; | ||
}) | ||
cmpCfg.sources; | ||
}; | ||
snippets = mkIf config.vim.snippets.luasnip.enable { | ||
preset = "luasnip"; | ||
}; | ||
|
||
keymap = { | ||
${mappings.complete} = ["show" "fallback"]; | ||
${mappings.close} = ["hide" "fallback"]; | ||
${mappings.scrollDocsUp} = ["scroll_documentation_up" "fallback"]; | ||
${mappings.scrollDocsDown} = ["scroll_documentation_down" "fallback"]; | ||
${mappings.confirm} = ["accept" "fallback"]; | ||
|
||
${mappings.next} = [ | ||
"select_next" | ||
"snippet_forward" | ||
(mkLuaInline '' | ||
function(cmp) | ||
local line, col = unpack(vim.api.nvim_win_get_cursor(0)) | ||
has_words_before = col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil | ||
if has_words_before then | ||
return cmp.show() | ||
end | ||
end | ||
'') | ||
"fallback" | ||
]; | ||
${mappings.previous} = [ | ||
"select_prev" | ||
"snippet_backward" | ||
"fallback" | ||
]; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
imports = [ | ||
./blink-cmp.nix | ||
./config.nix | ||
]; | ||
} |
Oops, something went wrong.