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

Workaround with tailwindcss lsp #10

Closed
villekivela opened this issue Feb 14, 2024 · 9 comments
Closed

Workaround with tailwindcss lsp #10

villekivela opened this issue Feb 14, 2024 · 9 comments
Labels
question Further information is requested

Comments

@villekivela
Copy link

Is there a known way to make the syntax highlighting work so that the tailwind autocomplete would work also in template files?

@dlvandenberg
Copy link
Owner

Isn't autocompletion part of a LSP?

@dlvandenberg dlvandenberg added the question Further information is requested label Mar 4, 2024
@Ask-786
Copy link
Contributor

Ask-786 commented Apr 19, 2024

This is what i do for all the LSPs to get attached correctly. I don't know if it's a right method or not. But it works.

vim.api.nvim_create_autocmd({ 'BufRead', 'BufEnter' }, {
	group = vim.api.nvim_create_augroup('set-angular-filetype', { clear = true }),
	pattern = '*.component.html',
	callback = function()
		-- Necessary for lsps to get attached.
		vim.cmd([[set filetype=html]])
		vim.cmd([[set filetype=angular.html]])
	end,
})

@villekivela
Copy link
Author

villekivela commented Apr 22, 2024

autocmd BufRead,BufEnter *.component.html set filetype=angular in ftdetect/angular.vim works also to get the highlighting. But I don't get the tailwind autocomplete with either method.
Screenshot 2024-04-22 at 21 52 15
Screenshot 2024-04-22 at 21 51 31
Same clients are attached.

@JoschuaSchneider
Copy link

I'm facing similar problems.
With the fix mentioned by @Ask-786 I'm getting the wrong hover results when trying to hover tailwind classnames.

Could you share the full example of your setup with tailwind?

@Ask-786
Copy link
Contributor

Ask-786 commented Jul 16, 2024

Hi @JoschuaSchneider,

That's all I do regarding file type setup. It's still buggy, though. You have to open any TypeScript file before going into a template for the Tailwind LSP to work correctly.

If you need more details, You can check out my nvim config repo here: nvim.

@JoschuaSchneider
Copy link

Thanks for the quick response @Ask-786 !

My problem was that I still had the setup steps from the docs present. I replaced it with your autocmd snipped and now both is working for me.

Thank you!

For anyone wondering, here is my full plugin code for this module using your fix:

return {
  {
    'dlvandenberg/tree-sitter-angular',
    dependencies = {
      'nvim-treesitter/nvim-treesitter',
    },
    config = function()
      vim.api.nvim_create_autocmd({ 'BufRead', 'BufEnter' }, {
        group = vim.api.nvim_create_augroup('set-angular-filetype', { clear = true }),
        pattern = '*.component.html',
        callback = function()
          -- Necessary for angular lsp to get attached.
          vim.cmd [[set filetype=html]]
          vim.cmd [[set filetype=angular.html]]
        end,
      })
    end,
  },
}

@Ask-786
Copy link
Contributor

Ask-786 commented Jul 16, 2024

I think you don't need to explicitly install tree-sitter-angular @JoschuaSchneider .

It just get installed automatically when you enter a template file.

Sorry for the "Quick" reply by the way. was out of office for last few days.

@dlvandenberg
Copy link
Owner

In the nightly neovim build, filetype detection is added for Angular Templates.
Filetype is htmlangular. Please adjust your LSP config accordingly.

You need to update to the latest nvim-treesitter version also, as the angular parser is coupled to the new filetype.

@Ask-786
Copy link
Contributor

Ask-786 commented Jul 19, 2024

I've created a pull request to nvim-lspconfig, and it got merged today. You can check it out here: neovim/nvim-lspconfig#3240 (comment). With this update, there's no need for any extra configurations for LSPs (emmet_language_server, emmet_ls, angularls and tailwindcss).

And if you are formatting with none-ls and prettier or prettierd, I have updated it there too.

note: as mentioned by @dlvandenberg, you need the nightly neovim build for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants