From d4e203a04c3958ecf57417f0855dd3e3ae94427d Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Thu, 6 Jul 2023 12:07:29 -0600 Subject: [PATCH] add vscode tf snippets, fix tf tree-sitter --- flake.lock | 17 +++++++++++++++++ flake.nix | 4 ++++ modules/common/neovim/config/completion.nix | 7 +++++++ modules/common/neovim/config/syntax.nix | 8 +++++++- modules/common/neovim/lua/settings.lua | 4 ++-- overlays/neovim-plugins.nix | 1 + 6 files changed, 38 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index f1fe9bc..ea700e0 100644 --- a/flake.lock +++ b/flake.lock @@ -413,6 +413,7 @@ "telescope-nvim-src": "telescope-nvim-src", "telescope-project-nvim-src": "telescope-project-nvim-src", "toggleterm-nvim-src": "toggleterm-nvim-src", + "vscode-terraform-snippets": "vscode-terraform-snippets", "wallpapers": "wallpapers", "wsl": "wsl" } @@ -522,6 +523,22 @@ "type": "github" } }, + "vscode-terraform-snippets": { + "flake": false, + "locked": { + "lastModified": 1688666727, + "narHash": "sha256-qw6/N1nDPgZXQ2T0DRK2WoNC2KLkNTJRVm5yNqzMcIg=", + "owner": "nmasur", + "repo": "vscode-terraform-snippets", + "rev": "6e37735ef6fdd72352e4b73e2bfaa3706fcff7e0", + "type": "github" + }, + "original": { + "owner": "nmasur", + "repo": "vscode-terraform-snippets", + "type": "github" + } + }, "wallpapers": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index 563787a..59b6350 100644 --- a/flake.nix +++ b/flake.nix @@ -103,6 +103,10 @@ url = "github:kyazdani42/nvim-tree.lua"; flake = false; }; + vscode-terraform-snippets = { + url = "github:nmasur/vscode-terraform-snippets"; + flake = false; + }; }; diff --git a/modules/common/neovim/config/completion.nix b/modules/common/neovim/config/completion.nix index d38aac5..37fc25f 100644 --- a/modules/common/neovim/config/completion.nix +++ b/modules/common/neovim/config/completion.nix @@ -135,6 +135,13 @@ }; lua = '' + -- Load snippets + -- Check status: :lua require("luasnip").log.open() + require("luasnip.loaders.from_vscode").lazy_load() + require("luasnip.loaders.from_vscode").lazy_load({ paths = { "${ + builtins.toString pkgs.vscode-terraform-snippets + }" } }) + -- Use buffer source for `/` require('cmp').setup.cmdline("/", { sources = { diff --git a/modules/common/neovim/config/syntax.nix b/modules/common/neovim/config/syntax.nix index 56b8529..d30d342 100644 --- a/modules/common/neovim/config/syntax.nix +++ b/modules/common/neovim/config/syntax.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: { +{ pkgs, lib, ... }: { plugins = [ (pkgs.vimPlugins.nvim-treesitter.withPlugins (_plugins: @@ -49,4 +49,10 @@ }; }; + # Use mkAfter to ensure tree-sitter is already loaded + lua = lib.mkAfter '' + -- Use HCL parser with .tf files + vim.treesitter.language.register('hcl', 'terraform') + ''; + } diff --git a/modules/common/neovim/lua/settings.lua b/modules/common/neovim/lua/settings.lua index 85a865d..fb6a244 100644 --- a/modules/common/neovim/lua/settings.lua +++ b/modules/common/neovim/lua/settings.lua @@ -4,8 +4,8 @@ vim.filetype.add({ pattern = { - [".*%.tfvars"] = "hcl", - [".*%.tf"] = "hcl", + [".*%.tfvars"] = "terraform", + [".*%.tf"] = "terraform", [".*%.rasi"] = "css", }, }) diff --git a/overlays/neovim-plugins.nix b/overlays/neovim-plugins.nix index 9941492..42594d8 100644 --- a/overlays/neovim-plugins.nix +++ b/overlays/neovim-plugins.nix @@ -17,6 +17,7 @@ let in { nil = inputs.nil.packages.${prev.system}.nil; + vscode-terraform-snippets = inputs.vscode-terraform-snippets; nvim-lspconfig = (withSrc prev.vimPlugins.nvim-lspconfig inputs.nvim-lspconfig);