ESSO0428 / lvim

0 stars 0 forks source link

`nvim-html-css` doesn't load when used with nVim v0.10.0 #1

Open savchenko opened 1 month ago

savchenko commented 1 month ago

EDIT

I think this is happening because the plugin loads prematurely. I can manually get user_config via Lua once cmp has loaded without any issues.

Adding nvim-cmp as the dependency of nvim-html-css makes it load successfully, but the cmp source is still unavailable:

# ready source names                                                                                                                                                                            
- async_path                                                                                                                                                                                    
- nvim_lsp:html                                                                                                                                                                                 

# unavailable source names                                                                                                                                                                      
- html-css

ORIGINAL MESSAGE

Sorry for creating this in the wrong repo, but the "Issues" section is disabled at ESSO0428/nvim-html-css.

This check:

if not vim.tbl_contains(self.option.enable_on, vim.bo.filetype) then

Fails with:

Error executing vim.schedule lua callback: vim/shared.lua:0: t: expected table, got nil
stack traceback:                                                                                                                                                                                
        [C]: in function 'error'                                                                                                                                                                
        vim/shared.lua: in function 'validate'                                                                                                                                                  
        vim/shared.lua: in function 'tbl_contains'                                                                                                                                              
        ...ocal/share/nvim/lazy/nvim-html-css/lua/html-css/init.lua:327: in function ''                                                                                                         
        vim/_editor.lua: in function ''                                                                                                                                                         
        vim/_editor.lua: in function <vim/_editor.lua:0>

Plugin is installed with default settings, nvim-cmp source added. Here is the content of self at the time:

{                                                                                                                                                                                               
  after_inert_before_update = true,                                                                                                                                                             
  cached_local_css_data = {},                                                                                                                                                                   
  embedded = "",                                                                                                                                                                                
  enable_file_patterns = { "*.html" },                                                                                                                                                          
  enable_on = {},                                                                                                                                                                               
  file_extensions = {},                                                                                                                                                                         
  href_links = {},                                                                                                                                                                              
  ids = {},                                                                                                                                                                                     
  isRemote = "^https?://",                                                                                                                                                                      
  items = {},                                                                                                                                                                                   
  last_html_buffer = 2,                                                                                                                                                                         
  local_classes = {},                                                                                                                                                                           
  local_css_file_mod_times = {},                                                                                                                                                                
  local_file = "",                                                                                                                                                                              
  local_ids = {},                                                                                                                                                                               
  local_style_sheets = {},                                                                                                                                                                      
  option = {},                                                                                                                                                                                  
  remote = "",                                                                                                                                                                                  
  remote_classes = {},                                                                                                                                                                          
  remote_ids = {},                                                                                                                                                                              
  remote_item_write = "",                                                                                                                                                                       
  remote_style_sheets = {},                                                                                                                                                                     
  source_name = "html-css",                                                                                                                                                                     
  style_sheets = {},                                                                                                                                                                            
  update_done = "",                                                                                                                                                                             
  user_config = {},                                                                                                                                                                             
  <metatable> = {                                                                                                                                                                               
    __index = {                                                                                                                                                                                 
      complete = <function 1>,                                                                                                                                                                  
      is_available = <function 2>,                                                                                                                                                              
      new = <function 3>,                                                                                                                                                                       
      update_completion_data = <function 4>                                                                                                                                                     
    }                                                                                                                                                                                           
  }                                                                                                                                                                                             
}

...and the relevant snippet from cmp config:

{
    name = 'html-css',
    option = {
        enable_on = {
            "htmldjango",
            "html",
        },
        enable_file_patterns = { "*.html" },
        file_extensions = { "css" },
        style_sheets = {}
    }
}
ESSO0428 commented 1 month ago

Hi @savchenko Thank you for the feedback!

I've handled the nil values for self.option.enable_on and vim.bo.filetype to prevent errors when these values are empty.

Additionally, based on your suggestions, here's how to configure the option settings in lazy.nvim to ensure all desired filetypes are set. Currently, it supports html, htmldjango, php, and enable_file_patterns (if not .html, like .php, please include it in file_extensions). Although it currently only detects css, this configuration ensures TSInstall works correctly with the html-css filetype.

Please make sure to run TSInstall html and TSInstall css to enable the Treesitter syntax trees for the required filetypes. Without this step, html-css completion for the specified filetypes will not work.

Additionally, ensure that enable_on, enable_file_patterns, and file_extensions are not empty in your configuration. The plugin will not function correctly if these values are missing.


{
  "hrsh7th/nvim-cmp",
  opts = {
    sources = {
      -- other sources
      {
        name = "html-css",
        option = {
          enable_on = {
            "htmldjango",
            "html",
            "php"
          },                                           -- set the file
types you want the plugin to work on
          enable_file_patterns = { "*.html" }, -- set the file patterns you
want the plugin to work on (default is *.html)
            -- enable_file_patterns = { "*.html", "*.php" }
          file_extensions = { "css", "sass", "less" }, -- set the local
filetypes from which you want to derive classes
          style_sheets = {
            -- example of remote styles, only css no js for now
            "
***@***.***/dist/css/bootstrap.min.css",
            ***@***.***/css/bulma.min.css",
          }
        }
      },
    },
  },
}

---

  If you are using other Neovim distributions like lunavim or lazyvim,
please find the corresponding configuration API for cmp. For example, with
lunarvim (confirmed with the latest version and Neovim 10), you can use:
---

table.insert(lvim.builtin.cmp.sources, 1, {
  name = "html-css",
  priority = 10,
  option = {
    max_count = {}, -- not ready yet
    enable_on = {
      "htmldjango",
      "html",
      "php",
    },                                            -- set the file types you
want the plugin to work on
    enable_file_patterns = { "*.html", "*.php" }, -- set the file patterns
you want the plugin to work on
    file_extensions = { "css", "sass", "less" },  -- set the local
filetypes from which you want to derive classes
    -- style_sheets = {
    -- example of remote styles, only css no js for now
    -- "
***@***.***/dist/css/bootstrap.min.css",
    -- ***@***.***/css/bulma.min.css",
    -- }
  }
})

---

Also, this cmp source dynamically adds completion sources based on the link
src in the HTML or the extends template in htmldjango, which is a
consideration for performance. Therefore, if the HTML doesn't link to any
src, it will only complete the CSS inside the style tag.

If you have any questions, feel free to ask. I have reopened the issue.

Thank you!

savchenko ***@***.***> 於 2024年6月9日 週日 上午10:37寫道:

> Sorry for creating this in the wrong repo, but the *"Issues"* section is
> disabled at ESSO0428/nvim-html-css
> <https://github.com/ESSO0428/nvim-html-css>.
>
> This check
> <https://github.com/ESSO0428/nvim-html-css/blob/8e797fedbfeeecce56a67156f097ab44a8f91d26/lua/html-css/init.lua#L327>
> :
>
> if not vim.tbl_contains(self.option.enable_on, vim.bo.filetype) then
>
> Fails with:
>
> Error executing vim.schedule lua callback: vim/shared.lua:0: t: expected table, got nil
> stack traceback:
>         [C]: in function 'error'
>         vim/shared.lua: in function 'validate'
>         vim/shared.lua: in function 'tbl_contains'
>         ...ocal/share/nvim/lazy/nvim-html-css/lua/html-css/init.lua:327: in function ''
>         vim/_editor.lua: in function ''
>         vim/_editor.lua: in function <vim/_editor.lua:0>
>
> Plugin is installed with default settings, nvim-cmp source added.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/ESSO0428/lvim/issues/1>, or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AWFQI5SV5CRSHCNW7U3UJVDZGO5XNAVCNFSM6AAAAABJAPNCZGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM2DCOJYGQ4TCOA>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>

savchenko ***@***.***> 於 2024年6月9日 週日 上午10:37寫道:

> Sorry for creating this in the wrong repo, but the *"Issues"* section is
> disabled at ESSO0428/nvim-html-css
> <https://github.com/ESSO0428/nvim-html-css>.
>
> This check
> <https://github.com/ESSO0428/nvim-html-css/blob/8e797fedbfeeecce56a67156f097ab44a8f91d26/lua/html-css/init.lua#L327>
> :
>
> if not vim.tbl_contains(self.option.enable_on, vim.bo.filetype) then
>
> Fails with:
>
> Error executing vim.schedule lua callback: vim/shared.lua:0: t: expected table, got nil
> stack traceback:
>         [C]: in function 'error'
>         vim/shared.lua: in function 'validate'
>         vim/shared.lua: in function 'tbl_contains'
>         ...ocal/share/nvim/lazy/nvim-html-css/lua/html-css/init.lua:327: in function ''
>         vim/_editor.lua: in function ''
>         vim/_editor.lua: in function <vim/_editor.lua:0>
>
> Plugin is installed with default settings, nvim-cmp source added.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/ESSO0428/lvim/issues/1>, or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AWFQI5SV5CRSHCNW7U3UJVDZGO5XNAVCNFSM6AAAAABJAPNCZGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM2DCOJYGQ4TCOA>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>