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

Code before:
    textlock = 0;
  }
  nvim_buf_set_lines(0, buf->handle, 0, -1, false, replacement, &arena, &err);
  textlock = original_textlock;
  if (ERROR_SET(&err)) {
    emsg(err.msg);
    api_clear_error(&err);
  }
  arena_mem_free(arena_finish(&arena));
  api_free_array(replacement);
  buf->b_p_ma = false;
}

/// adjust floating info preview window position
static void pum_adjust_info_position(win_T *wp, int width)
{
  int border_width = pum_border_width();
  int col = pum_col + pum_width + 1 + border_width;
  // When the popup menu has no border but has a scrollbar,
  // the info window needs a one-column offset.
  if (border_width == 0 && pum_scrollbar) {
    col += 1;
  }
  if (border_width < 0) {
    col += pum_scrollbar;
  }
  // TODO(glepnir): support config align border by using completepopup
  // align menu
  int right_extra = Columns - col;
  int left_extra = pum_col - 2;

  if (right_extra > width) {  // place in right
    wp->w_config.width = width;
    wp->w_config.col = col - 1;
  } else if (left_extra > width) {  // place in left
    wp->w_config.width = width;
    wp->w_config.col = pum_col - wp->w_config.width - 1;
  } else {  // either width is enough just use the biggest one.
    const bool place_in_right = right_extra > left_extra;
    wp->w_config.width = place_in_right ? right_extra : left_extra;
    wp->w_config.col = place_in_right ? col - 1 : pum_col - wp->w_config.width - 1;
  }
  // when pum_above is SW otherwise is NW
  wp->w_config.anchor = pum_above ? kFloatAnchorSouth : 0;
  linenr_T count = wp->w_buffer->b_ml.ml_line_count;
  wp->w_view_width = wp->w_config.width;
  wp->w_config.height = plines_m_win(wp, wp->w_topline, count, Rows);
  wp->w_config.row = pum_above ? pum_row + wp->w_config.height : pum_row;
  wp->w_config.hide = false;
  win_config_float(wp, wp->w_config);
}

Review comment (bug):
Was the existing `border_width < 0` check below meant to fix this? It looks like dead code; `border_width` can't be negative.

Would this work instead?

```suggestion
  int col = pum_col + pum_width + 1 + MAX(border_width, pum_scrollbar);
```

GitHub keeps bugging out when trying to suggest changes on mobile... 😔

Code after:
    textlock = 0;
  }
  nvim_buf_set_lines(0, buf->handle, 0, -1, false, replacement, &arena, &err);
  textlock = original_textlock;
  if (ERROR_SET(&err)) {
    emsg(err.msg);
    api_clear_error(&err);
  }
  arena_mem_free(arena_finish(&arena));
  api_free_array(replacement);
  buf->b_p_ma = false;
}

/// adjust floating info preview window position
static void pum_adjust_info_position(win_T *wp, int width)
{
  int border_width = pum_border_width();
  int col = pum_col + pum_width + 1 + MAX(border_width, pum_scrollbar);
  // TODO(glepnir): support config align border by using completepopup
  // align menu
  int right_extra = Columns - col;
  int left_extra = pum_col - 2;

  if (right_extra > width) {  // place in right
    wp->w_config.width = width;
    wp->w_config.col = col - 1;
  } else if (left_extra > width) {  // place in left
    wp->w_config.width = width;
    wp->w_config.col = pum_col - wp->w_config.width - 1;
  } else {  // either width is enough just use the biggest one.
    const bool place_in_right = right_extra > left_extra;
    wp->w_config.width = place_in_right ? right_extra : left_extra;
    wp->w_config.col = place_in_right ? col - 1 : pum_col - wp->w_config.width - 1;
  }
  // when pum_above is SW otherwise is NW
  wp->w_config.anchor = pum_above ? kFloatAnchorSouth : 0;
  linenr_T count = wp->w_buffer->b_ml.ml_line_count;
  wp->w_view_width = wp->w_config.width;
  wp->w_config.height = plines_m_win(wp, wp->w_topline, count, Rows);
  wp->w_config.row = pum_above ? pum_row + wp->w_config.height : pum_row;
  wp->w_config.hide = false;
  win_config_float(wp, wp->w_config);
}

/// Used for nvim__complete_set
///
/// @param selected the selected compl item.
/// @param info     Info string.
/// @return a win_T pointer.
win_T *pum_set_info(int selected, char *info)
{