-
monaco-editor version: 0.17.0 Steps or JS usage snippet reproducing the issue: I'm creating a custom snippet engine. To enable choice snippets (like the ones in VSCode) I need to show a dynamic suggestions. I tried copying the way the // tsconfig.json: compilerOptions.paths ["vs/*": ["node_modules/monaco-editor-core/esm/vs/*"]]
import * as monaco from 'monaco-editor'
import { showSimpleSuggestions } from 'vs/editor/contrib/suggest/suggest'
import { Range } from 'vs/editor/common/core/range'
import { repeat } from 'vs/base/common/strings'
const [first] = choice.children
showSimpleSuggestions(
this._editor,
choice.children.map((option, i) => {
return <monaco.languages.CompletionItem>{
kind: monaco.languages.CompletionItemKind.Value,
label: option.value,
insertText: option.value,
sortText: repeat('a', i + 1),
range: Range.fromPositions(
this._editor.getPosition()!,
this._editor.getPosition()!.delta(0, first.value.length)
),
}
})
) I've checked this ends up sending a valid CompletionItem[] to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Not entirely sure why it didn't work back then but I have recently revisited this and it works now. It seems top be missing the {
provideCompletionItems: (model: monaco.editor.ITextModel) => {
if (!choice || choice.options.length === 0) {
return undefined;
}
const word = model.getValueInRange(choice.range());
const isAnyOfOptions = Boolean(
choice.options.find((option) => option === word)
);
const suggestions: monaco.languages.CompletionItem[] = [];
for (let i = 0; i < choice.options.length; i++) {
let option = choice.options[i];
suggestions.push({
kind: monaco.languages.CompletionItemKind.Value,
label: option,
insertText: option,
sortText: 'a'.repeat(i + 1),
range: range,
filterText: isAnyOfOptions ? `${word}_${option}` : undefined,
});
}
return { suggestions };
},
};
} |
Beta Was this translation helpful? Give feedback.
Not entirely sure why it didn't work back then but I have recently revisited this and it works now. It seems top be missing the
provideCompletionItems
, but I haven't checked if this was there 4 years ago.