sora-editor icon indicating copy to clipboard operation
sora-editor copied to clipboard

feat: implement ghost text and generalize inline elements

Open itsvks19 opened this issue 1 month ago • 4 comments

Refactors the InlayHint system into a generic InlineElement architecture to support inline code completion.

  • Introduce InlineElement interface, InlineElementContainer, and InlineElementRenderer
  • Implement GhostText and GhostTextRenderer for displaying completion suggestions
  • Add InlineCompletionProvider API and requireInlineCompletion in Language
  • Update CodeEditor to support setInlineCompletionProvider and handle Tab key to accept ghost text
  • Refactor TextRow, LineBreakLayout, and WordwrapLayout to use InlineElement instead of InlayHint
  • Add GHOST_TEXT_FOREGROUND to EditorColorScheme

https://github.com/user-attachments/assets/2890550e-33d3-447e-93d9-42f2e3def2a4

Limitations

  • currently it only supports single line completions

itsvks19 avatar Dec 02 '25 17:12 itsvks19

I have a few questions:

  1. Does the rendered text support multi-line display and word wrapping? (As shown in the image below)
image
  1. Is the getInstance method in GhostTextRenderer necessary? Is there any risk of memory leaks?

  2. Does InlineCompletionItem support multi-line content (i.e., setting different display lines and defining the cursor position after the completion is applied)?

image

dingyi222666 avatar Dec 02 '25 18:12 dingyi222666

Does the rendered text support multi-line display and word wrapping? (As shown in the image below)

No, currently it only supports single line completions. It can be extended to support multiline completions.

Is the getInstance method in GhostTextRenderer necessary? Is there any risk of memory leaks?

It is not necessary now, but when I created that function I was added all editor's event listeners in that function but later I used GhostTextRenderer's init { } block for registering event listeners. Sorry, I forgot to remove that function.

Does InlineCompletionItem support multi-line content (i.e., setting different display lines and defining the cursor position after the completion is applied)?

It is absolutely possible but I need to make some changes, currently editor only renders one GhostText even if there are many GhostTexts present.

itsvks19 avatar Dec 02 '25 18:12 itsvks19

Here are my thoughts about the changes to inlay hints and inline elements:

  • use layout instead of renderer for inline elements, and inline element layout is capable of:
    • break associated logic elements into row fragments, and fits editor viewport in wordwrap mode
    • measure and draw the row fragments generated
  • add LineLayout to layout a single line with logic inline elements to rows with their row fragments
  • inlay hint works with a subset of inline element funcitonalities (inlay hints can not be multi-line or fit wordwrap)
  • editor layout takes care of line layouts
    • LineBreakLayout creates specific line layout if required (multi-line element detected)
    • WordwrapLayout always layout all lines
  • TextRow can draw according to a list of visually-reordered row fragments
  • TextRow can locate what row fragment is clicked by horizontal offset

Rosemoe avatar Dec 04 '25 04:12 Rosemoe

I will keep the InlineElementRenderer interface as it is. It will help user to add their own InlineElement such as Git Blame Annotation.

image

itsvks19 avatar Dec 06 '25 08:12 itsvks19