diff --git a/langserver/internal/source/completion/column.go b/langserver/internal/source/completion/column.go index 540cd48..26e8815 100644 --- a/langserver/internal/source/completion/column.go +++ b/langserver/internal/source/completion/column.go @@ -361,6 +361,12 @@ func (c *completor) getMostNarrowInputScanNode(node rast.ScanNode, termOffset in return n, true } return nil, false + case *rast.LimitOffsetScanNode: + node, ok := c.getMostNarrowInputScanNode(n.InputScan(), termOffset) + if ok { + return node, true + } + return nil, false default: c.logger.Printf("unknown scan node type: %T\n", n) return nil, false diff --git a/langserver/internal/source/completion/column_test.go b/langserver/internal/source/completion/column_test.go index d10d1b2..ed50717 100644 --- a/langserver/internal/source/completion/column_test.go +++ b/langserver/internal/source/completion/column_test.go @@ -809,6 +809,33 @@ func TestProject_CompleteColumns(t *testing.T) { }, }, }, + "Complete column on limit clause": { + files: map[string]string{ + "file1.sql": "SELECT | FROM `project.dataset.table` LIMIT 10", + }, + bqTableMetadataMap: map[string]*bq.TableMetadata{ + "project.dataset.table": { + Schema: bq.Schema{ + { + Name: "id", + Description: "id description", + Type: bq.IntegerFieldType, + }, + }, + }, + }, + expectCompletionItems: []CompletionItem{ + { + Kind: lsp.CIKField, + NewText: "id", + Documentation: lsp.MarkupContent{ + Kind: lsp.MKPlainText, + Value: "INTEGER\nid description", + }, + TypedPrefix: "", + }, + }, + }, } for n, tt := range tests {