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

tailwindcss-language-server does not work with htmldjango filetype #2488

Closed
nulty opened this issue Mar 1, 2023 · 8 comments
Closed

tailwindcss-language-server does not work with htmldjango filetype #2488

nulty opened this issue Mar 1, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@nulty
Copy link

nulty commented Mar 1, 2023

Description

When editing a django template [1] the tailwindcss-language-server is registered but no completion is provided.

In (n)vim, a django template is given the filetype htmldjango.
tailwindcss-language-server does provide responses for html and django-html filetypes, but not htmldjango [2].

You can force vim to change the filetype for htmldjango with an autocommand, but this shouldn't be necessary.

vim.api.nvim_create_autocmd({"FileType"}, {
	pattern = "htmldjango",
	command = "set ft=html"
})

This issue was made apparent here when htmldjango was added to the filetypes table but not mapped to django-html in the init_options.

It's clear from looking at the nvim-lspconfig for the tailwindcss-language-server default configuration what needs to be done to fix this in nvim-lspconfig.

So onto the reason I'm raising this issue and not instead raising a PR directly:

Should tailwindcss-language-server add htmldjango to it's list of accepted languages?

( have not tested that this would work, I assume it would


Writing this report I've learned that every piece of software has a different name for django templates
markdown_inline => django
vim => htmldjango
vs-code, tailwindcss => django-html

Neovim version

NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3

Nvim-lspconfig version

62856b2

Operating system and version

Ubuntu 20.20 Linux 5.15.0-60-generic

Affected language servers

tailwindcss-language-server

Steps to reproduce

  1. Create a django template in django.html
{% load static %}
<html>
<head>>
<title></title></head>
<body>
<div class="">
</div>
</body>
  1. nvim -nu minimal_init.lua django.html
  2. Run :set ft (returns htmldjango)
  3. Put cursor in class="|"
  4. Type 'b' (bg-red-500)

Actual behavior

No completion suggestions when django template has htmldjango filetype

Expected behavior

completion suggestions are provided.

Minimal config

vim.o.number = true
local on_windows = vim.loop.os_uname().version:match 'Windows'

local function join_paths(...)
  local path_sep = on_windows and '\\' or '/'
  local result = table.concat({ ... }, path_sep)
  return result
end

vim.cmd [[set runtimepath=$VIMRUNTIME]]

local temp_dir = vim.loop.os_getenv 'TEMP' or '/tmp'

vim.cmd('set packpath=' .. join_paths(temp_dir, 'nvim', 'site'))

local package_root = join_paths(temp_dir, 'nvim', 'site', 'pack')
local lspconfig_path = join_paths(package_root, 'test', 'start', 'nvim-lspconfig')

if vim.fn.isdirectory(lspconfig_path) ~= 1 then
  vim.fn.system { 'git', 'clone', 'https://github.com/neovim/nvim-lspconfig', lspconfig_path }
end

vim.lsp.set_log_level 'trace'
require('vim.lsp.log').set_format_func(vim.inspect)
local nvim_lsp = require 'lspconfig'
local on_attach = function(_, bufnr)
  local function buf_set_option(...)
    vim.api.nvim_buf_set_option(bufnr, ...)
  end

  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  -- Mappings.
  local opts = { buffer = bufnr, noremap = true, silent = true }
  vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
  vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
  vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
  vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
  vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
  vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
  vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
  vim.keymap.set('n', '<space>wl', function()
    print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
  end, opts)
  vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
  vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
  vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
  vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
  vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
  vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
  vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
end

-- Add the server that troubles you here
local name = 'tailwindcss'
local cmd = { 'tailwindcss-language-server', '--stdio' } -- needed for elixirls, lua_ls, omnisharp
if not name then
  print 'You have not defined a server name, please edit minimal_init.lua'
end
if not nvim_lsp[name].document_config.default_config.cmd and not cmd then
  print [[You have not defined a server default cmd for a server
    that requires it please edit minimal_init.lua]]
end

nvim_lsp[name].setup {
  cmd = cmd,
  on_attach = on_attach,
  -- Uncomment for working functionality
  -- init_options = {
  --   userLanguages = {
  --     htmldjango = "django-html",
  --   }
  -- }
}

LSP log

https://gist.github.com

@glepnir
Copy link
Member

glepnir commented Mar 2, 2023

what does lspinfo say ? does tailwindcss attached this buffer? test with the min config it attached the htmldjango filetype buffer.

@glepnir glepnir closed this as completed Mar 2, 2023
@nulty
Copy link
Author

nulty commented Mar 2, 2023

what does lspinfo say ? does tailwindcss attached this buffer? test with the min config it attached the htmldjango filetype buffer.

Yes, the LSP connects to the buffer, but the language server does not recognise the filetype so it does not respond. Maybe you didn't understand the point of this issue?

@nulty
Copy link
Author

nulty commented Mar 3, 2023

@glepnir Can you please re-open this issue? Or give an explanation as to why it was closed, please?

@rob32
Copy link

rob32 commented Mar 18, 2024

I have the same problem.
@nulty Have you found a solution?

@nulty
Copy link
Author

nulty commented Mar 20, 2024

@rob32 the filetype has been added upstream in tailwindcss-intellisense tailwindlabs/tailwindcss-intellisense#721

@rob32
Copy link

rob32 commented Mar 20, 2024

@nulty hey thanks for the answer <3

I've been working on getting tailwindcss to run with djangohtml for several days now. Without success...

I really don't get it.

Whether with plain lspconfig and cmp, with zero-lsp or even with LazyVim and tailwindcss extra.

Something is wrong here.

LspInfo shows that tailwindcss is atached to the buffer with filetype=htmldjango, no issues with that.
The tw config is located in the root directory and my django/html templates are located in the templates folder.

With "normal" html files there are no problems and autocomplete runs as expected...

I'm truly clueless, if you have an idea or suggestion I would be extremely grateful ;)

@nulty
Copy link
Author

nulty commented Mar 21, 2024

Have you monitored the logs of the lsp?

Make sure the logging is verbose

-- i can't remember how much of this is required...
-- vim lsp
vim.lsp.set_log_level(vim.lsp.log_levels.DEBUG)
require('vim.lsp.log').set_format_func(vim.inspect)
vim.lsp.set_log_level 'trace'
:LspLog
[INFO][2024-03-21 23:30:22] .../lua/vim/lsp.lua:1344	"LSP[tailwindcss]"	"server_capabilities"	{
  server_capabilities = {
    codeActionProvider = true,
    colorProvider = true,
    completionProvider = {
      resolveProvider = true,
      triggerCharacters = { '"', "'", "`", " ", ".", "(", "[", "!", "/", ":" }
    },
    documentLinkProvider = vim.empty_dict(),
    hoverProvider = true,
    textDocumentSync = {
      change = 1,
      openClose = true,
      save = {
        includeText = false
      },
      willSave = false,
      willSaveWaitUntil = false
    }
  }
}

...


[TRACE][2024-03-21 23:30:25] .../lua/vim/lsp.lua:1052	"notification"	"window/logMessage"	{
  message = "[tailwind.config.js] Loaded Tailwind CSS config file: /home/iain/Code/mine/inultycom-django/tailwind.config.js",
  type = 4
}

@rob32
Copy link

rob32 commented Mar 22, 2024

Hey, thank you very much!

I was able to find the error 🙏
In the repo where i always tested it was a "data" folder/volume (docker).

In the end it was a problem with permissions...

VsCode had no problems with it because of the files.watcherExclude settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants