mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	fix(lsp): fallback to label for completion items if all others are missing (#29522)
				
					
				
			This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							cb84cd5d9f
						
					
				
				
					commit
					aec7f1979a
				
			@@ -176,7 +176,7 @@ local function apply_defaults(item, defaults)
 | 
				
			|||||||
  if defaults.editRange then
 | 
					  if defaults.editRange then
 | 
				
			||||||
    local textEdit = item.textEdit or {}
 | 
					    local textEdit = item.textEdit or {}
 | 
				
			||||||
    item.textEdit = textEdit
 | 
					    item.textEdit = textEdit
 | 
				
			||||||
    textEdit.newText = textEdit.newText or item.textEditText or item.insertText
 | 
					    textEdit.newText = textEdit.newText or item.textEditText or item.insertText or item.label
 | 
				
			||||||
    if defaults.editRange.start then
 | 
					    if defaults.editRange.start then
 | 
				
			||||||
      textEdit.range = textEdit.range or defaults.editRange
 | 
					      textEdit.range = textEdit.range or defaults.editRange
 | 
				
			||||||
    elseif defaults.editRange.insert then
 | 
					    elseif defaults.editRange.insert then
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -427,6 +427,33 @@ describe('vim.lsp.completion: item conversion', function()
 | 
				
			|||||||
      eq('the-insertText', text)
 | 
					      eq('the-insertText', text)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  it(
 | 
				
			||||||
 | 
					    'defaults to label as textEdit.newText if insertText or textEditText are not present',
 | 
				
			||||||
 | 
					    function()
 | 
				
			||||||
 | 
					      local completion_list = {
 | 
				
			||||||
 | 
					        isIncomplete = false,
 | 
				
			||||||
 | 
					        itemDefaults = {
 | 
				
			||||||
 | 
					          editRange = {
 | 
				
			||||||
 | 
					            start = { line = 1, character = 1 },
 | 
				
			||||||
 | 
					            ['end'] = { line = 1, character = 4 },
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          insertTextFormat = 2,
 | 
				
			||||||
 | 
					          data = 'foobar',
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        items = {
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            label = 'hello',
 | 
				
			||||||
 | 
					            data = 'item-property-has-priority',
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      local result = complete('|', completion_list)
 | 
				
			||||||
 | 
					      eq(1, #result.items)
 | 
				
			||||||
 | 
					      local text = result.items[1].user_data.nvim.lsp.completion_item.textEdit.newText
 | 
				
			||||||
 | 
					      eq('hello', text)
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
end)
 | 
					end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('vim.lsp.completion: protocol', function()
 | 
					describe('vim.lsp.completion: protocol', function()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user