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

Completion doesn't close in .astro files #1471

Open
2 tasks done
bushblade opened this issue Mar 2, 2023 · 3 comments
Open
2 tasks done

Completion doesn't close in .astro files #1471

bushblade opened this issue Mar 2, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@bushblade
Copy link

bushblade commented Mar 2, 2023

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

-- setup lazy for plugins
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
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({
  {
    "neovim/nvim-lspconfig",
    config = function()
      require("lspconfig").emmet_ls.setup({
        filetypes = { "html", "css", "javascriptreact", "typescriptreact", "vue", "astro" },
      })
      require("lspconfig").astro.setup({
        init_options = {
          typescript = {
            -- needs to be installed in ~ by using `pnpm i typescript`. NOTE: do not use -g flag!
            serverPath = os.getenv("HOME") .. "/.npm-packages/lib/node_modules/typescript/lib/typescript.js",
          },
        },
      })
    end,
  },
  {
    "hrsh7th/nvim-cmp",
    dependencies = {
      "hrsh7th/cmp-nvim-lsp", -- lsp completions
      "saadparwaiz1/cmp_luasnip", -- snippets completions
      "L3MON4D3/LuaSnip",
      "rafamadriz/friendly-snippets",
    },
    config = function()
      local cmp = require("cmp")
      local luasnip = require("luasnip")
      local has_words_before = function()
        unpack = unpack or table.unpack
        local line, col = unpack(vim.api.nvim_win_get_cursor(0))
        return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
      end

      cmp.setup({
        snippet = {
          expand = function(args)
            require("luasnip").lsp_expand(args.body)
          end,
        },
        mapping = {
          ["<C-p>"] = cmp.mapping.select_prev_item(),
          ["<C-n>"] = cmp.mapping.select_next_item(),
          ["<C-d>"] = cmp.mapping.scroll_docs(-4),
          ["<C-f>"] = cmp.mapping.scroll_docs(4),
          ["<C-e>"] = cmp.mapping.close(),
          ["<CR>"] = cmp.mapping.confirm({
            select = true,
          }),
          ["<Tab>"] = cmp.mapping(function(fallback)
            if cmp.visible() then
              cmp.select_next_item()
            elseif luasnip.expand_or_jumpable() then
              luasnip.expand_or_jump()
            elseif has_words_before() then
              cmp.complete()
            else
              fallback()
            end
          end, { "i", "s" }),

          ["<S-Tab>"] = cmp.mapping(function(fallback)
            if cmp.visible() then
              cmp.select_prev_item()
            elseif luasnip.jumpable(-1) then
              luasnip.jump(-1)
            else
              fallback()
            end
          end, { "i", "s" }),
        },
        sources = cmp.config.sources({
          { name = "nvim_lsp" },
          { name = "luasnip" },
        }),
      })
    end,
  },
})

Description

In *.astro files the completion doesn't close after accepting a completion and shows another completion for the closing tag.
Subsequently pressing <CR> accepts the next completions suggestion.

Steps to reproduce

Create any .astro file and try an write some markup.

Expected behavior

Completion closes and <CR> goes to a new line, same behaviour as in .jsx/.tsx/.vue/.html etc.

Actual behavior

For example here I start typing

Screenshot_2023-03-02_15-42-09

And hit <CR> to accept the completion...

Screenshot_2023-03-02_15-42-46

Which then shows another completion, so if I hit <CR> instead of the expected behaviour of going to a new line, it accepts the next suggestion...

Screenshot_2023-03-02_15-44-29

Which inserts another closing tag and again offers the same completion, this just keeps repeating as long as you press <CR>

Additional context

No response

@bushblade bushblade added the bug Something isn't working label Mar 2, 2023
@chalop
Copy link

chalop commented Mar 27, 2023

Might be unrelated, but cmp does not show does not show astro's component props.

@bushblade
Copy link
Author

Hi @chalop
It does show completion on component props for me.

Screenshot_2023-04-09_16-53-49

Are you using JavaScript or TypeScript?

@chalop
Copy link

chalop commented Apr 9, 2023

Sorry, I meant when invoking / using a component. Here's some examples:

The component has the following interface:
Screenshot 2023-04-09 at 15 56 34

Nvim does not show the full list of available props:
Screenshot 2023-04-09 at 15 54 41

While vscode does:
Screenshot 2023-04-09 at 15 57 38

The lsp does give me the proper errors when I don't implement any required properties though, hence why I believe its an issue with nvim-cmp.

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

2 participants