Last active
August 12, 2024 19:38
-
-
Save pwang2/075c027cc334550046b75cc58ba44fb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('mason-lspconfig').setup { | |
ensure_installed = { | |
'lua_ls', | |
'vimls', | |
-- 'yamlls', | |
'azure_pipelines_ls', | |
'volar', | |
'pyright', | |
'bashls', | |
'tsserver', | |
'bicep', | |
'rust_analyzer', | |
}, | |
} | |
local lspconfig = require('lspconfig') | |
local lspConfigUtil = require 'lspconfig.util' | |
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview | |
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) | |
opts = opts or {} | |
-- opts.border = opts.border or 'single' | |
opts.border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" } | |
opts.max_width = opts.max_width or 80 | |
return orig_util_open_floating_preview(contents, syntax, opts, ...) | |
end | |
local on_attach = function(_, bufnr) | |
local bkm = vim.api.nvim_buf_set_keymap | |
local km = vim.api.nvim_set_keymap | |
local kb_opts = { noremap = true, silent = true } | |
local mkmp = function(key, cmd) | |
vim.lsp.util.make_floating_popup_options(80, 20) | |
bkm(bufnr, 'n', key, '<cmd>lua vim.lsp.buf.' .. cmd .. '()<CR>', kb_opts) | |
end | |
mkmp('gD', 'declaration') | |
mkmp('gd', 'definition') | |
mkmp('K', 'hover') | |
mkmp('gi', 'implementation') | |
mkmp('<space>k', 'signature_help') | |
mkmp('<space>D', 'type_definition') | |
mkmp('<space>rn', 'rename') | |
mkmp('<space>ca', 'code_action') | |
-- mkmp('<space>f', 'formatting') -- use Neoformat | |
-- mkmp('gr', 'references') -- use trouble gr | |
km('n', '<space>e', '<cmd>lua vim.diagnostic.open_float({width = 80})<CR>', kb_opts) | |
km('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', kb_opts) | |
km('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', kb_opts) | |
km('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', kb_opts) | |
km('n', 'gv', '<cmd>:vsplit | lua vim.lsp.buf.definition()<CR>', kb_opts) | |
end | |
local capabilities = require 'cmp_nvim_lsp'.default_capabilities(vim.lsp.protocol.make_client_capabilities()) | |
lspConfigUtil.default_config = vim.tbl_extend('force', lspConfigUtil.default_config, { | |
on_attach = on_attach, | |
capabilities = capabilities, | |
}) | |
lspconfig.bicep.setup {} | |
lspconfig.rust_analyzer.setup {} | |
-- lspconfig.r_language_server.setup { | |
-- cmd = { 'R', '--slave', '-e', 'languageserver::run()' }, | |
-- } | |
lspconfig.lua_ls.setup { | |
settings = { Lua = { diagnostics = { globals = { 'vim', 'hs', 'spoon' } } } }, | |
} | |
lspconfig.tsserver.setup {} | |
-- @vue/typescript-plugin is used | |
lspconfig.volar.setup { | |
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json' }, | |
on_attach = on_attach, | |
capabilities = capabilities, | |
init_options = { | |
vue = { | |
hybridMode = false | |
}, | |
plugins = { | |
{ | |
name = "@vue/typescript-plugin", | |
location = "~/.nvm/versions/node/v18.20.3/lib/node_modules/@vue/typescript-plugin", | |
languages = { "javascript", "typescript", "vue" }, | |
} | |
} | |
} | |
} | |
-- lspconfig.omnisharp.setup { | |
-- handlers = { | |
-- ["textDocument/definition"] = require('omnisharp_extended').handler, | |
-- } | |
-- } | |
--Enable (broadcasting) snippet capability for completion | |
local c = vim.lsp.protocol.make_client_capabilities() | |
c.textDocument.completion.completionItem.snippetSupport = true | |
--Enable (broadcasting) snippet capability for completion | |
-- | |
-- lspconfig.cssls.setup { | |
-- filetypes = { "css", "scss", "less", "vue" }, | |
-- single_file_support = false, | |
-- capabilities = c | |
-- } | |
lspconfig.vimls.setup {} | |
lspconfig.tailwindcss.setup { | |
filetypes = { 'vue', 'html', 'css', 'javascript', 'typescript' }, | |
} | |
lspconfig.gopls.setup {} | |
lspconfig.pyright.setup {} | |
lspconfig.bashls.setup {} | |
-- lspconfig.sourcery.setup {} | |
-- lspconfig.yamlls.setup {} | |
lspconfig.azure_pipelines_ls.setup { | |
settings = { | |
yaml = { | |
schemas = { | |
["https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/master/service-schema.json"] = { | |
"/azure-pipeline*.y*l", | |
"/*.azure*", | |
"Azure-Pipelines/**/*.y*l", | |
"Pipelines/*.y*l", | |
}, | |
}, | |
}, | |
}, | |
} | |
--GistID: 075c027cc334550046b75cc58ba44fb9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment