Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Commit 5646ed6

Browse files
Merge branch 'nvim-lua:master' into master
2 parents 1579df8 + d62fff8 commit 5646ed6

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ another completion source instead(Ex: snippets).
7575
* [completion-tabnine](https://github.com/aca/completion-tabnine): AI code completion tool TabNine integration.
7676
* [completion-tags](https://github.com/kristijanhusak/completion-tags): Slightly improved ctags completion
7777
* [completion-tmux](https://github.com/albertoCaroM/completion-tmux): tmux panels completion
78+
* [completion-vcard](https://github.com/cbarrete/completion-vcard): email completion from vCards
7879

7980
## Configuration
8081

lua/completion/signature_help.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ M.autoOpenSignatureHelp = function()
4242
if vim.tbl_isempty(lines) then
4343
return
4444
end
45-
local bufnr, _ = vim.lsp.util.focusable_preview(method, function()
45+
local bufnr, _ = vim.lsp.util.open_floating_preview(
4646
-- TODO show popup when signatures is empty?
47-
lines = vim.lsp.util.trim_empty_lines(lines)
48-
return lines, vim.lsp.util.try_trim_markdown_code_blocks(lines)
49-
end)
47+
vim.lsp.util.trim_empty_lines(lines),
48+
vim.lsp.util.try_trim_markdown_code_blocks(lines),
49+
{focus_id = method}
50+
)
5051
-- setup a variable for floating window, fix #223
5152
vim.api.nvim_buf_set_var(bufnr, "lsp_floating", true)
5253
end)

lua/completion/source.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ function M.triggerCompletion(force)
142142
local bufnr, line_to_cursor, cursor_to_end = getPositionParam()
143143
local textMatch = vim.fn.match(line_to_cursor, '\\k*$')
144144
local prefix = line_to_cursor:sub(textMatch+1)
145-
local rev_textMatch = #cursor_to_end - vim.fn.match(cursor_to_end:reverse(), '\\k*$')
146-
local suffix = cursor_to_end:sub(1, rev_textMatch)
145+
local suffix = cursor_to_end:sub(1, vim.fn.matchend(cursor_to_end, '^\\k*'))
147146
manager.insertChar = true
148147
-- force is used when manually trigger, so it doesn't repect the trigger word length
149148
triggerCurrentCompletion(bufnr, line_to_cursor, prefix, textMatch, suffix, force)
@@ -154,8 +153,7 @@ function M.autoCompletion()
154153
local bufnr, line_to_cursor, cursor_to_end = getPositionParam()
155154
local textMatch = vim.fn.match(line_to_cursor, '\\k*$')
156155
local prefix = line_to_cursor:sub(textMatch+1)
157-
local rev_textMatch = #cursor_to_end - vim.fn.match(cursor_to_end:reverse(), '\\k*$')
158-
local suffix = cursor_to_end:sub(1, rev_textMatch)
156+
local suffix = cursor_to_end:sub(1, vim.fn.matchend(cursor_to_end, '^\\k*'))
159157
local length = opt.get_option('trigger_keyword_length')
160158

161159
-- reset completion when deleting character in insert mode

lua/completion/source/lsp.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ local function get_completion_word(item, prefix, suffix)
3030
else
3131
newText = item.textEdit.newText
3232
end
33-
if protocol.InsertTextFormat[item.insertTextFormat] == "PlainText"
34-
or opt.get_option('enable_snippet') == "snippets.nvim" then
33+
if not item.insertTextFormat
34+
or protocol.InsertTextFormat[item.insertTextFormat] == "PlainText"
35+
or opt.get_option('enable_snippet') == "snippets.nvim" then
3536
return newText
3637
else
3738
return vim.lsp.util.parse_snippet(newText)
3839
end
3940
elseif item.insertText ~= nil and item.insertText ~= vim.NIL then
40-
if protocol.InsertTextFormat[item.insertTextFormat] == "PlainText"
41-
or opt.get_option('enable_snippet') == "snippets.nvim" then
41+
if not item.insertTextFormat
42+
or protocol.InsertTextFormat[item.insertTextFormat] == "PlainText"
43+
or opt.get_option('enable_snippet') == "snippets.nvim" then
4244
return item.insertText
4345
else
4446
return vim.lsp.util.parse_snippet(item.insertText)

lua/completion/util.lua

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,29 @@ end
1616
-- completion items --
1717
------------------------
1818

19-
function M.sort_completion_items(items)
20-
table.sort(items, function(a, b)
21-
if a.priority ~= b.priority and a.priority ~= nil and b.priority ~= nil then
22-
return a.priority > b.priority
23-
elseif a.score ~= b.score and a.score ~= nil and b.score ~= nil then
24-
return a.score < b.score
25-
elseif opt.get_option("sorting") == 'alphabet' then
19+
local function compare_strings(a, b)
20+
if opt.get_option("sorting") == 'alphabet' then
2621
return a.word < b.word
2722
elseif opt.get_option("sorting") == 'length_desc' then
2823
return string.len(a.word) > string.len(b.word)
2924
else
3025
return string.len(a.word) < string.len(b.word)
3126
end
27+
end
28+
29+
local function compare_scores_then_strings(a, b)
30+
if a.score == b.score or a.score == nil or b.score == nil then
31+
return compare_strings(a, b);
32+
end
33+
return a.score < b.score
34+
end
35+
36+
function M.sort_completion_items(items)
37+
table.sort(items, function(a, b)
38+
if a.priority == b.priority or a.priority == nil or b.priority == nil then
39+
return compare_scores_then_strings(a, b)
40+
end
41+
return a.priority > b.priority
3242
end)
3343
end
3444

0 commit comments

Comments
 (0)