Skip to content

Commit

Permalink
lsp: add native tailwindcss LSP with document colors & twin.macro sup…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
ecosse3 committed Nov 22, 2021
1 parent 5550339 commit 424f1f1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ require('lsp/html')
require('lsp/json')
require('lsp/lua')
require('lsp/tsserver')
require('lsp/tailwind')
57 changes: 57 additions & 0 deletions lua/lsp/tailwind.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
-- npm install -g @tailwindcss/language-server

local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities.textDocument.colorProvider = { dynamicRegistration = false }

require'lspconfig'.tailwindcss.setup {
capabilities = capabilities,
on_attach = function (client, bufnr)
if client.server_capabilities.colorProvider then
require"lsp/documentcolors".buf_attach(bufnr)
end
end,
cmd = { "tailwindcss-language-server", "--stdio" },
filetypes = { "aspnetcorerazor", "astro", "astro-markdown", "blade", "django-html", "edge", "eelixir", "ejs", "erb", "eruby", "gohtml", "haml", "handlebars", "hbs", "html", "html-eex", "jade", "leaf", "liquid", "markdown", "mdx", "mustache", "njk", "nunjucks", "php", "razor", "slim", "twig", "css", "less", "postcss", "sass", "scss", "stylus", "sugarss", "javascript", "javascriptreact", "reason", "rescript", "typescript", "typescriptreact", "vue", "svelte" },
init_options = {
userLanguages = {
eelixir = "html-eex",
eruby = "erb"
}
},
on_new_config = function(new_config)
if not new_config.settings then
new_config.settings = {}
end
if not new_config.settings.editor then
new_config.settings.editor = {}
end
if not new_config.settings.editor.tabSize then
-- set tab size for hover
new_config.settings.editor.tabSize = vim.lsp.util.get_effective_tabstop()
end
end,
settings = {
tailwindCSS = {
lint = {
cssConflict = "warning",
invalidApply = "error",
invalidConfigPath = "error",
invalidScreen = "error",
invalidTailwindDirective = "error",
invalidVariant = "error",
recommendedVariantOrder = "warning"
},
experimental = {
classRegex = {
"tw`([^`]*)",
"tw=\"([^\"]*)",
"tw={\"([^\"}]*)",
"tw\\.\\w+`([^`]*)",
"tw\\(.*?\\)`([^`]*)"
}
},
validate = true
}
}
}

0 comments on commit 424f1f1

Please sign in to comment.