Skip to content

Commit

Permalink
Merge pull request #50 from kitagry/hover-not-analyzed-table
Browse files Browse the repository at this point in the history
Hover table information for not analyzed table
  • Loading branch information
kitagry authored Aug 11, 2023
2 parents 81d7693 + c5c651d commit 2a488eb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions langserver/internal/source/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func (p *Project) TermDocument(uri string, position lsp.Position) ([]lsp.MarkedS

output, ok := parsedFile.FindTargetAnalyzeOutput(termOffset)
if !ok {
// If not found analyze output, lookup table metadata from ast node.
if targetNode, ok := lookupNode[*ast.TablePathExpressionNode](targetNode); ok {
result, ok := p.termDocumentFromAstNode(ctx, targetNode)
if ok {
return result, nil
}
}
p.logger.Debug("not found target analyze output")
return nil, nil
}
Expand Down Expand Up @@ -124,6 +131,24 @@ func (p *Project) TermDocument(uri string, position lsp.Position) ([]lsp.MarkedS
return nil, nil
}

func (p *Project) termDocumentFromAstNode(ctx context.Context, targetNode *ast.TablePathExpressionNode) ([]lsp.MarkedString, bool) {
name, ok := createTableNameFromTablePathExpressionNode(targetNode)
if !ok {
return nil, false
}

targetTable, err := p.getTableMetadataFromPath(ctx, name)
if err != nil {
return nil, false
}

result, err := buildBigQueryTableMetadataMarkedString(targetTable)
if err != nil {
return nil, false
}
return result, true
}

func (p *Project) termDocumentForInputScan(ctx context.Context, termOffset int, targetNode *ast.TablePathExpressionNode, output *zetasql.AnalyzerOutput, parsedFile ParsedFile) ([]lsp.MarkedString, bool) {
targetScanNode, ok := getMostNarrowScanNode(termOffset, output.Statement())
if !ok {
Expand Down

0 comments on commit 2a488eb

Please sign in to comment.