Cfn Lsp Extra
Project description
Cfn Lsp Extra
[!NOTE] There is no support for Python 3.14 yet due to incompatibilities with SAM
An experimental cloudformation language server (with support for SAM templates) built on top of cfn-lint and the Cloudformation user guide, aiming to provide hovering, completion, etc. YAML and JSON are supported, though YAML has more features currently implemented (for example snippets) and will give a better experience. Trust me.
Features
| Method | Status |
|---|---|
textDocument/hover |
Done for resources (in particular, required properties for a resource will be auto-expanded), resource properties, subproperties, !Refs and intrinsic functions. |
textDocument/completion |
Done for resources, resource properties, subproperties, property values (for enums), refs, !GetAtts and intrinsic functions. TODO Fn::GetAtt. |
textDocument/definition |
Done for !Refs and !GetAtts. TODO mappings. |
textDocument/publishDiagnostics |
Done through cfnlint. |
Also checkout the changelog.
Installation
First install the executable, pipx is recommended, but you can use pip instead if you like to live dangerously:
pipx install cfn-lsp-extra
Or get the bleeding edge from source:
pipx install git+https://github.com/laurencewarne/cfn-lsp-extra.git@$(git ls-remote git@github.com:laurencewarne/cfn-lsp-extra.git | head -1 | cut -f1)
Or from a local repository:
cd cfn-lsp-extra/
pipx install . --force # Or pipx install '.[parse]' --force
Updating:
pipx upgrade cfn-lsp-extra
Keeping cfnlint Up to Date
Updates to cfn-lsp-extra typically lag behind cfnlint which it uses for diagnostics, which can become an irritation when it leads diagnostics from cfn-lsp-extra becoming outdated and new desirable lint rules not showing. Assuming you installed cfnlint using pipx, you can use:
alias cfn-lsp-extra='env PYTHONPATH=$HOME/.local/pipx/venvs/cfn-lint/lib/python<PYTHON_VERSION>/site-packages/ cfn-lsp-extra'
To ensure cfn-lsp-extra uses your system cfnlint version. Note This comes with some risk with respect to clashing dependencies, but I would expect it to generally work as long as cfnlint and cfn-lsp-extra aren't wildly out of date.
Emacs
Install the lsp-cfn.el package.
Neovim
Make sure you're running at least 0.8, then add the following in ~/.config/nvim/filetype.lua:
vim.filetype.add {
pattern = {
['.*'] = {
priority = math.huge,
function(path, bufnr)
local line1 = vim.api.nvim_buf_get_lines(bufnr, 0, 1, false)[1] or ""
local line2 = vim.api.nvim_buf_get_lines(bufnr, 1, 2, false)[1] or ""
if vim.regex([[^AWSTemplateFormatVersion]]):match_str(line1) ~= nil or
vim.regex([[AWS::Serverless-2016-10-31]]):match_str(line1) ~= nil then
return 'yaml.cloudformation'
elseif vim.regex([[["']AWSTemplateFormatVersion]]):match_str(line1) ~= nil or
vim.regex([[["']AWSTemplateFormatVersion]]):match_str(line2) ~= nil or
vim.regex([[AWS::Serverless-2016-10-31]]):match_str(line1) ~= nil or
vim.regex([[AWS::Serverless-2016-10-31]]):match_str(line2) ~= nil then
return 'json.cloudformation'
end
end,
},
},
}
Then you can use one of:
- Neovim's built-in LSP client (requires 0.11.0 or greater):
vim.lsp.config("cfn-lsp-extra", {
cmd = { os.getenv("HOME") .. '/.local/bin/cfn-lsp-extra' },
filetypes = { 'yaml.cloudformation', 'json.cloudformation' },
root_markers = { '.git' },
settings = {
documentFormatting = false,
},
})
vim.lsp.enable("cfn-lsp-extra")
nvim-lspconfig, which is required for neovim below version 0.11.0:
require('lspconfig.configs').cfn_lsp = {
default_config = {
cmd = { os.getenv("HOME") .. '/.local/bin/cfn-lsp-extra' },
filetypes = { 'yaml.cloudformation', 'json.cloudformation' },
root_dir = function(fname)
return require('lspconfig').util.find_git_ancestor(fname) or vim.fn.getcwd()
end,
settings = {
documentFormatting = false,
},
},
}
require('lspconfig').cfn_lsp.setup{}
let g:LanguageClient_serverCommands = {
\ 'yaml.cloudformation': ['~/.local/bin/cfn-lsp-extra'],
\ 'json.cloudformation': ['~/.local/bin/cfn-lsp-extra']
\ }
Patches documenting integration for other editors are very welcome!
Development
cfn-lsp-extra uses uv for virtualenv and general project management.
Common commands:
uv run pytest # unit tests
uv run pytest --run-integration # integration tests
uv run ruff check # flake8 lints
uv run mypy cfn_lsp_extra/ # mypy checks
Alternatives
vscode-cfn-lint
cfn-lint
Note this is used by cfn-lsp-extra under the hood to generate diagnostics. One difference with cfn-lsp-extra is that diagnostics will be refreshed every time you make a change to the document, in other words you don't need to save the file.
yamlls
You can use yamlls in conjunction with the Cloudformation schema at https://www.schemastore.org/json/ as an alternative. For Emacs, lsp-mode can install yamlls for you, from there you could do something like:
(defun my-yamlls-cloudformation-setup ()
;; There's also one for serverless
(lsp-yaml-set-buffer-schema "https://raw.githubusercontent.com/awslabs/goformation/master/schema/cloudformation.schema.json")
(setq-local
lsp-yaml-custom-tags
["!And"
"!Base64"
"!Cidr"
"!Equals"
"!FindInMap sequence"
"!GetAZs"
"!GetAtt"
"!If"
"!ImportValue"
"!Join sequence"
"!Not"
"!Or"
"!Ref Scalar"
"!Ref"
"!Select"
"!Split"
"!Sub"
"!fn"]))
;; Using the mode defined by https://www.emacswiki.org/emacs/CfnLint
(add-hook 'cfn-yaml-mode-hook #'my-yamlls-cloudformation-setup)
(add-hook 'cfn-yaml-mode-hook #'lsp-deferred)
This will give you completions (and some support for value completions?), though no hover documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cfn_lsp_extra-0.7.5.tar.gz.
File metadata
- Download URL: cfn_lsp_extra-0.7.5.tar.gz
- Upload date:
- Size: 3.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ac711a75f55c0e1aaa93e4c89d449109bb762f0c85b1563182c9657c119da67
|
|
| MD5 |
73b7d09764c10fda0828a1d9057d46b0
|
|
| BLAKE2b-256 |
20367947683ebd7816272c80c4a47a6cc17b8f6cf9f4eb0bfc94d346e0562833
|
Provenance
The following attestation bundles were made for cfn_lsp_extra-0.7.5.tar.gz:
Publisher:
release.yml on LaurenceWarne/cfn-lsp-extra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cfn_lsp_extra-0.7.5.tar.gz -
Subject digest:
2ac711a75f55c0e1aaa93e4c89d449109bb762f0c85b1563182c9657c119da67 - Sigstore transparency entry: 788336590
- Sigstore integration time:
-
Permalink:
LaurenceWarne/cfn-lsp-extra@db4fdaf4def9bf5b7ce7a043779283162b41a242 -
Branch / Tag:
refs/tags/v0.7.5 - Owner: https://github.com/LaurenceWarne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@db4fdaf4def9bf5b7ce7a043779283162b41a242 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cfn_lsp_extra-0.7.5-py3-none-any.whl.
File metadata
- Download URL: cfn_lsp_extra-0.7.5-py3-none-any.whl
- Upload date:
- Size: 3.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f204d8ead7e15aa74a6a5d9a7b3627c5ea02dde9ff9406658a485e0201026bec
|
|
| MD5 |
fceab68c144c29c177299e7f4bed7c55
|
|
| BLAKE2b-256 |
8fafc598460a3cd6d1c5beb15974a07f7c219c11e712fe8698c0f830d00650bb
|
Provenance
The following attestation bundles were made for cfn_lsp_extra-0.7.5-py3-none-any.whl:
Publisher:
release.yml on LaurenceWarne/cfn-lsp-extra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cfn_lsp_extra-0.7.5-py3-none-any.whl -
Subject digest:
f204d8ead7e15aa74a6a5d9a7b3627c5ea02dde9ff9406658a485e0201026bec - Sigstore transparency entry: 788336593
- Sigstore integration time:
-
Permalink:
LaurenceWarne/cfn-lsp-extra@db4fdaf4def9bf5b7ce7a043779283162b41a242 -
Branch / Tag:
refs/tags/v0.7.5 - Owner: https://github.com/LaurenceWarne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@db4fdaf4def9bf5b7ce7a043779283162b41a242 -
Trigger Event:
push
-
Statement type: