Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kitagry committed Aug 27, 2023
1 parent f392758 commit c36f6c1
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 145 deletions.
14 changes: 13 additions & 1 deletion langserver/internal/lsp/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,23 @@ var completionItemKindName = map[CompletionItemKind]string{
CIKTypeParameter: "typeParameter",
}

type MarkupKind string

const (
MKPlainText MarkupKind = "plaintext"
MKMarkdown MarkupKind = "markdown"
)

type MarkupContent struct {
Kind MarkupKind `json:"kind"`
Value string `json:"value"`
}

type CompletionItem struct {
Label string `json:"label"`
Kind CompletionItemKind `json:"kind,omitempty"`
Detail string `json:"detail,omitempty"`
Documentation string `json:"documentation,omitempty"`
Documentation MarkupContent `json:"documentation,omitempty"`
SortText string `json:"sortText,omitempty"`
FilterText string `json:"filterText,omitempty"`
InsertText string `json:"insertText,omitempty"`
Expand Down
11 changes: 7 additions & 4 deletions langserver/internal/source/completion/builtin_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ func (c *completor) completeBuiltinFunction(ctx context.Context, parsedFile file
for _, f := range function.BuiltInFunctions {
if strings.HasPrefix(f.Name, incompleteColumnName) {
result = append(result, CompletionItem{
Kind: lsp.CIKFunction,
NewText: f.Name,
TypedPrefix: incompleteColumnName,
Documentation: f.Description,
Kind: lsp.CIKFunction,
NewText: f.Name,
TypedPrefix: incompleteColumnName,
Documentation: lsp.MarkupContent{
Kind: lsp.MKMarkdown,
Value: f.Description,
},
})
}
}
Expand Down
66 changes: 42 additions & 24 deletions langserver/internal/source/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,13 @@ func (c *completor) completeTableScanField(ctx context.Context, tableScanNode *r
if strings.HasPrefix(tableScanNode.Alias(), incompleteColumnName) {
return []CompletionItem{
{
Kind: lsp.CIKField,
NewText: tableScanNode.Alias(),
Documentation: tableScanNode.Table().FullName(),
TypedPrefix: incompleteColumnName,
Kind: lsp.CIKField,
NewText: tableScanNode.Alias(),
Documentation: lsp.MarkupContent{
Kind: lsp.MKPlainText,
Value: tableScanNode.Table().FullName(),
},
TypedPrefix: incompleteColumnName,
},
}
}
Expand Down Expand Up @@ -277,10 +280,13 @@ func (c *completor) completeProjectForTablePath(ctx context.Context, param table
}

result = append(result, CompletionItem{
Kind: lsp.CIKModule,
NewText: p.ProjectId,
Documentation: p.Name,
TypedPrefix: param.ProjectID,
Kind: lsp.CIKModule,
NewText: p.ProjectId,
Documentation: lsp.MarkupContent{
Kind: lsp.MKPlainText,
Value: p.Name,
},
TypedPrefix: param.ProjectID,
})
}

Expand All @@ -300,10 +306,13 @@ func (c *completor) completeDatasetForTablePath(ctx context.Context, param table
}

result = append(result, CompletionItem{
Kind: lsp.CIKModule,
NewText: d.DatasetID,
Documentation: fmt.Sprintf("%s.%s", d.ProjectID, d.DatasetID),
TypedPrefix: param.DatasetID,
Kind: lsp.CIKModule,
NewText: d.DatasetID,
Documentation: lsp.MarkupContent{
Kind: lsp.MKPlainText,
Value: fmt.Sprintf("%s.%s", d.ProjectID, d.DatasetID),
},
TypedPrefix: param.DatasetID,
})
}

Expand All @@ -323,10 +332,13 @@ func (c *completor) completeTableForTablePath(ctx context.Context, param tablePa
}

result = append(result, CompletionItem{
Kind: lsp.CIKModule,
NewText: t.TableID,
Documentation: fmt.Sprintf("%s.%s.%s", t.ProjectID, t.DatasetID, t.TableID),
TypedPrefix: param.TableID,
Kind: lsp.CIKModule,
NewText: t.TableID,
Documentation: lsp.MarkupContent{
Kind: lsp.MKPlainText,
Value: fmt.Sprintf("%s.%s.%s", t.ProjectID, t.DatasetID, t.TableID),
},
TypedPrefix: param.TableID,
})
}

Expand Down Expand Up @@ -426,10 +438,13 @@ type columnInterface interface {

func createCompletionItemFromColumn(column columnInterface, incompleteColumnName string) CompletionItem {
return CompletionItem{
Kind: lsp.CIKField,
NewText: column.Name(),
Documentation: column.Type().TypeName(types.ProductExternal),
TypedPrefix: incompleteColumnName,
Kind: lsp.CIKField,
NewText: column.Name(),
Documentation: lsp.MarkupContent{
Kind: lsp.MKPlainText,
Value: column.Type().TypeName(types.ProductExternal),
},
TypedPrefix: incompleteColumnName,
}
}

Expand All @@ -439,9 +454,12 @@ func createCompletionItemFromSchema(schema *bq.FieldSchema, incompleteColumnName
detail += "\n" + schema.Description
}
return CompletionItem{
Kind: lsp.CIKField,
NewText: schema.Name,
Documentation: detail,
TypedPrefix: incompleteColumnName,
Kind: lsp.CIKField,
NewText: schema.Name,
Documentation: lsp.MarkupContent{
Kind: lsp.MKPlainText,
Value: detail,
},
TypedPrefix: incompleteColumnName,
}
}
Loading

0 comments on commit c36f6c1

Please sign in to comment.