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

Luasnip autosnippet doesn't hide menu #1018

Open
2 tasks done
yifan0414 opened this issue Jan 15, 2025 · 1 comment
Open
2 tasks done

Luasnip autosnippet doesn't hide menu #1018

yifan0414 opened this issue Jan 15, 2025 · 1 comment
Labels
bug Something isn't working snippets Built-in provider and library for snippets

Comments

@yifan0414
Copy link

yifan0414 commented Jan 15, 2025

Make sure you have done the following

  • Updated to the latest version of blink.cmp
  • Searched for existing issues and documentation (try <C-k> on https://cmp.saghen.dev)

Bug Description

I use the luasnip autosnippet, When i trigger, there is still a cmp window. It is undesirable.
BUT it I use tab select and accept, it works normally.

Screen.Recording.2025-01-16.at.00.09.45.mov

Relevant configuration

return {
  "saghen/blink.cmp",
  event = "InsertEnter",
  dependencies = {
    {
      "L3MON4D3/LuaSnip",
      config = function()
        require("luasnip.loaders.from_vscode").lazy_load({ paths = "./snippets" })
        require("luasnip.loaders.from_lua").lazy_load({ paths = "./snippets_lua" })
      end,
    },
  },

  version = "*",

  opts = function()
    return {
      snippets = { preset = "luasnip" },

      keymap = {
        -- set to 'none' to disable the 'default' preset
        ["<Tab>"] = {
          function(cmp) if cmp.is_visible() then return cmp.select_next() else cmp.hide() return cmp.snippet_forward() end end,
          "fallback",
        },
        ["<S-Tab>"] = {
          function(cmp) if cmp.is_visible() then return cmp.select_prev() else cmp.hide() return cmp.snippet_backward() end
          end,
          "fallback",
        },
        ["<CR>"] = {
          "select_and_accept",
          "fallback",
        },
      },
      completion = {
        keyword = { range = "prefix" },
        list = {
          selection = {
            preselect = false,
            auto_insert = true,
          },
        },
      },
      sources = {
        default = { "lsp", "path", "snippets", "buffer" },
      },
    }
  end,
}

autosnippet snippets
lua snippets

local treesitter_postfix = require("luasnip.extras.treesitter_postfix").treesitter_postfix
local postfix_builtin = require("luasnip.extras.treesitter_postfix").builtin
local expr_query = [[
            [
              (if_statement)
              (call_expression)
              (identifier)
              (type_identifier)
              (template_function)
              (subscript_expression)
              (field_expression)
              (user_defined_literal)
            ] @prefix
]]
  treesitter_postfix(
    {
      trig = ".cout",
      matchTSNode = {
        query = expr_query,
        query_lang = "cpp",
        select = "longest",
      },
      reparseBuffer = "live",
      snippetType = "autosnippet",
    },
    fmt(
      [[
          cout << {expr} << endl;
      ]],
      {
        expr = f(function(_, parent)
          return parent.snippet.env.LS_TSMATCH
        end, {}),
      }
    )
  ),

json snippets

  "example1": {
    "prefix": "options",
    "body": ["whoa! :O"],
    "luasnip": {
      "priority": 2000,
      "autotrigger": true,
      "wordTrig": false
    }
  },

neovim version

NVIM v0.11.0-dev-1550+g69ad6b12ec-Homebrew (nightly)

blink.cmp version

0.10.0

@yifan0414 yifan0414 added the bug Something isn't working label Jan 15, 2025
@Saghen Saghen added the snippets Built-in provider and library for snippets label Jan 15, 2025
@Saghen Saghen changed the title Luasnip automatically expands after not hiding the cmp window. Luasnip autosnippet doesn't hide menu Jan 15, 2025
@yifan0414
Copy link
Author

yifan0414 commented Jan 16, 2025

completion = {
  keyword = { range = "prefix" },
  trigger = {
    show_on_x_blocked_trigger_characters = { "'", '"', "(", "."},
  },
}
sources = {
  default = { "lsp", "path", "snippets", "buffer" },
  providers = {
    snippets = {
      max_items = 4,
      should_show_items = function(ctx)
        return ctx.trigger.initial_kind ~= "trigger_character"
      end,
      min_keyword_length = 1, -- don't show when triggered manually, useful for JSON keys
      opts = {
        use_show_condition = true,
        show_autosnippets = false,
      },
    },
    buffer = {
      max_items = 5,
      should_show_items = function(ctx)
        return ctx.trigger.initial_kind ~= "trigger_character"
      end,
    },
  },
},

use this config Temporarily resolved the issue triggered by the. in the postfix autosnippet.

The issue of direct text triggering like json snippet options above still exists.

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

No branches or pull requests

2 participants