Monaco-editor: Providing ISingleEditOperation in CompletionItem

Created on 28 Jul 2016  路  4Comments  路  Source: microsoft/monaco-editor

I'm trying to implement CompletionItemProvider.provideCompletionItems and I would like to explicitly specify the edit operation - this is because the language allows identifiers with spaces and so the completion needs to replace text in a range that may include spaces (the default mechanism does not seem to work in this case - it probably searches for the last space and inserts the text there (?)).

However, no matter what I do, I get "No suggestions":

monaco-1

The completion items that I'm returning look like this:

monaco-2

When I do not set textEdit, the completion list shows possible completions just fine (but it inserts text badly when the completion involves spaces). In the screenshot, I set filterText and insertText, but when I do not do that, the result is the same.

Am I doing something obviously wrong here? Is there a working sample of using textEdit somewhere?

PS: Also, is this the right place to ask questions like this, or do you have another recommended channel?

Most helpful comment

Well, this is is embarrassing. So it was all just off-by-one error. Works great now.

monaco

If you want to see it in action, click on "source" in any of the visualizations here: http://rio2016.thegamma.net :+1:

All 4 comments

(I'm aware that the above might not quite provide enough information about the issue - I'm hoping that Monaco experts might immediately spot what I'm doing wrong - but if no, let me know and I can try to create a simple shareable repro.)

The text edit you return is a single edit operation - so you are on the right path. By default, when you don't give a text edit, we basically build an edit from the current word range until position and the label of the suggestion. Then, the editor compares the text that got selected by the edit and compares that against the label or filterText. In your case it like this: [1,9, 1,10] == '.d' which is compared against data etc. Since none match you see an empty list. The rule is that your filterText or label matches at least what you select for replacing and what you will insert

Well, this is is embarrassing. So it was all just off-by-one error. Works great now.

monaco

If you want to see it in action, click on "source" in any of the visualizations here: http://rio2016.thegamma.net :+1:

@tpetricek I saw the website a couple of days ago! Very cool! :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Panhaiwei picture Panhaiwei  路  3Comments

inf9144 picture inf9144  路  3Comments

fabiospampinato picture fabiospampinato  路  3Comments

galyech picture galyech  路  3Comments

chengtie picture chengtie  路  3Comments