Why CompletionItemProvider not work when enter charactor?

844 Views Asked by At

I have uploaded my code at https://github.com/Hfutsora/monaco-kaco.

Steps to reproduce:

  1. Open github page https://hfutsora.github.io/monaco-kaco/
  2. Enter char 'O' at the endline then you can get suggestion
    provide suggestions
  3. Enter char 'O' before the endline there are no suggestions appeared
    none suggestion
2

There are 2 best solutions below

1
On BEST ANSWER

I think the problem is that VS Code filters out your candidates because it gets the wrong already typed characters. In my completion providers I use a different method:

const info = model.getWordUntilPosition(position);

which finds the word before the current caret position.

0
On

CompletionItem.Range Note

The range in CompletionItem must be a SingleLine, I provided a error range with different startLine and endLine, I thought this was the problem.

monaco.Range({
  position.lineNumber,
  word?.startColumn ?? position.column,
  model.getLineCount(), // not the same line
  model.getLineMaxColumn(model.getLineCount())
})