Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------------------------------------------------------
- ---------------------------------------------------------------------------------------
- --[[
- __ __ _ __
- / / ____ _________ _/ / | | / /___ ___________
- / / / __ \/ ___/ __ `/ / | | / / __ `/ ___/ ___/
- / /___/ /_/ / /__/ /_/ / / | |/ / /_/ / / (__ )
- /_____/\____/\___/\__,_/_/ |___/\__,_/_/ /____/
- --]]
- local lsp = require('lspconfig')
- local completion = require('completion') --> CAN US BUILT IN OMNIFUNC BUT WE USE THIS FOR NOW
- local api = vim.api
- local configs = require('lspconfig/configs')
- local util = require 'lspconfig/util'
- local cwd = vim.loop.cwd
- local lsp_status = require('lsp-status') --> LSP progress, errors etc in your statusline
- --ERROR HANDLING INSPO --> https://raw.githubusercontent.com/nymann/dotfiles/master/dots/nvim/lua/lsp.lua
- --local has_lsp, lspconfig = pcall(require, 'lspconfig')
- --local has_completion, completion = pcall(require, 'completion')
- --local has_diagnostic, diagnostic = pcall(require, 'diagnostic')
- --if not has_lsp then
- --return
- --end
- --Configure the exclusion pattterns
- local exclude_patterns = {
- '**/node_modules/**/*',
- '**/bin/**/*',
- '**/obj/**/*',
- '/tmp/**/*'
- }
- ---------------------------------------------------------------------------------------
- ---------------------------------------------------------------------------------------
- --[[
- ______ __ __ _ ____ __ _
- / ____/___ ____ ___ ____ / /__ / /_(_)___ ____ / __ \____ / /_(_)___ ____ _____
- / / / __ \/ __ `__ \/ __ \/ / _ \/ __/ / __ \/ __ \ / / / / __ \/ __/ / __ \/ __ \/ ___/
- / /___/ /_/ / / / / / / /_/ / / __/ /_/ / /_/ / / / / / /_/ / /_/ / /_/ / /_/ / / / (__ )
- \____/\____/_/ /_/ /_/ .___/_/\___/\__/_/\____/_/ /_/ \____/ .___/\__/_/\____/_/ /_/____/
- /_/ /_/
- --]]
- --" Set completeopt to have a better completion experience
- api.nvim_command('set completeopt=longest,menuone,noinsert,noselect')
- --" Use <Tab> and <S-Tab> to navigate through popup menu
- api.nvim_command('inoremap <expr> <Tab> pumvisible() ? "<C-n>" : "<Tab>"')
- api.nvim_command('inoremap <expr> <S-Tab> pumvisible() ? "<C-p>" : "<S-Tab>"')
- --" Avoid showing message extra message when using completion
- api.nvim_command('set shortmess+=c')
- --api.nvim_command('')
- ---------------------------------------------------------------------------------------
- ---------------------------------------------------------------------------------------
- --[[
- __ __ __ ______ __ _
- / / / /__ / /___ ___ _____ / ____/_ ______ _____/ /_(_)___ ____ _____
- / /_/ / _ \/ / __ \/ _ \/ ___/ / /_ / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
- / __ / __/ / /_/ / __/ / / __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__ )
- /_/ /_/\___/_/ .___/\___/_/ /_/ \__,_/_/ /_/\___/\__/_/\____/_/ /_/____/
- /_/
- --]]
- --A custom mapper function to make mapping our lsp functions to vim key sequences less verbose
- local mapper = function(mode, key, result)
- api.nvim_buf_set_keymap(0, mode, key, "<cmd>lua "..result.."<cr>", {noremap = true, silent = true})
- end
- -- stolen from https://github.com/fsouza/vimfiles
- local get_python_tool = function(bin_name)
- local result = bin_name
- if os.getenv('VIRTUAL_ENV') then
- local venv_bin_name = os.getenv('VIRTUAL_ENV') .. '/bin/' .. bin_name
- if vim.fn.executable(venv_bin_name) == 1 then
- result = venv_bin_name
- end
- end
- return result
- end
- ---------------------------------------------------------------------------------------
- ---------------------------------------------------------------------------------------
- --[[
- __ _____ ____ __________ _ _______________________
- / / / ___// __ \ / ____/ __ \/ | / / ____/ _/ ____/ ___/
- / / \__ \/ /_/ / / / / / / / |/ / /_ / // / __ \__ \
- / /______/ / ____/ / /___/ /_/ / /| / __/ _/ // /_/ /___/ /
- /_____/____/_/ \____/\____/_/ |_/_/ /___/\____//____/
- --]]
- -- async formatting
- -- https://www.reddit.com/r/neovim/comments/jvisg5/lets_talk_formatting_again/
- vim.lsp.handlers["textDocument/formatting"] = function(err, _, result, _, bufnr)
- if err ~= nil or result == nil then
- return
- end
- if not vim.api.nvim_buf_get_option(bufnr, "modified") then
- local view = vim.fn.winsaveview()
- vim.lsp.util.apply_text_edits(result, bufnr)
- vim.fn.winrestview(view)
- vim.api.nvim_command("noautocmd :update")
- end
- end
- -- Diagnostics
- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
- vim.lsp.diagnostic.on_publish_diagnostics, {
- underline = false,
- virtual_text = true,
- signs = true,
- update_in_insert = false,
- }
- )
- -- Statusline
- --lsp_status.config({
- --kind_labels = vim.g.completion_customize_lsp_label
- --})
- lsp_status.register_progress()
- ---------------------------------------------------------------------------------------
- ---------------------------------------------------------------------------------------
- --[[
- ___ __ __ __ ______ __ _
- / | / /_/ /_____ ______/ /_ / ____/_ ______ _____/ /_(_)___ ____
- / /| |/ __/ __/ __ `/ ___/ __ \ / /_ / / / / __ \/ ___/ __/ / __ \/ __ \
- / ___ / /_/ /_/ /_/ / /__/ / / / / __/ / /_/ / / / / /__/ /_/ / /_/ / / / /
- /_/ |_\__/\__/\__,_/\___/_/ /_/ /_/ \__,_/_/ /_/\___/\__/_/\____/_/ /_/
- --]]
- --When our LSP starts, this is what happens. Completion enabled, set some mappings, print lsp starting message
- local custom_attach = function(client,bufnr) --> Added client,bufnr works also without, inspo from https://github.com/kuator/nvim/blob/master/lua/plugins/lsp.lua
- --ERROR HANDLING INSPO
- --if has_status then
- --lsp_status.on_attach(client)
- --end
- --if has_diagnostic then
- --diagnostic.on_attach()
- --end
- --if has_completion then
- --completion.on_attach({
- --sorter = 'alphabet',
- --matcher = {'exact', 'fuzzy'}
- --})
- --end
- completion.on_attach(client,bufnr)
- lsp_status.on_attach(client) --> REQUIRED for lsp statusbar
- --vim.lsp.set_log_level('debug') ENABLE LOGGING
- -- Move cursor to the next and previous diagnostic
- mapper('n', '<leader>dn', 'vim.lsp.diagnostic.goto_next()')
- mapper('n', '<leader>dp', 'vim.lsp.diagnostic.goto_prev()')
- -- Keybindings for LSPs
- -- Close quickfix with :cclose
- mapper('n', 'gd', 'vim.lsp.buf.definition()')
- mapper('n', 'gh', 'vim.lsp.buf.hover()')
- mapper('n', 'gD', 'vim.lsp.buf.implementation()')
- mapper('n', '<c-k>', 'vim.lsp.buf.signature_help()')
- mapper('n', '1gD', 'vim.lsp.buf.type_definition()')
- mapper('n', 'gr', 'vim.lsp.buf.references()')
- mapper('n', 'g0', 'vim.lsp.buf.document_symbol()')
- mapper('n', 'gW', 'vim.lsp.buf.workspace_symbol()')
- print("LSP Started.. Let's get this bread homie")
- --vim.fn.nvim_set_keymap("n", "<leader>ge", "<cmd>lua vim.lsp.buf.declaration()<CR>", {noremap = true, silent = true})
- --vim.fn.nvim_set_keymap("n", "<leader>gh", "<cmd>lua vim.lsp.buf.hover()<CR>", {noremap = true, silent = true})
- --vim.fn.nvim_set_keymap("n", "<leader>gf", "<cmd>lua vim.lsp.buf.formatting()<CR>", {noremap = true, silent = true})
- --vim.fn.nvim_set_keymap("n", "<leader>gy", "<cmd>lua vim.lsp.buf.type_definition()<CR>", {noremap = true, silent = true})
- --vim.fn.nvim_set_keymap("n", "<leader>gr", "<cmd>lua vim.lsp.buf.references()<CR>", {noremap = true, silent = true})
- --vim.fn.nvim_set_keymap("n", "<leader>gt", "<cmd>lua vim.lsp.buf.document_symbol()<CR>", {noremap = true, silent = true})
- --vim.fn.nvim_set_keymap("n", "<leader>gw", "<cmd>lua vim.lsp.buf.workspace_symbol()<CR>", {noremap = true, silent = true})
- --vim.fn.nvim_set_keymap("n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", {noremap = true, silent = true})
- --vim.fn.nvim_set_keymap("n", "<a-.>", "<cmd>lua vim.lsp.buf.code_action()<CR>", {noremap = true, silent = true})
- --vim.api.nvim_command('setlocal omnifunc=v:lua.vim.lsp.omnifunc')
- end
- ---------------------------------------------------------------------------------------
- ---------------------------------------------------------------------------------------
- --[[
- __ ______ _____
- / / ____ _____ ____ ___ ______ _____ ____ / ____/___ ____ / __(_)___ ______
- / / / __ `/ __ \/ __ `/ / / / __ `/ __ `/ _ \ / / / __ \/ __ \/ /_/ / __ `/ ___/
- / /___/ /_/ / / / / /_/ / /_/ / /_/ / /_/ / __/ / /___/ /_/ / / / / __/ / /_/ (__ )
- /_____/\__,_/_/ /_/\__, /\__,_/\__,_/\__, /\___/ \____/\____/_/ /_/_/ /_/\__, /____/
- /____/ /____/ /____/
- --]]
- --NOTE: The rest of this file deals with language specific configurations
- ---------------------------------------------------------------------------------------
- ---------------------------------------------------------------------------------------
- --[[
- _ ___ _ __
- | | / (_)___ ___ _______________(_)___ / /_
- | | / / / __ `__ \/ ___/ ___/ ___/ / __ \/ __/
- | |/ / / / / / / (__ ) /__/ / / / /_/ / /_
- |___/_/_/ /_/ /_/____/\___/_/ /_/ .___/\__/
- /_/
- --]]
- lsp.vimls.setup {on_attach = custom_attach, root_dir = cwd}
- ---------------------------------------------------------------------------------------
- --[[
- ____ __ __
- / __ \__ __/ /_/ /_ ____ ____
- / /_/ / / / / __/ __ \/ __ \/ __ \
- / ____/ /_/ / /_/ / / / /_/ / / / /
- /_/ \__, /\__/_/ /_/\____/_/ /_/
- /____/
- --]]
- lsp.pyls.setup{
- on_attach = custom_attach
- }
- ---------------------------------------------------------------------------------------
- --[[
- ______ _ __
- /_ __/_ ______ ___ _______________(_)___ / /_
- / / / / / / __ \/ _ \/ ___/ ___/ ___/ / __ \/ __/
- / / / /_/ / /_/ / __(__ ) /__/ / / / /_/ / /_
- /_/ \__, / .___/\___/____/\___/_/ /_/ .___/\__/
- /____/_/ /_/
- --]]
- lsp.tsserver.setup {on_attach = custom_attach,
- root_dir = function(fname)
- return util.find_git_ancestor(fname) or
- util.path.dirname(fname)
- end,
- }
- --root_dir = util.root_pattern('package.json', 'tsconfig.json', '.git') or cwd
- --root_dir = vim.loop.cwd --Sets global cwd
- --root_dir = function() --NOT WORKING: RETURNS FUNCTION NAME NOT THE DATA
- --return cwd
- --end,
- --root_dir = util.root_pattern('package.json', 'tsconfig.json', '.git') or cwd
- --local util = require 'lspconfig/util'
- --local cwd = vim.loop.cwd
- --SetTsServerCWD = function()
- --return util.root_pattern('package.json', 'tsconfig.json', '.git') or cwd
- --end
- ---------------------------------------------------------------------------------------
- --[[
- __
- / /___ __ ______ _
- __ / / __ `/ | / / __ `/
- / /_/ / /_/ /| |/ / /_/ /
- \____/\__,_/ |___/\__,_/
- --]]
- --NOTE: NOT WORKING
- lsp.jdtls.setup {on_attach = custom_attach,
- root_dir = cwd
- }
- --configs.jdtls.handlers == {
- --['client/registerCapability'] = function(_, _, _, _)
- --return {
- --result = nil;
- --error = nil;
- --}
- --end
- --},
- --root_dir = lsp.util.root_pattern('.git', 'pom.xml', 'build.xml')
- ---------------------------------------------------------------------------------------
- --[[
- __
- / / __ ______ _
- / / / / / / __ `/
- / /___/ /_/ / /_/ /
- /_____/\__,_/\__,_/
- --]]
- lsp.sumneko_lua.setup {
- on_attach = custom_attach,
- root_dir = function(fname)
- return util.find_git_ancestor(fname) or
- util.path.dirname(fname)
- end,
- --root_dir = vim.loop.cwd,
- --root_dir = util.root_pattern('.git') or cwd, --Not working
- capabilities = {
- textDocument = {
- completion = {
- completionItem = {
- snippetSupport=true
- }
- }
- }
- },
- lsp_status.capabilities, --> REQUIRED FOR LSP STATUS
- settings = {
- Lua = {
- runtime = {
- -- Tell the language server which version of Lua you're using (LuaJIT in the case of Neovim)
- version = 'LuaJIT',
- -- Setup your lua path
- path = vim.split(package.path, ';'),
- },
- diagnostics = {
- -- Get the language server to recognize the `vim` global
- globals = {'vim'},
- },
- workspace = {
- -- Make the server aware of Neovim runtime files
- library = {
- [vim.fn.expand('$VIMRUNTIME/lua')] = true,
- [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
- },
- },
- },
- },
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement