function triggerSuggestDialogWhenCompletionItemSelected()

in package/src/monaco.contribution.ts [134:159]


function triggerSuggestDialogWhenCompletionItemSelected(editor: monaco.editor.ICodeEditor) {
    editor.onDidChangeCursorSelection((event: monaco.editor.ICursorSelectionChangedEvent) => {
        // checking the condition inside the event makes sure we will stay up to date when kusto configuration changes at runtime.
        if (
            kustoDefaults &&
            kustoDefaults.languageSettings &&
            kustoDefaults.languageSettings.openSuggestionDialogAfterPreviousSuggestionAccepted
        ) {
            var didAcceptSuggestion =
                event.source === 'snippet' && event.reason === monaco.editor.CursorChangeReason.NotSet;
            // If the word at the current position is not null - meaning we did not add a space after completion.
            // In this case we don't want to activate the eager mode, since it will display the current selected word..
            if (!didAcceptSuggestion || editor.getModel().getWordAtPosition(event.selection.getPosition()) !== null) {
                return;
            }
            event.selection;
            // OK so now we in a situation where we know a suggestion was selected, and we want to trigger another one.
            // the only problem is that the suggestion widget itself listens to this same event in order to know it needs to close.
            // The only problem is that we're ahead in line, so we're triggering a suggest operation that will be shut down once
            // the next callback is called. This is why we're waiting here - to let all the callbacks run synchronously and be
            // the 'last' subscriber to run. Granted this is hacky, but until monaco provides a specific event for suggestions,
            // this is the best we have.
            setTimeout(() => editor.trigger('monaco-kusto', 'editor.action.triggerSuggest', {}), 10);
        }
    });
}