neovim / nvim-lspconfig

Quickstart configs for Nvim LSP
Apache License 2.0
10.46k stars 2.06k forks source link

HTML autocomplete not working with snippet enabled #2912

Closed Dynastray closed 9 months ago

Dynastray commented 10 months ago

Description

Hi, since 3 days straight i am trying to get HTML autocompletion to work, I tried everything form the other Issues but none of them worked.

my lazy configuration:

local plugins = {
    --- Uncomment these if you want to manage LSP servers from neovim
    --{'williamboman/mason.nvim'},
    --{'williamboman/mason-lspconfig.nvim'},
    --{'VonHeikemen/lsp-zero.nvim', branch = 'v3.x'},
    -- LSP Support
    {'neovim/nvim-lspconfig'},

    -- Autocompletion
    {'hrsh7th/cmp-nvim-lsp'},
    {'hrsh7th/cmp-buffer'},
    {'hrsh7th/cmp-path'},
    {'hrsh7th/cmp-cmdline'},
    {'hrsh7th/nvim-cmp'},

    -- Snippet engine
    {'hrsh7th/cmp-vsnip'},
    {'hrsh7th/vim-vsnip'},
    {'hrsh7th/vim-vsnip-integ'},
    --{'L3MON4D3/LuaSnip'},
    --{'saadparwaiz1/cmp_luasnip'},

    --[[{
        'windwp/nvim-autopairs',
        event = "InsertEnter",
        opts = {} -- this is equalent to setup({}) function
    },]]--

    -- nvim dashboard
    {
        'nvimdev/dashboard-nvim',
        event = 'VimEnter',
        config = function()
            require('dashboard').setup {
                theme = 'hyper',
                config = {
                    header = require('flow-dash').logo(),
                    footer = {},
                    week_header = {
                        enable = false,
                    },
                    shortcut = {
                        { desc = '󰊳 Update', group = '@property', action = 'Lazy update', key = 'u' },
                    },
                },
            }
        end,
        dependencies = { {'nvim-tree/nvim-web-devicons'}}
    },
}

local opts = {
    ui = {
        icons = {
            cmd = "⌘",
            config = "🛠",
            event = "📅",
            ft = "📂",
            init = "⚙",
            keys = "🗝",
            plugin = "🔌",
            runtime = "💻",
            require = "🌙",
            source = "📄",
            start = "🚀",
            task = "📌",
            lazy = "💤 ",
        },
    },
}

-- Lazy vim init
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"

local function init()
    if not vim.loop.fs_stat(lazypath) then
        vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable", -- latest stable release
        lazypath,
    })
    end

    vim.opt.rtp:prepend(lazypath)
    require("lazy").setup(plugins, opts)
end

return {
    print("Init Lazy package manager..."),
    init()
}

my /after/plugin/lsp.lua:

local cmp = require('cmp')
--local luasnip = require("luasnip") 
cmp.setup({
    preselect = 'item',
    completion = {
        completeopt = 'menu,menuone,noinsert'
    },
    snippet = {
        expand = function(args)
            vim.fn["vsnip#anonymous"](args.body)
            --require('luasnip').lsp_expand(args.body)
        end,
    },
    window = {
        completion = cmp.config.window.bordered(),
        documentation = cmp.config.window.bordered(),
    },
    mapping = cmp.mapping.preset.insert({
        ["<Tab>"] = cmp.mapping(function(fallback)
      -- This little snippet will confirm with tab, and if no entry is selected, will confirm the first item
      if cmp.visible() then
        local entry = cmp.get_selected_entry()
    if not entry then
      cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
    else
      cmp.confirm()
    end
      else
        fallback()
      end
    end, {"i","s","c",}),
    }),
    sources = cmp.config.sources({
      { name = 'nvim_lsp' },
      { name = 'vsnip' }, -- For vsnip users.
      --{ name = 'luasnip' }, -- For luasnip users.
      -- { name = 'ultisnips' }, -- For ultisnips users.
      -- { name = 'snippy' }, -- For snippy users.
    }, {
      { name = 'buffer' },
    })
})

-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true

require('lspconfig').lua_ls.setup {
   capabilities = capabilities,
}
require('lspconfig').html.setup {
    capabilities = capabilities,
    cmd = { "vscode-html-language-server", "--stdio" },
    filetypes = { "html" },
    init_options = {
        {
            configurationSection = { "html", "css", "javascript" },
            embeddedLanguages = {
                css = true,
                javascript = true
            },
            provideFormatter = true
        }
    },
    single_file_support = true,
}

would be nice if some body could help me out and not close this cause of a duplicate as i mentioned in the beginning i tried the things the other issues mentioned.

Neovim version

NVIM v0.9.4 Build type: RelWithDebInfo LuaJIT 2.1.1696883897

Nvim-lspconfig version

No response

Operating system and version

Windows 11

Affected language servers

html

Steps to reproduce

install the plugins as i have them installed using Lazy go into an html document and check for autocompletion

Actual behavior

As I type '<html' and try to autocomplete using the TAB key I just get '' .

Expected behavior

It should autocomplete with '' the cherry on top would be if my cursor would land inside the tag like >|< here where the | is located.

Minimal config

I installed html language server using: npm i -g vscode-langservers-extracted

LSP log

https://gist.github.com/Dynastray/80a2e4c3346f1ce6c19563893411841a

Dynastray commented 9 months ago

Closed due to inactivity

dlulakov commented 5 months ago

Did you find a solution i have the same problem