Skip to content

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

Open

Description

@Bewear777

Your Environments (required)

  • NebulaGraph Console: master
  • Go Prompt mode: enabled (--enable_go_prompt=true)
  • OS/Architecture: Linux
  • Input encoding: UTF-8

How To Reproduce(required)

  1. Start NebulaGraph Console with Go Prompt enabled:
./nebula-console -addr 127.0.0.1 -port 9669 -u root -p nebula --enable_go_prompt=true
  1. Type the following statement and press Tab at the end of re:
YIELD "中文" AS re

Actual behavior

The completion callback passes d.CursorPositionCol() to completer.NewCompleter().

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

When multibyte UTF-8 characters appear before the cursor, the input is truncated at the wrong position.

For example, the completion logic may use A instead of RE as the completion prefix.

Expected behavior

Tab completion should correctly identify the word immediately before the cursor, regardless of whether the input contains ASCII, Chinese, or mixed UTF-8 characters.

The completion result should be based on the RE prefix in the example above.

Proposed solution

Use the byte length of d.CurrentLineBeforeCursor() as the cursor position passed to completer.NewCompleter().

This ensures that the position matches the byte indexing used by Go string slicing.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions