浏览代码

[Feature] Make common_on_attach configurable (#1024)

kylo252 4 年之前
父节点
当前提交
840e07c7fc
共有 5 个文件被更改,包括 40 次插入3 次删除
  1. 10 0
      README.md
  2. 1 0
      lua/default-config.lua
  3. 7 3
      lua/lsp/init.lua
  4. 11 0
      utils/installer/lv-config.example-no-ts.lua
  5. 11 0
      utils/installer/lv-config.example.lua

+ 10 - 0
README.md

@@ -108,6 +108,16 @@ O.treesitter.ensure_installed = "all"
 O.treesitter.ignore_install = {"haskell"}
 O.treesitter.ignore_install = {"haskell"}
 O.treesitter.highlight.enabled = true
 O.treesitter.highlight.enabled = true
 
 
+-- you can set a custom on_attach function that will be used for all the language servers
+-- See <https://github.com/neovim/nvim-lspconfig#keybindings-and-completion>
+-- O.lsp.on_attach_callback = function(client, bufnr)
+--   local function buf_set_option(...)
+--     vim.api.nvim_buf_set_option(bufnr, ...)
+--   end
+--   --Enable completion triggered by <c-x><c-o>
+--   buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
+-- end
+
 -- lua
 -- lua
 O.lang.lua.autoformat = false
 O.lang.lua.autoformat = false
 O.lang.lua.formatter = 'lua-format'
 O.lang.lua.formatter = 'lua-format'

+ 1 - 0
lua/default-config.lua

@@ -73,6 +73,7 @@ O = {
     document_highlight = true,
     document_highlight = true,
     popup_border = "single",
     popup_border = "single",
     default_keybinds = true,
     default_keybinds = true,
+    on_attach_callback = nil,
   },
   },
 
 
   disabled_built_ins = {
   disabled_built_ins = {

+ 7 - 3
lua/lsp/init.lua

@@ -111,7 +111,10 @@ autocmd BufWritePre *.lua lua vim.lsp.buf.formatting_sync(nil, 100) ]]
 -- Java
 -- Java
 -- autocmd FileType java nnoremap ca <Cmd>lua require('jdtls').code_action()<CR>
 -- autocmd FileType java nnoremap ca <Cmd>lua require('jdtls').code_action()<CR>
 
 
-local function documentHighlight(client, _)
+local function lsp_highlight_document(client)
+  if O.lsp.document_highlight == false then
+    return -- we don't need further
+  end
   -- Set autocommands conditional on server_capabilities
   -- Set autocommands conditional on server_capabilities
   if client.resolved_capabilities.document_highlight then
   if client.resolved_capabilities.document_highlight then
     vim.api.nvim_exec(
     vim.api.nvim_exec(
@@ -197,9 +200,10 @@ function lsp_config.PeekImplementation()
 end
 end
 
 
 function lsp_config.common_on_attach(client, bufnr)
 function lsp_config.common_on_attach(client, bufnr)
-  if O.lsp.document_highlight then
-    documentHighlight(client, bufnr)
+  if O.lsp.on_attach_callback then
+    O.lsp.on_attach_callback(client, bufnr)
   end
   end
+  lsp_highlight_document(client)
 end
 end
 
 
 function lsp_config.tsserver_on_attach(client, _)
 function lsp_config.tsserver_on_attach(client, _)

+ 11 - 0
utils/installer/lv-config.example-no-ts.lua

@@ -50,6 +50,17 @@ O.treesitter.ensure_installed = {}
 O.treesitter.ignore_install = { "haskell" }
 O.treesitter.ignore_install = { "haskell" }
 O.treesitter.highlight.enabled = true
 O.treesitter.highlight.enabled = true
 
 
+-- generic LSP settings
+-- you can set a custom on_attach function that will be used for all the language servers
+-- See <https://github.com/neovim/nvim-lspconfig#keybindings-and-completion>
+-- O.lsp.on_attach_callback = function(client, bufnr)
+--   local function buf_set_option(...)
+--     vim.api.nvim_buf_set_option(bufnr, ...)
+--   end
+--   --Enable completion triggered by <c-x><c-o>
+--   buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
+-- end
+
 -- python
 -- python
 O.lang.python.diagnostics.virtual_text = true
 O.lang.python.diagnostics.virtual_text = true
 O.lang.python.analysis.use_library_code_types = true
 O.lang.python.analysis.use_library_code_types = true

+ 11 - 0
utils/installer/lv-config.example.lua

@@ -50,6 +50,17 @@ O.treesitter.ensure_installed = "maintained"
 O.treesitter.ignore_install = { "haskell" }
 O.treesitter.ignore_install = { "haskell" }
 O.treesitter.highlight.enabled = true
 O.treesitter.highlight.enabled = true
 
 
+-- generic LSP settings
+-- you can set a custom on_attach function that will be used for all the language servers
+-- See <https://github.com/neovim/nvim-lspconfig#keybindings-and-completion>
+-- O.lsp.on_attach_callback = function(client, bufnr)
+--   local function buf_set_option(...)
+--     vim.api.nvim_buf_set_option(bufnr, ...)
+--   end
+--   --Enable completion triggered by <c-x><c-o>
+--   buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
+-- end
+
 -- python
 -- python
 O.lang.python.diagnostics.virtual_text = true
 O.lang.python.diagnostics.virtual_text = true
 O.lang.python.analysis.use_library_code_types = true
 O.lang.python.analysis.use_library_code_types = true