private getCurrentCommand()

in package/src/languageServiceManager/kustoLanguageService.ts [1932:1955]


    private getCurrentCommand(document: TextDocument, caretAbsolutePosition: number): k.CslCommand | undefined {
        let commands = this.toArray(this._parser.Results);

        let command = commands.filter(
            (command) => command.AbsoluteStart <= caretAbsolutePosition && command.AbsoluteEnd >= caretAbsolutePosition
        )[0];

        // There is an edge case when cursor appears at the end of the command
        // which is not yet considered to be part of the parsed command (therefore: +1 for the AbsoluteEdit property)
        if (!command) {
            command = commands.filter(
                (command) =>
                    command.AbsoluteStart <= caretAbsolutePosition && command.AbsoluteEnd + 1 >= caretAbsolutePosition
            )[0];

            // If we have 2 newlines in the end of the text the cursor is _probably_ at the end of the text
            // which this means that we're not actually standing on any command. Thus return null.
            if (!command || command.Text.endsWith('\r\n\r\n')) {
                return null;
            }
        }

        return command;
    }