mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	fix(runtime): respect 'fileignorecase' when sourcing (#24344)
This commit is contained in:
		@@ -1810,7 +1810,7 @@ bool path_with_extension(const char *path, const char *extension)
 | 
			
		||||
  if (!last_dot) {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
  return strcmp(last_dot + 1, extension) == 0;
 | 
			
		||||
  return mb_strcmp_ic((bool)p_fic, last_dot + 1, extension) == 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Return true if "name" is a full (absolute) path name or URL.
 | 
			
		||||
 
 | 
			
		||||
@@ -275,7 +275,7 @@ static bool source_callback_vim_lua(int num_fnames, char **fnames, bool all, voi
 | 
			
		||||
  bool did_one = false;
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; i < num_fnames; i++) {
 | 
			
		||||
    if (str_ends_with(fnames[i], ".vim")) {
 | 
			
		||||
    if (path_with_extension(fnames[i], "vim")) {
 | 
			
		||||
      (void)do_source(fnames[i], false, DOSO_NONE, cookie);
 | 
			
		||||
      did_one = true;
 | 
			
		||||
      if (!all) {
 | 
			
		||||
@@ -285,7 +285,7 @@ static bool source_callback_vim_lua(int num_fnames, char **fnames, bool all, voi
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; i < num_fnames; i++) {
 | 
			
		||||
    if (str_ends_with(fnames[i], ".lua")) {
 | 
			
		||||
    if (path_with_extension(fnames[i], "lua")) {
 | 
			
		||||
      (void)do_source(fnames[i], false, DOSO_NONE, cookie);
 | 
			
		||||
      did_one = true;
 | 
			
		||||
      if (!all) {
 | 
			
		||||
@@ -308,7 +308,8 @@ static bool source_callback(int num_fnames, char **fnames, bool all, void *cooki
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; i < num_fnames; i++) {
 | 
			
		||||
    if (!str_ends_with(fnames[i], ".vim") && !str_ends_with(fnames[i], ".lua")) {
 | 
			
		||||
    if (!path_with_extension(fnames[i], "vim")
 | 
			
		||||
        && !path_with_extension(fnames[i], "lua")) {
 | 
			
		||||
      (void)do_source(fnames[i], false, DOSO_NONE, cookie);
 | 
			
		||||
      did_one = true;
 | 
			
		||||
      if (!all) {
 | 
			
		||||
 
 | 
			
		||||
@@ -436,25 +436,6 @@ char *vim_strchr(const char *const string, const int c)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Test if "str" ends with "suffix"
 | 
			
		||||
///
 | 
			
		||||
/// @param[in] str
 | 
			
		||||
/// @param[in] suffix to match
 | 
			
		||||
///
 | 
			
		||||
/// @return [allocated] Copy of the string.
 | 
			
		||||
bool str_ends_with(const char *str, const char *suffix)
 | 
			
		||||
{
 | 
			
		||||
  if (!str || !suffix) {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
  size_t lenstr = strlen(str);
 | 
			
		||||
  size_t lensuffix = strlen(suffix);
 | 
			
		||||
  if (lensuffix > lenstr) {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
  return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Sort an array of strings.
 | 
			
		||||
 | 
			
		||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
 | 
			
		||||
 
 | 
			
		||||
@@ -177,6 +177,31 @@ describe('runtime:', function()
 | 
			
		||||
      exec('setfiletype new-ft')
 | 
			
		||||
      eq('ABCDEFabcdef', eval('g:seq'))
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    it("'rtp' order is respected with 'fileignorecase'", function()
 | 
			
		||||
      exec('set fileignorecase')
 | 
			
		||||
      local after_ftplugin_folder = table.concat({plug_dir, 'after', 'ftplugin'}, sep)
 | 
			
		||||
      mkdir_p(table.concat({ftplugin_folder, 'new-ft'}, sep))
 | 
			
		||||
      mkdir_p(table.concat({after_ftplugin_folder, 'new-ft'}, sep))
 | 
			
		||||
      exec('set rtp+=' .. plug_dir .. '/after')
 | 
			
		||||
      exec('let g:seq = ""')
 | 
			
		||||
      -- A .lua file is loaded after a .vim file if they only differ in extension.
 | 
			
		||||
      -- All files in after/ftplugin/ are loaded after all files in ftplugin/.
 | 
			
		||||
      write_file(table.concat({ftplugin_folder, 'new-ft.VIM'}, sep), [[let g:seq ..= 'A']])
 | 
			
		||||
      write_file(table.concat({ftplugin_folder, 'new-ft.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
 | 
			
		||||
      write_file(table.concat({ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'C']])
 | 
			
		||||
      write_file(table.concat({ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']])
 | 
			
		||||
      write_file(table.concat({ftplugin_folder, 'new-ft', 'a.VIM'}, sep), [[let g:seq ..= 'E']])
 | 
			
		||||
      write_file(table.concat({ftplugin_folder, 'new-ft', 'a.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'F']])
 | 
			
		||||
      write_file(table.concat({after_ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']])
 | 
			
		||||
      write_file(table.concat({after_ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
 | 
			
		||||
      write_file(table.concat({after_ftplugin_folder, 'new-ft_a.VIM'}, sep), [[let g:seq ..= 'c']])
 | 
			
		||||
      write_file(table.concat({after_ftplugin_folder, 'new-ft_a.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'd']])
 | 
			
		||||
      write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'e']])
 | 
			
		||||
      write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'f']])
 | 
			
		||||
      exec('setfiletype new-ft')
 | 
			
		||||
      eq('ABCDEFabcdef', eval('g:seq'))
 | 
			
		||||
    end)
 | 
			
		||||
  end)
 | 
			
		||||
 | 
			
		||||
  describe('indent', function()
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,7 @@ local mkdir = helpers.mkdir
 | 
			
		||||
 | 
			
		||||
cimport('string.h')
 | 
			
		||||
local cimp = cimport('./src/nvim/os/os.h', './src/nvim/path.h')
 | 
			
		||||
local options = cimport('./src/nvim/option_defs.h')
 | 
			
		||||
 | 
			
		||||
local length = 0
 | 
			
		||||
local buffer = nil
 | 
			
		||||
@@ -636,6 +637,15 @@ describe('path.c', function()
 | 
			
		||||
      eq(false, path_with_extension('/some/path/file.vim', 'lua'))
 | 
			
		||||
      eq(false, path_with_extension('/some/path/file', 'lua'))
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    itp("respects 'fileignorecase' option", function()
 | 
			
		||||
      options.p_fic = false
 | 
			
		||||
      eq(false, path_with_extension('/some/path/file.VIM', 'vim'))
 | 
			
		||||
      eq(false, path_with_extension('/some/path/file.LUA', 'lua'))
 | 
			
		||||
      options.p_fic = true
 | 
			
		||||
      eq(true, path_with_extension('/some/path/file.VIM', 'vim'))
 | 
			
		||||
      eq(true, path_with_extension('/some/path/file.LUA', 'lua'))
 | 
			
		||||
    end)
 | 
			
		||||
  end)
 | 
			
		||||
 | 
			
		||||
  describe('path_with_url', function()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user