Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support terraform-vars highlighting #6465

Closed
omar25h opened this issue Apr 18, 2024 · 8 comments · Fixed by #6815
Closed

Support terraform-vars highlighting #6465

omar25h opened this issue Apr 18, 2024 · 8 comments · Fixed by #6815
Labels
bug Something isn't working

Comments

@omar25h
Copy link

omar25h commented Apr 18, 2024

Describe the bug

There seems to be a missing parser for tfvars. The filetype in neovim is terraform-vars. The related line in Neovim https://github.com/neovim/neovim/blob/206475d7919ccdefd32022a32b204c8941b48fa6/runtime/lua/vim/filetype.lua#L1072

To Reproduce

  1. Make sure that treesitter terraform parser is set up.
  2. Execute echo 'example = true' > test.tfvars && nvim test.tfvars.
  3. Execute :set ft=terraform and notice how the text is highlighted

Expected behavior

code is highlighted.

Output of :checkhealth nvim-treesitter

==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- OK `tree-sitter` found 0.22.5 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v20.9.0 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `clang` executable found. Selected from { "clang" }
  Version: Homebrew clang version 17.0.6
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
  machine = "x86_64",
  release = "23.4.0",
  sysname = "Darwin",
  version = "Darwin Kernel Version 23.4.0: Fri Mar 15 00:11:05 PDT 2024; root:xnu-10063.101.17~1/RELEASE_X86_64"
} ~

Parser/Features         H L F I J
  - ada                 ✓ ✓ ✓ . .
  - agda                ✓ . ✓ . .
  - angular             ✓ ✓ ✓ ✓ ✓
  - apex                ✓ ✓ ✓ . .
  - arduino             ✓ ✓ ✓ ✓ ✓
  - asm                 ✓ . . . ✓
  - astro               ✓ ✓ ✓ ✓ ✓
  - authzed             ✓ . . . ✓
  - awk                 ✓ . . . ✓
  - bash                ✓ ✓ ✓ . ✓
  - bass                ✓ ✓ ✓ ✓ ✓
  - beancount           ✓ . ✓ . ✓
  - bibtex              ✓ . ✓ ✓ .
  - bicep               ✓ ✓ ✓ ✓ ✓
  - bitbake             ✓ ✓ ✓ ✓ ✓
  - blueprint           ✓ . . . .
  - c                   ✓ ✓ ✓ ✓ ✓
  - c_sharp             ✓ ✓ ✓ . ✓
  - cairo               ✓ ✓ ✓ ✓ ✓
  - capnp               ✓ ✓ ✓ ✓ ✓
  - chatito             ✓ ✓ ✓ ✓ ✓
  - clojure             ✓ ✓ ✓ . ✓
  - cmake               ✓ . ✓ ✓ .
  - comment             ✓ . . . .
  - commonlisp          ✓ ✓ ✓ . .
  - cooklang            ✓ . . . .
  - corn                ✓ ✓ ✓ ✓ .
  - cpon                ✓ ✓ ✓ ✓ ✓
  - cpp                 ✓ ✓ ✓ ✓ ✓
  - css                 ✓ . ✓ ✓ ✓
  - csv                 ✓ . . . .
  - cuda                ✓ ✓ ✓ ✓ ✓
  - cue                 ✓ ✓ ✓ ✓ ✓
  - d                   ✓ ✓ ✓ ✓ ✓
  - dart                ✓ ✓ ✓ ✓ ✓
  - devicetree          ✓ ✓ ✓ ✓ ✓
  - dhall               ✓ . ✓ . ✓
  - diff                ✓ . . . .
  - disassembly         ✓ . . . ✓
  - djot                ✓ ✓ ✓ ✓ ✓
  - dockerfile          ✓ . . . ✓
  - dot                 ✓ . . ✓ ✓
  - doxygen             ✓ . . ✓ ✓
  - dtd                 ✓ ✓ ✓ . ✓
  - earthfile           ✓ . . . ✓
  - ebnf                ✓ . . . .
  - eds                 ✓ . ✓ . .
  - eex                 ✓ . . . ✓
  - elixir              ✓ ✓ ✓ ✓ ✓
  - elm                 ✓ . . . ✓
  - elsa                ✓ ✓ ✓ ✓ ✓
  - elvish              ✓ . . . ✓
  - embedded_template   ✓ . . . ✓
  - erlang              ✓ . ✓ . .
  - facility            ✓ . ✓ ✓ ✓
  - faust               ✓ . . . ✓
  - fennel              ✓ ✓ ✓ . ✓
  - fidl                ✓ . ✓ . ✓
  - firrtl              ✓ ✓ ✓ ✓ ✓
  - fish                ✓ ✓ ✓ ✓ ✓
  - foam                ✓ ✓ ✓ ✓ ✓
  - forth               ✓ ✓ ✓ ✓ ✓
  - fortran             ✓ . ✓ ✓ .
  - fsh                 ✓ . . . .
  - func                ✓ . . . .
  - fusion              ✓ ✓ ✓ ✓ .
  - gdscript            ✓ ✓ ✓ ✓ ✓
  - gdshader            ✓ . . . ✓
  - git_config          ✓ . ✓ . ✓
  - git_rebase          ✓ . . . ✓
  - gitattributes       ✓ ✓ . . ✓
  - gitcommit           ✓ . . . ✓
  - gitignore           ✓ . . . .
  - gleam               ✓ ✓ ✓ ✓ ✓
  - glimmer             ✓ ✓ ✓ ✓ .
  - glsl                ✓ ✓ ✓ ✓ ✓
  - gn                  ✓ ✓ ✓ ✓ ✓
  - gnuplot             ✓ . . . ✓
  - go                  ✓ ✓ ✓ ✓ ✓
  - godot_resource      ✓ ✓ ✓ . ✓
  - gomod               ✓ . . . ✓
  - gosum               ✓ . . . .
  - gotmpl              ✓ . . . ✓
  - gowork              ✓ . . . ✓
  - gpg                 ✓ . . . ✓
  - graphql             ✓ . . ✓ ✓
  - groovy              ✓ ✓ ✓ ✓ ✓
  - gstlaunch           ✓ . . . .
  - hack                ✓ . . . .
  - hare                ✓ ✓ ✓ ✓ ✓
  - haskell             ✓ . ✓ . ✓
  - haskell_persistent  ✓ . ✓ . .
  - hcl                 ✓ . ✓ ✓ ✓
  - heex                ✓ ✓ ✓ ✓ ✓
  - helm                ✓ . . . ✓
  - hjson               ✓ ✓ ✓ ✓ ✓
  - hlsl                ✓ ✓ ✓ ✓ ✓
  - hlsplaylist         ✓ . . . ✓
  - hocon               ✓ . ✓ . ✓
  - hoon                ✓ ✓ ✓ . .
  - html                ✓ ✓ ✓ ✓ ✓
  - htmldjango          ✓ . ✓ ✓ ✓
  - http                ✓ . . . ✓
  - hurl                ✓ . ✓ ✓ ✓
  - hyprlang            ✓ . ✓ ✓ ✓
  - ini                 ✓ . ✓ . .
  - ispc                ✓ ✓ ✓ ✓ ✓
  - janet_simple        ✓ ✓ ✓ . ✓
  - java                ✓ ✓ ✓ ✓ ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - jq                  ✓ ✓ . . ✓
  - jsdoc               ✓ . . . .
  - json                ✓ ✓ ✓ ✓ .
  - json5               ✓ . . . ✓
  - jsonc               ✓ ✓ ✓ ✓ ✓
  - jsonnet             ✓ ✓ ✓ . .
  - julia               ✓ ✓ ✓ ✓ ✓
  - just                ✓ ✓ ✓ ✓ ✓
  - kconfig             ✓ ✓ ✓ ✓ ✓
  - kdl                 ✓ ✓ ✓ ✓ ✓
  - kotlin              ✓ ✓ ✓ . ✓
  - kusto               ✓ . . . ✓
  - lalrpop             ✓ ✓ . . ✓
  - latex               ✓ . ✓ . ✓
  - ledger              ✓ . ✓ ✓ ✓
  - leo                 ✓ . . ✓ ✓
  - linkerscript        ✓ ✓ ✓ ✓ ✓
  - liquid              ✓ . . . ✓
  - liquidsoap          ✓ ✓ ✓ ✓ .
  - llvm                ✓ . . . .
  - lua                 ✓ ✓ ✓ ✓ ✓
  - luadoc              ✓ . . . .
  - luap                ✓ . . . .
  - luau                ✓ ✓ ✓ ✓ ✓
  - m68k                ✓ ✓ ✓ . ✓
  - make                ✓ . ✓ . ✓
  - markdown            ✓ . ✓ ✓ ✓
  - markdown_inline     ✓ . . . ✓
  - matlab              ✓ ✓ ✓ ✓ ✓
  - menhir              ✓ . . . ✓
  - mermaid             ✓ . . . .
  - meson               ✓ . ✓ ✓ ✓
  - mlir                ✓ ✓ . . .
  - muttrc              ✓ . . . ✓
  - nasm                ✓ . . . ✓
  - nickel              ✓ . . ✓ .
  - nim                 ✓ ✓ ✓ . ✓
  - nim_format_string   ✓ . . . ✓
  - ninja               ✓ . ✓ ✓ .
  - nix                 ✓ ✓ ✓ . ✓
  - norg                . . . . .
  - nqc                 ✓ ✓ ✓ ✓ ✓
  - objc                ✓ ✓ ✓ ✓ ✓
  - objdump             ✓ . . . ✓
  - ocaml               ✓ ✓ ✓ ✓ ✓
  - ocaml_interface     ✓ ✓ ✓ ✓ ✓
  - ocamllex            ✓ . . . ✓
  - odin                ✓ ✓ ✓ ✓ ✓
  - org                 . . . . .
  - pascal              ✓ ✓ ✓ ✓ ✓
  - passwd              ✓ . . . .
  - pem                 ✓ . ✓ . ✓
  - perl                ✓ . ✓ . ✓
  - php                 ✓ ✓ ✓ ✓ ✓
  - php_only            ✓ ✓ ✓ ✓ ✓
  - phpdoc              ✓ . . . .
  - pioasm              ✓ . . . ✓
  - po                  ✓ . ✓ . ✓
  - pod                 ✓ . . . .
  - poe_filter          ✓ . ✓ ✓ ✓
  - pony                ✓ ✓ ✓ ✓ ✓
  - printf              ✓ . . . .
  - prisma              ✓ . ✓ . .
  - promql              ✓ . . . ✓
  - properties          ✓ ✓ . . ✓
  - proto               ✓ . ✓ . .
  - prql                ✓ . . . ✓
  - psv                 ✓ . . . .
  - pug                 ✓ . . . ✓
  - puppet              ✓ ✓ ✓ ✓ ✓
  - purescript          ✓ ✓ . . ✓
  - pymanifest          ✓ . . . ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - ql                  ✓ ✓ ✓ ✓ ✓
  - qmldir              ✓ . . . ✓
  - qmljs               ✓ . ✓ . .
  - query               ✓ ✓ ✓ ✓ ✓
  - r                   ✓ ✓ . ✓ ✓
  - racket              ✓ . ✓ . ✓
  - rasi                ✓ ✓ ✓ ✓ .
  - rbs                 ✓ . ✓ ✓ ✓
  - re2c                ✓ ✓ ✓ ✓ ✓
  - readline            ✓ . ✓ ✓ ✓
  - regex               ✓ . . . .
  - rego                ✓ . . . ✓
  - requirements        ✓ . . . ✓
  - rnoweb              ✓ . ✓ . ✓
  - robot               ✓ . ✓ ✓ .
  - roc                 ✓ ✓ . . ✓
  - ron                 ✓ ✓ ✓ ✓ ✓
  - rst                 ✓ ✓ . . ✓
  - ruby                ✓ ✓ ✓ ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - scala               ✓ ✓ ✓ . ✓
  - scfg                ✓ . . . ✓
  - scheme              ✓ . ✓ . ✓
  - scss                ✓ . ✓ ✓ .
  - slang               ✓ ✓ ✓ ✓ ✓
  - slint               ✓ ✓ ✓ ✓ ✓
  - smali               ✓ ✓ ✓ ✓ ✓
  - smithy              ✓ . . . .
  - snakemake           ✓ ✓ ✓ ✓ ✓
  - solidity            ✓ . ✓ . .
  - soql                ✓ . . . .
  - sosl                ✓ . . . .
  - sourcepawn          ✓ ✓ . . ✓
  - sparql              ✓ ✓ ✓ ✓ ✓
  - sql                 ✓ . . ✓ ✓
  - squirrel            ✓ ✓ ✓ ✓ ✓
  - ssh_config          ✓ ✓ ✓ ✓ ✓
  - starlark            ✓ ✓ ✓ ✓ ✓
  - strace              ✓ . . . ✓
  - styled              ✓ . ✓ ✓ ✓
  - supercollider       ✓ ✓ ✓ ✓ ✓
  - surface             ✓ . ✓ ✓ ✓
  - svelte              ✓ ✓ ✓ ✓ ✓
  - swift               ✓ ✓ . ✓ .
  - sxhkdrc             ✓ . ✓ . ✓
  - systemtap           ✓ ✓ ✓ . ✓
  - t32                 ✓ ✓ ✓ ✓ ✓
  - tablegen            ✓ ✓ ✓ ✓ ✓
  - tcl                 ✓ . ✓ ✓ .
  - teal                ✓ ✓ ✓ ✓ ✓
  - templ               ✓ . . . ✓
  - terraform           ✓ . ✓ ✓ ✓
  - textproto           ✓ . ✓ ✓ .
  - thrift              ✓ ✓ ✓ ✓ ✓
  - tiger               ✓ ✓ ✓ ✓ ✓
  - tlaplus             ✓ ✓ ✓ . ✓
  - tmux                ✓ . . . ✓
  - todotxt             ✓ . . . .
  - toml                ✓ ✓ ✓ ✓ ✓
  - tsv                 ✓ . . . .
  - tsx                 ✓ ✓ ✓ ✓ ✓
  - turtle              ✓ ✓ ✓ ✓ ✓
  - twig                ✓ . . . ✓
  - typescript          ✓ ✓ ✓ ✓ ✓
  - typoscript          ✓ . ✓ ✓ ✓
  - typst               ✓ . ✓ ✓ ✓
  - udev                ✓ ✓ . . ✓
  - ungrammar           ✓ ✓ ✓ ✓ ✓
  - unison              ✓ . . . ✓
  - usd                 ✓ ✓ ✓ ✓ .
  - uxntal              ✓ ✓ ✓ ✓ ✓
  - v                   ✓ ✓ ✓ ✓ ✓
  - vala                ✓ . ✓ . .
  - vento               ✓ . . . ✓
  - verilog             ✓ ✓ ✓ . ✓
  - vhs                 ✓ . . . .
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - vue                 ✓ . ✓ ✓ ✓
  - wgsl                ✓ . ✓ ✓ .
  - wgsl_bevy           ✓ . ✓ ✓ .
  - wing                ✓ ✓ ✓ . .
  - wit                 ✓ . . . ✓
  - xcompose            ✓ ✓ . . ✓
  - xml                 ✓ ✓ ✓ ✓ ✓
  - yaml                ✓ ✓ ✓ ✓ ✓
  - yang                ✓ . ✓ ✓ ✓
  - yuck                ✓ ✓ ✓ ✓ ✓
  - zathurarc           ✓ . . . ✓
  - zig                 ✓ ✓ ✓ ✓ ✓

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang} ~

Output of nvim --version

NVIM v0.10.0-dev-2947+ge1ca7a7bf
Build type: RelWithDebInfo
LuaJIT 2.1.1710088188
Run "nvim -V1 -v" for more info

Additional context

No response

@omar25h omar25h added the bug Something isn't working label Apr 18, 2024
@lucario387
Copy link
Member

PR welcome

@clason
Copy link
Contributor

clason commented Apr 18, 2024

We don't take requests. If you know of a (good) parser and are willing to write (compatible) queries, please do so; otherwise you'll just have to wait until someone is motivated.

@clason clason closed this as not planned Won't fix, can't repro, duplicate, stale Apr 18, 2024
@ckipp01
Copy link
Contributor

ckipp01 commented May 17, 2024

I was under the understanding that the syntax in .tf files and tfvars file are the same? For example even in the tree-sitter-hcl repo they use tfvars files in their examples for testing. So is it possible to just have terraform-vars files fall under terraform somehow?

@olisikh
Copy link

olisikh commented May 17, 2024

It sounds like something essential to support *.tfvars file highlighting.
Could we please reopen this issue and implement it?

@clason
Copy link
Contributor

clason commented May 17, 2024

PR welcome; languages are user-contributed.

@olisikh
Copy link

olisikh commented May 17, 2024

For anyone who came across this issue, you can just set syntax for *.tfvars files to tf and it would be highlighted in your buffers:

local my_group = vim.api.nvim_create_augroup('MyGroup', { clear = true })

-- fix highlighting in *.tfvars
vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufRead' }, {
  group = my_group,
  pattern = { '*.tfvars' },
  command = 'set syntax=tf',
})

@clason
Copy link
Contributor

clason commented May 17, 2024

A better approach (probably; I have no idea about the relation between terraform and terraform-vars files, hence my leaving this to the community) would be to register the terraform language for the terraform-vars filetype via :h vim.treesitter.language.register().

@olisikh
Copy link

olisikh commented May 17, 2024

Indeed, this also works and looks less hacky. Thanks!

vim.treesitter.language.register('terraform', { 'terraform', 'terraform-vars' })

opa-oz added a commit to opa-oz/nvim-treesitter that referenced this issue Jun 26, 2024
opa-oz added a commit to opa-oz/nvim-treesitter that referenced this issue Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants