neovim: remove unused shit
This commit is contained in:
@@ -1,13 +1,4 @@
|
|||||||
local git = require("daniil.git")
|
local git = require("daniil.git")
|
||||||
local u = require("daniil.utils")
|
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("OrganizeImports", function()
|
|
||||||
u.lsp_organize_imports()
|
|
||||||
end, {})
|
|
||||||
vim.api.nvim_create_user_command("AddMissingImports", function()
|
|
||||||
u.addMissingImports(0)
|
|
||||||
u.lsp_format(0)
|
|
||||||
end, {})
|
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("GitShowCommit", function()
|
vim.api.nvim_create_user_command("GitShowCommit", function()
|
||||||
local commit = git.get_commit_hash_for_current_line()
|
local commit = git.get_commit_hash_for_current_line()
|
||||||
|
|||||||
@@ -1,22 +1,5 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.objectAssign = function(target, ...)
|
|
||||||
local sources = { ... }
|
|
||||||
for i = 1, #sources do
|
|
||||||
local source = sources[i]
|
|
||||||
for key in pairs(source) do
|
|
||||||
target[key] = source[key]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return target
|
|
||||||
end
|
|
||||||
|
|
||||||
M.get_lsp_client = function(name, bufnr)
|
|
||||||
local clients = vim.lsp.get_active_clients({ bufnr = bufnr, name = name })
|
|
||||||
|
|
||||||
return clients[1]
|
|
||||||
end
|
|
||||||
|
|
||||||
M.yank = function(message)
|
M.yank = function(message)
|
||||||
vim.cmd(":!echo -n '" .. message .. "' | wl-copy")
|
vim.cmd(":!echo -n '" .. message .. "' | wl-copy")
|
||||||
end
|
end
|
||||||
@@ -57,44 +40,6 @@ M.copy_diagnostic_message = function()
|
|||||||
print("Diagnostic message was yanked")
|
print("Diagnostic message was yanked")
|
||||||
end
|
end
|
||||||
|
|
||||||
M.run_lsp_codeaction = function(codeAction, bufnr, timeout, clientName)
|
|
||||||
local params = M.objectAssign({}, vim.lsp.util.make_range_params(), {
|
|
||||||
context = {
|
|
||||||
only = { codeAction },
|
|
||||||
diagnostics = vim.diagnostic.get(bufnr),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
local client = M.get_lsp_client(clientName, bufnr)
|
|
||||||
if not client then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local res = client.request_sync("textDocument/codeAction", params, timeout, bufnr)
|
|
||||||
if not res.result[1] then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local edits = res.result[1].edit.documentChanges[1].edits
|
|
||||||
vim.lsp.util.apply_text_edits(edits, bufnr, client.offset_encoding)
|
|
||||||
end
|
|
||||||
|
|
||||||
M.removeUnusedImports = function(bufnr, timeout)
|
|
||||||
M.run_lsp_codeaction("source.removeUnusedImports.ts", bufnr, timeout, "tsserver")
|
|
||||||
end
|
|
||||||
|
|
||||||
M.addMissingImports = function(bufnr, timeout)
|
|
||||||
M.run_lsp_codeaction("source.addMissingImports.ts", bufnr, timeout, "tsserver")
|
|
||||||
end
|
|
||||||
|
|
||||||
M.lsp_organize_imports = function(bufnr, timeout)
|
|
||||||
if not bufnr then
|
|
||||||
bufnr = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
M.removeUnusedImports(bufnr, timeout)
|
|
||||||
end
|
|
||||||
|
|
||||||
M.open_url_in_browser = function(url)
|
M.open_url_in_browser = function(url)
|
||||||
local _url = string.format('"%s"', url)
|
local _url = string.format('"%s"', url)
|
||||||
|
|
||||||
@@ -104,8 +49,6 @@ end
|
|||||||
function M.lsp_format(bufnr)
|
function M.lsp_format(bufnr)
|
||||||
bufnr = bufnr or 0
|
bufnr = bufnr or 0
|
||||||
|
|
||||||
M.lsp_organize_imports(bufnr)
|
|
||||||
|
|
||||||
vim.lsp.buf.format({
|
vim.lsp.buf.format({
|
||||||
filter = function(client)
|
filter = function(client)
|
||||||
if client.name == "tsserver" then
|
if client.name == "tsserver" then
|
||||||
@@ -157,21 +100,4 @@ function M.toggle_locationlist()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.is_inside_tmux()
|
|
||||||
local TMUX = os.getenv("TMUX")
|
|
||||||
|
|
||||||
return TMUX ~= nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.open_error_on_stackoverflow()
|
|
||||||
local diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
|
|
||||||
local selected_diagnostic = M.select_diagnostic(diagnostics, "Select diagnostic to open on Stack Overflow")
|
|
||||||
|
|
||||||
local url = string.format("https://stackoverflow.com/search?q=%s", selected_diagnostic)
|
|
||||||
|
|
||||||
M.open_url_in_browser(url)
|
|
||||||
|
|
||||||
M.yank(selected_diagnostic)
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user