all repos — dotfiles @ 689d7c59fe5957e0ac6efe7d3f79a7c2e51499a6

my *nix dotfiles

nvim: Configure Python, Lua and YAML LSPs
Anirudh Oppiliappan x@icyphox.sh
Wed, 10 Feb 2021 21:55:50 +0530
commit

689d7c59fe5957e0ac6efe7d3f79a7c2e51499a6

parent

4e7c63e8f8a18a3a48448ba85199895edd01fa06

M config/nvim/init.luaconfig/nvim/init.lua

@@ -9,14 +9,19 @@ paq 'dbeniamine/vim-mail'

paq 'tpope/vim-surround' paq 'plasticboy/vim-markdown' paq{ 'vim/better-text-objs', url='https://git.peppe.rs' } -paq 'ervandew/supertab' paq 'wellle/targets.vim' paq 'tpope/vim-rsi' paq 'editorconfig/editorconfig-vim' paq 'zah/nim.vim' paq 'neovim/nvim-lspconfig' -paq 'nvim-lua/completion-nvim' require('settings') require('maps') require('statusline') + +-- lsp setup +require('lsp.yaml') +require('lsp.lua') +require('lsp.python') + +vim.lsp.set_log_level 'debug'
A config/nvim/lua/lsp/lua.lua

@@ -0,0 +1,39 @@

+-- only on macOS +util = require('lspconfig.util') + + +local root_path = '/Users/icy/Leet/lua-language-server' +local bin_path = root_path .. '/bin/macOS/lua-language-server' + +require'lspconfig'.sumneko_lua.setup { + cmd = { bin_path, "-E", root_path .. '/main.lua' }, + root_dir = function(fname) + return util.find_git_ancestor(fname) or + util.path.dirname(fname) + end, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely 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, + }, + }, + telemetry = { + enable = false, + } + }, + }, + on_attach = require('maps').on_attach, +}
A config/nvim/lua/lsp/python.lua

@@ -0,0 +1,1 @@

+require('lspconfig').pyright.setup{ on_attach = require('maps').on_attach }
M config/nvim/lua/lsp/yaml.luaconfig/nvim/lua/lsp/yaml.lua

@@ -1,1 +1,1 @@

-require('lspconfig').yamlls.setup{on_attach=require('completion').on_attach} +require('lspconfig').yamlls.setup{ on_attach = require('maps').on_attach }
M config/nvim/lua/maps.luaconfig/nvim/lua/maps.lua

@@ -1,5 +1,6 @@

local cmd = vim.cmd local map = vim.api.nvim_set_keymap +local M = {} -- map the leader key map('n', '<Space>', '', {})

@@ -32,8 +33,8 @@ -- fzy mappings

if vim.fn.executable('fzy') then _G.fzy_shell_cmd = require('fzy.shell').fzy_shell_cmd map( - '', - '<leader>e', + '', + '<leader>e', string.format( ':call v:lua.fzy_shell_cmd("find -L . -type f %s", ":e")<cr>', fzy_ignore{'*.git/*', '*node_modules*', '*.pyc'}

@@ -57,3 +58,17 @@ )

else print('fzy not in PATH!') end + +-- lspconfig +function M.on_attach(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + local opts = { noremap=true, silent=true } + buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts) + buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts) +end + +return M