mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	API: nvim_get_commands(): builtin is irrelevant for buffer-local
builtin commands are never buffer-local, so we can return empty for that case.
This commit is contained in:
		@@ -481,8 +481,7 @@ ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err)
 | 
			
		||||
/// Gets a list of buffer-local |user-commands|.
 | 
			
		||||
///
 | 
			
		||||
/// @param  buffer  Buffer handle.
 | 
			
		||||
/// @param  opts  Optional parameters. Currently only supports
 | 
			
		||||
///               {"builtin":false}
 | 
			
		||||
/// @param  opts  Optional parameters. Currently not used.
 | 
			
		||||
/// @param[out]  err   Error details, if any.
 | 
			
		||||
///
 | 
			
		||||
/// @returns Array of dictionaries describing commands.
 | 
			
		||||
@@ -490,27 +489,31 @@ ArrayOf(Dictionary) nvim_buf_get_commands(Buffer buffer, Dictionary opts,
 | 
			
		||||
                                          Error *err)
 | 
			
		||||
    FUNC_API_SINCE(4)
 | 
			
		||||
{
 | 
			
		||||
  bool global = (buffer == -1);
 | 
			
		||||
  bool builtin = false;
 | 
			
		||||
 | 
			
		||||
  for (size_t i = 0; i < opts.size; i++) {
 | 
			
		||||
    String k = opts.items[i].key;
 | 
			
		||||
    Object v = opts.items[i].value;
 | 
			
		||||
    if (!strequal("builtin", k.data)) {
 | 
			
		||||
      api_set_error(err, kErrorTypeValidation, "unexpected key: %s",
 | 
			
		||||
                    k.data);
 | 
			
		||||
      api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
 | 
			
		||||
      return (Array)ARRAY_DICT_INIT;
 | 
			
		||||
    }
 | 
			
		||||
    if (v.type != kObjectTypeBoolean || v.data.boolean != false) {
 | 
			
		||||
      api_set_error(err, kErrorTypeValidation,
 | 
			
		||||
                    "builtin commands not supported yet");
 | 
			
		||||
      return (Array)ARRAY_DICT_INIT;
 | 
			
		||||
    if (strequal("builtin", k.data)) {
 | 
			
		||||
      builtin = v.data.boolean;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (buffer == -1) {
 | 
			
		||||
  if (global) {
 | 
			
		||||
    if (builtin) {
 | 
			
		||||
      api_set_error(err, kErrorTypeValidation, "builtin=true not implemented");
 | 
			
		||||
      return (Array)ARRAY_DICT_INIT;
 | 
			
		||||
    }
 | 
			
		||||
    return commands_array(NULL);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  buf_T *buf = find_buffer_by_handle(buffer, err);
 | 
			
		||||
  if (!buf) {
 | 
			
		||||
  if (builtin || !buf) {
 | 
			
		||||
    return (Array)ARRAY_DICT_INIT;
 | 
			
		||||
  }
 | 
			
		||||
  return commands_array(buf);
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ describe('nvim_get_commands', function()
 | 
			
		||||
  end)
 | 
			
		||||
 | 
			
		||||
  it('validates input', function()
 | 
			
		||||
    expect_err('builtin commands not supported yet', meths.get_commands,
 | 
			
		||||
    expect_err('builtin=true not implemented', meths.get_commands,
 | 
			
		||||
               {builtin=true})
 | 
			
		||||
    expect_err('unexpected key: foo', meths.get_commands,
 | 
			
		||||
               {foo='blah'})
 | 
			
		||||
@@ -47,6 +47,9 @@ describe('nvim_get_commands', function()
 | 
			
		||||
    -- Delete a command.
 | 
			
		||||
    command('delcommand Pwd')
 | 
			
		||||
    eq({cmd_dict}, curbufmeths.get_commands({builtin=false}))
 | 
			
		||||
 | 
			
		||||
    -- {builtin=true} always returns empty for buffer-local case.
 | 
			
		||||
    eq({}, curbufmeths.get_commands({builtin=true}))
 | 
			
		||||
  end)
 | 
			
		||||
 | 
			
		||||
  it('gets various command attributes', function()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user