mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	LSP: Fix nil settings handling in workspace/configuration (#13708)
The `workspace/configuration` handler could fail with the following
error if `config.settings` is nil:
    runtime/lua/vim/lsp/util.lua:1432: attempt to index local 'settings' (a nil value)"
This ensures that `config.settings` is always initialized to an empty
table.
			
			
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							51936126d3
						
					
				
				
					commit
					3f63100d5b
				
			@@ -229,6 +229,7 @@ local function validate_client_config(config)
 | 
				
			|||||||
    before_init     = { config.before_init, "f", true };
 | 
					    before_init     = { config.before_init, "f", true };
 | 
				
			||||||
    offset_encoding = { config.offset_encoding, "s", true };
 | 
					    offset_encoding = { config.offset_encoding, "s", true };
 | 
				
			||||||
    flags           = { config.flags, "t", true };
 | 
					    flags           = { config.flags, "t", true };
 | 
				
			||||||
 | 
					    settings        = { config.settings, "t", true };
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  -- TODO(remove-callbacks)
 | 
					  -- TODO(remove-callbacks)
 | 
				
			||||||
@@ -458,6 +459,7 @@ function lsp.start_client(config)
 | 
				
			|||||||
  local cmd, cmd_args, offset_encoding = cleaned_config.cmd, cleaned_config.cmd_args, cleaned_config.offset_encoding
 | 
					  local cmd, cmd_args, offset_encoding = cleaned_config.cmd, cleaned_config.cmd_args, cleaned_config.offset_encoding
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  config.flags = config.flags or {}
 | 
					  config.flags = config.flags or {}
 | 
				
			||||||
 | 
					  config.settings = config.settings or {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local client_id = next_client_id()
 | 
					  local client_id = next_client_id()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -162,6 +162,7 @@ M['workspace/configuration'] = function(err, _, params, client_id)
 | 
				
			|||||||
  local client = vim.lsp.get_client_by_id(client_id)
 | 
					  local client = vim.lsp.get_client_by_id(client_id)
 | 
				
			||||||
  if not client then
 | 
					  if not client then
 | 
				
			||||||
    err_message("LSP[id=", client_id, "] client has shut down after sending the message")
 | 
					    err_message("LSP[id=", client_id, "] client has shut down after sending the message")
 | 
				
			||||||
 | 
					    return
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  if err then error(vim.inspect(err)) end
 | 
					  if err then error(vim.inspect(err)) end
 | 
				
			||||||
  if not params.items then
 | 
					  if not params.items then
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -303,6 +303,21 @@ describe('LSP', function()
 | 
				
			|||||||
        end;
 | 
					        end;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    end)
 | 
					    end)
 | 
				
			||||||
 | 
					    it('workspace/configuration returns NIL per section if client was started without config.settings', function()
 | 
				
			||||||
 | 
					      fake_lsp_server_setup('workspace/configuration no settings')
 | 
				
			||||||
 | 
					      eq({
 | 
				
			||||||
 | 
					        NIL,
 | 
				
			||||||
 | 
					        NIL,
 | 
				
			||||||
 | 
					      }, exec_lua [[
 | 
				
			||||||
 | 
					        local params = {
 | 
				
			||||||
 | 
					          items = {
 | 
				
			||||||
 | 
					            {section = 'foo'},
 | 
				
			||||||
 | 
					            {section = 'bar'},
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return vim.lsp.handlers['workspace/configuration'](nil, nil, params, TEST_RPC_CLIENT_ID)
 | 
				
			||||||
 | 
					      ]])
 | 
				
			||||||
 | 
					    end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it('should verify capabilities sent', function()
 | 
					    it('should verify capabilities sent', function()
 | 
				
			||||||
      local expected_callbacks = {
 | 
					      local expected_callbacks = {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user