aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp/completion_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:18 +0100
committerJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:29 +0100
commit04f2f864e270e772c6326cefdf24947f0130e492 (patch)
tree46f83f909b888a66c741032ab955afc6eab84292 /test/functional/plugin/lsp/completion_spec.lua
parent59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff)
downloadrneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz
rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2
rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip
refactor: format test/*
Diffstat (limited to 'test/functional/plugin/lsp/completion_spec.lua')
-rw-r--r--test/functional/plugin/lsp/completion_spec.lua90
1 files changed, 51 insertions, 39 deletions
diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua
index 9354654afe..b49f970385 100644
--- a/test/functional/plugin/lsp/completion_spec.lua
+++ b/test/functional/plugin/lsp/completion_spec.lua
@@ -3,7 +3,6 @@ local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq
local exec_lua = helpers.exec_lua
-
--- Convert completion results.
---
---@param line string line contents. Mark cursor position with `|`
@@ -13,9 +12,10 @@ local exec_lua = helpers.exec_lua
local function complete(line, candidates, lnum)
lnum = lnum or 0
-- nvim_win_get_cursor returns 0 based column, line:find returns 1 based
- local cursor_col = line:find("|") - 1
- line = line:gsub("|", "")
- return exec_lua([[
+ local cursor_col = line:find('|') - 1
+ line = line:gsub('|', '')
+ return exec_lua(
+ [[
local line, cursor_col, lnum, result = ...
local line_to_cursor = line:sub(1, cursor_col)
local client_start_boundary = vim.fn.match(line_to_cursor, '\\k*$')
@@ -32,18 +32,22 @@ local function complete(line, candidates, lnum)
items = items,
server_start_boundary = server_start_boundary
}
- ]], line, cursor_col, lnum, candidates)
+ ]],
+ line,
+ cursor_col,
+ lnum,
+ candidates
+ )
end
-
-describe("vim.lsp._completion", function()
+describe('vim.lsp._completion', function()
before_each(helpers.clear)
-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
it('prefers textEdit over label as word', function()
local range0 = {
start = { line = 0, character = 0 },
- ["end"] = { line = 0, character = 0 },
+ ['end'] = { line = 0, character = 0 },
}
local completion_list = {
-- resolves into label
@@ -57,7 +61,12 @@ describe("vim.lsp._completion", function()
{ label = 'foocar', sortText = 'c', insertText = 'foobar' },
{ label = 'foocar', sortText = 'd', insertText = 'foobar' },
-- resolves into textEdit.newText
- { label = 'foocar', sortText = 'e', insertText = 'foodar', textEdit = { newText = 'foobar', range = range0 } },
+ {
+ label = 'foocar',
+ sortText = 'e',
+ insertText = 'foodar',
+ textEdit = { newText = 'foobar', range = range0 },
+ },
{ label = 'foocar', sortText = 'f', textEdit = { newText = 'foobar', range = range0 } },
-- real-world snippet text
{
@@ -65,7 +74,10 @@ describe("vim.lsp._completion", function()
sortText = 'g',
insertText = 'foodar',
insertTextFormat = 2,
- textEdit = { newText = 'foobar(${1:place holder}, ${2:more ...holder{\\}})', range = range0 },
+ textEdit = {
+ newText = 'foobar(${1:place holder}, ${2:more ...holder{\\}})',
+ range = range0,
+ },
},
{
label = 'foocar',
@@ -81,7 +93,7 @@ describe("vim.lsp._completion", function()
insertTextFormat = 2,
},
-- braced tabstop
- { label = 'foocar', sortText = 'j', insertText = 'foodar()${0}', insertTextFormat = 2},
+ { label = 'foocar', sortText = 'j', insertText = 'foodar()${0}', insertTextFormat = 2 },
-- plain text
{
label = 'foocar',
@@ -140,32 +152,32 @@ describe("vim.lsp._completion", function()
result = vim.tbl_map(function(x)
return {
abbr = x.abbr,
- word = x.word
+ word = x.word,
}
end, result.items)
eq(expected, result)
end)
- it("uses correct start boundary", function()
+ it('uses correct start boundary', function()
local completion_list = {
isIncomplete = false,
items = {
{
- filterText = "this_thread",
- insertText = "this_thread",
+ filterText = 'this_thread',
+ insertText = 'this_thread',
insertTextFormat = 1,
kind = 9,
- label = " this_thread",
+ label = ' this_thread',
score = 1.3205767869949,
- sortText = "4056f757this_thread",
+ sortText = '4056f757this_thread',
textEdit = {
- newText = "this_thread",
+ newText = 'this_thread',
range = {
start = { line = 0, character = 7 },
- ["end"] = { line = 0, character = 11 },
+ ['end'] = { line = 0, character = 11 },
},
- }
+ },
},
- }
+ },
}
local expected = {
abbr = ' this_thread',
@@ -176,50 +188,50 @@ describe("vim.lsp._completion", function()
menu = '',
word = 'this_thread',
}
- local result = complete(" std::this|", completion_list)
+ local result = complete(' std::this|', completion_list)
eq(7, result.server_start_boundary)
local item = result.items[1]
item.user_data = nil
eq(expected, item)
end)
- it("should search from start boundary to cursor position", function()
+ it('should search from start boundary to cursor position', function()
local completion_list = {
isIncomplete = false,
items = {
{
- filterText = "this_thread",
- insertText = "this_thread",
+ filterText = 'this_thread',
+ insertText = 'this_thread',
insertTextFormat = 1,
kind = 9,
- label = " this_thread",
+ label = ' this_thread',
score = 1.3205767869949,
- sortText = "4056f757this_thread",
+ sortText = '4056f757this_thread',
textEdit = {
- newText = "this_thread",
+ newText = 'this_thread',
range = {
start = { line = 0, character = 7 },
- ["end"] = { line = 0, character = 11 },
+ ['end'] = { line = 0, character = 11 },
},
- }
+ },
},
{
- filterText = "notthis_thread",
- insertText = "notthis_thread",
+ filterText = 'notthis_thread',
+ insertText = 'notthis_thread',
insertTextFormat = 1,
kind = 9,
- label = " notthis_thread",
+ label = ' notthis_thread',
score = 1.3205767869949,
- sortText = "4056f757this_thread",
+ sortText = '4056f757this_thread',
textEdit = {
- newText = "notthis_thread",
+ newText = 'notthis_thread',
range = {
start = { line = 0, character = 7 },
- ["end"] = { line = 0, character = 11 },
+ ['end'] = { line = 0, character = 11 },
},
- }
+ },
},
- }
+ },
}
local expected = {
abbr = ' this_thread',
@@ -230,7 +242,7 @@ describe("vim.lsp._completion", function()
menu = '',
word = 'this_thread',
}
- local result = complete(" std::this|is", completion_list)
+ local result = complete(' std::this|is', completion_list)
eq(1, #result.items)
local item = result.items[1]
item.user_data = nil