diff --git a/filetype.lua b/filetype.lua new file mode 100644 index 00000000..124f59a4 --- /dev/null +++ b/filetype.lua @@ -0,0 +1,18 @@ +vim.filetype.add { + pattern = { + ['.*'] = { + priority = math.huge, + function(path, bufnr) + local line1 = vim.filetype.getlines(bufnr, 1) + local line2 = vim.filetype.getlines(bufnr, 2) + if vim.filetype.matchregex(line1, [[^AWSTemplateFormatVersion]] ) or + vim.filetype.matchregex(line2, [[^AWSTemplateFormatVersion]] ) then + return 'yaml.cloudformation' + elseif vim.filetype.matchregex(line1, [[["']AWSTemplateFormatVersion]] ) or + vim.filetype.matchregex(line2, [[["']AWSTemplateFormatVersion]] ) then + return 'json.cloudformation' + end + end, + }, + }, +} diff --git a/init.lua b/init.lua index 2cfe3cdf..5b2a3c20 100644 --- a/init.lua +++ b/init.lua @@ -172,6 +172,9 @@ require('lazy').setup({ end, }, + 'b0o/schemastore', + 'mfussenegger/nvim-lint', + -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart -- These are some example plugins that I've included in the kickstart repository. -- Uncomment any of the lines below to enable them. @@ -288,7 +291,7 @@ vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { de -- See `:help nvim-treesitter` require('nvim-treesitter.configs').setup { -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'help', 'vim' }, + ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim' }, -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) auto_install = false, @@ -416,6 +419,7 @@ local servers = { tflint = {}, terraformls = {}, eslint = {}, + --yamlls = {}, lua_ls = { Lua = { @@ -452,6 +456,59 @@ mason_lspconfig.setup_handlers { end, } +require'lspconfig'.yamlls.setup { + on_attach = on_attach, + filetypes = { "yaml", "yaml.cloudformation" }, + flags = { debounce_test_changes = 150 }, + capabilities = capabilities, + settings = { + yaml = { + format = { + enable = true, + singleQuote = true, + printWidth = 120, + }, + hover = true, + completion = true, + customTags = { + "!fn", + "!And", + "!If", + "!Not", + "!Equals", + "!Or", + "!FindInMap sequence", + "!Base64", + "!Cidr", + "!Ref", + "!Ref scalar", + "!Sub", + "!GetAtt", + "!GetAZs", + "!ImportValue", + "!Select", + "!Split", + "!Join sequence" + }, + validate = true, + schemas = { + ["https://raw.githubusercontent.com/awslabs/goformation/v6.10.0/schema/cloudformation.schema.json"] = { + "/cloudformation.yml", + "/cloudformation.yaml", + "/cloudformation.template.yml", + "/cloudformation.template.yaml", + "/*.cf.yml", + "/cf.yaml", + }, + }, + schemaStore = { + enable = true, + url = "https://www.schemastore.org/json", + }, + }, + }, +} + -- nvim-cmp setup local cmp = require 'cmp' local luasnip = require 'luasnip' @@ -497,6 +554,32 @@ cmp.setup { }, } +setupLinter = function (name) + --require('lint').try_lint(name) + local lintcmd = "lua require('lint').try_lint('" .. name .. "')" + vim.cmd(lintcmd) + vim.api.nvim_create_autocmd("BufWritePost", { + --command = "silent! lua require('lint').try_lint(" .. name .. ")", + command = lintcmd, + desc = "Adding linter " .. name + }) +end +-- setup linting for Cloudformation cfn_lint +vim.api.nvim_create_autocmd({'BufReadPost'}, { + pattern = { + '*.cf.json', + '*.cf.yml', + '*.cf.yaml', + 'cloudformation.template.yml', + 'cloudformation.template.yaml', + 'cloudformation.json', + 'cloudformation.yaml', + 'cloudformation.yml' + }, + command = "lua setupLinter('cfn_lint')", + desc = 'Adding linting command for Cloudformation files with cfn_lint' +}) + -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et