~havi/nvim.d

4d28a50c91f72c53514b991e26267277c029baee — havi 4 months ago 1620186
style: formatting
M after/ftplugin/rust.lua => after/ftplugin/rust.lua +14 -14
@@ 195,28 195,28 @@ vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagn
-- https://github.com/PaterJason/dotfiles/blob/master/stowed/.config/nvim/lua/diagnostic.lua
-- https://neovim.io/doc/user/api.html#nvim_create_autocmd()
-- show/refresh diagnostics after saving
local augroup = vim.api.nvim_create_augroup('Rust', {})
vim.api.nvim_create_autocmd('DiagnosticChanged', {
local augroup = vim.api.nvim_create_augroup("Rust", {})
vim.api.nvim_create_autocmd("DiagnosticChanged", {
   buffer = vim.api.nvim_get_current_buf(),
   callback = function()
    if vim.fn.getqflist({ title = 0 }).title == 'Diagnostics' then
      vim.diagnostic.setqflist { open = false }
    end
    if vim.fn.getloclist(0, { title = 0 }).title == 'Diagnostics' then
      vim.diagnostic.setloclist { open = false }
    end
  end,
  group = augroup,
      if vim.fn.getqflist({ title = 0 }).title == "Diagnostics" then
         vim.diagnostic.setqflist({ open = false })
      end
      if vim.fn.getloclist(0, { title = 0 }).title == "Diagnostics" then
         vim.diagnostic.setloclist({ open = false })
      end
   end,
   group = augroup,
})
-- auto format before saving
vim.api.nvim_create_autocmd('BufWritePre', {
vim.api.nvim_create_autocmd("BufWritePre", {
   buffer = vim.api.nvim_get_current_buf(),
   callback = function()
      vim.lsp.buf.format({async = false})
      vim.lsp.buf.format({ async = false })
   end,
   group = augroup,
 })
-- vim.api.nvim_exec([[ 
})
-- vim.api.nvim_exec([[
--       augroup Rust
--          autocmd! * <buffer>
--          autocmd BufWritePre <buffer> lua vim.lsp.buf.format({async = false})

M after/plugin/user_commands.lua => after/plugin/user_commands.lua +19 -27
@@ 1,33 1,25 @@
-- vim: filetype=lua syntax=lua softtabstop=3 tabstop=3 shiftwidth=3 fileencoding=utf-8 smartindent autoindent expandtab
-- code: language=lua insertSpaces=true tabSize=3
-- NeatFoldText
vim.api.nvim_create_user_command(
	'SpacesToTabs',
	function(tbl)
		vim.opt.expandtab = false
		local previous_tabstop = vim.bo.tabstop
		vim.opt.tabstop = tonumber(tbl.args)
		vim.api.nvim_command 'retab!'
		vim.opt.tabstop = previous_tabstop
	end,
	{force = true, nargs = 1}
)
vim.api.nvim_create_user_command("SpacesToTabs", function(tbl)
   vim.opt.expandtab = false
   local previous_tabstop = vim.bo.tabstop
   vim.opt.tabstop = tonumber(tbl.args)
   vim.api.nvim_command("retab!")
   vim.opt.tabstop = previous_tabstop
end, { force = true, nargs = 1 })

vim.api.nvim_create_user_command(
	'TabsToSpaces',
	function(tbl)
		vim.opt.expandtab = true
		local previous_tabstop = vim.bo.tabstop
		vim.opt.tabstop = tonumber(tbl.args)
		vim.api.nvim_command 'retab'
		vim.opt.tabstop = previous_tabstop
	end,
	{force = true, nargs = 1}
)
vim.api.nvim_create_user_command("TabsToSpaces", function(tbl)
   vim.opt.expandtab = true
   local previous_tabstop = vim.bo.tabstop
   vim.opt.tabstop = tonumber(tbl.args)
   vim.api.nvim_command("retab")
   vim.opt.tabstop = previous_tabstop
end, { force = true, nargs = 1 })

-- Vim LSP stuff
vim.api.nvim_create_user_command(
	'LspOrganizeImports',
	'lua vim.lsp.buf.code_action{source = {organizeImports = true}}',
	{force = true}
   "LspOrganizeImports",
   "lua vim.lsp.buf.code_action{source = {organizeImports = true}}",
   { force = true }
)



M lua/lib/lsp.lua => lua/lib/lsp.lua +8 -12
@@ 83,10 83,8 @@ function M:setup(name, opts)
   end
   local server_is_found, server = lsp_installer.get_server(name)
   if not server_is_found then
      msg = string.format(
         "lsp installer was not able to find configuration/install instruction for '%s' LSP server",
         name
      )
      msg =
         string.format("lsp installer was not able to find configuration/install instruction for '%s' LSP server", name)
      -- stylua: ignore start
      if logger then return logger:warn(msg) else return end
      -- stylua: ignore end


@@ 123,27 121,25 @@ function M:setup(name, opts)
            -- https://github.com/susliko/dotfiles/blob/master/nvim/.config/nvim/lua/susliko/lang/lsp/handlers.lua
            if client.resolved_capabilities.document_highlight then
               vim.api.nvim_exec(
                 [[
                  [[
                 augroup lsp_document_highlight
                   autocmd! * <buffer>
                   autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
                   autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
                 augroup END
               ]] ,
                 false
               ]],
                  false
               )
             end
           
            end

             if client.resolved_capabilities.code_lens then
            if client.resolved_capabilities.code_lens then
               vim.cmd([[
                 augroup lsp_document_codelens
                 autocmd! * <buffer>
                   autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh()
                 augroup end
               ]])
             end
           
            end
         end,
      })
      -- https://github.com/alpha2phi/neovim-for-beginner/blob/ae2abb02326034a92f61b47e66c3001d4cf9ba70/lua/config/lsp/installer.lua#L6

M lua/lib/plugins/nvim-tree.lua => lua/lib/plugins/nvim-tree.lua +28 -26
@@ 108,33 108,35 @@ function M.mv()
      local relative_dir = dir:gsub(cwd, "")
      table.insert(relative_dirs, relative_dir)
   end
   pickers.new(opts, {
      prompt_title = "Target directory",
      finder = finders.new_table({ results = relative_dirs }),
      sorter = conf.generic_sorter(opts),
      attach_mappings = function(prompt_bufnr)
         actions.select_default:replace(function()
            actions.close(prompt_bufnr)
            local selection = action_state.get_selected_entry()
            local source_file = node.absolute_path
            local target_dir = cwd .. selection[1]
            -- local target_dir = cwd
            -- if not selection[1] == "./" then
            --    local target_dir = cwd .. selection[1]
            -- end
   pickers
      .new(opts, {
         prompt_title = "Target directory",
         finder = finders.new_table({ results = relative_dirs }),
         sorter = conf.generic_sorter(opts),
         attach_mappings = function(prompt_bufnr)
            actions.select_default:replace(function()
               actions.close(prompt_bufnr)
               local selection = action_state.get_selected_entry()
               local source_file = node.absolute_path
               local target_dir = cwd .. selection[1]
               -- local target_dir = cwd
               -- if not selection[1] == "./" then
               --    local target_dir = cwd .. selection[1]
               -- end

            if not require("lib.utils").is_dir(target_dir) then
               vim.notify("Target is not a directory")
               return
            end
            os.execute(string.format("mv %s %s", vim.fn.shellescape(source_file), vim.fn.shellescape(target_dir)))
            lib.refresh_tree()
            -- lib.change_dir(vim.fn.fnamemodify(target_dir, ':p:h'))
            -- lib.set_index_and_redraw(target_dir)
         end)
         return true
      end,
   }):find()
               if not require("lib.utils").is_dir(target_dir) then
                  vim.notify("Target is not a directory")
                  return
               end
               os.execute(string.format("mv %s %s", vim.fn.shellescape(source_file), vim.fn.shellescape(target_dir)))
               lib.refresh_tree()
               -- lib.change_dir(vim.fn.fnamemodify(target_dir, ':p:h'))
               -- lib.set_index_and_redraw(target_dir)
            end)
            return true
         end,
      })
      :find()
end
-- ╭────────────────────────────────────────────────────────────────────╮
-- │                      function definition end                       │

M lua/lib/plugins/telescope.lua => lua/lib/plugins/telescope.lua +26 -24
@@ 40,29 40,31 @@ function M:terraform_state()
   local sorters = to_require_map["telescope.nvim"]["telescope.sorters"]
   local finders = to_require_map["telescope.nvim"]["telescope.finders"]

   pickers.new({
      results_title = "Resources",
      -- Run an external command and show the results in the finder window
      finder = finders.new_oneshot_job({ "terraform", "show" }),
      sorter = sorters.get_fuzzy_file(),
      previewer = previewers.new_buffer_previewer({
         -- luacheck: no unused args
         -- luacheck: ignore 432
         -- selene: allow(unused_variable,shadowing)
         define_preview = function(self, entry, status)
            -- selene: deny(unused_variable,shadowing)
            -- luacheck: enable 432
            -- luacheck: unused args
            -- Execute another command using the highlighted entry
            return previewers_utils.job_maker({ "terraform", "state", "list", entry.value }, self.state.bufnr, {
               callback = function(bufnr, content)
                  if content ~= nil then
                     previewers_utils.regex_highlighter(bufnr, "terraform")
                  end
               end,
            })
         end,
      }),
   }):find()
   pickers
      .new({
         results_title = "Resources",
         -- Run an external command and show the results in the finder window
         finder = finders.new_oneshot_job({ "terraform", "show" }),
         sorter = sorters.get_fuzzy_file(),
         previewer = previewers.new_buffer_previewer({
            -- luacheck: no unused args
            -- luacheck: ignore 432
            -- selene: allow(unused_variable,shadowing)
            define_preview = function(self, entry, status)
               -- selene: deny(unused_variable,shadowing)
               -- luacheck: enable 432
               -- luacheck: unused args
               -- Execute another command using the highlighted entry
               return previewers_utils.job_maker({ "terraform", "state", "list", entry.value }, self.state.bufnr, {
                  callback = function(bufnr, content)
                     if content ~= nil then
                        previewers_utils.regex_highlighter(bufnr, "terraform")
                     end
                  end,
               })
            end,
         }),
      })
      :find()
end
return M

M lua/mappings/files.lua => lua/mappings/files.lua +24 -22
@@ 41,28 41,30 @@ return function(register)
         function()
            local conf = require("telescope.config").values
            local actions = require("telescope.actions")
            require("telescope.pickers").new({}, {
               prompt_title = "CD Dir",
               finder = require("telescope.finders").new_oneshot_job({ "fd", "-t", "d", "-H" }, {
                  cwd = vim.fn.getcwd(),
               }),
               sorter = conf.generic_sorter({}),
               previewer = conf.file_previewer({}),
               attach_mappings = function(prompt_bufnr, _)
                  actions.select_default:replace(function()
                     local selected = require("telescope.actions.state").get_selected_entry(prompt_bufnr)
                     actions.close(prompt_bufnr)
                     if selected == nil then
                        return
                     end
                     local result = vim.fn.chdir(selected.value)
                     if result == "" then
                        error("failed to cd to " .. selected.value, vim.diagnostic.severity.E)
                     end
                  end)
                  return true
               end,
            }):find()
            require("telescope.pickers")
               .new({}, {
                  prompt_title = "CD Dir",
                  finder = require("telescope.finders").new_oneshot_job({ "fd", "-t", "d", "-H" }, {
                     cwd = vim.fn.getcwd(),
                  }),
                  sorter = conf.generic_sorter({}),
                  previewer = conf.file_previewer({}),
                  attach_mappings = function(prompt_bufnr, _)
                     actions.select_default:replace(function()
                        local selected = require("telescope.actions.state").get_selected_entry(prompt_bufnr)
                        actions.close(prompt_bufnr)
                        if selected == nil then
                           return
                        end
                        local result = vim.fn.chdir(selected.value)
                        if result == "" then
                           error("failed to cd to " .. selected.value, vim.diagnostic.severity.E)
                        end
                     end)
                     return true
                  end,
               })
               :find()
         end,
         "Change Directory",
      },