Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.72 KB | None | 0 0
  1. local util = require 'lspconfig.util'
  2. local async = require 'lspconfig.async'
  3. local mod_cache = nil
  4.  
  5. vim.lsp.start({
  6.     name = "gopls",
  7.     cmd = { "path/to/yout/gopls/executable" },
  8.      root_dir = function(fname)
  9.       if not mod_cache then
  10.         local result = async.run_command { 'go', 'env', 'GOMODCACHE' }
  11.         if result and result[1] then
  12.           mod_cache = vim.trim(result[1])
  13.         end
  14.       end
  15.       if fname:sub(1, #mod_cache) == mod_cache then
  16.         local clients = vim.lsp.get_active_clients { name = 'gopls' }
  17.         if #clients > 0 then
  18.           return clients[#clients].config.root_dir
  19.         end
  20.       end
  21.       return util.root_pattern('go.work', 'go.mod', '.git')(fname)
  22.     end,
  23. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement