From cfc94b79853889b0124543336fcf897b0904c83b Mon Sep 17 00:00:00 2001 From: Juni Kim Date: Thu, 26 Jan 2023 14:20:39 -0500 Subject: [PATCH] bash language server support --- after/plugin/lsp.lua | 21 +++++++++++++++++++-- after/plugin/telescope.lua | 27 ++++++++++++++++++++++++++- lua/junikim/init.lua | 4 ++-- lua/junikim/options.lua | 23 ++++++++++++++++++----- lua/junikim/packer.lua | 32 +++++++++++++++++--------------- lua/junikim/remap.lua | 2 +- plugin/packer_compiled.lua | 5 +++++ 7 files changed, 88 insertions(+), 26 deletions(-) diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index 06ea967..641ab12 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -1,6 +1,7 @@ -- Learn the keybindings, see :help lsp-zero-keybindings -- Learn to configure LSP servers, see :help lsp-zero-api-showcase local lsp = require('lsp-zero') +local lspconfig = require('lspconfig'); lsp.preset('recommended') -- (Optional) Configure lua language server for neovim @@ -11,12 +12,28 @@ lsp.ensure_installed({ 'tsserver', 'texlab', 'pyright', - 'sumneko_lua' + 'sumneko_lua', + 'efm' +}) + +lsp.configure("efm", { + settings = { + languages = { + sh = "shellcheck -x" + } + }, + filetypes = { "sh" } }) lsp.on_attach(function(client, bufnr) - local opts = {buffer = bufnr, remap=false} + local opts = { buffer = bufnr, remap = false } vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) end) lsp.setup() + +vim.diagnostic.config({ + virtual_text = true, + underline = true, + float = true, +}) diff --git a/after/plugin/telescope.lua b/after/plugin/telescope.lua index 26c5003..bf8cbaf 100644 --- a/after/plugin/telescope.lua +++ b/after/plugin/telescope.lua @@ -1,5 +1,30 @@ local builtin = require("telescope.builtin") -vim.keymap.set('n', '', builtin.git_files, {}) + +local function git_exists() + local path = require("pl.path") + local p = "." + while true do + local gitpath = p .. "/.git" + local d = io.open(gitpath) + if d then + d:close() + return true + else + p = p .. "/.." + end + if path.abspath(p) ~= "/" then + return false + end + end +end + +vim.keymap.set('n', '', function() + if git_exists() then + builtin.git_files() + else + builtin.find_files() + end +end, {}) vim.keymap.set('n', 'ff', builtin.find_files, {}) vim.keymap.set('n', 'fg', builtin.live_grep, {}) vim.keymap.set('n', 'fh', builtin.help_tags, {}) diff --git a/lua/junikim/init.lua b/lua/junikim/init.lua index 23c8688..759482b 100644 --- a/lua/junikim/init.lua +++ b/lua/junikim/init.lua @@ -1,3 +1,3 @@ -require("junikim.remap") -require("junikim.options") require("junikim.packer") +require("junikim.options") +require("junikim.remap") diff --git a/lua/junikim/options.lua b/lua/junikim/options.lua index 5550cb7..61806cf 100644 --- a/lua/junikim/options.lua +++ b/lua/junikim/options.lua @@ -1,3 +1,4 @@ +vim.opt.mouse:append('a') vim.opt.number = true vim.opt.linebreak = true vim.opt.shiftwidth = 2 @@ -5,13 +6,17 @@ vim.opt.tabstop = 2 vim.opt.softtabstop = 2 vim.opt.expandtab = true vim.opt.smarttab = true +vim.opt.shiftround = true vim.opt.autoindent = true vim.opt.textwidth = 80 vim.opt.colorcolumn = "80" vim.opt.list = true vim.g.airline_theme = "base16_chalk" ---vim.g.airline_powerline_fonts = 1 +vim.g.airline_powerline_fonts = 1 + +vim.cmd("filetype plugin indent on") +vim.cmd("filetype on") vim.api.nvim_create_autocmd("FileType", { pattern = "python", @@ -25,15 +30,15 @@ vim.api.nvim_create_autocmd("FileType", { }) vim.api.nvim_create_autocmd("FileType", { - pattern = {"markdown", "tex", "text"}, + pattern = { "markdown", "tex", "text" }, callback = function(args) - vim.bo.expandtab = false + vim.o.smarttab = false vim.bo.autoindent = false end }) vim.api.nvim_create_autocmd("FileType", { - pattern = {"c", "cpp", "slang"}, + pattern = { "c", "cpp", "slang" }, callback = function(args) vim.bo.cindent = true end @@ -48,6 +53,14 @@ vim.api.nvim_create_autocmd("FileType", { vim.bo.softtabstop = 4 vim.bo.preserveindent = true vim.bo.copyindent = true - vim.api.nvim_set_keymap("n", "", ":w|:!cpgo test", {noremap = true}) + vim.bo.formatprg = "gofmt -e -w" + vim.api.nvim_set_keymap("n", "", ":w|:!cpgo test", { noremap = true }) + end +}) + +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = { "*.go", "*.py", "*.lua", "*.ts", "*.tsx", "*.js", "*.md", "*.json" }, + callback = function(args) + vim.lsp.buf.formatting_sync() end }) diff --git a/lua/junikim/packer.lua b/lua/junikim/packer.lua index 1f7a8bd..d9f7e98 100644 --- a/lua/junikim/packer.lua +++ b/lua/junikim/packer.lua @@ -3,9 +3,11 @@ vim.cmd [[packadd packer.nvim]] return require('packer').startup(function(use) -- Packer can manage itself use 'wbthomason/packer.nvim' + use 'tpope/vim-sensible' + use_rocks 'penlight' use { 'nvim-telescope/telescope.nvim', tag = '0.1.1', - requires = { {'nvim-lua/plenary.nvim'} } + requires = { { 'nvim-lua/plenary.nvim' } } } use 'Townk/vim-autoclose' use { @@ -13,11 +15,11 @@ return require('packer').startup(function(use) vim.cmd("colorscheme onedark") end } - use ( - 'nvim-treesitter/nvim-treesitter', {run = ':TSUpdate'} + use( + 'nvim-treesitter/nvim-treesitter', { run = ':TSUpdate' } ) use 'nvim-tree/nvim-web-devicons' - use {'romgrk/barbar.nvim', wants = 'nvim-web-devicons'} + use { 'romgrk/barbar.nvim', wants = 'nvim-web-devicons' } use 'vim-airline/vim-airline' use 'vim-airline/vim-airline-themes' use { @@ -25,21 +27,21 @@ return require('packer').startup(function(use) branch = 'v1.x', requires = { -- LSP Support - {'neovim/nvim-lspconfig'}, -- Required - {'williamboman/mason.nvim'}, -- Optional - {'williamboman/mason-lspconfig.nvim'}, -- Optional + { 'neovim/nvim-lspconfig' }, -- Required + { 'williamboman/mason.nvim' }, -- Optional + { 'williamboman/mason-lspconfig.nvim' }, -- Optional -- Autocompletion - {'hrsh7th/nvim-cmp'}, -- Required - {'hrsh7th/cmp-nvim-lsp'}, -- Required - {'hrsh7th/cmp-buffer'}, -- Optional - {'hrsh7th/cmp-path'}, -- Optional - {'saadparwaiz1/cmp_luasnip'}, -- Optional - {'hrsh7th/cmp-nvim-lua'}, -- Optional + { 'hrsh7th/nvim-cmp' }, -- Required + { 'hrsh7th/cmp-nvim-lsp' }, -- Required + { 'hrsh7th/cmp-buffer' }, -- Optional + { 'hrsh7th/cmp-path' }, -- Optional + { 'saadparwaiz1/cmp_luasnip' }, -- Optional + { 'hrsh7th/cmp-nvim-lua' }, -- Optional -- Snippets - {'L3MON4D3/LuaSnip'}, -- Required - {'rafamadriz/friendly-snippets'}, -- Optional + { 'L3MON4D3/LuaSnip' }, -- Required + { 'rafamadriz/friendly-snippets' }, -- Optional } } diff --git a/lua/junikim/remap.lua b/lua/junikim/remap.lua index 246a519..0dda0b1 100644 --- a/lua/junikim/remap.lua +++ b/lua/junikim/remap.lua @@ -1,4 +1,4 @@ -function map(mode, lhs, rhs, opts) +local function map(mode, lhs, rhs, opts) local options = { noremap = true } if opts then options = vim.tbl_extend("force", options, opts) diff --git a/plugin/packer_compiled.lua b/plugin/packer_compiled.lua index fadc105..f108901 100644 --- a/plugin/packer_compiled.lua +++ b/plugin/packer_compiled.lua @@ -196,6 +196,11 @@ _G.packer_plugins = { path = "/home/junikim/.local/share/nvim/site/pack/packer/start/vim-autoclose", url = "https://github.com/Townk/vim-autoclose" }, + ["vim-sensible"] = { + loaded = true, + path = "/home/junikim/.local/share/nvim/site/pack/packer/start/vim-sensible", + url = "https://github.com/tpope/vim-sensible" + }, vimtex = { loaded = true, path = "/home/junikim/.local/share/nvim/site/pack/packer/start/vimtex",