Jezda1337 / nvim-html-css

CSS Intellisense for HTML
115 stars 13 forks source link

Failed to run `config` : no parser for 'html' language #4

Closed mrbradleylee closed 10 months ago

mrbradleylee commented 10 months ago

I'm having an issue getting the plugin to load, where if any *.html file exists in the file tree I get an error running the config function:

Failed to run `config` for nvim-html-css
...0.9.1/share/nvim/runtime/lua/vim/treesitter/language.lua:94: no parser for 'html' language, see :help treesitter-parsers
# stacktrace:
  - /opt/homebrew/Cellar/neovim/0.9.1/share/nvim/runtime/lua/vim/treesitter/language.lua:94 _in_ **add**
  - /opt/homebrew/Cellar/neovim/0.9.1/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:98 _in_ **get_string_parser**
  - ~/.config/nvim/lua/config/plugins.lua:55 _in_ **config**
  - ~/.config/nvim/lua/config/plugins.lua:69
  - ~/.config/nvim/init.lua:9

TSInstall html shows html and css are already loaded, they're also under ensure_installed in TS config file

~/.config/nvim has lua/init.lua which calls lua/config/plugins.lua

plugins are defined like so (nothing is lazy loaded yet):

...
local plugins = {
  {
  'folke/tokyonight.nvim', --storm/night/moon/day
  -- 'catppuccin/nvim', -- -latte/frappe/macchiato/mocha (default)
  lazy = false,
  priority = 1000,
  },
  'nvim-tree/nvim-tree.lua',
  'nvim-tree/nvim-web-devicons',
  'akinsho/bufferline.nvim',
  'nvim-lualine/lualine.nvim',
  {
    'echasnovski/mini.indentscope', -- fancy indent line
    version = false
  },
  'max397574/better-escape.nvim',
  'numToStr/Comment.nvim',
  'ggandor/leap.nvim',
  'nvim-treesitter/nvim-treesitter',

  -- lsp > completion > snippets TODO
  'williamboman/mason.nvim',
  'williamboman/mason-lspconfig.nvim',
  'neovim/nvim-lspconfig',
  'nvimdev/lspsaga.nvim',
  'hrsh7th/nvim-cmp',
  'hrsh7th/cmp-nvim-lsp', -- nvim_lsp completion source
  'L3MON4D3/LuaSnip',
  'saadparwaiz1/cmp_luasnip', -- luasnip snippet completion source
  'rafamadriz/friendly-snippets',
  'hrsh7th/cmp-buffer', -- buffer completion source
  'hrsh7th/cmp-path', -- path completion source
  {
    'Jezda1337/nvim-html-css',
    config = function()
      require('html-css'):setup()
    end,
  },
  {
    'nvim-telescope/telescope.nvim',
    dependencies = {
       'nvim-lua/plenary.nvim',
       { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' }
       }
  },
}

-- load plugins from plugins.lua or alternatively lua/plugins/init.lua
-- should be EOF
require("lazy").setup(plugins, opts)

full cmp setup:

local cmp = require('cmp') -- nvim-cmp

require('luasnip.loaders.from_vscode').lazy_load() -- for friendlysnippets and cmpluasnip

cmp.setup({
  mapping = cmp.mapping.preset.insert({
    ['<C-k>'] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
    ['<C-j>'] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
    ['<Tab>'] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
    ['<C-b>'] = cmp.mapping.scroll_docs(-4),
    ['<C-f>'] = cmp.mapping.scroll_docs(4),
    ['<C-o>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.abort(),
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
  }),
  snippet = { -- configure required snippet engine
    expand = function(args)
      require('luasnip').lsp_expand(args.body)
    end,
  },

  sources = cmp.config.sources{
    { name = 'nvim_lsp' }, --complete from nvim_lsp
    { name = 'luasnip' }, --complete from luasnip
    {
      name = 'html-css',
      option = {
        enable_on = {
          "html"
        },
        file_extensions = { "css", "sass", "less" }, -- set local filetypes for class list
        style_sheets = {
          -- remote style config eg bootstrap/tailwind
          'https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css',
        }
      }
    },
  }, {
    { name = 'buffer' }, --complete from buffer
    { name = 'path' }, --complete from buffer
  },

  -- enable filename path for css config
  formatting = {
        format = function(entry, vim_item)
            if entry.source.name == "html-css" then
                vim_item.menu = entry.source.menu
            end
            return vim_item
        end
    }
})

Feel like I'm so close to getting this working, but am missing something really small and hoping you can help!

Jezda1337 commented 10 months ago

Can you add dependencies to plugin?

dependencies = {
  "nvim-treesitter/nvim-treesitter",
  "nvim-lua/plenary.nvim"
 },
mrbradleylee commented 10 months ago

When I add dependencies to the plugin, nvim won't start at all. Just flashes and returns to terminal immediately.

{
    'Jezda1337/nvim-html-css',
    dependencies = {
      'nvim-treesitter/nvim-treesitter',
      'nvim-lua/plenary.nvim'
    },
    config = function()
      require('html-css'):setup()
    end,
  },
Jezda1337 commented 10 months ago

Finally I make the config that produce the bug, now I will start with debugging, wish me luck šŸ«”

mrbradleylee commented 10 months ago

Finally I make the config that produce the bug, now I will start with debugging, wish me luck šŸ«”

Appreciate you taking the time to work on this! The last step towards dumping VSCode šŸ‘

Jezda1337 commented 10 months ago

Hey @mrbradleylee, accually there is no bug in the code, the reason why doesn't work is bcs, you load html-css plugin 1st, and then nvim-cmp, so html-css plugin can't read the settings and can't be injected into cmp so that was the issue, to solve this there is 2 options, to call your configuration using config prop like this:

so inside plugins you will only set the name of the plugin "Jezda1337/nvim-html-css"

edit: to be able to have file names in cmp menu you should put this: ( I will change this on repo later)

formatting = {
    format = function(entry, vim_item)
        if entry.source.name == "html-css" then
            vim_item.menu = entry.completion_item.menu -- change just his line of code
        end
        return vim_item
    end
}

You can try both ways if you want, but I would like to hear some feedback cheers šŸ«”

mrbradleylee commented 10 months ago

That was it šŸ¤Æ !! Went with solution number 2. Much cleaner plugins file now. Many thanks! Already working on some projects and am loving it so far. Will keep a close eye on this one šŸ‘Øā€šŸ³ šŸ’‹