Skip to content

fix: handle Unicode cursor position in Go Prompt completion - #265

Open
Bewear777 wants to merge 1 commit into
vesoft-inc:masterfrom
Bewear777:fix/goprompt-unicode-completion-position
Open

Bewear777 wants to merge 1 commit into
vesoft-inc:masterfrom
Bewear777:fix/goprompt-unicode-completion-position

Conversation

@Bewear777

@Bewear777 Bewear777 commented Nov 2, 2026 •

Copy link
Copy Markdown

What type of PR is this?

  • bug
  • feature
  • enhancement
  • documentation

What problem(s) does this PR solve?

Issue(s) number:

Fixes #264

Description:

In Go Prompt mode, auto-completion may use the wrong word when the input contains multibyte UTF-8 characters before the cursor.

The completion callback in cli/terminal.go passes d.CursorPositionCol() to completer.NewCompleter().

In go-prompt v0.2.6, CursorPositionCol() returns a character (rune) index. However, NewCompleter() uses the position to slice a Go string, which requires a byte offset.

As a result, Chinese characters before the cursor may cause the input to be truncated at the wrong position, resulting in incorrect completion suggestions.

How do you solve it?

  • Get the current line using d.CurrentLine().
  • Calculate the byte offset using len(d.CurrentLineBeforeCursor()).
  • Pass the byte offset to completer.NewCompleter().

This fixes the character-index and byte-index mismatch without changing the existing completion implementation.

Special notes for your reviewer, ex. impact of this fix, design document, etc:

  • Minimal change limited to cli/terminal.go.
  • Fixes auto-completion with Chinese and other multibyte UTF-8 characters.
  • Existing ASCII completion behavior remains unchanged.
  • The default liner terminal implementation is not affected.
  • No public API changes.
  • No backward compatibility impact.
  • Automated tests have not been run.

How to verify:

  1. Enable Go Prompt mode.
  2. Enter MATCH (v:player) WHERE v.name == "Yao Ming" RET.
  3. Press Tab at the end of RET.
  4. Verify that completion suggestions are based on the RET prefix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go Prompt auto-completion uses a character index as a byte offset

1 participant