Saghen / blink.cmp

Performant, batteries-included completion plugin for Neovim
MIT License
1.34k stars 77 forks source link

Regression for snippets with auto import #223

Open strash opened 3 weeks ago

strash commented 3 weeks ago

Make sure you have done the following

Bug Description

now

After expanding a snippet that triggers auto import, the line with import is placed after the snippet.

image

before

This wasn't the case in 0.4.1. The import line was placed at the top of the buffer but with minor inconvenience - the cursor remained on this line.

Relevant configuration

{
    keymap = {
        ["<CR>"] = { "accept", "select_and_accept", "fallback" },
        ["<C-f>"] = { "show", "show_documentation", "hide_documentation", "fallback" },
        ["<C-e>"] = { "hide", "fallback" },
        ["<C-p>"] = { "select_prev", "fallback" },
        ["<C-n>"] = { "select_next", "fallback" },
        ["<C-k>"] = { "scroll_documentation_up", "fallback" },
        ["<C-j>"] = { "scroll_documentation_down", "fallback" },
        ["<S-Tab>"] = { "snippet_backward", "fallback" },
        ["<Tab>"] = {
            function(cmp)
                if cmp.is_in_snippet() then
                    return cmp.accept()
                else
                    return cmp.select_and_accept()
                end
            end,
            "snippet_forward", "fallback"
        },
    },
    trigger = {
        completion = {
            blocked_trigger_characters = { " ", "\n", "\t", "{", "}", "," },
        },
        signature_help = {
            enabled = true,
            show_on_insert_on_trigger_character = false,
        }
    },
    windows = {
        documentation = {
            max_width = 90,
            max_height = 40,
            auto_show = true,
            auto_show_delay_ms = 250,
        },
        ghost_text = {
            enabled = true,
        },
    },
}

neovim version

NVIM v0.10.2 Build type: Release LuaJIT 2.1.1727870382

blink.cmp version: branch, tag, or commit

v0.*

Rishabh672003 commented 3 weeks ago

doesnt seem to happen with gopls and clangd, might be a special case with your lsp

Saghen commented 2 weeks ago

Which LSP are you using? Would be super helpful if you could send the item itself so I can test it. You can do this by adding a vim.print(item) in accept/init.lua which you can find at ~/.local/share/nvim/lazy/blink.cmp/lua/accept/init.lua (assuming lazy.nvim on linux)

strash commented 2 weeks ago

Hi! The lsp is dartls.

{                                                                                                                                                                                               
  client_id = 1,                                                                                                                                                                                
  cursor_column = 3,                                                                                                                                                                            
  documentation = {                                                                                                                                                                             
    kind = "markdown",                                                                                                                                                                          
    value = "Insert a Flutter StatelessWidget."                                                                                                                                                 
  },                                                                                                                                                                                            
  editRange = {                                                                                                                                                                                 
    ["end"] = {                                                                                                                                                                                 
      character = 3,                                                                                                                                                                            
      line = 10                                                                                                                                                                                 
    },                                                                                                                                                                                          
    start = {                                                                                                                                                                                   
      character = 0,                                                                                                                                                                            
      line = 10                                                                                                                                                                                 
    }                                                                                                                                                                                           
  },                                                                                                                                                                                            
  filterText = "stless",                                                                                                                                                                        
  insertTextFormat = 2,                                                                                                                                                                         
  insertTextMode = 1,                                                                                                                                                                           
  kind = 15,                                                                                                                                                                                    
  label = "Flutter Stateless Widget",                                                                                                                                                           
  score_offset = 0,                                                                                                                                                                             
  sortText = "zzzstless",                                                                                                                                                                       
  source_id = "lsp",                                                                                                                                                                            
  source_name = "LSP",                                                                                                                                                                          
  textEditText = "class ${1:MyWidget} extends StatelessWidget {\n  const ${1:MyWidget}({super.key});\n\n  @override\n  Widget build(BuildContext context) {\n    return ${0:const Placeholder()}
;\n  }\n}"                                                                                                                                                                                      
}

or

{                                                                                                                                                                                               
  client_id = 1,                                                                                                                                                                                
  cursor_column = 1,                                                                                                                                                                            
  documentation = {                                                                                                                                                                             
    kind = "markdown",                                                                                                                                                                          
    value = "Insert a Flutter StatefulWidget."                                                                                                                                                  
  },                                                                                                                                                                                            
  editRange = {                                                                                                                                                                                 
    ["end"] = {                                                                                                                                                                                 
      character = 1,                                                                                                                                                                            
      line = 11                                                                                                                                                                                 
    },                                                                                                                                                                                          
    start = {                                                                                                                                                                                   
      character = 0,                                                                                                                                                                            
      line = 11                                                                                                                                                                                 
    }                                                                                                                                                                                           
  },                                                                                                                                                                                            
  filterText = "stful",                                                                                                                                                                         
  insertTextFormat = 2,                                                                                                                                                                         
  insertTextMode = 1,                                                                                                                                                                           
  kind = 15,                                                                                                                                                                                    
  label = "Flutter Stateful Widget",                                                                                                                                                            
  score_offset = 0,                                                                                                                                                                             
  sortText = "zzzstful",                                                                                                                                                                        
  source_id = "lsp",                                                                                                                                                                            
  source_name = "LSP",                                                                                                                                                                          
  textEditText = "class ${1:MyWidget} extends StatefulWidget {\n  const ${1:MyWidget}({super.key});\n\n  @override\n  State<${1:MyWidget}> createState() => _${1:MyWidget}State();\n}\n\nclass _
${1:MyWidget}State extends State<${1:MyWidget}> {\n  @override\n  Widget build(BuildContext context) {\n    return ${0:const Placeholder()};\n  }\n}"                                           
}
Saghen commented 2 weeks ago

Sorry I messed up, I actually need the value of resolved_item

strash commented 2 weeks ago

Sure, no worries

{                                                                                                                                                                                                
  additionalTextEdits = { {                                                                                                                                                                      
      insertTextFormat = 2,                                                                                                                                                                      
      newText = 'import "package:flutter/widgets.dart";\n\n',                                                                                                                                    
      range = {                                                                                                                                                                                  
        ["end"] = {                                                                                                                                                                              
          character = 0,                                                                                                                                                                         
          line = 0                                                                                                                                                                               
        },                                                                                                                                                                                       
        start = {                                                                                                                                                                                
          character = 0,                                                                                                                                                                         
          line = 0                                                                                                                                                                               
        }                                                                                                                                                                                        
      }                                                                                                                                                                                          
    } },                                                                                                                                                                                         
  documentation = {                                                                                                                                                                              
    kind = "markdown",                                                                                                                                                                           
    value = "Insert a Flutter StatelessWidget."                                                                                                                                                  
  },                                                                                                                                                                                             
  filterText = "stless",                                                                                                                                                                         
  insertTextFormat = 2,                                                                                                                                                                          
  insertTextMode = 1,                                                                                                                                                                            
  kind = 15,                                                                                                                                                                                     
  label = "Flutter Stateless Widget",                                                                                                                                                            
  sortText = "zzzstless",                                                                                                                                                                        
  textEditText = "class ${1:MyWidget} extends StatelessWidget {\n  const ${1:MyWidget}({super.key});\n\n  @override\n  Widget build(BuildContext context) {\n    return ${0:const Placeholder()};
\n  }\n}"                                                                                                                                                                                        
}

or

{                                                                                                                                                                                                
  additionalTextEdits = { {                                                                                                                                                                      
      insertTextFormat = 2,                                                                                                                                                                      
      newText = 'import "package:flutter/widgets.dart";\n\n',                                                                                                                                    
      range = {                                                                                                                                                                                  
        ["end"] = {                                                                                                                                                                              
          character = 0,                                                                                                                                                                         
          line = 0                                                                                                                                                                               
        },                                                                                                                                                                                       
        start = {                                                                                                                                                                                
          character = 0,                                                                                                                                                                         
          line = 0                                                                                                                                                                               
        }                                                                                                                                                                                        
      }                                                                                                                                                                                          
    } },                                                                                                                                                                                         
  documentation = {                                                                                                                                                                              
    kind = "markdown",                                                                                                                                                                           
    value = "Insert a Flutter StatefulWidget."                                                                                                                                                   
  },                                                                                                                                                                                             
  filterText = "stful",                                                                                                                                                                          
  insertTextFormat = 2,                                                                                                                                                                          
  insertTextMode = 1,                                                                                                                                                                            
  kind = 15,                                                                                                                                                                                     
  label = "Flutter Stateful Widget",                                                                                                                                                             
  sortText = "zzzstful",                                                                                                                                                                         
  textEditText = "class ${1:MyWidget} extends StatefulWidget {\n  const ${1:MyWidget}({super.key});\n\n  @override\n  State<${1:MyWidget}> createState() => _${1:MyWidget}State();\n}\n\nclass _$
{1:MyWidget}State extends State<${1:MyWidget}> {\n  @override\n  Widget build(BuildContext context) {\n    return ${0:const Placeholder()};\n  }\n}"                                             
}