mirror of
https://github.com/stevenproctor/dotfiles.git
synced 2026-01-28 14:19:55 -06:00
nvim - fix lsp mappings
This commit is contained in:
@@ -4,20 +4,23 @@
|
|||||||
(local lspconfig (require :lspconfig))
|
(local lspconfig (require :lspconfig))
|
||||||
(local cmp_nvim_lsp (require :cmp_nvim_lsp))
|
(local cmp_nvim_lsp (require :cmp_nvim_lsp))
|
||||||
|
|
||||||
(fn bufmap [mode from to] (u.noremap mode from to {:local? true}))
|
(fn bufmap [mode from to opts]
|
||||||
|
(u.noremap mode from to (a.merge {:local? true} opts)))
|
||||||
|
|
||||||
(fn nbufmap [from to] (bufmap :n from to))
|
(fn nbufmap [from to opts] (bufmap :n from to opts))
|
||||||
|
|
||||||
(fn xbufmap [from to] (bufmap :x from to))
|
(fn xbufmap [from to opts] (bufmap :x from to opts))
|
||||||
|
|
||||||
(fn lsp-execute-command [cmd ...]
|
(fn lsp-execute-command [client cmd ...]
|
||||||
(let [buf-uri (vim.uri_from_bufnr 0)
|
(let [buf-uri (vim.uri_from_bufnr 0)
|
||||||
cursor (vim.api.nvim_win_get_cursor 0)
|
cursor (vim.api.nvim_win_get_cursor 0)
|
||||||
r (- (a.first cursor) 1)
|
r (- (a.first cursor) 1)
|
||||||
c (a.second cursor)
|
c (a.second cursor)
|
||||||
opts [buf-uri r c]
|
opts [buf-uri r c]
|
||||||
args (a.concat opts [...])]
|
args (a.concat opts [...])]
|
||||||
(vim.lsp.buf.execute_command {:command cmd :arguments args})))
|
;;(client.exec_cmd {:command cmd :arguments args} {:bufnr 0})
|
||||||
|
(client.request_sync :workspace/executeCommand
|
||||||
|
{:command cmd :arguments args} nil 0)))
|
||||||
|
|
||||||
(vim.diagnostic.config {:signs {:text {vim.diagnostic.severity.ERROR "☢️"
|
(vim.diagnostic.config {:signs {:text {vim.diagnostic.severity.ERROR "☢️"
|
||||||
vim.diagnostic.severity.WARN "⚠️"
|
vim.diagnostic.severity.WARN "⚠️"
|
||||||
@@ -45,21 +48,23 @@
|
|||||||
:<leader>rn "lua vim.lsp.buf.rename()"
|
:<leader>rn "lua vim.lsp.buf.rename()"
|
||||||
:<leader>fa "lua vim.lsp.buf.format()"})
|
:<leader>fa "lua vim.lsp.buf.format()"})
|
||||||
|
|
||||||
(local client-nmappings
|
(local client-nmappings {:clojure_lsp {;;:<leader>cn "call LspExecuteCommand('clean-ns')"
|
||||||
{:clojure_lsp {:<leader>cn "call LspExecuteCommand('clean-ns')"
|
;; :<leader>ref "call LspExecuteCommand('extract-function', input('Function name: '))"
|
||||||
:<leader>ref "call LspExecuteCommand('extract-function', input('Function name: '))"
|
;; :<leader>id "call LspExecuteCommand('inline-symbol')"
|
||||||
:<leader>id "call LspExecuteCommand('inline-symbol')"
|
;; :<leader>il "call LspExecuteCommand('introduce-let', input('Binding name: '))"
|
||||||
:<leader>il "call LspExecuteCommand('introduce-let', input('Binding name: '))"
|
;;:<leader>m2l "call LspExecuteCommand('move-to-let', input('Binding name: '))"
|
||||||
:<leader>m2l "call LspExecuteCommand('move-to-let', input('Binding name: '))"}})
|
}})
|
||||||
|
|
||||||
|
;;(vim.fn.input "foo: ")
|
||||||
|
|
||||||
(local client-command-lnmappings
|
(local client-command-lnmappings
|
||||||
{:clojure_lsp {:ai [:add-import-to-namespace
|
{:clojure_lsp {:ai [:add-import-to-namespace
|
||||||
["input('Namespace name: ')"]]
|
[(lambda [] (vim.fn.input "Namespace name: "))]]
|
||||||
:am [:add-missing-libspec []]
|
:am [:add-missing-libspec []]
|
||||||
:as [:add-require-suggestion
|
:as [:add-require-suggestion
|
||||||
["input('Namespace name: ')"
|
[(lambda [] (vim.fn.input "Namespace name: "))
|
||||||
"input('Namespace as: ')"
|
(lambda [] (vim.fn.input "Namespace as: "))
|
||||||
"input('Namespace name: ')"]]
|
(lambda [] (vim.fn.input "Namespace name: "))]]
|
||||||
:cc [:cycle-coll []]
|
:cc [:cycle-coll []]
|
||||||
:cn [:clean-ns []]
|
:cn [:clean-ns []]
|
||||||
:cp [:cycle-privacy []]
|
:cp [:cycle-privacy []]
|
||||||
@@ -68,17 +73,25 @@
|
|||||||
:db [:drag-backward []]
|
:db [:drag-backward []]
|
||||||
:df [:drag-forward []]
|
:df [:drag-forward []]
|
||||||
:dk [:destructure-keys []]
|
:dk [:destructure-keys []]
|
||||||
:ed [:extract-to-def ["input('Definition name: ')"]]
|
:ed [:extract-to-def
|
||||||
:ef [:extract-function ["input('Function name: ')"]]
|
[(lambda [] (vim.fn.input "Definition name: "))]]
|
||||||
|
:ref [:extract-function
|
||||||
|
[(lambda [] (vim.fn.input "Function name: "))]]
|
||||||
:el [:expand-let []]
|
:el [:expand-let []]
|
||||||
:fe [:create-function []]
|
:fe [:create-function []]
|
||||||
:il [:introduce-let ["input('Binding name: ')"]]
|
:il [:introduce-let
|
||||||
|
[(lambda [] (vim.fn.input "Binding name: "))]]
|
||||||
:is [:inline-symbol []]
|
:is [:inline-symbol []]
|
||||||
:ma [:resolve-macro-as []]
|
:ma [:resolve-macro-as []]
|
||||||
:mf [:move-form ["input('File name: ')"]]
|
:mf [:move-form
|
||||||
:ml [:move-to-let ["input('Binding name: ')"]]
|
[(lambda [] (vim.fn.input "File name: "))]]
|
||||||
:pf [:promote-fn ["input('Function name: ')"]]
|
:ml [:move-to-let
|
||||||
:sc [:change-collection ["input('Collection type: ')"]]
|
[(lambda [] (vim.fn.input "Binding name: "))]]
|
||||||
|
:pf [:promote-fn
|
||||||
|
[(lambda [] (vim.fn.input "Function name: "))]]
|
||||||
|
:sc [:change-collection
|
||||||
|
[(lambda [] (vim.fn.input ""))
|
||||||
|
"input('Collection type: ')"]]
|
||||||
:sm [:sort-map []]
|
:sm [:sort-map []]
|
||||||
:tf [:thread-first-all []]
|
:tf [:thread-first-all []]
|
||||||
:tF [:thread-first []]
|
:tF [:thread-first []]
|
||||||
@@ -95,21 +108,26 @@
|
|||||||
command-lnmappings (a.get client-command-lnmappings client-name)]
|
command-lnmappings (a.get client-command-lnmappings client-name)]
|
||||||
(when mappings
|
(when mappings
|
||||||
(each [mapping cmd (pairs mappings)]
|
(each [mapping cmd (pairs mappings)]
|
||||||
(nbufmap mapping cmd)))
|
(nbufmap mapping cmd {})))
|
||||||
(when command-lnmappings
|
(when command-lnmappings
|
||||||
(each [lnmapping command-mapping (pairs command-lnmappings)]
|
(each [lnmapping command-mapping (pairs command-lnmappings)]
|
||||||
(let [lsp-cmd (a.first command-mapping)
|
(let [lsp-cmd (a.first command-mapping)
|
||||||
opts-str (accumulate [s "" i opt (ipairs (a.second command-mapping))]
|
;;lsp-cmd (.. client-name "." (a.first command-mapping))
|
||||||
(.. s ", " opt))
|
;;opts (a.second command-mapping)
|
||||||
mapping (.. :<leader> lnmapping)
|
mapping (.. :<leader> lnmapping)
|
||||||
cmd (fn []
|
cmd (lambda []
|
||||||
(lsp-execute-command lsp-cmd opts-str))]
|
(let [opts (accumulate [s "" _i opt (ipairs (a.second command-mapping))]
|
||||||
(nbufmap mapping cmd))))))
|
(.. s
|
||||||
|
(if (= :function (type opt))
|
||||||
|
(opt)
|
||||||
|
opt)))]
|
||||||
|
(lsp-execute-command client lsp-cmd opts)))]
|
||||||
|
(nbufmap mapping cmd {:desc (.. "LSP command `" lsp-cmd "`")}))))))
|
||||||
|
|
||||||
(fn on_attach [client bufnr]
|
(fn on_attach [client bufnr]
|
||||||
(each [mapping cmd (pairs core-nmappings)]
|
(each [mapping cmd (pairs core-nmappings)]
|
||||||
(nbufmap mapping cmd)) ; x mode mappings
|
(nbufmap mapping cmd {})) ; x mode mappings
|
||||||
(xbufmap :<leader>fa "lua vim.lsp.buf.format()") ; -- buf_set_keymap('n', 'gs', '<Cmd>lua vim.lsp.buf.document_symbol()<CR>', opts)
|
(xbufmap :<leader>fa "lua vim.lsp.buf.format()" {:desc "Format buffer"}) ; -- buf_set_keymap('n', 'gs', '<Cmd>lua vim.lsp.buf.document_symbol()<CR>', opts)
|
||||||
; -- buf_set_keymap('n', 'gS', '<Cmd>lua vim.lsp.buf.workspace_symbol()<CR>', opts)
|
; -- buf_set_keymap('n', 'gS', '<Cmd>lua vim.lsp.buf.workspace_symbol()<CR>', opts)
|
||||||
; -- buf_set_keymap('n', 'gt', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
; -- buf_set_keymap('n', 'gt', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
||||||
; -- buf_set_keymap('n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
; -- buf_set_keymap('n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
||||||
|
|||||||
@@ -4,12 +4,14 @@
|
|||||||
(= :function (type x)))
|
(= :function (type x)))
|
||||||
|
|
||||||
(fn noremap [mode from to opts]
|
(fn noremap [mode from to opts]
|
||||||
(let [map-opts {:noremap true :silent true}
|
(let [local? (a.get opts :local?)
|
||||||
|
opts (a.assoc opts :local? nil)
|
||||||
|
map-opts (a.merge opts {:noremap true :silent true})
|
||||||
to (if (fn? to)
|
to (if (fn? to)
|
||||||
to
|
to
|
||||||
(.. ":" to :<cr>))
|
(.. ":" to :<cr>))
|
||||||
buff-num (a.get opts :buff-num)]
|
buff-num (a.get opts :buff-num)]
|
||||||
(if (or (a.get opts :local?) buff-num)
|
(if (or local? buff-num)
|
||||||
(vim.keymap.set mode from to
|
(vim.keymap.set mode from to
|
||||||
(a.merge map-opts {:buffer (or buff-num 0)}))
|
(a.merge map-opts {:buffer (or buff-num 0)}))
|
||||||
(vim.keymap.set mode from to map-opts))))
|
(vim.keymap.set mode from to map-opts))))
|
||||||
@@ -22,7 +24,7 @@
|
|||||||
|
|
||||||
(fn vnoremap [from to opts] (noremap :v from to opts))
|
(fn vnoremap [from to opts] (noremap :v from to opts))
|
||||||
|
|
||||||
(fn lnnoremap [from to] (nnoremap (.. :<leader> from) to))
|
(fn lnnoremap [from to opts] (nnoremap (.. :<leader> from) to opts))
|
||||||
|
|
||||||
(fn ltnoremap [from to opts] (noremap :v (.. :<leader> from) to opts))
|
(fn ltnoremap [from to opts] (noremap :v (.. :<leader> from) to opts))
|
||||||
|
|
||||||
|
|||||||
@@ -4,28 +4,62 @@ local u = require("dotfiles.util")
|
|||||||
local lsp = require("vim.lsp")
|
local lsp = require("vim.lsp")
|
||||||
local lspconfig = require("lspconfig")
|
local lspconfig = require("lspconfig")
|
||||||
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
||||||
local function bufmap(mode, from, to)
|
local function bufmap(mode, from, to, opts)
|
||||||
return u.noremap(mode, from, to, {["local?"] = true})
|
return u.noremap(mode, from, to, a.merge({["local?"] = true}, opts))
|
||||||
end
|
end
|
||||||
local function nbufmap(from, to)
|
local function nbufmap(from, to, opts)
|
||||||
return bufmap("n", from, to)
|
return bufmap("n", from, to, opts)
|
||||||
end
|
end
|
||||||
local function xbufmap(from, to)
|
local function xbufmap(from, to, opts)
|
||||||
return bufmap("x", from, to)
|
return bufmap("x", from, to, opts)
|
||||||
end
|
end
|
||||||
local function lsp_execute_command(cmd, ...)
|
local function lsp_execute_command(client, cmd, ...)
|
||||||
local buf_uri = vim.uri_from_bufnr(0)
|
local buf_uri = vim.uri_from_bufnr(0)
|
||||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||||
local r = (a.first(cursor) - 1)
|
local r = (a.first(cursor) - 1)
|
||||||
local c = a.second(cursor)
|
local c = a.second(cursor)
|
||||||
local opts = {buf_uri, r, c}
|
local opts = {buf_uri, r, c}
|
||||||
local args = a.concat(opts, {...})
|
local args = a.concat(opts, {...})
|
||||||
return vim.lsp.buf.execute_command({command = cmd, arguments = args})
|
return client.request_sync("workspace/executeCommand", {command = cmd, arguments = args}, nil, 0)
|
||||||
end
|
end
|
||||||
vim.diagnostic.config({signs = {text = {[vim.diagnostic.severity.ERROR] = "\226\152\162\239\184\143", [vim.diagnostic.severity.WARN] = "\226\154\160\239\184\143", [vim.diagnostic.severity.INFO] = "\226\132\185\239\184\143", [vim.diagnostic.severity.HINT] = "\240\159\148\142"}}})
|
vim.diagnostic.config({signs = {text = {[vim.diagnostic.severity.ERROR] = "\226\152\162\239\184\143", [vim.diagnostic.severity.WARN] = "\226\154\160\239\184\143", [vim.diagnostic.severity.INFO] = "\226\132\185\239\184\143", [vim.diagnostic.severity.HINT] = "\240\159\148\142"}}})
|
||||||
local core_nmappings = {gd = "lua vim.lsp.buf.definition()", gD = "lua vim.lsp.buf.declaration()", gi = "lua vim.lsp.buf.implementation()", gr = "lua vim.lsp.buf.references()", K = "lua vim.lsp.buf.hover()", ["[g"] = "lua vim.diagnostic.goto_prev()", ["]g"] = "lua vim.diagnostic.goto_next()", ["<leader>ca"] = "lua vim.lsp.buf.code_action()", ["<leader>cl"] = "lua vim.lsp.codelens.run()", ["<leader>ic"] = "lua vim.lsp.buf.incoming_calls()", ["<leader>sld"] = "lua vim.diagnostic.open_float(nil, {source = 'always'})", ["<leader>rn"] = "lua vim.lsp.buf.rename()", ["<leader>fa"] = "lua vim.lsp.buf.format()"}
|
local core_nmappings = {gd = "lua vim.lsp.buf.definition()", gD = "lua vim.lsp.buf.declaration()", gi = "lua vim.lsp.buf.implementation()", gr = "lua vim.lsp.buf.references()", K = "lua vim.lsp.buf.hover()", ["[g"] = "lua vim.diagnostic.goto_prev()", ["]g"] = "lua vim.diagnostic.goto_next()", ["<leader>ca"] = "lua vim.lsp.buf.code_action()", ["<leader>cl"] = "lua vim.lsp.codelens.run()", ["<leader>ic"] = "lua vim.lsp.buf.incoming_calls()", ["<leader>sld"] = "lua vim.diagnostic.open_float(nil, {source = 'always'})", ["<leader>rn"] = "lua vim.lsp.buf.rename()", ["<leader>fa"] = "lua vim.lsp.buf.format()"}
|
||||||
local client_nmappings = {clojure_lsp = {["<leader>cn"] = "call LspExecuteCommand('clean-ns')", ["<leader>ref"] = "call LspExecuteCommand('extract-function', input('Function name: '))", ["<leader>id"] = "call LspExecuteCommand('inline-symbol')", ["<leader>il"] = "call LspExecuteCommand('introduce-let', input('Binding name: '))", ["<leader>m2l"] = "call LspExecuteCommand('move-to-let', input('Binding name: '))"}}
|
local client_nmappings = {clojure_lsp = {}}
|
||||||
local client_command_lnmappings = {clojure_lsp = {ai = {"add-import-to-namespace", {"input('Namespace name: ')"}}, am = {"add-missing-libspec", {}}, as = {"add-require-suggestion", {"input('Namespace name: ')", "input('Namespace as: ')", "input('Namespace name: ')"}}, cc = {"cycle-coll", {}}, cn = {"clean-ns", {}}, cp = {"cycle-privacy", {}}, ct = {"create-test", {}}, df = {"drag-forward", {}}, db = {"drag-backward", {}}, dk = {"destructure-keys", {}}, ed = {"extract-to-def", {"input('Definition name: ')"}}, ef = {"extract-function", {"input('Function name: ')"}}, el = {"expand-let", {}}, fe = {"create-function", {}}, il = {"introduce-let", {"input('Binding name: ')"}}, is = {"inline-symbol", {}}, ma = {"resolve-macro-as", {}}, mf = {"move-form", {"input('File name: ')"}}, ml = {"move-to-let", {"input('Binding name: ')"}}, pf = {"promote-fn", {"input('Function name: ')"}}, sc = {"change-collection", {"input('Collection type: ')"}}, sm = {"sort-map", {}}, tf = {"thread-first-all", {}}, tF = {"thread-first", {}}, tl = {"thread-last-all", {}}, tL = {"thread-last", {}}, ua = {"unwind-all", {}}, uw = {"unwind-thread", {}}}}
|
local client_command_lnmappings
|
||||||
|
local function _1_()
|
||||||
|
return vim.fn.input("Namespace name: ")
|
||||||
|
end
|
||||||
|
local function _2_()
|
||||||
|
return vim.fn.input("Namespace name: ")
|
||||||
|
end
|
||||||
|
local function _3_()
|
||||||
|
return vim.fn.input("Namespace as: ")
|
||||||
|
end
|
||||||
|
local function _4_()
|
||||||
|
return vim.fn.input("Namespace name: ")
|
||||||
|
end
|
||||||
|
local function _5_()
|
||||||
|
return vim.fn.input("Definition name: ")
|
||||||
|
end
|
||||||
|
local function _6_()
|
||||||
|
return vim.fn.input("Function name: ")
|
||||||
|
end
|
||||||
|
local function _7_()
|
||||||
|
return vim.fn.input("Binding name: ")
|
||||||
|
end
|
||||||
|
local function _8_()
|
||||||
|
return vim.fn.input("File name: ")
|
||||||
|
end
|
||||||
|
local function _9_()
|
||||||
|
return vim.fn.input("Binding name: ")
|
||||||
|
end
|
||||||
|
local function _10_()
|
||||||
|
return vim.fn.input("Function name: ")
|
||||||
|
end
|
||||||
|
local function _11_()
|
||||||
|
return vim.fn.input("")
|
||||||
|
end
|
||||||
|
client_command_lnmappings = {clojure_lsp = {ai = {"add-import-to-namespace", {_1_}}, am = {"add-missing-libspec", {}}, as = {"add-require-suggestion", {_2_, _3_, _4_}}, cc = {"cycle-coll", {}}, cn = {"clean-ns", {}}, cp = {"cycle-privacy", {}}, ct = {"create-test", {}}, df = {"drag-forward", {}}, db = {"drag-backward", {}}, dk = {"destructure-keys", {}}, ed = {"extract-to-def", {_5_}}, ref = {"extract-function", {_6_}}, el = {"expand-let", {}}, fe = {"create-function", {}}, il = {"introduce-let", {_7_}}, is = {"inline-symbol", {}}, ma = {"resolve-macro-as", {}}, mf = {"move-form", {_8_}}, ml = {"move-to-let", {_9_}}, pf = {"promote-fn", {_10_}}, sc = {"change-collection", {_11_, "input('Collection type: ')"}}, sm = {"sort-map", {}}, tf = {"thread-first-all", {}}, tF = {"thread-first", {}}, tl = {"thread-last-all", {}}, tL = {"thread-last", {}}, ua = {"unwind-all", {}}, uw = {"unwind-thread", {}}}}
|
||||||
local server_specific_opts = {}
|
local server_specific_opts = {}
|
||||||
local function bind_client_mappings(client)
|
local function bind_client_mappings(client)
|
||||||
local client_name = a.get(client, "name")
|
local client_name = a.get(client, "name")
|
||||||
@@ -33,28 +67,34 @@ local function bind_client_mappings(client)
|
|||||||
local command_lnmappings = a.get(client_command_lnmappings, client_name)
|
local command_lnmappings = a.get(client_command_lnmappings, client_name)
|
||||||
if mappings then
|
if mappings then
|
||||||
for mapping, cmd in pairs(mappings) do
|
for mapping, cmd in pairs(mappings) do
|
||||||
nbufmap(mapping, cmd)
|
nbufmap(mapping, cmd, {})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
end
|
end
|
||||||
if command_lnmappings then
|
if command_lnmappings then
|
||||||
for lnmapping, command_mapping in pairs(command_lnmappings) do
|
for lnmapping, command_mapping in pairs(command_lnmappings) do
|
||||||
local lsp_cmd = a.first(command_mapping)
|
local lsp_cmd = a.first(command_mapping)
|
||||||
local opts_str
|
|
||||||
do
|
|
||||||
local s = ""
|
|
||||||
for i, opt in ipairs(a.second(command_mapping)) do
|
|
||||||
s = (s .. ", " .. opt)
|
|
||||||
end
|
|
||||||
opts_str = s
|
|
||||||
end
|
|
||||||
local mapping = ("<leader>" .. lnmapping)
|
local mapping = ("<leader>" .. lnmapping)
|
||||||
local cmd
|
local cmd
|
||||||
local function _2_()
|
local function _13_()
|
||||||
return lsp_execute_command(lsp_cmd, opts_str)
|
local opts
|
||||||
|
do
|
||||||
|
local s = ""
|
||||||
|
for _i, opt in ipairs(a.second(command_mapping)) do
|
||||||
|
local _14_
|
||||||
|
if ("function" == type(opt)) then
|
||||||
|
_14_ = opt()
|
||||||
|
else
|
||||||
|
_14_ = opt
|
||||||
end
|
end
|
||||||
cmd = _2_
|
s = (s .. _14_)
|
||||||
nbufmap(mapping, cmd)
|
end
|
||||||
|
opts = s
|
||||||
|
end
|
||||||
|
return lsp_execute_command(client, lsp_cmd, opts)
|
||||||
|
end
|
||||||
|
cmd = _13_
|
||||||
|
nbufmap(mapping, cmd, {desc = ("LSP command `" .. lsp_cmd .. "`")})
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
else
|
else
|
||||||
@@ -63,9 +103,9 @@ local function bind_client_mappings(client)
|
|||||||
end
|
end
|
||||||
local function on_attach(client, bufnr)
|
local function on_attach(client, bufnr)
|
||||||
for mapping, cmd in pairs(core_nmappings) do
|
for mapping, cmd in pairs(core_nmappings) do
|
||||||
nbufmap(mapping, cmd)
|
nbufmap(mapping, cmd, {})
|
||||||
end
|
end
|
||||||
xbufmap("<leader>fa", "lua vim.lsp.buf.format()")
|
xbufmap("<leader>fa", "lua vim.lsp.buf.format()", {desc = "Format buffer"})
|
||||||
vim.api.nvim_set_option_value("omnifunc", "v:lua.vim.lsp.omnifunc", {buf = 0})
|
vim.api.nvim_set_option_value("omnifunc", "v:lua.vim.lsp.omnifunc", {buf = 0})
|
||||||
bind_client_mappings(client)
|
bind_client_mappings(client)
|
||||||
if client.server_capabilities.documentHighlightProvider then
|
if client.server_capabilities.documentHighlightProvider then
|
||||||
@@ -73,21 +113,21 @@ local function on_attach(client, bufnr)
|
|||||||
vim.api.nvim_set_hl(0, hlgroup, a.merge(vim.api.nvim_get_hl_by_name(base_group, true), {italic = true, foreground = "#6c71c4", background = "NONE"}))
|
vim.api.nvim_set_hl(0, hlgroup, a.merge(vim.api.nvim_get_hl_by_name(base_group, true), {italic = true, foreground = "#6c71c4", background = "NONE"}))
|
||||||
end
|
end
|
||||||
local group = vim.api.nvim_create_augroup("LspDocumentHighlight", {clear = true})
|
local group = vim.api.nvim_create_augroup("LspDocumentHighlight", {clear = true})
|
||||||
local function _4_()
|
local function _17_()
|
||||||
return vim.lsp.buf.document_highlight()
|
return vim.lsp.buf.document_highlight()
|
||||||
end
|
end
|
||||||
vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI"}, {group = group, pattern = "<buffer>", callback = _4_})
|
vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI"}, {group = group, pattern = "<buffer>", callback = _17_})
|
||||||
local function _5_()
|
local function _18_()
|
||||||
return vim.lsp.buf.clear_references()
|
return vim.lsp.buf.clear_references()
|
||||||
end
|
end
|
||||||
vim.api.nvim_create_autocmd({"CursorMoved"}, {group = group, pattern = "<buffer>", callback = _5_})
|
vim.api.nvim_create_autocmd({"CursorMoved"}, {group = group, pattern = "<buffer>", callback = _18_})
|
||||||
else
|
else
|
||||||
end
|
end
|
||||||
if client.server_capabilities.documentFormattingProvider then
|
if client.server_capabilities.documentFormattingProvider then
|
||||||
local function _7_()
|
local function _20_()
|
||||||
return vim.lsp.buf.format()
|
return vim.lsp.buf.format()
|
||||||
end
|
end
|
||||||
vim.api.nvim_create_autocmd({"BufWritePre"}, {pattern = "<buffer>", callback = _7_})
|
vim.api.nvim_create_autocmd({"BufWritePre"}, {pattern = "<buffer>", callback = _20_})
|
||||||
else
|
else
|
||||||
end
|
end
|
||||||
return print("LSP Client Attached.")
|
return print("LSP Client Attached.")
|
||||||
|
|||||||
@@ -4,15 +4,17 @@ local function fn_3f(x)
|
|||||||
return ("function" == type(x))
|
return ("function" == type(x))
|
||||||
end
|
end
|
||||||
local function noremap(mode, from, to, opts)
|
local function noremap(mode, from, to, opts)
|
||||||
local map_opts = {noremap = true, silent = true}
|
local local_3f = a.get(opts, "local?")
|
||||||
|
local opts0 = a.assoc(opts, "local?", nil)
|
||||||
|
local map_opts = a.merge(opts0, {noremap = true, silent = true})
|
||||||
local to0
|
local to0
|
||||||
if fn_3f(to) then
|
if fn_3f(to) then
|
||||||
to0 = to
|
to0 = to
|
||||||
else
|
else
|
||||||
to0 = (":" .. to .. "<cr>")
|
to0 = (":" .. to .. "<cr>")
|
||||||
end
|
end
|
||||||
local buff_num = a.get(opts, "buff-num")
|
local buff_num = a.get(opts0, "buff-num")
|
||||||
if (a.get(opts, "local?") or buff_num) then
|
if (local_3f or buff_num) then
|
||||||
return vim.keymap.set(mode, from, to0, a.merge(map_opts, {buffer = (buff_num or 0)}))
|
return vim.keymap.set(mode, from, to0, a.merge(map_opts, {buffer = (buff_num or 0)}))
|
||||||
else
|
else
|
||||||
return vim.keymap.set(mode, from, to0, map_opts)
|
return vim.keymap.set(mode, from, to0, map_opts)
|
||||||
@@ -30,8 +32,8 @@ end
|
|||||||
local function vnoremap(from, to, opts)
|
local function vnoremap(from, to, opts)
|
||||||
return noremap("v", from, to, opts)
|
return noremap("v", from, to, opts)
|
||||||
end
|
end
|
||||||
local function lnnoremap(from, to)
|
local function lnnoremap(from, to, opts)
|
||||||
return nnoremap(("<leader>" .. from), to)
|
return nnoremap(("<leader>" .. from), to, opts)
|
||||||
end
|
end
|
||||||
local function ltnoremap(from, to, opts)
|
local function ltnoremap(from, to, opts)
|
||||||
return noremap("v", ("<leader>" .. from), to, opts)
|
return noremap("v", ("<leader>" .. from), to, opts)
|
||||||
|
|||||||
Reference in New Issue
Block a user