Skip to content

Commit

Permalink
compengine,comprules: API rename
Browse files Browse the repository at this point in the history
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
  • Loading branch information
knz committed Feb 6, 2023
1 parent b4c088f commit 30fd1b0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
8 changes: 5 additions & 3 deletions pkg/sql/compengine/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/compengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/sql/comprules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 30fd1b0

Please sign in to comment.