From 30fd1b05914f83d1e759cf2ab2254b4a8e35ef4c Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Mon, 6 Feb 2023 21:32:06 +0100 Subject: [PATCH] compengine,comprules: API rename The API `AtWord()` was hiding its true purpose, it returns true also when the cursor is in the middle of whitespace following a word. This change renames the method accordingly to `AtWordOrInSpaceFollowingWord()`. Release note: None --- pkg/sql/compengine/api.go | 8 +++++--- pkg/sql/compengine/engine.go | 4 ++-- pkg/sql/comprules/rules.go | 14 +++++++------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pkg/sql/compengine/api.go b/pkg/sql/compengine/api.go index 95f0d87d0002..ae1a35aa4b2d 100644 --- a/pkg/sql/compengine/api.go +++ b/pkg/sql/compengine/api.go @@ -71,9 +71,11 @@ type Context interface { // returned. RelToken(pos int) scanner.InspectToken - // AtWord is equivalent to .RelMarker(0) == MarkIdentOrKeyword, - // and is provided for convenience. - AtWord() bool + // AtWordOrInSpaceFollowingWord is equivalent to .RelMarker(0) == + // MarkIdentOrKeyword, and is provided for convenience. This returns + // true both when the cursor is _on_ an identifier/keyword, or _at + // any whitespace position afterwards_. + AtWordOrInSpaceFollowingWord() bool // Query perform a SQL query. Query(ctx context.Context, query string, args ...interface{}) (Rows, error) diff --git a/pkg/sql/compengine/engine.go b/pkg/sql/compengine/engine.go index ca93f2e3acfb..421968ded22c 100644 --- a/pkg/sql/compengine/engine.go +++ b/pkg/sql/compengine/engine.go @@ -221,8 +221,8 @@ func (c *completions) RelToken(idx int) scanner.InspectToken { return c.tokens[off] } -// AtWord implements the Context interface. -func (c *completions) AtWord() bool { +// AtWordOrInSpaceFollowingWord implements the Context interface. +func (c *completions) AtWordOrInSpaceFollowingWord() bool { return c.RelMarker(0) == MarkIdentOrKeyword } diff --git a/pkg/sql/comprules/rules.go b/pkg/sql/comprules/rules.go index f6156c7ae8eb..3b6620fd5048 100644 --- a/pkg/sql/comprules/rules.go +++ b/pkg/sql/comprules/rules.go @@ -67,7 +67,7 @@ func completeKeyword(ctx context.Context, c compengine.Context) (compengine.Rows start = c.QueryPos() end = start - case c.AtWord() && !curTok.Quoted: + case c.AtWordOrInSpaceFollowingWord() && !curTok.Quoted: prefix = curTok.Str start = int(curTok.Start) end = int(curTok.End) @@ -107,7 +107,7 @@ func completeFunction(ctx context.Context, c compengine.Context) (compengine.Row var prefix string var start, end int var schemaName string - atWord := c.AtWord() + atWord := c.AtWordOrInSpaceFollowingWord() sketch := c.Sketch() switch { case compMaybeQualProcRe.MatchString(sketch): @@ -183,7 +183,7 @@ func completeDatabase(ctx context.Context, c compengine.Context) (compengine.Row c.Trace("not completing") return nil, nil - case c.CursorInToken() && c.AtWord(): + case c.CursorInToken() && c.AtWordOrInSpaceFollowingWord(): curTok := c.RelToken(0) prefix = curTok.Str start = int(curTok.Start) @@ -225,7 +225,7 @@ func completeObjectInCurrentDatabase( ctx context.Context, c compengine.Context, ) (compengine.Rows, error) { var schema string - atWord := c.AtWord() + atWord := c.AtWordOrInSpaceFollowingWord() sketch := c.Sketch() hasSchemaPrefix := false switch { @@ -300,7 +300,7 @@ func completeSchemaInCurrentDatabase( var prefix string var start, end int switch { - case c.CursorInToken() && c.AtWord(): + case c.CursorInToken() && c.AtWordOrInSpaceFollowingWord(): curTok := c.RelToken(0) prefix = curTok.Str start = int(curTok.Start) @@ -331,7 +331,7 @@ func completeSchemaInOtherDatabase( ctx context.Context, c compengine.Context, ) (compengine.Rows, error) { var dbname string - atWord := c.AtWord() + atWord := c.AtWordOrInSpaceFollowingWord() switch { case compOneQualPrefixRe.MatchString(c.Sketch()): dbTok := c.RelToken(-1) @@ -385,7 +385,7 @@ func completeObjectInOtherDatabase( ctx context.Context, c compengine.Context, ) (compengine.Rows, error) { var schema string - atWord := c.AtWord() + atWord := c.AtWordOrInSpaceFollowingWord() sketch := c.Sketch() var dbTok scanner.InspectToken switch {