themaxmarchuk / tailwindcss-colors.nvim

Highlights Tailwind CSS class names when @tailwindcss/language-server is connected
MIT License
54 stars 1 forks source link

Setup #1

Open trevorhiley opened 2 years ago

trevorhiley commented 2 years ago

First of all, thank you for making this. I've been working on switching from vscode to neovim and I've been working with Svelte/Tailwind a lot. The one feature I couldn't seem to find was a way to show the colors on the tailwind classes.

I've installed the plugin, and I called require 'tailwindcss-colors'.setup() in a lua script thinking that's what I was missing, but I'm not getting colors on the tailwind classes anywhere. I thought maybe it was a problem using Svelte so I tried html as well.

The tailwindcss lsp is working and I see it running with LspInfo so I know that's not the issue. Any setup instructions I might be missing?

themaxmarchuk commented 2 years ago

Hi sorry, the plugin wasn't quite done yet, you got here very early 😄

I've gone ahead and updated the README with instructions on how to set things up.

bdillahu commented 2 years ago

Probably my lack of lsp knowledge (new user to that), but I'm still not totally succeeding.

When I open a file, I get:

Spawning language server with cmd: tailwindcss-language-server failed. The language server is either not installed, mi ssing from PATH, or not executable.

I can do the :TailwindColorsAttach and it all works, but trying to get it to "autostart".

I have the lspconfig on_attach function copied from their setup example with the

require("tailwindcss-colors").buf_attach(bufnr)

included at the end of the function:

`local nvim_lsp = require('lspconfig')

-- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_attach = function(client, bufnr) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end

-- Enable completion triggered by buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

-- Mappings. local opts = { noremap=true, silent=true }

-- See :help vim.lsp.* for documentation on any of the below functions buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) buf_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', opts) buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) buf_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', opts) buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts)

require("tailwindcss-colors").buf_attach(bufnr) end

-- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches local servers = { 'pyright', 'tailwindcss', 'rustanalyzer', 'tsserver' } for , lsp in ipairs(servers) do nvim_lsp[lsp].setup { on_attach = on_attach, flags = { debounce_text_changes = 150, } } end`

Anybody got an idea of what to check? Thanks!

themaxmarchuk commented 2 years ago

So from what I can tell, the setup function shouldn't be able to affect the language server startup because the on_attach function is run after the language server has already been started.

Are you sure the on_attach function call is what's causing the issue? If it isn't then as you suspected, it might just be something going on with lsp-config.

So I'm surprised that TailwindColorsAttach works since it basically just does the same thing. You could setup an autocmd to run whenever you load a javascript/ect. file. It's a bit of a band-aid solution but it could work.