aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksa Vučković <aleksav013@gmail.com>2022-01-05 15:35:38 +0100
committerAleksa Vučković <aleksav013@gmail.com>2022-01-05 15:35:38 +0100
commit6c1c6ba2f5b45c0c3ba178ee34a9992ce23b7180 (patch)
tree48fad4a844d874303149f829db4a062634b10f79
parent2a5f4d72d21d495408a52a2cad271b1e5775967b (diff)
ccls working as intended
-rw-r--r--init.lua10
-rw-r--r--lua/cmp.lua35
-rw-r--r--lua/cmp1.lua14
-rw-r--r--lua/user/cmp.lua130
-rw-r--r--lua/user/keymaps.lua (renamed from lua/keymaps.lua)0
-rw-r--r--lua/user/lsp/handlers.lua104
-rw-r--r--lua/user/lsp/init.lua9
-rw-r--r--lua/user/lsp/lsp-installer.lua28
-rw-r--r--lua/user/lsp/settings/bashls.lua (renamed from lua/lsp/init.lua)0
-rw-r--r--lua/user/lsp/settings/ccls.lua34
-rw-r--r--lua/user/lsp/settings/texlab.lua0
-rw-r--r--lua/user/options.lua (renamed from lua/options.lua)0
-rw-r--r--lua/user/plugins.lua (renamed from lua/plugins.lua)12
-rwxr-xr-xsync.sh9
14 files changed, 322 insertions, 63 deletions
diff --git a/init.lua b/init.lua
index eec635f..baeabbd 100644
--- a/init.lua
+++ b/init.lua
@@ -1,5 +1,5 @@
-require "options"
-require "keymaps"
-require "plugins"
-require "cmp"
-require "lsp"
+require "user.options"
+require "user.keymaps"
+require "user.plugins"
+require "user.cmp"
+require "user.lsp"
diff --git a/lua/cmp.lua b/lua/cmp.lua
deleted file mode 100644
index ec6695f..0000000
--- a/lua/cmp.lua
+++ /dev/null
@@ -1,35 +0,0 @@
-local status, cmp = pcall(require, "cmp")
-if not status then
- return
-end
-
-local status, luasnip = pcall(require, "luasnip")
-if not status then
- return
-end
-
-
-cmp.setup({
- snippet = {
- expand = function(args)
- luasnip.lsp_expand(args.body)
- end,
- },
- mapping = {
- ['<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-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
- ['<C-e>'] = cmp.mapping({
- i = cmp.mapping.abort(),
- c = cmp.mapping.close(),
- }),
- ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
- },
- sources = {
--- { name = 'nvim_lsp' },
--- { name = 'luasnip' },
--- { name = 'buffer' },
--- { name = "path" },
- },
-})
diff --git a/lua/cmp1.lua b/lua/cmp1.lua
deleted file mode 100644
index 092402c..0000000
--- a/lua/cmp1.lua
+++ /dev/null
@@ -1,14 +0,0 @@
- config = function ()
- require'cmp'.setup {
- snippet = {
- expand = function(args)
- require'luasnip'.lsp_expand(args.body)
- end
- },
-
- sources = {
- { name = 'luasnip' },
- -- more sources
- },
- }
- end
diff --git a/lua/user/cmp.lua b/lua/user/cmp.lua
new file mode 100644
index 0000000..5a005e8
--- /dev/null
+++ b/lua/user/cmp.lua
@@ -0,0 +1,130 @@
+local cmp_status_ok, cmp = pcall(require, "cmp")
+if not cmp_status_ok then
+ return
+end
+
+local snip_status_ok, luasnip = pcall(require, "luasnip")
+if not snip_status_ok then
+ return
+end
+
+
+local check_backspace = function()
+ local col = vim.fn.col "." - 1
+ return col == 0 or vim.fn.getline("."):sub(col, col):match "%s"
+end
+
+--   פּ ﯟ   some other good icons
+local kind_icons = {
+ Text = "",
+ Method = "m",
+ Function = "",
+ Constructor = "",
+ Field = "",
+ Variable = "",
+ Class = "",
+ Interface = "",
+ Module = "",
+ Property = "",
+ Unit = "",
+ Value = "",
+ Enum = "",
+ Keyword = "",
+ Snippet = "",
+ Color = "",
+ File = "",
+ Reference = "",
+ Folder = "",
+ EnumMember = "",
+ Constant = "",
+ Struct = "",
+ Event = "",
+ Operator = "",
+ TypeParameter = "",
+}
+-- find more here: https://www.nerdfonts.com/cheat-sheet
+
+cmp.setup {
+ snippet = {
+ expand = function(args)
+ luasnip.lsp_expand(args.body) -- For `luasnip` users.
+ end,
+ },
+ mapping = {
+ ["<C-k>"] = cmp.mapping.select_prev_item(),
+ ["<C-j>"] = cmp.mapping.select_next_item(),
+ ["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
+ ["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
+ ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
+ ["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
+ ["<C-e>"] = cmp.mapping {
+ i = cmp.mapping.abort(),
+ c = cmp.mapping.close(),
+ },
+ -- Accept currently selected item. If none selected, `select` first item.
+ -- Set `select` to `false` to only confirm explicitly selected items.
+ ["<CR>"] = cmp.mapping.confirm { select = true },
+ ["<Tab>"] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_next_item()
+ elseif luasnip.expandable() then
+ luasnip.expand()
+ elseif luasnip.expand_or_jumpable() then
+ luasnip.expand_or_jump()
+ elseif check_backspace() then
+ fallback()
+ else
+ fallback()
+ end
+ end, {
+ "i",
+ "s",
+ }),
+ ["<S-Tab>"] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_prev_item()
+ elseif luasnip.jumpable(-1) then
+ luasnip.jump(-1)
+ else
+ fallback()
+ end
+ end, {
+ "i",
+ "s",
+ }),
+ },
+ formatting = {
+ fields = { "kind", "abbr", "menu" },
+ format = function(entry, vim_item)
+ -- Kind icons
+ vim_item.kind = string.format("%s", kind_icons[vim_item.kind])
+ -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind
+ vim_item.menu = ({
+ nvim_lsp = "[LSP]",
+ luasnip = "[Snippet]",
+ buffer = "[Buffer]",
+ path = "[Path]",
+ nvim_lua = "[NVIM_LUA]",
+ })[entry.source.name]
+ return vim_item
+ end,
+ },
+ sources = {
+ { name = "nvim_lsp" },
+ { name = "luasnip" },
+ { name = "buffer" },
+ { name = "path" },
+ { name = "nvim-lua" },
+ },
+ confirm_opts = {
+ behavior = cmp.ConfirmBehavior.Replace,
+ select = false,
+ },
+ documentation = {
+ border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
+ },
+ experimental = {
+ ghost_text = false,
+ native_menu = false,
+ },
+}
diff --git a/lua/keymaps.lua b/lua/user/keymaps.lua
index be9bb45..be9bb45 100644
--- a/lua/keymaps.lua
+++ b/lua/user/keymaps.lua
diff --git a/lua/user/lsp/handlers.lua b/lua/user/lsp/handlers.lua
new file mode 100644
index 0000000..76b4572
--- /dev/null
+++ b/lua/user/lsp/handlers.lua
@@ -0,0 +1,104 @@
+local M = {}
+
+-- TODO: backfill this to template
+M.setup = function()
+ local signs = {
+ { name = "DiagnosticSignError", text = "" },
+ { name = "DiagnosticSignWarn", text = "" },
+ { name = "DiagnosticSignHint", text = "" },
+ { name = "DiagnosticSignInfo", text = "" },
+ }
+
+ for _, sign in ipairs(signs) do
+ vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" })
+ end
+
+ local config = {
+ -- disable virtual text
+ virtual_text = false,
+ -- show signs
+ signs = {
+ active = signs,
+ },
+ update_in_insert = true,
+ underline = true,
+ severity_sort = true,
+ float = {
+ focusable = false,
+ style = "minimal",
+ border = "rounded",
+ source = "always",
+ header = "",
+ prefix = "",
+ },
+ }
+
+ vim.diagnostic.config(config)
+
+ vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
+ border = "rounded",
+ })
+
+ vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
+ border = "rounded",
+ })
+end
+
+local function lsp_highlight_document(client)
+ -- Set autocommands conditional on server_capabilities
+ if client.resolved_capabilities.document_highlight then
+ vim.api.nvim_exec(
+ [[
+ augroup lsp_document_highlight
+ autocmd! * <buffer>
+ autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
+ autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
+ augroup END
+ ]],
+ false
+ )
+ end
+end
+
+local function lsp_keymaps(bufnr)
+ local opts = { noremap = true, silent = true }
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
+ -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
+ -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
+ -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>f", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", '<cmd>lua vim.diagnostic.goto_prev({ border = "rounded" })<CR>', opts)
+ vim.api.nvim_buf_set_keymap(
+ bufnr,
+ "n",
+ "gl",
+ '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ border = "rounded" })<CR>',
+ opts
+ )
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", '<cmd>lua vim.diagnostic.goto_next({ border = "rounded" })<CR>', opts)
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>q", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts)
+ vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]
+end
+
+M.on_attach = function(client, bufnr)
+ if client.name == "tsserver" then
+ client.resolved_capabilities.document_formatting = false
+ end
+ lsp_keymaps(bufnr)
+ lsp_highlight_document(client)
+end
+
+local capabilities = vim.lsp.protocol.make_client_capabilities()
+
+local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
+if not status_ok then
+ return
+end
+
+M.capabilities = cmp_nvim_lsp.update_capabilities(capabilities)
+
+return M
diff --git a/lua/user/lsp/init.lua b/lua/user/lsp/init.lua
new file mode 100644
index 0000000..c218647
--- /dev/null
+++ b/lua/user/lsp/init.lua
@@ -0,0 +1,9 @@
+local status_ok, _ = pcall(require, "lspconfig")
+if not status_ok then
+ return
+end
+
+require "user.lsp.lsp-installer"
+require("user.lsp.handlers").setup()
+
+require "user.lsp.settings.ccls"
diff --git a/lua/user/lsp/lsp-installer.lua b/lua/user/lsp/lsp-installer.lua
new file mode 100644
index 0000000..18490ce
--- /dev/null
+++ b/lua/user/lsp/lsp-installer.lua
@@ -0,0 +1,28 @@
+local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer")
+if not status_ok then
+ return
+end
+
+-- Register a handler that will be called for all installed servers.
+-- Alternatively, you may also register handlers on specific server instances instead (see example below).
+lsp_installer.on_server_ready(function(server)
+ local opts = {
+ on_attach = require("user.lsp.handlers").on_attach,
+ capabilities = require("user.lsp.handlers").capabilities,
+ }
+
+ if server.name == "bashls" then
+ local bashls_opts = require("user.lsp.settings.bashls")
+ opts = vim.tbl_deep_extend("force", bashls_opts, opts)
+ end
+
+ if server.name == "texlab" then
+ local texlab_opts = require("user.lsp.settings.texlab")
+ opts = vim.tbl_deep_extend("force", texlab_opts, opts)
+ end
+
+
+ -- This setup() function is exactly the same as lspconfig's setup function.
+ -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
+ server:setup(opts)
+end)
diff --git a/lua/lsp/init.lua b/lua/user/lsp/settings/bashls.lua
index e69de29..e69de29 100644
--- a/lua/lsp/init.lua
+++ b/lua/user/lsp/settings/bashls.lua
diff --git a/lua/user/lsp/settings/ccls.lua b/lua/user/lsp/settings/ccls.lua
new file mode 100644
index 0000000..d663f7c
--- /dev/null
+++ b/lua/user/lsp/settings/ccls.lua
@@ -0,0 +1,34 @@
+local status, lspconfig = pcall(require, "lspconfig")
+if not status then
+ return
+end
+
+
+vim.notify(vim.fn.expand('%:p'));
+local extraArgs_opt = {};
+
+if string.match(vim.fn.expand('%:p'),"/home/aleksa/mygit/mykernel/") then
+ extraArgs_opt = { "--sysroot=/home/aleksa/mygit/mykernel/sysroot", "--gcc-toolchain=/usr/bin/i686-elf-gcc", "-ffreestanding", "-nobuiltininc"};
+else
+end
+
+
+lspconfig.ccls.setup {
+ on_attach = on_attach,
+ flags = {
+ debounce_text_changes = 150,
+ };
+ init_options = {
+ compilationDatabaseDirectory = "build";
+ cache = {
+ directory = "/tmp/ccls-cache";
+ };
+ index = {
+ threads = 0;
+ };
+ clang = {
+ excludeArgs = { "-frounding-math"};
+ extraArgs = extraArgs_opt;
+ }
+ };
+}
diff --git a/lua/user/lsp/settings/texlab.lua b/lua/user/lsp/settings/texlab.lua
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/lua/user/lsp/settings/texlab.lua
diff --git a/lua/options.lua b/lua/user/options.lua
index a15e0e4..a15e0e4 100644
--- a/lua/options.lua
+++ b/lua/user/options.lua
diff --git a/lua/plugins.lua b/lua/user/plugins.lua
index 3f7c1e8..d1e7c69 100644
--- a/lua/plugins.lua
+++ b/lua/user/plugins.lua
@@ -2,8 +2,10 @@ local fn = vim.fn
local install_path = fn.stdpath("data").."/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
packer_bootstrap = fn.system({"git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path})
+ vim.cmd [[packadd packer.nvim]]
end
+-- Autocommand that reloads neovim whenever you save the plugins.lua file
vim.cmd([[
augroup packer_user_config
autocmd!
@@ -31,11 +33,11 @@ return packer.startup(function(use)
-- cmp
use "hrsh7th/nvim-cmp"
use "saadparwaiz1/cmp_luasnip"
--- use "hrsh7th/cmp-nvim-lsp"
--- use "hrsh7th/cmp-buffer"
--- use "hrsh7th/cmp-path"
--- use "hrsh7th/cmp-cmdline"
--- use "hrsh7th/cmp-nvim-lua"
+ use "hrsh7th/cmp-nvim-lsp"
+ use "hrsh7th/cmp-buffer"
+ use "hrsh7th/cmp-path"
+ use "hrsh7th/cmp-cmdline"
+ use "hrsh7th/cmp-nvim-lua"
-- snippets
use "L3MON4D3/LuaSnip"
diff --git a/sync.sh b/sync.sh
index 1ad25aa..5507b54 100755
--- a/sync.sh
+++ b/sync.sh
@@ -1,8 +1,9 @@
#!/bin/bash
-NVIM_DIR=~/.config/nvim
+NVIM_DIR=
+
+rm -rf ~/.config/nvim
+mkdir -p ~/.config/nvim
+stow --no-folding --ignore="LICENCE|README.md|sync.sh" -t ~/.config/nvim .
-rm -r $NVIM_DIR
-mkdir -p $NVIM_DIR
-stow --no-folding --ignore="LICENCE|README.md|sync.sh" -t $NVIM_DIR .
rm -rf ~/.local/share/nvim