* Atelier dédié à LSP & DAP https://microsoft.github.io/language-server-protocol/ https://microsoft.github.io/debug-adapter-protocol/ # Notes Config de frajus (présenté pour la partie python #jedi, #pyright, #pylsp) : https://github.com/manteapi/nvim Config PacoV: https://gitlab.com/pcoves/nvim/blob/main/.config/nvim/lua/plugins.lua (Mason + LSP ~l134) Démo OpenTelemerty + Jaeger pour visualisation code parallèle: https://gitlab.com/draftware/otl git diff avec tree sitter: https://docs.rs/crate/difftastic/latest https://github.com/fabi1cazenave/dotFiles/blob/master/config/nvim/init.lua Configuration LSP from scratch (init.lua + packer requis !) require('packer').startup(function(use) use 'wbthomason/packer.nvim' -- Packer can manage itself -- Language Server Protocol use 'neovim/nvim-lspconfig' -- LSP/DAP package manager use 'williamboman/mason.nvim' require('mason').setup() -- Auto-Completion use 'hrsh7th/cmp-nvim-lsp' use 'hrsh7th/cmp-buffer' use 'hrsh7th/cmp-path' use 'hrsh7th/cmp-cmdline' use 'hrsh7th/nvim-cmp' -- For vsnip users. use 'hrsh7th/cmp-vsnip' use 'hrsh7th/vim-vsnip' end) -- -- auto-completion (nvim-cmp) -- local cmp = require('cmp') local has_words_before = function() local line, col = unpack(vim.api.nvim_win_get_cursor(0)) return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil end local feedkey = function(key, mode) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) end cmp.setup({ sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'vsnip' }, { name = 'buffer' }, }), snippet = { expand = function(args) vim.fn["vsnip#anonymous"](args.body) end, }, mapping = { [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif vim.fn["vsnip#available"](1) == 1 then feedkey("(vsnip-expand-or-jump)", "") elseif has_words_before() then cmp.complete() else fallback() -- The fallback function sends an already mapped key (probably `` here). end end, { "i", "s" }), [""] = cmp.mapping(function() if cmp.visible() then cmp.select_prev_item() elseif vim.fn["vsnip#jumpable"](-1) == 1 then feedkey("(vsnip-jump-prev)", "") end end, { "i", "s" }), -- [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), -- [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), -- [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), -- [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), -- [''] = cmp.config.disable, -- remove the default `` mapping -- [''] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close() }), -- [''] = cmp.mapping.confirm({ select = true }), }, }) -- -- LSP buffer-specific options and keymaps -- local set_lsp_keymaps = function(client, bufnr) local opts = { buffer=bufnr, noremap=true, silent=true } local telescope = require('telescope.builtin') -- mappings vim.keymap.set( 'n', 'K', vim.lsp.buf.hover, opts) vim.keymap.set( 'n', '', vim.lsp.buf.signature_help, opts) vim.keymap.set( 'n', 'gA', vim.lsp.buf.code_action, opts) -- {apply=true} vim.keymap.set( 'n', 'gR', vim.lsp.buf.rename, opts) vim.keymap.set({'n', 'v'}, 'g=', vim.lsp.buf.format, opts) vim.keymap.set( 'n', 'gi', vim.lsp.buf.implementation, opts) vim.keymap.set( 'n', '[', vim.diagnostic.goto_prev, opts) vim.keymap.set( 'n', ']', vim.diagnostic.goto_next, opts) -- LSP references, definitions and diagnostics are handled by Telescope vim.keymap.set( 'n', 'gr', telescope.lsp_references, opts) vim.keymap.set( 'n', 'gd', telescope.lsp_definitions, opts) vim.keymap.set( 'n', 'gD', telescope.diagnostics, opts) -- source/header switch (should be restricted to clangd) vim.keymap.set('n', 'gh', ':ClangdSwitchSourceHeader', opts) -- enable completion triggered by (and nvim-cmp) vim.bo.omnifunc = 'v:lua.vim.lsp.omnifunc' end -- -- LSP activation: call 'setup' on multiple servers -- and add local keybindings and snippet capabilities when the language server attaches -- local lsp_servers = { 'clangd', 'pylsp' } -- see also: null-ls local nvim_lsp = require('lspconfig') local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) for _, lsp in ipairs(lsp_servers) do nvim_lsp[lsp].setup { on_attach = set_lsp_keymaps, flags = { debounce_text_changes = 150, }, capabilities = capabilities, } end