Skip to content

Commit

Permalink
chore: use stylua for formatting (nvim-telescope#1040)
Browse files Browse the repository at this point in the history
* chore: stylua job and config

* reformat with stylua
  • Loading branch information
Conni2461 authored Jul 23, 2021
1 parent 6646900 commit 79644ab
Show file tree
Hide file tree
Showing 75 changed files with 3,208 additions and 2,816 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ jobs:
- name: Lint
run: sudo make lint

stylua:
name: stylua
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: JohnnyMorganz/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
# CLI arguments
args: --color always --check lua/
6 changes: 6 additions & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
column_width = 120
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferDouble"
no_call_parentheses = true
36 changes: 17 additions & 19 deletions lua/telescope/WIP.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@

local make_entry = require('telescope.make_entry')
local actions = require('telescope.actions')
local action_state = require('telescope.actions.state')
local finders = require('telescope.finders')
local previewers = require('telescope.previewers')
local pickers = require('telescope.pickers')
local sorters = require('telescope.sorters')
local make_entry = require "telescope.make_entry"
local actions = require "telescope.actions"
local action_state = require "telescope.actions.state"
local finders = require "telescope.finders"
local previewers = require "telescope.previewers"
local pickers = require "telescope.pickers"
local sorters = require "telescope.sorters"

local WIP = {}

WIP.git_diff = function()
local file_picker = pickers.new {
previewer = previewers.new_termopen {
command = "git diff %s"
command = "git diff %s",
},
}

Expand All @@ -24,13 +23,13 @@ WIP.git_diff = function()

fn_command = function()
return {
command = 'git',
args = {'ls-files', '-m'}
command = "git",
args = { "ls-files", "-m" },
}
end,
},

sorter = sorters.get_norcalli_sorter()
sorter = sorters.get_norcalli_sorter(),
}
end

Expand All @@ -43,12 +42,12 @@ WIP.completion = function(opts)
end

local lsp_reference_finder = finders.new {
results = results
results = results,
}

-- TODO: Open the help text for the line.
local reference_picker = pickers.new(opts, {
prompt = 'vim.api Help Reference',
prompt = "vim.api Help Reference",
finder = lsp_reference_finder,
sorter = sorters.get_norcalli_sorter(),
previewer = previewers.help,
Expand All @@ -57,12 +56,11 @@ WIP.completion = function(opts)
reference_picker:find {}
end


WIP.reloader = function(opts)
opts = opts or {}

pickers.new(opts, {
prompt = 'Packages',
prompt = "Packages",
finder = finders.new_table {
results = vim.tbl_keys(package.loaded),
entry_maker = make_entry.gen_from_string(opts),
Expand All @@ -78,11 +76,11 @@ WIP.reloader = function(opts)
print(vim.inspect(selection))
end

map('i', '<CR>', reload_package)
map('n', '<CR>', reload_package)
map("i", "<CR>", reload_package)
map("n", "<CR>", reload_package)

return true
end
end,
}):find()
end

Expand Down
6 changes: 3 additions & 3 deletions lua/telescope/_compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ vim.deepcopy = (function()

return copy
end,
['function'] = _id or function(orig)
["function"] = _id or function(orig)
local ok, dumped = pcall(string.dump, orig)
if not ok then
error(debug.traceback(dumped))
Expand All @@ -41,7 +41,7 @@ vim.deepcopy = (function()
end,
number = _id,
string = _id,
['nil'] = _id,
["nil"] = _id,
boolean = _id,
}

Expand All @@ -50,7 +50,7 @@ vim.deepcopy = (function()
if f then
return f(orig)
else
error("Cannot deepcopy object of type "..type(orig))
error("Cannot deepcopy object of type " .. type(orig))
end
end
end)()
4 changes: 2 additions & 2 deletions lua/telescope/_extensions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ extensions._config = {}
extensions.manager = setmetatable({}, {
__index = function(t, k)
-- See if this extension exists.
local ok, ext = pcall(require, 'telescope._extensions.' .. k)
local ok, ext = pcall(require, "telescope._extensions." .. k)
if not ok then
error("This extension doesn't exist or is not installed: " .. k .. "\n" .. ext)
end

if ext.setup then
ext.setup(extensions._config[k] or {}, require('telescope.config').values)
ext.setup(extensions._config[k] or {}, require("telescope.config").values)
end

t[k] = ext.exports or {}
Expand Down
54 changes: 36 additions & 18 deletions lua/telescope/actions/history.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local conf = require('telescope.config').values
local Path = require('plenary.path')
local conf = require("telescope.config").values
local Path = require "plenary.path"

local uv = vim.loop

Expand Down Expand Up @@ -37,7 +37,9 @@ local write_async = function(path, txt, flag)
end)
end

local append_async = function(path, txt) write_async(path, txt, "a") end
local append_async = function(path, txt)
write_async(path, txt, "a")
end

local histories = {}

Expand Down Expand Up @@ -86,7 +88,9 @@ end

--- Will reset the history index to the default initial state. Will happen after the picker closed
function histories.History:reset()
if not self.enabled then return end
if not self.enabled then
return
end
self._reset(self)
end

Expand All @@ -95,7 +99,9 @@ end
---@param picker table: the current picker object
---@param no_reset boolean: On default it will reset the state at the end. If you don't want to do this set to true
function histories.History:append(line, picker, no_reset)
if not self.enabled then return end
if not self.enabled then
return
end
self._append(self, line, picker, no_reset)
end

Expand All @@ -105,11 +111,15 @@ end
---@return string: the next history item
function histories.History:get_next(line, picker)
if not self.enabled then
print("You are cycling to next the history item but history is disabled.",
"Read ':help telescope.defaults.history'")
print(
"You are cycling to next the history item but history is disabled.",
"Read ':help telescope.defaults.history'"
)
return false
end
if self._pre_get then self._pre_get(self, line, picker) end
if self._pre_get then
self._pre_get(self, line, picker)
end

local next_idx = self.index + 1
if next_idx <= #self.content then
Expand All @@ -126,15 +136,21 @@ end
---@return string: the previous history item
function histories.History:get_prev(line, picker)
if not self.enabled then
print("You are cycling to previous the history item but history is disabled.",
"Read ':help telescope.defaults.history'")
print(
"You are cycling to previous the history item but history is disabled.",
"Read ':help telescope.defaults.history'"
)
return false
end
if self._pre_get then self._pre_get(self, line, picker) end
if self._pre_get then
self._pre_get(self, line, picker)
end

local next_idx = self.index - 1
if self.index == #self.content + 1 then
if line ~= '' then self:append(line, picker, true) end
if line ~= "" then
self:append(line, picker, true)
end
end
if next_idx >= 1 then
self.index = next_idx
Expand All @@ -147,10 +163,12 @@ end
---
--- It will keep one unified history across all pickers.
histories.get_simple_history = function()
return histories.new({
return histories.new {
init = function(obj)
local p = Path:new(obj.path)
if not p:exists() then p:touch({ parents = true }) end
if not p:exists() then
p:touch { parents = true }
end

obj.content = Path:new(obj.path):readlines()
obj.index = #obj.content
Expand All @@ -160,7 +178,7 @@ histories.get_simple_history = function()
self.index = #self.content + 1
end,
append = function(self, line, _, no_reset)
if line ~= '' then
if line ~= "" then
if self.content[#self.content] ~= line then
table.insert(self.content, line)

Expand All @@ -170,17 +188,17 @@ histories.get_simple_history = function()
for i = diff, 1, -1 do
table.remove(self.content, i)
end
write_async(self.path, table.concat(self.content, '\n') .. '\n', 'w')
write_async(self.path, table.concat(self.content, "\n") .. "\n", "w")
else
append_async(self.path, line .. '\n')
append_async(self.path, line .. "\n")
end
end
end
if not no_reset then
self:reset()
end
end,
})
}
end

return histories
Loading

0 comments on commit 79644ab

Please sign in to comment.