-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
72 changed files
with
2,225 additions
and
1,775 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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
local PAIRS_AND_INVALID_CHARS = {} | ||
string.gsub('\'"=$()[]<>{} \t\n\r', '.', function(char) PAIRS_AND_INVALID_CHARS[string.byte(char)] = true end) | ||
|
||
local CLOSING_PAIR = { | ||
[string.byte('<')] = string.byte('>'), | ||
[string.byte('[')] = string.byte(']'), | ||
[string.byte('(')] = string.byte(')'), | ||
[string.byte('{')] = string.byte('}'), | ||
[string.byte('"')] = string.byte('"'), | ||
[string.byte("'")] = string.byte("'"), | ||
} | ||
|
||
local ALPHANUMERIC = {} | ||
string.gsub( | ||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', | ||
'.', | ||
function(char) ALPHANUMERIC[string.byte(char)] = true end | ||
) | ||
|
||
--- Gets the prefix of the given text, stopping at brackets and quotes | ||
--- @param text string | ||
--- @return string | ||
local function get_prefix_before_brackets_and_quotes(text) | ||
local closing_pairs_stack = {} | ||
local word = '' | ||
|
||
local add = function(char) | ||
word = word .. string.char(char) | ||
|
||
-- if we've seen the opening pair, and we've just received the closing pair, | ||
-- remove it from the closing pairs stack | ||
if closing_pairs_stack[#closing_pairs_stack] == char then | ||
table.remove(closing_pairs_stack, #closing_pairs_stack) | ||
-- if the character is an opening pair, add it to the closing pairs stack | ||
elseif CLOSING_PAIR[char] ~= nil then | ||
table.insert(closing_pairs_stack, CLOSING_PAIR[char]) | ||
end | ||
end | ||
|
||
local has_alphanumeric = false | ||
for i = 1, #text do | ||
local char = string.byte(text, i) | ||
if PAIRS_AND_INVALID_CHARS[char] == nil then | ||
add(char) | ||
has_alphanumeric = has_alphanumeric or ALPHANUMERIC[char] | ||
elseif not has_alphanumeric or #closing_pairs_stack ~= 0 then | ||
add(char) | ||
-- if we had an alphanumeric, and the closing pairs stuck *just* emptied, | ||
-- because the current character is a closing pair, we exit | ||
if has_alphanumeric and #closing_pairs_stack == 0 then break end | ||
else | ||
break | ||
end | ||
end | ||
return word | ||
end | ||
|
||
return get_prefix_before_brackets_and_quotes |
8 changes: 4 additions & 4 deletions
8
lua/blink/cmp/accept/preview.lua → lua/blink/cmp/completion/accept/preview.lua
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
File renamed without changes.
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 @@ | ||
local brackets = {} | ||
|
||
brackets.add_brackets = require('blink.cmp.completion.brackets.kind') | ||
brackets.add_brackets_via_semantic_token = require('blink.cmp.completion.brackets.semantic') | ||
|
||
return brackets |
4 changes: 2 additions & 2 deletions
4
lua/blink/cmp/accept/brackets/kind.lua → lua/blink/cmp/completion/brackets/kind.lua
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
4 changes: 2 additions & 2 deletions
4
lua/blink/cmp/accept/brackets/semantic.lua → ...link/cmp/completion/brackets/semantic.lua
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
4 changes: 2 additions & 2 deletions
4
lua/blink/cmp/accept/brackets/utils.lua → lua/blink/cmp/completion/brackets/utils.lua
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,64 @@ | ||
local config = require('blink.cmp.config') | ||
local completion = {} | ||
|
||
function completion.setup() | ||
-- trigger controls when to show the window and the current context for caching | ||
local trigger = require('blink.cmp.completion.trigger') | ||
trigger.activate() | ||
|
||
-- sources fetch completion items and documentation | ||
local sources = require('blink.cmp.sources.lib') | ||
|
||
-- manages the completion list state: | ||
-- fuzzy matching items | ||
-- when to show/hide the windows | ||
-- selection | ||
-- accepting and previewing items | ||
local list = require('blink.cmp.completion.list') | ||
|
||
-- trigger -> sources: request completion items from the sources on show | ||
trigger.show_emitter:on(function(event) sources.request_completions(event.context) end) | ||
trigger.hide_emitter:on(function() | ||
sources.cancel_completions() | ||
list.hide() | ||
end) | ||
|
||
-- sources -> list | ||
sources.completions_emitter:on(function(event) | ||
-- schedule for later to avoid adding 0.5-4ms to insertion latency | ||
vim.schedule(function() | ||
-- since this was performed asynchronously, we check if the context has changed | ||
if trigger.context == nil or event.context.id ~= trigger.context.id then return end | ||
list.show(event.context, event.items) | ||
end) | ||
end) | ||
|
||
--- list -> windows: ghost text and completion menu | ||
-- setup completion menu | ||
if config.completion.window.enabled then | ||
list.show_emitter:on( | ||
function(event) require('blink.cmp.completion.windows.menu').open_with_items(event.context, event.items) end | ||
) | ||
list.hide_emitter:on(function() require('blink.cmp.completion.windows.menu').close() end) | ||
list.select_emitter:on( | ||
function(event) require('blink.cmp.completion.windows.menu').set_selected_item_idx(event.idx) end | ||
) | ||
end | ||
|
||
-- setup ghost text | ||
if config.completion.ghost_text.enabled then | ||
list.select_emitter:on( | ||
function(event) require('blink.cmp.completion.windows.ghost_text').show_preview(event.item) end | ||
) | ||
list.hide_emitter:on(function() require('blink.cmp.completion.windows.ghost_text').clear_preview() end) | ||
end | ||
|
||
-- run 'resolve' on the item ahead of time to avoid delays | ||
-- when accepting the item or showing documentation | ||
list.select_emitter:on(function(event) | ||
if event.item == nil then return end | ||
require('blink.cmp.completion.prefetch')(event.context, event.item) | ||
end) | ||
end | ||
|
||
return completion |
Oops, something went wrong.