From 1a02c0e649f87790a2ef8c5cea808d8bdfbadf6a Mon Sep 17 00:00:00 2001 From: Chun Li Date: Fri, 10 Oct 2025 23:35:14 -0700 Subject: [PATCH] Add LSP configurations to neovim. Add conform/telescope plugins. --- config/nvim/init.lua | 5 +---- config/nvim/lazy-lock.json | 8 ++++--- config/nvim/lsp/lua_ls.lua | 30 +++++++++++++++++++++++++++ config/nvim/lua/config/lsp.lua | 28 +++++++++++++++++++++++++ config/nvim/lua/keymaps.lua | 2 -- config/nvim/lua/options.lua | 9 +++++++- config/nvim/lua/plugins/conform.lua | 15 ++++++++++++++ config/nvim/lua/plugins/telescope.lua | 8 +++++-- zsh/dot-profile | 4 ---- zsh/dot-zshrc | 13 +++++++----- 10 files changed, 101 insertions(+), 21 deletions(-) create mode 100644 config/nvim/lsp/lua_ls.lua create mode 100644 config/nvim/lua/config/lsp.lua create mode 100644 config/nvim/lua/plugins/conform.lua delete mode 100644 zsh/dot-profile diff --git a/config/nvim/init.lua b/config/nvim/init.lua index 26cd534..3df01e5 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -5,13 +5,10 @@ vim.g.maplocalleader = ',' -- Set to true if you have a Nerd Font installed and selected in the terminal vim.g.have_nerd_font = true --- [[ Setting options ]] require 'options' - --- [[ Basic Keymaps ]] require 'keymaps' --- [[ Install `lazy.nvim` plugin manager ]] require 'config.lazy' +require 'config.lsp' vim.cmd.colorscheme 'catppuccin-mocha' diff --git a/config/nvim/lazy-lock.json b/config/nvim/lazy-lock.json index 637268e..11ae434 100644 --- a/config/nvim/lazy-lock.json +++ b/config/nvim/lazy-lock.json @@ -1,9 +1,11 @@ { - "catppuccin": { "branch": "main", "commit": "e79d09fa347b367e0e7f693bfe87dba932a8cbd1" }, - "lazy.nvim": { "branch": "main", "commit": "59334064f8604ca073791c25dcc5c9698865406e" }, - "neo-tree.nvim": { "branch": "v3.x", "commit": "f14ac20f98fb62769eaf4de1dc69fbee5fcf3384" }, + "catppuccin": { "branch": "main", "commit": "af58927c55c9f3272c940ff02b3cee94a1249f26" }, + "conform.nvim": { "branch": "master", "commit": "fbcb4fa7f34bfea9be702ffff481a8e336ebf6ed" }, + "lazy.nvim": { "branch": "main", "commit": "1ea3c4085785f460fb0e46d2fe1ee895f5f9e7c1" }, + "neo-tree.nvim": { "branch": "main", "commit": "4c60a198e3f92098778a32a1c76d2bd7ba46a3b5" }, "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, "nvim-web-devicons": { "branch": "master", "commit": "b8221e42cf7287c4dcde81f232f58d7b947c210d" }, "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" } } diff --git a/config/nvim/lsp/lua_ls.lua b/config/nvim/lsp/lua_ls.lua new file mode 100644 index 0000000..aecf32b --- /dev/null +++ b/config/nvim/lsp/lua_ls.lua @@ -0,0 +1,30 @@ +-- config for lua-language-server +return { + -- Command and arguments to start the server. + cmd = { 'lua-language-server' }, + + -- Filetypes to automatically attach to. + filetypes = { 'lua' }, + + -- Sets the "root directory" to the parent directory of the file in the + -- current buffer that contains either a ".luarc.json" or a + -- ".luarc.jsonc" file. Files that share a root directory will reuse + -- the connection to the same LSP server. + -- Nested lists indicate equal priority, see |vim.lsp.Config|. + root_markers = { { '.luarc.json', '.luarc.jsonc' }, '.git' }, + + -- Specific settings to send to the server. The schema for this is + -- defined by the server. For example the schema for lua-language-server + -- can be found here https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json + settings = { + Lua = { + runtime = { + version = 'LuaJIT', + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { 'vim' }, + }, + } + } +} diff --git a/config/nvim/lua/config/lsp.lua b/config/nvim/lua/config/lsp.lua new file mode 100644 index 0000000..dce8628 --- /dev/null +++ b/config/nvim/lua/config/lsp.lua @@ -0,0 +1,28 @@ +-- enables LSPs and configures useful bindings + +vim.lsp.enable('lua_ls') + +vim.api.nvim_create_autocmd('LspAttach', { + callback = function(ev) + local client = vim.lsp.get_client_by_id(ev.data.client_id) + if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_completion) then + vim.opt.completeopt = { 'menu', 'menuone', 'noinsert', 'fuzzy', 'popup' } + vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true }) + vim.keymap.set('i', '', function() + vim.lsp.completion.get() + end) + end + end +}) + +-- Diagnostics +vim.diagnostic.config({ + -- Use the default configuration + -- virtual_lines = true + + -- Alternatively, customize specific options + virtual_lines = { + -- Only show virtual line diagnostics for the current cursor line + current_line = true, + }, +}) diff --git a/config/nvim/lua/keymaps.lua b/config/nvim/lua/keymaps.lua index aaccb34..d3c13e1 100644 --- a/config/nvim/lua/keymaps.lua +++ b/config/nvim/lua/keymaps.lua @@ -16,5 +16,3 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the left wind vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) - --- vim: ts=2 sts=2 sw=2 et diff --git a/config/nvim/lua/options.lua b/config/nvim/lua/options.lua index 6546a5e..e4e00b8 100644 --- a/config/nvim/lua/options.lua +++ b/config/nvim/lua/options.lua @@ -2,7 +2,7 @@ -- See `:help vim.o` -- Make line numbers default -vim.o.number = true +vim.o.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.o.mouse = 'a' @@ -58,3 +58,10 @@ vim.o.scrolloff = 10 -- instead raise a dialog asking if you wish to save the current file(s) -- See `:help 'confirm'` vim.o.confirm = true + +-- default tab/space configuration +vim.o.tabstop = 2 +vim.o.softtabstop = 2 +vim.o.shiftwidth = 2 +vim.o.expandtab = true + diff --git a/config/nvim/lua/plugins/conform.lua b/config/nvim/lua/plugins/conform.lua new file mode 100644 index 0000000..da20597 --- /dev/null +++ b/config/nvim/lua/plugins/conform.lua @@ -0,0 +1,15 @@ +return { + { + 'stevearc/conform.nvim', + opts = { + formatters_by_ft = { + lua = { 'stylua' }, + javascript = { 'prettier' }, + }, + format_on_save = { + timeout_ms = 500, + lsp_format = 'fallback', + }, + }, + }, +} diff --git a/config/nvim/lua/plugins/telescope.lua b/config/nvim/lua/plugins/telescope.lua index 8eb1c0d..be344dc 100644 --- a/config/nvim/lua/plugins/telescope.lua +++ b/config/nvim/lua/plugins/telescope.lua @@ -1,4 +1,8 @@ return { - 'nvim-telescope/telescope.nvim', tag = '0.1.8', - dependencies = { 'nvim-lua/plenary.nvim' } + { + 'nvim-telescope/telescope.nvim', + tag = '0.1.8', + dependencies = { 'nvim-lua/plenary.nvim', { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' } }, + config = function() end, + }, } diff --git a/zsh/dot-profile b/zsh/dot-profile deleted file mode 100644 index 06418f2..0000000 --- a/zsh/dot-profile +++ /dev/null @@ -1,4 +0,0 @@ -# Install packages locally to prevent interference with packages installed with pacman -PATH=$PATH:~/.npm-global/bin -export GEM_HOME="$(gem env user_gemhome)" -PATH="$PATH:$GEM_HOME/bin" diff --git a/zsh/dot-zshrc b/zsh/dot-zshrc index 96d21d9..ec1d1d4 100644 --- a/zsh/dot-zshrc +++ b/zsh/dot-zshrc @@ -13,13 +13,16 @@ compinit # Simple prompt PROMPT='%F{magenta}%* %F{cyan}%~ %(?.%F{green}.%F{red})%#%f ' +# PATH configuration +PATH=$PATH:~/.npm-global/bin +# Install packages locally to prevent interference with packages installed with pacman +export GEM_HOME="$(gem env user_gemhome)" +PATH="$PATH:$GEM_HOME/bin" + +# Useful aliases alias ls='ls --color=auto' alias vim='nvim' -alias ..='cd ..' -alias ...='cd ../..' -alias ....='cd ../../..' -alias .....='cd ../../../..' -alias ......='cd ../../../../..' +alias open='xdg-open' # Fun tools alias transcat='queercat -f transgender'