private getTextToInsert()

in package/src/languageServiceManager/kustoLanguageService.ts [1961:1991]


    private getTextToInsert(
        rule: k.IntelliSenseRule,
        option: k.CompletionOption
    ): { insertText: string; insertTextFormat: ls.InsertTextFormat } {
        const beforeApplyInfo = rule.GetBeforeApplyInfo(option.Value);
        const afterApplyInfo = rule.GetAfterApplyInfo(option.Value);

        // this is the basic text to be inserted,
        // but we still need to figure out where the cursor will end up after completion is applied.
        let insertText = beforeApplyInfo.Text || '' + option.Value + afterApplyInfo.Text || '';
        let insertTextFormat: ls.InsertTextFormat = ls.InsertTextFormat.PlainText;

        const snippetFinalTabStop = '$0';
        if (afterApplyInfo.OffsetToken && afterApplyInfo.OffsetPosition) {
            const tokenOffset = insertText.indexOf(afterApplyInfo.OffsetToken);
            if (tokenOffset >= 0) {
                insertText = this.insertToString(
                    insertText,
                    snippetFinalTabStop,
                    tokenOffset - insertText.length + afterApplyInfo.OffsetPosition
                );
                insertTextFormat = ls.InsertTextFormat.Snippet;
            }
        } else if (afterApplyInfo.OffsetPosition) {
            // We only handle negative offsets
            insertText = this.insertToString(insertText, snippetFinalTabStop, afterApplyInfo.OffsetPosition);
            insertTextFormat = ls.InsertTextFormat.Snippet;
        }

        return { insertText, insertTextFormat };
    }