This guide assumes you have installed the server by following instructions in the README.md if that is applicable to your client (i.e. if the client doesn't download the server itself).
Instructions for popular IDEs are below and pull requests for updates or addition of more IDEs are welcomed.
See also settings to understand how you may configure the settings.
- Install lsp-mode
- Add the following to your
.emacs
:
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection '("/path/to/terraform-ls/terraform-ls" "serve"))
:major-modes '(terraform-mode)
:server-id 'terraform-ls))
(add-hook 'terraform-mode-hook #'lsp)
The last line can instead be (add-hook 'terraform-mode-hook #'lsp-deferred)
if you prefer the server to lazy load.
- Install LSP Support plugin
- Open Settings
- Go to
Languages & Frameworks → Language Server Protocol → Server Definitions
- Pick
Executable
- set
Extension
totf
- set
Path
toterraform-ls
- set
Args
toserve
- Pick
- Confirm by clicking
Apply
Please note that the Terraform plugin provides overlapping functionality (and more features at the time of writing). As a result having both enabled at the same time may result in suboptimal UX, such as duplicate completion candidates.
- Install the LSP package
- Add the following snippet to your User
LSP.sublime-settings
(editable viaPreferences → Package Settings → LSP → Settings
or via the command pallete →Preferences: LSP Settings
)
{
"clients": {
"terraform": {
"command": ["terraform-ls", "serve"],
"enabled": true,
"languageId": "terraform",
"scopes": ["source.terraform"],
"syntaxes": ["Packages/Terraform/Terraform.sublime-syntax"]
}
}
}
- Install the coc.nvim plugin
- Add the following snippet to the
coc-setting.json
file (editable via:CocConfig
in NeoVim)
{
"languageserver": {
"terraform": {
"command": "terraform-ls",
"args": ["serve"],
"filetypes": [
"terraform",
"tf"
],
"initializationOptions": {},
"settings": {}
}
}
}
Make sure to read through the example vim configuration of the plugin, especially key remapping, which is required for completion to work correctly:
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
- Install the following plugins:
- Add the following to your
.vimrc
:
if executable('terraform-ls')
au User lsp_setup call lsp#register_server({
\ 'name': 'terraform-ls',
\ 'cmd': {server_info->['terraform-ls', 'serve']},
\ 'whitelist': ['terraform'],
\ })
endif
- Install Terraform VS Code Extension
>=2.0.0
- Latest version of the language server should be installed automatically on VS Code launch
- In case you are upgrading from v1 you may need to reset the settings to reflect v2 default, as shown below
"terraform.languageServer": {
"args": [
"serve",
],
},