Repository: neovim/neovim
File: src/nvim/insexpand.c (C)

Code before:
  }

  return OK;
}

/// Get the pattern, column and length for filename completion.
/// Sets the global variables: compl_col, compl_length and compl_pattern.
static int get_filename_compl_info(char *line, int startcol, colnr_T curs_col)
{
  // Go back to just before the first filename character.
  if (startcol > 0) {
    char *p = line + startcol;

    MB_PTR_BACK(line, p);
    while (p > line && vim_isfilec(utf_ptr2char(p))) {
      MB_PTR_BACK(line, p);
    }
    bool p_is_filec;
#ifdef MSWIN
    // check for drive letters on mswin
    if (p > line && path_has_drive_letter(p - 1, line + startcol - (p - 1))) {
      p -= p == line + 1 ? 1 : 2;
      p_is_filec = true;
    } else
#endif
    p_is_filec = vim_isfilec(utf_ptr2char(p));

    if (p == line && p_is_filec) {
      startcol = 0;
    } else {
      startcol = (int)(p - line) + 1;
    }
  }

  compl_col += startcol;
  compl_length = (int)curs_col - startcol;
  compl_pattern = cstr_as_string(addstar(line + compl_col,
                                         (size_t)compl_length, EXPAND_FILES));

  return OK;
}

/// Get the pattern, column and length for command-line completion.
/// Sets the global variables: compl_col, compl_length and compl_pattern.
static int get_cmdline_compl_info(char *line, colnr_T curs_col)
{
  compl_pattern = cbuf_to_string(line, (size_t)curs_col);
  set_cmd_context(&compl_xp, compl_pattern.data,
                  (int)compl_pattern.size, curs_col, false);
  if (compl_xp.xp_context == EXPAND_LUA) {
    nlua_expand_pat(&compl_xp);

Review comment (bug):
the `else #endif` trick can lead to bugs, can we do something like this instead:


```suggestion
    bool p_is_filec = false;
#ifdef MSWIN
    // check for drive letters on mswin
    if (p > line && path_has_drive_letter(p - 1, line + startcol - (p - 1))) {
      p -= p == line + 1 ? 1 : 2;
      p_is_filec = true;
    }
#endif
    p_is_filec = p_is_filec || vim_isfilec(utf_ptr2char(p));
```

Code after:
  }

  return OK;
}

/// Get the pattern, column and length for filename completion.
/// Sets the global variables: compl_col, compl_length and compl_pattern.
static int get_filename_compl_info(char *line, int startcol, colnr_T curs_col)
{
  // Go back to just before the first filename character.
  if (startcol > 0) {
    char *p = line + startcol;

    MB_PTR_BACK(line, p);
    while (p > line && vim_isfilec(utf_ptr2char(p))) {
      MB_PTR_BACK(line, p);
    }
    bool p_is_filec = false;
#ifdef MSWIN
    // check for drive letters on mswin
    if (p > line && path_has_drive_letter(p - 1, line + startcol - (p - 1))) {
      p -= p == line + 1 ? 1 : 2;
      p_is_filec = true;
    }
#endif
    p_is_filec = p_is_filec || vim_isfilec(utf_ptr2char(p));

    if (p == line && p_is_filec) {
      startcol = 0;
    } else {
      startcol = (int)(p - line) + 1;
    }
  }

  compl_col += startcol;
  compl_length = (int)curs_col - startcol;
  compl_pattern = cstr_as_string(addstar(line + compl_col,
                                         (size_t)compl_length, EXPAND_FILES));

  return OK;
}

/// Get the pattern, column and length for command-line completion.
/// Sets the global variables: compl_col, compl_length and compl_pattern.
static int get_cmdline_compl_info(char *line, colnr_T curs_col)
{
  compl_pattern = cbuf_to_string(line, (size_t)curs_col);
  set_cmd_context(&compl_xp, compl_pattern.data,
                  (int)compl_pattern.size, curs_col, false);
  if (compl_xp.xp_context == EXPAND_LUA) {
    nlua_expand_pat(&compl_xp);