Add a rule to install stylua and use the local one for other rules (#1307)

This commit is contained in:
Zhizhen He
2022-11-16 13:22:24 +08:00
committed by GitHub
parent e820335208
commit a188be8559
6 changed files with 42 additions and 58 deletions

View File

@@ -1,6 +1,12 @@
.PHONY: install-stylua
install-stylua:
@if [ ! -f "./utils/stylua" ]; then \
sh ./utils/install_stylua.sh; \
fi
.PHONY: fmt .PHONY: fmt
fmt: fmt: install-stylua
stylua --config-path stylua.toml --glob 'lua/**/*.lua' -- lua ./utils/stylua --config-path stylua.toml --glob 'lua/**/*.lua' -- lua
.PHONY: lint .PHONY: lint
lint: lint:
@@ -11,13 +17,13 @@ test:
vusted --output=gtest ./lua vusted --output=gtest ./lua
.PHONY: pre-commit .PHONY: pre-commit
pre-commit: pre-commit: install-stylua
./utils/stylua --config-path stylua.toml --glob 'lua/**/*.lua' -- lua ./utils/stylua --config-path stylua.toml --glob 'lua/**/*.lua' -- lua
luacheck lua luacheck lua
vusted lua vusted lua
.PHONY: integration .PHONY: integration
integration: integration: install-stylua
./utils/stylua --config-path stylua.toml --check --glob 'lua/**/*.lua' -- lua ./utils/stylua --config-path stylua.toml --check --glob 'lua/**/*.lua' -- lua
luacheck lua luacheck lua
vusted lua vusted lua

View File

@@ -8,7 +8,7 @@ Completion sources are installed from external repositories and "sourced".
Readme! Readme!
==================== ====================
1. There is a Github issue that documents [breaking changes](https://github.com/hrsh7th/nvim-cmp/issues/231) for nvim-cmp. Subscribe to the issue to be notified of upcoming breaking changes. 1. There is a GitHub issue that documents [breaking changes](https://github.com/hrsh7th/nvim-cmp/issues/231) for nvim-cmp. Subscribe to the issue to be notified of upcoming breaking changes.
2. This is my hobby project. You can support me via GitHub sponsors. 2. This is my hobby project. You can support me via GitHub sponsors.
3. Bug reports are welcome, but don't expect a fix unless you provide minimal configuration and steps to reproduce your issue. 3. Bug reports are welcome, but don't expect a fix unless you provide minimal configuration and steps to reproduce your issue.

View File

@@ -413,11 +413,7 @@ core.confirm = function(self, e, option, callback)
end) end)
else else
vim.cmd([[silent! undojoin]]) vim.cmd([[silent! undojoin]])
vim.lsp.util.apply_text_edits( vim.lsp.util.apply_text_edits(e:get_completion_item().additionalTextEdits, ctx.bufnr, e.source:get_position_encoding_kind())
e:get_completion_item().additionalTextEdits,
ctx.bufnr,
e.source:get_position_encoding_kind()
)
end end
end) end)
feedkeys.call('', 'n', function() feedkeys.call('', 'n', function()
@@ -453,13 +449,7 @@ core.confirm = function(self, e, option, callback)
local texts = vim.split(completion_item.textEdit.newText, '\n') local texts = vim.split(completion_item.textEdit.newText, '\n')
vim.api.nvim_win_set_cursor(0, { vim.api.nvim_win_set_cursor(0, {
completion_item.textEdit.range.start.line + #texts, completion_item.textEdit.range.start.line + #texts,
( (#texts == 1 and (completion_item.textEdit.range.start.character + #texts[1]) or #texts[#texts]),
#texts == 1 and (
completion_item.textEdit.range.start.character + #texts[1]
) or (
#texts[#texts]
)
)
}) })
if is_snippet then if is_snippet then
config.get().snippet.expand({ config.get().snippet.expand({

View File

@@ -18,9 +18,9 @@ describe('cmp.core', function()
local c = core.new() local c = core.new()
local s = source.new('spec', { local s = source.new('spec', {
get_position_encoding_kind = function() get_position_encoding_kind = function()
return option.position_encoding_kind or types.lsp.PositionEncodingKind.UTF16 return option.position_encoding_kind or types.lsp.PositionEncodingKind.UTF16
end, end,
complete = function(_, _, callback) complete = function(_, _, callback)
callback({ completion_item }) callback({ completion_item })
end, end,
@@ -33,8 +33,7 @@ describe('cmp.core', function()
end) end)
end) end)
feedkeys.call(filter, 'n', function() feedkeys.call(filter, 'n', function()
c:confirm(c.sources[s.id].entries[1], {}, function() c:confirm(c.sources[s.id].entries[1], {}, function() end)
end)
end) end)
local state = {} local state = {}
feedkeys.call('', 'x', function() feedkeys.call('', 'x', function()
@@ -127,37 +126,37 @@ describe('cmp.core', function()
for _, case in ipairs({ for _, case in ipairs({
{ {
encoding = types.lsp.PositionEncodingKind.UTF8, encoding = types.lsp.PositionEncodingKind.UTF8,
char_size = #char char_size = #char,
}, },
{ {
encoding = types.lsp.PositionEncodingKind.UTF16, encoding = types.lsp.PositionEncodingKind.UTF16,
char_size = select(2, vim.str_utfindex(char)) char_size = select(2, vim.str_utfindex(char)),
}, },
{ {
encoding = types.lsp.PositionEncodingKind.UTF32, encoding = types.lsp.PositionEncodingKind.UTF32,
char_size = select(1, vim.str_utfindex(char)) char_size = select(1, vim.str_utfindex(char)),
}, },
}) do }) do
it('textEdit & multibyte: ' .. case.encoding , function() it('textEdit & multibyte: ' .. case.encoding, function()
local state = confirm(keymap.t('i%s:%s%s:%s<Left><Left><Left>'):format(char, char, char, char), char, { local state = confirm(keymap.t('i%s:%s%s:%s<Left><Left><Left>'):format(char, char, char, char), char, {
label = char .. char .. char, label = char .. char .. char,
textEdit = { textEdit = {
range = { range = {
start = { start = {
line = 0, line = 0,
character = case.char_size + #':' character = case.char_size + #':',
}, },
['end'] = { ['end'] = {
line = 0, line = 0,
character = case.char_size + #':' + case.char_size + case.char_size character = case.char_size + #':' + case.char_size + case.char_size,
}, },
}, },
newText = char .. char .. char .. char .. char, newText = char .. char .. char .. char .. char,
} },
}, { }, {
position_encoding_kind = case.encoding position_encoding_kind = case.encoding,
}) })
vim.pretty_print({ state = state, case = case }) vim.pretty_print({ state = state, case = case })
assert.are.same(state.buffer, { ('%s:%s%s%s%s%s:%s'):format(char, char, char, char, char, char, char) }) assert.are.same(state.buffer, { ('%s:%s%s%s%s%s:%s'):format(char, char, char, char, char, char, char) })
assert.are.same(state.cursor, { 1, #('%s:%s%s%s%s%s'):format(char, char, char, char, char, char) }) assert.are.same(state.cursor, { 1, #('%s:%s%s%s%s%s'):format(char, char, char, char, char, char) })
end) end)

View File

@@ -138,15 +138,13 @@ entry.get_overwrite = function(self)
if misc.safe(self:get_completion_item().textEdit) then if misc.safe(self:get_completion_item().textEdit) then
local range = self:get_insert_range() local range = self:get_insert_range()
if range then if range then
return self.context.cache:ensure({ 'entry', 'get_overwrite', tostring(range.start.character), return self.context.cache:ensure({ 'entry', 'get_overwrite', tostring(range.start.character), tostring(range['end'].character) }, function()
tostring(range['end'].character) }, local vim_start = range.start.character + 1
function() local vim_end = range['end'].character + 1
local vim_start = range.start.character + 1 local before = self.context.cursor.col - vim_start
local vim_end = range['end'].character + 1 local after = vim_end - self.context.cursor.col
local before = self.context.cursor.col - vim_start return { before, after }
local after = vim_end - self.context.cursor.col end)
return { before, after }
end)
end end
end end
return { 0, 0 } return { 0, 0 }
@@ -192,8 +190,7 @@ end
---Return the item is deprecated or not. ---Return the item is deprecated or not.
---@return boolean ---@return boolean
entry.is_deprecated = function(self) entry.is_deprecated = function(self)
return self:get_completion_item().deprecated or return self:get_completion_item().deprecated or vim.tbl_contains(self:get_completion_item().tags or {}, types.lsp.CompletionItemTag.Deprecated)
vim.tbl_contains(self:get_completion_item().tags or {}, types.lsp.CompletionItemTag.Deprecated)
end end
---Return view information. ---Return view information.
@@ -217,9 +214,7 @@ entry.get_view = function(self, suggest_offset, entries_buf)
view.kind.text = item.kind or '' view.kind.text = item.kind or ''
view.kind.bytes = #view.kind.text view.kind.bytes = #view.kind.text
view.kind.width = vim.fn.strdisplaywidth(view.kind.text) view.kind.width = vim.fn.strdisplaywidth(view.kind.text)
view.kind.hl_group = item.kind_hl_group or view.kind.hl_group = item.kind_hl_group or ('CmpItemKind' .. (types.lsp.CompletionItemKind[self:get_kind()] or ''))
('CmpItemKind' .. (types.lsp.CompletionItemKind[self:get_kind()] or '')
)
view.menu = {} view.menu = {}
view.menu.text = item.menu or '' view.menu.text = item.menu or ''
view.menu.bytes = #view.menu.text view.menu.bytes = #view.menu.text
@@ -358,7 +353,7 @@ entry.get_replace_range = function(self)
replace_range = { replace_range = {
start = { start = {
line = self.source_replace_range.start.line, line = self.source_replace_range.start.line,
character = self:get_offset() - 1 character = self:get_offset() - 1,
}, },
['end'] = self.source_replace_range['end'], ['end'] = self.source_replace_range['end'],
} }
@@ -537,7 +532,7 @@ entry.fill_defaults = function(_, completion_item, defaults)
} }
else else
completion_item.textEdit = { completion_item.textEdit = {
range = defaults.editRange --[[@as lsp.Range]] , range = defaults.editRange, --[[@as lsp.Range]]
newText = completion_item.textEditText or completion_item.label, newText = completion_item.textEditText or completion_item.label,
} }
end end
@@ -550,15 +545,9 @@ end
---Convert the oneline range encoding. ---Convert the oneline range encoding.
entry.convert_position_encoding = function(self, position) entry.convert_position_encoding = function(self, position)
local from_encoding = self.source:get_position_encoding_kind() local from_encoding = self.source:get_position_encoding_kind()
return self.context.cache:ensure('entry.convert_position_encoding.' .. position.character .. '.' .. from_encoding, return self.context.cache:ensure('entry.convert_position_encoding.' .. position.character .. '.' .. from_encoding, function()
function() return types.lsp.Position.to_utf8(self.context.cursor_line, position, from_encoding)
return types.lsp.Position.to_utf8( end)
self.context.cursor_line,
position,
from_encoding
)
end
)
end end
return entry return entry

View File

@@ -118,7 +118,7 @@ lsp.Position = {
end end
end end
return position return position
end end,
} }
lsp.Range = { lsp.Range = {