From 38032efea7d91669bda07144fe84748e258c57a9 Mon Sep 17 00:00:00 2001 From: Asmir A Date: Fri, 7 Jul 2023 12:44:05 +0200 Subject: [PATCH] add PoC skelet --- flake.lock | 27 +++++++ flake.nix | 34 +++++++++ nvim-lsp.nix | 56 ++++++++++++++ vimrc.lua | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 318 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nvim-lsp.nix create mode 100644 vimrc.lua diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..01d1d30 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1688646010, + "narHash": "sha256-kCeza5eKI2NEi8k0EoeZfv3lN1r1Vwx+L/VA6I8tmG4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5daaa32204e9c46b05cd709218b7ba733d07e80c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..14a1054 --- /dev/null +++ b/flake.nix @@ -0,0 +1,34 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + + outputs = { + self, + nixpkgs, + }: let + pkgs = nixpkgs.legacyPackages.x86_64-linux.pkgs; + in { + nvim = pkgs.mkShell { + nativeBuildInputs = [ + pkgs.alejandra + pkgs.ccls + pkgs.clang + pkgs.luaformatter + pkgs.nixd + pkgs.nixd + pkgs.pyright + pkgs.rust-analyzer + pkgs.sumneko-lua-language-server + pkgs.svls + pkgs.texlab + pkgs.tree-sitter + pkgs.verible + pkgs.zls + (import ./nvim-lsp.nix {inherit pkgs;}) + ]; + }; + }; +} diff --git a/nvim-lsp.nix b/nvim-lsp.nix new file mode 100644 index 0000000..61ad1ce --- /dev/null +++ b/nvim-lsp.nix @@ -0,0 +1,56 @@ +{pkgs ? import {}}: let + neovim = pkgs.neovim.override { + configure = { + customRC = '' + lua < boolean + max_file_lines = 1000, -- Do not enable for files with more than 1000 lines, int + colors = { + '#ff0000', '#ffa500', '#ffff00', '#008000', '#0051a0', '#8003f2' + } -- table of hex strings + } +} + +-- Mappings. +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +local opts = { noremap = true, silent = true } +vim.api.nvim_set_keymap('n', 'e', + 'lua vim.diagnostic.open_float()', opts) +vim.api.nvim_set_keymap('n', 'q', + 'lua vim.diagnostic.setloclist()', opts) +vim.api.nvim_set_keymap('n', 'Q', 'nohl', opts) +vim.api.nvim_set_keymap('n', 'j', 'gj', opts) +vim.api.nvim_set_keymap('n', 'k', 'gk', opts) +vim.api.nvim_set_keymap('v', 'j', 'gj', opts) +vim.api.nvim_set_keymap('v', 'k', 'gk', opts) +vim.api.nvim_set_keymap('n', '', '', opts) +vim.api.nvim_set_keymap('n', '', '', opts) +vim.api.nvim_set_keymap('n', '', '', opts) +vim.api.nvim_set_keymap('n', '', '', opts) + +vim.api.nvim_create_autocmd('LspAttach', { + desc = 'LSP actions', + callback = function() + local bufmap = function(mode, lhs, rhs) + vim.keymap.set(mode, lhs, rhs, { buffer = true }) + end + + -- Displays hover information about the symbol under the cursor + bufmap('n', 'K', 'lua vim.lsp.buf.hover()') + + -- Jump to the definition + bufmap('n', 'gd', 'lua vim.lsp.buf.definition()') + + -- Jump to declaration + bufmap('n', 'gD', 'lua vim.lsp.buf.declaration()') + + -- Lists all the implementations for the symbol under the cursor + bufmap('n', 'gi', 'lua vim.lsp.buf.implementation()') + + -- Jumps to the definition of the type symbol + bufmap('n', 'go', 'lua vim.lsp.buf.type_definition()') + + -- Lists all the references + bufmap('n', 'gr', 'lua vim.lsp.buf.references()') + + -- Displays a function's signature information + bufmap('n', '', 'lua vim.lsp.buf.signature_help()') + + -- Renames all references to the symbol under the cursor + bufmap('n', 'rn', 'lua vim.lsp.buf.rename()') + + -- Selects a code action available at the current cursor position + bufmap('n', '', 'lua vim.lsp.buf.code_action()') + bufmap('x', '', 'lua vim.lsp.buf.range_code_action()') + + -- Show diagnostics in a floating window + bufmap('n', 'gl', 'lua vim.diagnostic.open_float()') + + -- Move to the previous diagnostic + bufmap('n', '[d', 'lua vim.diagnostic.goto_prev()') + + -- Move to the next diagnostic + bufmap('n', ']d', 'lua vim.diagnostic.goto_next()') + + -- Format current buffer + bufmap('n', 'f', function() vim.lsp.buf.format { async = true } end) + end +}) + +-- Use a loop to conveniently call 'setup' on multiple servers and +-- map buffer local keybindings when the language server attaches +local cmp = require 'cmp' +cmp.setup({ + snippet = { + expand = function(args) + vim.fn["UltiSnips#Anon"](args.body) + end, + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'buffer' }, + { name = 'path' }, + { name = 'ultisnips' }, + }), + mapping = { + [""] = cmp.mapping({ + i = function(fallback) + if cmp.visible() then + cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert }) + else + fallback() + end + end, + }), + [""] = cmp.mapping({ + i = function(fallback) + if cmp.visible() then + cmp.select_prev_item({ behavior = cmp.SelectBehavimr.Insert }) + else + fallback() + end + end, + }), + [''] = cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), { 'i' }), + [''] = cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), { 'i' }), + [''] = cmp.mapping({ + i = function(fallback) + if cmp.visible() then + cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) + else + fallback() + end + end + }), + [''] = cmp.mapping({ + i = function(fallback) + if cmp.visible() then + cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select }) + else + fallback() + end + end + }), + [''] = 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.mapping({ i = cmp.mapping.close(), c = cmp.mapping.close() }), + [''] = cmp.mapping({ + i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }), + }), + } +}) + +local servers = { 'pyright', 'rust_analyzer', 'ccls', 'lua_ls', 'nixd', 'texlab', 'verible' } +local capabilities = require('cmp_nvim_lsp').default_capabilities() +for _, lsp in pairs(servers) do + require('lspconfig')[lsp].setup { + capabilities = capabilities + } +end + +require('lspconfig').lua_ls.setup({ + single_file_support = true, +}) + +require('lspconfig').verible.setup({ + root_dir = function() return vim.loop.cwd() end +}) + +if vim.fn.exists('+undofile') ~= 0 then + local undo_dir = vim.env.HOME .. '/.config/nvim/undo' + if vim.fn.isdirectory(undo_dir) == 0 then vim.fn.mkdir(undo_dir, 'p') end + vim.o.undodir = undo_dir + vim.o.undofile = true +end + +vim.cmd([[syntax sync minlines=100]]) +vim.cmd([[syntax sync maxlines=140]])