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
fmt:
stylua --config-path stylua.toml --glob 'lua/**/*.lua' -- lua
fmt: install-stylua
./utils/stylua --config-path stylua.toml --glob 'lua/**/*.lua' -- lua
.PHONY: lint
lint:
@@ -11,13 +17,13 @@ test:
vusted --output=gtest ./lua
.PHONY: pre-commit
pre-commit:
pre-commit: install-stylua
./utils/stylua --config-path stylua.toml --glob 'lua/**/*.lua' -- lua
luacheck lua
vusted lua
.PHONY: integration
integration:
integration: install-stylua
./utils/stylua --config-path stylua.toml --check --glob 'lua/**/*.lua' -- lua
luacheck lua
vusted lua

View File

@@ -8,7 +8,7 @@ Completion sources are installed from external repositories and "sourced".
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.
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)
else
vim.cmd([[silent! undojoin]])
vim.lsp.util.apply_text_edits(
e:get_completion_item().additionalTextEdits,
ctx.bufnr,
e.source:get_position_encoding_kind()
)
vim.lsp.util.apply_text_edits(e:get_completion_item().additionalTextEdits, ctx.bufnr, e.source:get_position_encoding_kind())
end
end)
feedkeys.call('', 'n', function()
@@ -453,13 +449,7 @@ core.confirm = function(self, e, option, callback)
local texts = vim.split(completion_item.textEdit.newText, '\n')
vim.api.nvim_win_set_cursor(0, {
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
config.get().snippet.expand({

View File

@@ -33,8 +33,7 @@ describe('cmp.core', function()
end)
end)
feedkeys.call(filter, 'n', function()
c:confirm(c.sources[s.id].entries[1], {}, function()
end)
c:confirm(c.sources[s.id].entries[1], {}, function() end)
end)
local state = {}
feedkeys.call('', 'x', function()
@@ -127,35 +126,35 @@ describe('cmp.core', function()
for _, case in ipairs({
{
encoding = types.lsp.PositionEncodingKind.UTF8,
char_size = #char
char_size = #char,
},
{
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,
char_size = select(1, vim.str_utfindex(char))
char_size = select(1, vim.str_utfindex(char)),
},
}) 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, {
label = char .. char .. char,
textEdit = {
range = {
start = {
line = 0,
character = case.char_size + #':'
character = case.char_size + #':',
},
['end'] = {
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,
}
},
}, {
position_encoding_kind = case.encoding
position_encoding_kind = case.encoding,
})
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) })

View File

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

View File

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