Skip to content

jakub-m/lsp-helm-values

Repository files navigation

Kubernetes YAML LSP

LSP server to autocomplete Helm files.

The Helm files are parsed as YAML files. The trick is that the Helm files are "redacted", i.e. all the {{...}} template placeholders are substituted with # comment characters, so most of the time YAML tree-sitter parser can figure proper hints.

I used YAML examples from ContainerSolutions and helm templates from helm/examples. A good playground to view tree-sitter output is on ast-grep.

How to use

When a file is opened, LSP can run an external initialization script. The script can, for example, download helm charts with helm dependencies update or helmfile fetch --output-dir charts/

How to use with [LazyVim][lazyvim]

[lazyvim][https://www.lazyvim.org/]

Autocompletion of k8s definitions

Definitions are taken from Kubernetes API. For sake of testing, in the repo we have only selected keys (the original from cluster can be much larger).

kubectl proxy
curl http://localhost:8001/openapi/v2 | python3 testdata/filter_kubernetes_api_schema.py > filtered_v2.json

Not supported

  • Show YAML parse errors (e.g. when there is a missing colon after a key) - It seems that tree-sitter for YAML marks the whole top node as erroneous.

Autocompletion of values.yaml files

Prerequisite is to have charts/ loaded with

helm dependencies update

Development

  1. Copy the configuration to ~/.config/nvim/lua/plugins/lsp-yaml.lua
  2. cargo build

To make Helm autocomplete work, you need to deliver OpenAPI V2 definitions for your cluster resources, see below.

How to add custom LazyVim LSP server

LazyVim/LazyVim#2263

TODO

  • Autocomplete for top-level props (when there is no "path to property").
    • Go to charts/ directory
    • Parse Charts.yaml
      • Parse name from Charts.yaml
      • Later, parse dependencies.
    • Parse tgz
      • Find the chart with "name"
      • Load all the values files
      • Parse all the values files
    • On edit, find all the matching values and display hints.
  • Fix "redacting" by being more smart on what is replaced with what. e.g. values with placeholder, if-else blocks with spaces.
  • BUG: Helm autocomplete does not work for top level fields.
  • Autocomplete for all the values_... files.
  • Have some reasonable installation script that bootstraps the schema.
  • Underline error for API version and Kind, if not in the schema.
  • Handle hemlfile.yaml and its dir structure: helmfile fetch --output-dir charts

About

A LSP server for yaml files in helm charts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors