Browse Source

Add some more coc plugins, configure them

master
Adam Pippin 2 years ago
parent
commit
d2e1e9c439
  1. 4
      coc-settings.json
  2. 5
      lua/config/_keymap.lua
  3. 76
      lua/config/plugins/development.lua
  4. 8
      lua/module/keymap.lua
  5. 45
      lua/plugin/neoclide/coc-nvim.lua

4
coc-settings.json

@ -1,4 +0,0 @@
{
"html.autoClosingTags": false,
"html.autoCreateQuotes": false
}

5
lua/config/_keymap.lua

@ -2,7 +2,7 @@
-- If a keymap is tied to a specific plugin, it should generally be specified
-- in the plugins file attached to that plugin.
--
-- When making a binding, group, etc, the key to bind to shoudl be specified
-- When making a binding, group, etc, the key to bind to should be specified
-- as an array. However, as long as _each character_ represents a single keypress
-- the key can be specified as a string. E.g., `key = 'jj'` and `key = { 'j', 'j' }`
-- are equivalent. However, `key = { '<A-h>' }` would be parsed as
@ -28,6 +28,9 @@ return {
-- { mode = 'n', key = { '<F5>' }, map = ':call SynStack()<CR>', label = 'show syntax token' },
{ mode = 'n', key = { '<F49>' }, map = ':lua nukevim:help()<CR>', label = 'help' },
-- Bind backspace to Ctrl+^ to go to previous buffer
{ mode = 'n', key = { '<BS>' }, map = ':b#<CR>', label = 'previous buffer' },
-- Provide labels for the main leader groups
{ mode = 'n', key = { '<leader>', 'c' }, group = true, label = 'code' },
{ mode = 'n', key = { '<leader>', 'd' }, group = true, label = 'dev tools' },

76
lua/config/plugins/development.lua

@ -47,6 +47,36 @@ return {
--------------------------------------------------------------------------------
-- Things that provide code insights and completion.
----------------------------------------------------------------------------
-- Code completion provider
--
-- Provides completions for a bunch of stuff, integrated with the LSP.
--
----------------------------------------------------------------------------
-- Code completion provider
--
-- Provides completions for a bunch of stuff, integrated with the LSP.
--
{
enable = false,
name = 'ms-jpq/coq_nvim',
opts = {
branch = 'coq',
['do'] = 'python3 -m coq deps'
},
config = {
auto_start = 'shut-up',
clients = {
tags = { enabled = false },
snippets = { enabled = false },
tree_sitter = { enabled = false },
buffers = { enabled = false },
tmux = { enabled = false },
}
}
},
----------------------------------------------------------------------------
-- Code completion provider
--
@ -54,6 +84,7 @@ return {
-- the coc package.json
--
{
enable = true,
name = 'neoclide/coc.nvim',
opts = {
-- Only enable if npm is installed
@ -62,18 +93,45 @@ return {
},
config = {
extensions = {
'coc-css',
'coc-html',
'coc-json',
'coc-markdownlint',
'coc-marketplace',
'coc-phpls',
'coc-sql',
'coc-yaml'
['coc-blade'] = {
-- TODO: Figure out if there's some way we can set formatting
-- options globally?
},
-- ['coc-calc'] = { },
['coc-css'] = { },
['coc-cfn-lint'] = { },
['coc-dotenv'] = { },
['coc-highlight'] = { },
['coc-html'] = {
['html.autoClosingTags'] = false,
['html.autoCreateQuotes'] = false
},
['@yaegassy/coc-intelephense'] = {
-- ['codeLens.enable'] = true
},
['coc-json'] = { },
['coc-markdownlint'] = { },
['coc-markdown-preview-enhanced'] = { },
['coc-marketplace'] = { },
-- ['coc-phpls'] = {
-- ['intelephense.licenceKey'] = nil,
-- },
['coc-spell-checker'] = { },
['coc-sql'] = { },
['coc-swagger'] = { },
['coc-tsserver'] = { },
['coc-webpack'] = { },
['coc-webview'] = { },
['coc-yaml'] = { },
['@yaegassy/coc-tailwindcss3'] = { },
}
},
keys = {
{ mode = 'n', key = { '<leader>', 'c', 'r' }, map = ":call CocAction('jumpReferences')<CR>", label = "references" },
{ mode = 'n', key = { '<leader>', 'c', 'a' }, map = "<Plug>(coc-codeaction-line)", label = "action" },
{ mode = 'n', key = { '<leader>', 'c', 'f' }, map = ":call CocAction('jumpReferences')<CR>", label = "find references" },
{ mode = 'n', key = { '<leader>', 'c', 'r' }, map = ":call CocAction('refactor')<CR>", label = "rename" },
{ mode = 'n', key = { '<leader>', 'c', 'd' }, map = ":call CocAction('jumpDefinition')<CR>", label = "go to definition" },
{ filetype = 'markdown', mode = 'n', key = { '<leader>', 'l', 'p' }, map = ':CocCommand markdown-preview-enhanced.openPreview<CR>', label = "preview" },
}
},

8
lua/module/keymap.lua

@ -85,7 +85,7 @@ function M:map(mode, key, map, options)
mode = mode,
key = key,
map = map,
options = options or { noremap = true }
options = options or { noremap = (not map:lower():find('<plug>')) }
})
end
@ -101,7 +101,11 @@ function M:add(keymap)
keymap.key = parts
end
keymap.map = keymap.map or nil
keymap.options = keymap.options or { noremap = true }
if (keymap.map == nil) then
keymap.options = keymap.options or { noremap = true }
else
keymap.options = keymap.options or { noremap = (not keymap.map:lower():find('<plug>')) }
end
keymap.label = keymap.label or nil
keymap.virtual = keymap.virtual or false
keymap.hidden = keymap.hidden or false

45
lua/plugin/neoclide/coc-nvim.lua

@ -1,18 +1,53 @@
local M = require('module'):new()
function M:boot()
extensions = { }
for extension, config in pairs(self.config.extensions) do
table.insert(extensions, extension)
end
vim.g.coc_global_extensions = extensions
opts = {}
for extension, config in pairs(self.config.extensions) do
for key,value in pairs(config) do
components = {}
for str in key:gmatch('([^.]+)') do
table.insert(components, str)
end
key = components[#components]
table.remove(components, #components)
namespace = table.concat(components, '.')
if (opts[namespace] == nil) then
opts[namespace] = {}
end
opts[namespace][key] = value
end
end
for namespace,config in pairs(opts) do
vim.fn['coc#config'](namespace, config)
end
end
function M:run()
-- if you leave the cursor on a variable/etc for a moment, this will cause
-- all other occurrences to be subtly highlighted.
vim.api.nvim_create_autocmd('CursorHold', {
pattern = { '*' },
command = "silent call CocActionAsync('highlight')"
})
end
function M:install()
if (self.config.extensions == nil) then return end
exts = table.concat(self.config.extensions, ' ')
vim.cmd(':CocInstall -sync '..exts)
-- enable tailwindcss completion in blade files
-- TODO: Figure out a better way to enable tailwind in blade.
-- Currently this only works when opening in an existing instance, not when
-- starting vim with a blade file.
-- Also maybe the tailwindCSS.includeLanguages option should do this?
vim.api.nvim_create_autocmd('FileType', {
pattern = { 'blade' },
command = 'silent CocCommand tailwindCSS.forceActivate'
})
end
return M

Loading…
Cancel
Save