in src/Kusto.Language/Editor/Kusto/KustoCompleter.cs [73:163]
public bool ShouldAutoComplete(int position, char key)
{
if (key == '\0')
return false;
// don't auto complete when we know we won't produce completions
if (!ShouldComplete(position))
return false;
// don't auto complete when cursor is just being moved around
if (char.IsControl(key) && key != '\b')
return false;
// don't auto complete just because a new line was added
if (key == '\r' || key == '\n')
return false;
var token = GetTokenLeftOfPosition(position);
if (token != null)
{
// insert whitespace immediately after token?
if (char.IsWhiteSpace(key) && position == token.End + 1)
{
// punctuation that usually has expressions following
switch (token.Kind)
{
case SyntaxKind.OpenParenToken:
case SyntaxKind.OpenBracketToken:
case SyntaxKind.OpenBraceToken:
case SyntaxKind.CommaToken:
case SyntaxKind.ColonToken:
case SyntaxKind.BarToken:
case SyntaxKind.EqualToken:
case SyntaxKind.FatArrowToken:
case SyntaxKind.CloseParenToken: // some clauses end in ) but there is more to go
return true;
}
// can have syntax or expressions following
switch (token.Kind.GetCategory())
{
case SyntaxCategory.Identifier:
case SyntaxCategory.Operator:
case SyntaxCategory.Keyword:
return true;
}
// after a complete expression
var expr = GetCompleteExpressionLeftOfPosition(position);
if (expr != null)
return true;
}
// at ending edge of token
else if (token.End == position)
{
// auto complete if backspacing into ending edge of identifier
if (key == '\b')
{
return token.Kind.GetCategory() == SyntaxCategory.Identifier;
}
// inserting punctuation that usually has immediate followers?
switch (token.Kind)
{
case SyntaxKind.OpenParenToken:
case SyntaxKind.OpenBracketToken:
case SyntaxKind.OpenBraceToken:
case SyntaxKind.DotToken:
case SyntaxKind.ColonToken:
case SyntaxKind.EqualToken:
return true;
// could be leading part of some keywords
case SyntaxKind.BangToken:
return true;
}
// just typed leading part of one of these tokens
switch (token.Kind.GetCategory())
{
case SyntaxCategory.Identifier:
case SyntaxCategory.Operator:
case SyntaxCategory.Keyword:
return true;
}
}
}
return false;
}