add PoC skelet
This commit is contained in:
commit
38032efea7
27
flake.lock
generated
Normal file
27
flake.lock
generated
Normal file
@ -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
|
||||
}
|
34
flake.nix
Normal file
34
flake.nix
Normal file
@ -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;})
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
56
nvim-lsp.nix
Normal file
56
nvim-lsp.nix
Normal file
@ -0,0 +1,56 @@
|
||||
{pkgs ? import <nixpkgs> {}}: let
|
||||
neovim = pkgs.neovim.override {
|
||||
configure = {
|
||||
customRC = ''
|
||||
lua <<EOF
|
||||
${luaRc}
|
||||
EOF
|
||||
'';
|
||||
|
||||
packages.myPlugins.start = with pkgs.vimPlugins; [
|
||||
(nvim-treesitter.withPlugins (parsers: [
|
||||
parsers.c
|
||||
parsers.cpp
|
||||
parsers.json
|
||||
parsers.latex
|
||||
parsers.lua
|
||||
parsers.nix
|
||||
parsers.python
|
||||
parsers.query
|
||||
parsers.verilog
|
||||
parsers.vimdoc
|
||||
parsers.zig
|
||||
parsers.rust
|
||||
]))
|
||||
cmp-buffer
|
||||
cmp-cmdline
|
||||
cmp-nvim-lsp
|
||||
cmp-nvim-ultisnips
|
||||
cmp-path
|
||||
colorizer
|
||||
fugitive
|
||||
fzf-vim
|
||||
gruvbox
|
||||
nvim-cmp
|
||||
nvim-lspconfig
|
||||
nvim-treesitter
|
||||
nvim-ts-rainbow
|
||||
repeat
|
||||
targets-vim
|
||||
UltiSnips
|
||||
vim-addon-nix
|
||||
vim-signify
|
||||
vim-slime
|
||||
vim-snippets
|
||||
zig-vim
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
# lua
|
||||
luaRc = builtins.readFile ./vimrc.lua;
|
||||
in
|
||||
pkgs.runCommand "nvim-lsp" {} ''
|
||||
mkdir -p $out/bin
|
||||
ln -s ${neovim}/bin/nvim $out/bin/nvim-lsp
|
||||
''
|
201
vimrc.lua
Normal file
201
vimrc.lua
Normal file
@ -0,0 +1,201 @@
|
||||
-- Basic settings
|
||||
vim.g.loaded_matchparen = true
|
||||
vim.g.netrw_liststyle = 3
|
||||
vim.go.background = 'dark'
|
||||
vim.go.belloff = 'all'
|
||||
vim.go.breakindent = true
|
||||
vim.go.hlsearch = false
|
||||
vim.go.laststatus = 0
|
||||
vim.go.lazyredraw = true
|
||||
vim.go.showcmd = true
|
||||
vim.go.synmaxcol = 800
|
||||
vim.go.syntax = 'on'
|
||||
vim.go.termguicolors = true
|
||||
vim.go.titleold = vim.fn.getcwd()
|
||||
vim.go.title = true
|
||||
vim.go.wildmenu = true
|
||||
vim.go.wrap = true
|
||||
vim.wo.number = true
|
||||
|
||||
vim.cmd([[colorscheme gruvbox]])
|
||||
|
||||
-- Defines a read-write directory for treesitters in nvim's cache dir
|
||||
local parser_install_dir = vim.fn.stdpath("cache") .. "/treesitters"
|
||||
if vim.fn.isdirectory(parser_install_dir) == 0 then
|
||||
vim.fn.mkdir(parser_install_dir, "p")
|
||||
end
|
||||
-- Adding runtime needed for Nix setup on non NixOS
|
||||
vim.o.runtimepath = vim.o.runtimepath .. "," .. parser_install_dir
|
||||
|
||||
require 'nvim-treesitter.install'.compilers = { 'gcc' }
|
||||
|
||||
require 'nvim-treesitter.configs'.setup {
|
||||
ensure_installed = { "c", "cpp", "zig", "python", "verilog", "nix", "lua", "latex" },
|
||||
parser_install_dir = parser_install_dir,
|
||||
highlight = { enable = true, disable = {} },
|
||||
indent = { enable = false, disable = {} },
|
||||
rainbow = {
|
||||
enable = true,
|
||||
extended_mode = true, -- Highlight also non-parentheses delimiters, boolean or table: lang -> 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', '<space>e',
|
||||
'<cmd>lua vim.diagnostic.open_float()<CR>', opts)
|
||||
vim.api.nvim_set_keymap('n', '<space>q',
|
||||
'<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
|
||||
vim.api.nvim_set_keymap('n', 'Q', '<cmd>nohl<CR>', 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', '<C-J>', '<C-W><C-J>', opts)
|
||||
vim.api.nvim_set_keymap('n', '<C-K>', '<C-W><C-K>', opts)
|
||||
vim.api.nvim_set_keymap('n', '<C-L>', '<C-W><C-L>', opts)
|
||||
vim.api.nvim_set_keymap('n', '<C-H>', '<C-W><C-H>', 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', '<cmd>lua vim.lsp.buf.hover()<cr>')
|
||||
|
||||
-- Jump to the definition
|
||||
bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
|
||||
|
||||
-- Jump to declaration
|
||||
bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
|
||||
|
||||
-- Lists all the implementations for the symbol under the cursor
|
||||
bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>')
|
||||
|
||||
-- Jumps to the definition of the type symbol
|
||||
bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
|
||||
|
||||
-- Lists all the references
|
||||
bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>')
|
||||
|
||||
-- Displays a function's signature information
|
||||
bufmap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
|
||||
|
||||
-- Renames all references to the symbol under the cursor
|
||||
bufmap('n', 'rn', '<cmd>lua vim.lsp.buf.rename()<cr>')
|
||||
|
||||
-- Selects a code action available at the current cursor position
|
||||
bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>')
|
||||
bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>')
|
||||
|
||||
-- Show diagnostics in a floating window
|
||||
bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>')
|
||||
|
||||
-- Move to the previous diagnostic
|
||||
bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
|
||||
|
||||
-- Move to the next diagnostic
|
||||
bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>')
|
||||
|
||||
-- Format current buffer
|
||||
bufmap('n', '<space>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 = {
|
||||
["<Tab>"] = cmp.mapping({
|
||||
i = function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
}),
|
||||
["<S-Tab>"] = cmp.mapping({
|
||||
i = function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item({ behavior = cmp.SelectBehavimr.Insert })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
}),
|
||||
['<Down>'] = cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), { 'i' }),
|
||||
['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), { 'i' }),
|
||||
['<C-n>'] = cmp.mapping({
|
||||
i = function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end
|
||||
}),
|
||||
['<C-p>'] = cmp.mapping({
|
||||
i = function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end
|
||||
}),
|
||||
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
||||
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
||||
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
|
||||
['<C-e>'] = cmp.mapping({ i = cmp.mapping.close(), c = cmp.mapping.close() }),
|
||||
['<CR>'] = 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]])
|
Loading…
Reference in New Issue
Block a user