Bläddra i källkod

nixpkgs/neovim: add exrc and do not enable LSP by default

Thomas Dy 2 dagar sedan
förälder
incheckning
cd46b272f8

+ 1 - 0
.config/git/ignore

@@ -1,2 +1,3 @@
 .DS_Store
 .rgignore
+.nvim.lua

+ 19 - 0
.config/nixpkgs/neovim/config/lua/user/exrc.lua

@@ -0,0 +1,19 @@
+-- exrc does not work when using -u. Also, unlike exrc, we only evaluate
+-- .nvim.lua and only the one in the project root.
+
+local dirs = vim.fs.find({ '.git' }, {
+  type = 'directory',
+  upward = true,
+  stop = vim.env.HOME,
+})
+
+if #dirs == 1 then
+  local file = vim.fs.joinpath(vim.fs.dirname(dirs[1]), '.nvim.lua')
+  local stat = vim.uv.fs_stat(file)
+  if stat and stat.type == 'file' then
+    local trusted = vim.secure.read(file)
+    if trusted then
+      assert(loadstring(trusted, '@' .. file))()
+    end
+  end
+end

+ 1 - 0
.config/nixpkgs/neovim/config/lua/user/init.lua

@@ -4,3 +4,4 @@ require('user.terminal')
 require('user.lsp')
 require('user.commands')
 require('user.theme')
+require('user.exrc')

+ 44 - 79
.config/nixpkgs/neovim/config/lua/user/lsp.lua

@@ -1,5 +1,3 @@
-local util = require('user.util')
-
 vim.diagnostic.config({
   -- only show virtual text for WARN and higher
   virtual_text = { severity = { min = vim.diagnostic.severity.WARN } },
@@ -11,79 +9,49 @@ vim.lsp.config('*', {
   }
 })
 
-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')
-  end
-end
-
-if vim.fn.executable('deno') == 1 then
-  vim.lsp.enable('deno');
-else
-  local preferences = {
-    importModuleSpecifierPreference = 'non-relative',
-    -- this prevents renames from aliasing when destructuring
-    providePrefixAndSuffixTextForRename = false,
+local preferences = {
+  importModuleSpecifierPreference = 'non-relative',
+  -- this prevents renames from aliasing when destructuring
+  providePrefixAndSuffixTextForRename = false,
+}
+
+local function make_settings()
+  -- we disable formatting but these are still used when performing some code
+  -- actions
+  local format = {
+    indentSize = vim.bo.shiftwidth,
+    convertTabsToSpaces = vim.o.expandtab,
+  }
+  return {
+    javascript = { format = format },
+    typescript = { format = format },
   }
-
-  local helix_preferences = vim.tbl_get(
-    util.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
-
-  local function make_settings()
-    -- we disable formatting but these are still used when performing some code
-    -- actions
-    local format = {
-      indentSize = vim.bo.shiftwidth,
-      convertTabsToSpaces = vim.o.expandtab,
-    }
-    return {
-      javascript = { format = format },
-      typescript = { format = format },
-    }
-  end
-
-  vim.lsp.config('ts_ls', {
-    init_options = {
-      completionDisableFilterText = true,
-      preferences = preferences,
-    },
-    settings = make_settings(),
-    handlers = {
-      ['$/typescriptVersion'] = function(err, result, ctx, config)
-        vim.notify(string.format('Typescript %s', result.version))
-      end,
-    },
-    on_init = function(client)
-      -- mark tsserver as not having formatting available as we rely on
-      -- eslint and dprint for that
-      client.server_capabilities.documentFormattingProvider = false
-      client.server_capabilities.documentRangeFormattingProvider = false
-
-      -- we only really know our settings once we've opened a file so report
-      -- the new formatting settings
-      client:notify(vim.lsp.protocol.Methods.workspace_didChangeConfiguration, {
-        settings = make_settings(),
-      })
-    end,
-  })
-  vim.lsp.enable('ts_ls')
 end
 
-vim.lsp.enable('svelte')
+vim.lsp.config('ts_ls', {
+  init_options = {
+    completionDisableFilterText = true,
+    preferences = preferences,
+  },
+  settings = make_settings(),
+  handlers = {
+    ['$/typescriptVersion'] = function(err, result, ctx, config)
+      vim.notify(string.format('Typescript %s', result.version))
+    end,
+  },
+  on_init = function(client)
+    -- mark tsserver as not having formatting available as we rely on
+    -- eslint and dprint for that
+    client.server_capabilities.documentFormattingProvider = false
+    client.server_capabilities.documentRangeFormattingProvider = false
 
-vim.lsp.enable('gopls')
+    -- we only really know our settings once we've opened a file so report
+    -- the new formatting settings
+    client:notify(vim.lsp.protocol.Methods.workspace_didChangeConfiguration, {
+      settings = make_settings(),
+    })
+  end,
+})
 
 vim.lsp.config('ruby_lsp', {
   init_options = {
@@ -92,7 +60,6 @@ vim.lsp.config('ruby_lsp', {
     },
   }
 })
-vim.lsp.enable('ruby_lsp')
 
 vim.lsp.config('pyright', {
   handlers = {
@@ -101,7 +68,6 @@ vim.lsp.config('pyright', {
     end
   },
 })
-vim.lsp.enable('pyright')
 
 vim.lsp.config('nil_ls', {
   on_init = function(client)
@@ -111,8 +77,6 @@ vim.lsp.config('nil_ls', {
   end,
 })
 
-vim.lsp.enable('nil_ls')
-
 vim.lsp.config('jdtls', {
   handlers = {
     ['$/progress'] = function()
@@ -120,9 +84,6 @@ vim.lsp.config('jdtls', {
     end
   },
 })
-vim.lsp.enable('jdtls')
-
-vim.lsp.enable('lua_ls')
 
 -- custom LSP servers
 vim.lsp.config('elvish', {
@@ -130,7 +91,6 @@ vim.lsp.config('elvish', {
   filetypes = { 'elvish' },
   settings = {},
 })
-vim.lsp.enable('elvish')
 
 -- diagnostics
 vim.keymap.set('n', '<space>e', function() vim.diagnostic.open_float() end)
@@ -215,3 +175,8 @@ vim.api.nvim_create_autocmd('User', {
   end,
   nested = true,
 })
+
+-- only enable LSP servers for shell languages, otherwise they have to be
+-- enabled manually or via .nvim.lua
+vim.lsp.enable('bashls')
+vim.lsp.enable('elvish')

+ 0 - 12
.config/nixpkgs/neovim/config/lua/user/util.lua

@@ -25,16 +25,4 @@ function M.resolve_git_path(buf_id)
   }
 end
 
-function M.read_helix_config()
-  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
-      return data
-    end
-  end
-  return {}
-end
-
 return M