Jelajahi Sumber

nixpkgs/neovim: add lua-language-server and format

Thomas Dy 3 minggu lalu
induk
melakukan
18f38ee87f

+ 4 - 0
.config/nixpkgs/neovim/.editorconfig

@@ -0,0 +1,4 @@
+[*.lua]
+indent_style = space
+indent_size = 2
+quote_style = single

+ 8 - 0
.config/nixpkgs/neovim/.luarc.json

@@ -0,0 +1,8 @@
+{
+  "diagnostics.globals": [
+    "vim"
+  ],
+  "diagnostics.globalsRegex": [
+    "^Mini"
+  ]
+}

+ 4 - 4
.config/nixpkgs/neovim/config/after/compiler/typescript.lua

@@ -1,6 +1,6 @@
-if vim.fn.executable("tsgo") == 1 then
-  vim.bo.makeprg = "tsgo --noEmit --pretty false $*"
+if vim.fn.executable('tsgo') == 1 then
+  vim.bo.makeprg = 'tsgo --noEmit --pretty false $*'
 else
-  vim.bo.makeprg = "tsc --noEmit --incremental $*"
+  vim.bo.makeprg = 'tsc --noEmit --incremental $*'
 end
-vim.bo.errorformat = "%+A %#%f %#(%l\\,%c): %m,%C%m"
+vim.bo.errorformat = '%+A %#%f %#(%l\\,%c): %m,%C%m'

+ 3 - 3
.config/nixpkgs/neovim/config/lua/user/autocmd.lua

@@ -23,7 +23,7 @@ vim.api.nvim_create_autocmd('TermClose', {
 
 -- automatically enter/leave terminal mode
 vim.api.nvim_create_autocmd('TermOpen', { command = 'startinsert' })
-vim.api.nvim_create_autocmd({'WinEnter','BufWinEnter'}, {
+vim.api.nvim_create_autocmd({ 'WinEnter', 'BufWinEnter' }, {
   pattern = 'term://*',
   command = 'startinsert',
 })
@@ -37,10 +37,10 @@ vim.api.nvim_create_autocmd('User', {
   pattern = 'MiniFilesActionRename',
   callback = function(opts)
     local params = {
-      files = {{
+      files = { {
         oldUri = vim.uri_from_fname(opts.data.from),
         newUri = vim.uri_from_fname(opts.data.to),
-      }}
+      } }
     }
     local bufnr = vim.fn.bufadd(opts.data.to)
 

+ 32 - 29
.config/nixpkgs/neovim/config/lua/user/lsp.lua

@@ -3,15 +3,15 @@ vim.diagnostic.config({
   virtual_text = { severity = { min = vim.diagnostic.severity.WARN } },
 })
 
-vim.lsp.config("*", {
+vim.lsp.config('*', {
   flags = {
     debounce_text_changes = 250,
   }
 })
 
 local function read_helix_config()
-  local tinytoml = require("tinytoml")
-  local data = vim.secure.read(".helix/languages.toml")
+  local tinytoml = require('tinytoml')
+  local data = vim.secure.read('.helix/languages.toml')
   if data ~= nil then
     local status, data = pcall(tinytoml.parse, data, { load_from_string = true })
     if status then
@@ -21,18 +21,18 @@ local function read_helix_config()
   return {}
 end
 
-vim.lsp.enable("bashls");
-vim.lsp.enable("eslint");
+vim.lsp.enable('bashls');
+vim.lsp.enable('eslint');
 
-if vim.fn.executable("dprint") == 1 then
-  local version = vim.version.parse(vim.fn.system("dprint --version"))
-  if vim.version.cmp(version, {0,45,0}) >= 0 then
-    vim.lsp.enable("dprint")
+if vim.fn.executable('dprint') == 1 then
+  local version = vim.version.parse(vim.fn.system('dprint --version'))
+  if vim.version.cmp(version, { 0, 45, 0 }) >= 0 then
+    vim.lsp.enable('dprint')
   end
 end
 
-if vim.fn.executable("deno") == 1 then
-  vim.lsp.enable("deno");
+if vim.fn.executable('deno') == 1 then
+  vim.lsp.enable('deno');
 else
   local preferences = {
     importModuleSpecifierPreference = 'non-relative',
@@ -40,7 +40,8 @@ else
     providePrefixAndSuffixTextForRename = false,
   }
 
-  local helix_preferences = vim.tbl_get(read_helix_config(), 'language-server', 'typescript-language-server', 'config', 'preferences')
+  local helix_preferences = vim.tbl_get(read_helix_config(), 'language-server', 'typescript-language-server', 'config',
+    'preferences')
   if helix_preferences ~= nil then
     preferences = vim.tbl_deep_extend('force', preferences, helix_preferences)
   end
@@ -58,7 +59,7 @@ else
     }
   end
 
-  vim.lsp.config("ts_ls", {
+  vim.lsp.config('ts_ls', {
     init_options = {
       completionDisableFilterText = true,
       preferences = preferences,
@@ -82,43 +83,45 @@ else
       })
     end,
   })
-  vim.lsp.enable("ts_ls")
+  vim.lsp.enable('ts_ls')
 end
 
-if vim.fn.executable("gopls") == 1 then
-  vim.lsp.enable("gopls")
+if vim.fn.executable('gopls') == 1 then
+  vim.lsp.enable('gopls')
 end
 
-if vim.fn.executable("ruby-lsp") == 1 then
-  vim.lsp.config("ruby_lsp", {
+if vim.fn.executable('ruby-lsp') == 1 then
+  vim.lsp.config('ruby_lsp', {
     init_options = {
       enabledFeatures = {
         formatting = false,
       },
     }
   })
-  vim.lsp.enable("ruby_lsp")
+  vim.lsp.enable('ruby_lsp')
 end
 
-if vim.fn.executable("nil") == 1 then
-  vim.lsp.enable("nil_ls")
+if vim.fn.executable('nil') == 1 then
+  vim.lsp.enable('nil_ls')
 end
 
-if vim.fn.executable("jdtls") == 1 then
-  vim.lsp.config("jdtls", {
+if vim.fn.executable('jdtls') == 1 then
+  vim.lsp.config('jdtls', {
     handlers = {
-      ["$/progress"] = function()
+      ['$/progress'] = function()
         -- this is quite noisy so just disable it
       end
     },
   })
-  vim.lsp.enable("jdtls")
+  vim.lsp.enable('jdtls')
 end
 
+vim.lsp.enable('lua_ls')
+
 -- custom LSP servers
-vim.lsp.config("elvish", {
-  cmd = {'elvish', '--lsp'},
-  filetypes = {'elvish'},
+vim.lsp.config('elvish', {
+  cmd = { 'elvish', '--lsp' },
+  filetypes = { 'elvish' },
   settings = {},
 })
-vim.lsp.enable("elvish")
+vim.lsp.enable('elvish')

+ 11 - 7
.config/nixpkgs/neovim/config/lua/user/mappings.lua

@@ -1,14 +1,14 @@
 local opts = { silent = true }
 
 -- ; as :
-vim.keymap.set({'n', 'v'}, ';', ':')
+vim.keymap.set({ 'n', 'v' }, ';', ':')
 
 -- leave insert mode via jj
 vim.keymap.set('i', 'jj', '<ESC>', opts)
 
 -- j/k with wraps
-vim.keymap.set({'n', 'v'}, 'j', 'gj', opts)
-vim.keymap.set({'n', 'v'}, 'k', 'gk', opts)
+vim.keymap.set({ 'n', 'v' }, 'j', 'gj', opts)
+vim.keymap.set({ 'n', 'v' }, 'k', 'gk', opts)
 
 -- treesitter navigation
 vim.keymap.set({ 'n', 'v' }, '<C-k>', '<cmd>Treewalker Up<cr>', opts)
@@ -81,12 +81,16 @@ vim.keymap.set('i', '<C-;>', function() toggle_end_char(';') end, opts)
 
 -- diagnostics
 vim.keymap.set('n', '<space>e', function() vim.diagnostic.open_float() end, opts)
-vim.keymap.set('n', '[d', function() vim.diagnostic.jump({ count = -1, float = true, severity = vim.diagnostic.severity.ERROR }) end, opts)
-vim.keymap.set('n', ']d', function() vim.diagnostic.jump({ count = 1, float = true, severity = vim.diagnostic.severity.ERROR }) end, opts)
+vim.keymap.set('n', '[d',
+  function() vim.diagnostic.jump({ count = -1, float = true, severity = vim.diagnostic.severity.ERROR }) end, opts)
+vim.keymap.set('n', ']d',
+  function() vim.diagnostic.jump({ count = 1, float = true, severity = vim.diagnostic.severity.ERROR }) end, opts)
 vim.keymap.set('n', '[D', function() vim.diagnostic.jump({ count = -1, float = true }) end, opts)
 vim.keymap.set('n', ']D', function() vim.diagnostic.jump({ count = 1, float = true }) end, opts)
-vim.keymap.set('n', '<space>qe', function() vim.diagnostic.setqflist({ severity = vim.diagnostic.severity.ERROR }) end, opts)
-vim.keymap.set('n', '<space>qw', function() vim.diagnostic.setqflist({ severity = { min = vim.diagnostic.severity.WARN } }) end, opts)
+vim.keymap.set('n', '<space>qe', function() vim.diagnostic.setqflist({ severity = vim.diagnostic.severity.ERROR }) end,
+  opts)
+vim.keymap.set('n', '<space>qw',
+  function() vim.diagnostic.setqflist({ severity = { min = vim.diagnostic.severity.WARN } }) end, opts)
 vim.keymap.set('n', '<space>qd', function() vim.diagnostic.setqflist({}) end, opts)
 vim.keymap.set('n', '<space>qc', '<cmd>cclose<CR>', opts)
 

+ 28 - 28
.config/nixpkgs/neovim/config/lua/user/plugins.lua

@@ -15,7 +15,7 @@ vim.filetype.add({
 -- helpers
 local function resolve_git_path(buf_id)
   local bufname = vim.api.nvim_buf_get_name(buf_id)
-  if not vim.startswith(bufname, "fugitive://") then
+  if not vim.startswith(bufname, 'fugitive://') then
     return false
   end
 
@@ -23,7 +23,7 @@ local function resolve_git_path(buf_id)
   local resolved_path = parsed[1]
   local repo = parsed[2]
 
-  if resolved_path == "" then
+  if resolved_path == '' then
     return false
   end
 
@@ -88,23 +88,23 @@ require('telescope').setup({
 
     vimgrep_arguments = {
       -- defaults
-      "rg",
-      "--color=never",
-      "--no-heading",
-      "--with-filename",
-      "--line-number",
-      "--column",
-      "--smart-case",
+      'rg',
+      '--color=never',
+      '--no-heading',
+      '--with-filename',
+      '--line-number',
+      '--column',
+      '--smart-case',
       -- search "hidden" files except git folder
-      "--hidden",
-      "--iglob=!.git"
+      '--hidden',
+      '--iglob=!.git'
     },
 
     -- ignore things we're likely not to edit
     file_ignore_patterns = {
-      "%.zip$",
-      "%.yarn/releases/",
-      "%.yarn/plugins/"
+      '%.zip$',
+      '%.yarn/releases/',
+      '%.yarn/plugins/'
     },
 
     -- picker history
@@ -123,7 +123,7 @@ require('telescope').setup({
       },
     },
     find_files = {
-      find_command = { "fd", "--type", "f", "--strip-cwd-prefix" }
+      find_command = { 'fd', '--type', 'f', '--strip-cwd-prefix' }
     },
     git_commits = {
       mappings = commit_mappings,
@@ -154,16 +154,16 @@ end
 _G.commit_files = function(opts)
   local resolved = resolve_git_path(0)
   if not resolved then
-    vim.print("current file is not a fugitive path")
+    vim.print('current file is not a fugitive path')
     return
   end
 
   opts = opts or {}
   telescope_pickers.new(opts, {
     prompt_title = resolved.commit,
-    finder = telescope_finders.new_oneshot_job({ "git", "ls-tree", "--name-only", "-r", resolved.commit }, {
+    finder = telescope_finders.new_oneshot_job({ 'git', 'ls-tree', '--name-only', '-r', resolved.commit }, {
       entry_maker = function(entry)
-        local path = string.format("fugitive://%s//%s/%s", resolved.repo, resolved.commit, entry)
+        local path = string.format('fugitive://%s//%s/%s', resolved.repo, resolved.commit, entry)
         return {
           path = path,
           value = entry,
@@ -210,14 +210,14 @@ MiniDiff.setup({
     MiniDiff.gen_source.git(),
     -- handle fugitive paths
     {
-      name = "fugitive",
+      name = 'fugitive',
       attach = function(buf_id)
         local resolved = resolve_git_path(buf_id)
-        if not resolved or resolved.path == "" then
+        if not resolved or resolved.path == '' then
           return false
         end
 
-        local source = vim.fn.FugitiveFind(string.format("%s~1:%s", resolved.commit, resolved.path))
+        local source = vim.fn.FugitiveFind(string.format('%s~1:%s', resolved.commit, resolved.path))
         local text = vim.fn['fugitive#readfile'](source)
         MiniDiff.set_ref_text(buf_id, text)
       end
@@ -242,8 +242,8 @@ require('mini.statusline').setup({
       local location      = MiniStatusline.section_location({ trunc_width = 75 })
 
       return MiniStatusline.combine_groups({
-        { hl = mode_hl,                  strings = { mode } },
-        { hl = 'MiniStatuslineDevinfo',  strings = { git, diagnostics } },
+        { hl = mode_hl,                 strings = { mode } },
+        { hl = 'MiniStatuslineDevinfo', strings = { git, diagnostics } },
         '%<', -- Mark general truncate point
         { hl = 'MiniStatuslineFilename', strings = { filename } },
         '%=', -- End left alignment
@@ -341,9 +341,9 @@ require('nvim-treesitter.configs').setup({
   incremental_selection = {
     enable = true,
     keymaps = {
-      init_selection = "]t",
-      node_incremental = "]t",
-      node_decremental = "[t",
+      init_selection = ']t',
+      node_incremental = ']t',
+      node_decremental = '[t',
     },
   },
   textobjects = {
@@ -398,8 +398,8 @@ require('blink.cmp').setup({
     menu = {
       draw = {
         columns = {
-          { "label", "label_description", gap = 1 },
-          { "kind" },
+          { 'label', 'label_description', gap = 1 },
+          { 'kind' },
         },
       },
     },

+ 2 - 2
.config/nixpkgs/neovim/config/lua/user/theme.lua

@@ -18,7 +18,7 @@ local active_ns = vim.api.nvim_create_namespace('active')
 
 function init_active_ns()
   local hls = vim.api.nvim_get_hl(0, {})
-  for k,v in ipairs(hls) do
+  for k, v in ipairs(hls) do
     vim.api.nvim_set_hl(active_ns, k, v)
   end
 
@@ -49,7 +49,7 @@ vim.api.nvim_create_autocmd('ColorScheme', {
     vim.api.nvim_set_hl(0, 'MiniIndentscopeSymbol', { link = 'Whitespace' })
 
     local configuration = vim.fn['sonokai#get_configuration']()
-    local palette = vim.fn['sonokai#get_palette'](configuration.style, {[vim.type_idx]=vim.types.dictionary})
+    local palette = vim.fn['sonokai#get_palette'](configuration.style, { [vim.type_idx] = vim.types.dictionary })
 
     vim.fn['sonokai#highlight']('MiniStatuslineModeNormal', palette.black, palette.blue)
     vim.fn['sonokai#highlight']('MiniStatuslineModeCommand', palette.black, palette.yellow)

+ 6 - 0
.config/nixpkgs/neovim/flake.nix

@@ -31,6 +31,12 @@
         packages.neovim = pkgs.callPackage ./neovim.nix {};
         packages.neovim-minimal = (pkgs.callPackage ./neovim.nix {}).minimal;
         packages.default = self.packages.${system}.neovim;
+
+        devShells.default = pkgs.mkShell {
+          packages = with pkgs; [
+            lua-language-server
+          ];
+        };
       }
     );
 }