Configurations - WhoIsSethDaniel/goldsmith.nvim GitHub Wiki
This page provides examples of configuring Goldsmith with particular emphasis on the ways in which the supported LSP servers can be configured. The Goldsmith help documentation gives a bit more technical detail about how it all works, including defaults configured for each server.
All code samples are in Lua. If you are using Vimscript for configuration you can simply wrap all Lua code in a Lua here-doc. e.g.:
lua<<EOF
...lua code...
EOF
Supported LSP Servers
At the time of this writing Goldsmith supports two LSP servers: gopls and null-ls. For the best experience when using Goldsmith you should use both services.
Defaults
Goldsmith can configure all services for you, and even when it doesn't do all the work it can edit your configuration. See the defaults page for information on the defaults that Goldsmith provides.
Basic Configuration
Configure Everything For Me
require 'goldsmith'.config()
This will configure all supported LSP servers automatically. This includes running lspconfig's setup() or null's setup() for each server Goldsmith configures. If you already have configuration for gopls and/or null-ls this is likely not what you want to do. You especially never want to run lspconfig's setup() more than once for the same server.
Running Goldsmith's config() is not required. If you do not run config() it is the same as running config() with no arguments. That is, you get all the defaults.
Configure Nothing For Me
require 'goldsmith'.config({ autoconfig = false })
This turns off auto configuration. Turning off auto configuration will ensure that Goldsmith will not attempt to configure any supported LSP servers. This is not recommended as it means that at least a few features will not be supported.
More Complex Configurations
You can pass complete configurations for gopls and null-ls to Goldsmith. Some editing will be done by Goldsmith but no value you pass in will be changed. Any conflict between what Goldsmith wants to set and what the user passes in will always favor the user's configuration.
Configurations may be passed as tables or as functions that must return a table. It is recommended to use functions for highly dynamic configurations.
Custom gopls Configuration
If you want to pass a pre-existing gopls configuration to gopls or you simply want to slightly tweak the Goldsmith configuration for gopls you can do this:
require'goldsmith'.config({
...
gopls = {
config = function()
return {
cmd = { "gopls" },
settings = {
gopls = {
gofumpt = false,
codelenses = {
gc_details = false
}
}
}
}
end
},
...
})
The above sets the server command for gopls
to the plain gopls
with no arguments. It also changes the Goldsmith defaults for
gofumpt and codelenses.gc_details.
You can pass anything that you would have also passed to lspconfig.
When you pass configuration to Goldsmith you do not (and should not) need to call lspconfig's setup() function for that server. Goldsmith will do this for you.
Custom null-ls Configuration
If you want to pass a pre-existing null-ls configuration to null-ls or you simply want to slightly tweak the Goldsmith configuration for null-ls you can do this:
require'goldsmith'.config({
...
null = {
run_setup = true, -- this is the default
config = {
sources = {
fmt.stylua,
fmt.shfmt.with { args = { '-i=4', '-ci', '-s', '-bn' } },
diag.vint,
diag.shellcheck
}
}
},
...
})
The above tells null-ls to run a number of other formatters and linters that the user is interested in. Goldsmith will add the appropriate Go-related formatters and linters to the configuration and then will call null's setup() function. You can also set null.run_setup to false. This means that Goldsmith will not run null's setup function and you must do so.
You can pass anything that you would have also passed to null's setup function.
Complete Examples
With just lspconfig
Scenario: We want Goldsmith to configure our Go-related servers, but we also have other servers that we want lspconfig to configure. All servers are installed manually.
The below assumes the following servers are installed manually: gopls, efm, null-ls, clangd.
require'goldsmith'.config({
...
gopls = {
config = function()
return {
settings = {
gopls = {
gofumpt = false,
semanticTokens = true,
codelenses = {
gc_details = false
}
}
}
}
end
},
null = {
config = function()
return { sources = { fmt.stylua, diag.vint } }
end
},
...
})
[...]
local function setup_servers()
local servers = { 'gopls', 'efm', 'null-ls', 'clangd' }
for _, server in pairs(servers) do
if not require('goldsmith').needed(server) then
local config = get_config(server)
require('lspconfig')[server].setup(config)
end
end
end
setup_servers()
The above is a fairly complete example of how you can setup your servers with the help of Goldsmith. One important thing to note is that require('goldsmith').needed(server) in the above will return false if the given server is not one that Goldsmith is familiar with. It returns true otherwise. It can be used to more easily skip over Goldsmith-supported servers when configuring a large number of servers.
With nvim-lsp-installer
Scenario: We want Goldsmith to configure our Go-related servers, but we also have other servers that we do want lspconfig to configure and we have nvim-lsp-installer installed.
The below assumes the following servers are installed by nvim-lsp-installer: gopls, efm. The below assumes the following servers are installed manually: null-ls, clangd.
require'goldsmith'.config({
...
gopls = {
config = function()
return {
settings = {
gopls = {
gofumpt = false,
semanticTokens = true,
codelenses = {
gc_details = false
}
}
}
}
end
},
null = {
config = function()
return { sources = { fmt.stylua, diag.shellcheck, fmt.shfmt } }
end
},
...
})
[...]
local function setup_servers()
local servers = require'nvim-lsp-installer'.get_installed_servers()
for _, server in pairs(servers) do
if not require('goldsmith').needed(server.name) then
local config = get_config(server.name)
require'lspconfig'.[server.name].setup(config)
end
end
require'lspconfig'.clangd.setup{}
end
setup_servers()
The above is a fairly complete example of how you can setup your servers with the help of Goldsmith. One thing to note is that require('goldsmith').needed(server.name) in the above will return false if the given server is not one that Goldsmith is familiar with. It returns true otherwise. It can be used to more easily skip over Goldsmith-supported servers when configuring a large number of servers.
Reporting Problems / Asking Questions
Goldsmith is very new. It works for the author, but does it work for you? If not, please consider asking a question or reporting a problem.