Skip to content

Commit 39b85ba

Browse files
authored
Merge pull request #55 from kitagry/update-documentation
Update completion documentation
2 parents f392758 + c36f6c1 commit 39b85ba

File tree

5 files changed

+280
-145
lines changed

5 files changed

+280
-145
lines changed

langserver/internal/lsp/service.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,23 @@ var completionItemKindName = map[CompletionItemKind]string{
435435
CIKTypeParameter: "typeParameter",
436436
}
437437

438+
type MarkupKind string
439+
440+
const (
441+
MKPlainText MarkupKind = "plaintext"
442+
MKMarkdown MarkupKind = "markdown"
443+
)
444+
445+
type MarkupContent struct {
446+
Kind MarkupKind `json:"kind"`
447+
Value string `json:"value"`
448+
}
449+
438450
type CompletionItem struct {
439451
Label string `json:"label"`
440452
Kind CompletionItemKind `json:"kind,omitempty"`
441453
Detail string `json:"detail,omitempty"`
442-
Documentation string `json:"documentation,omitempty"`
454+
Documentation MarkupContent `json:"documentation,omitempty"`
443455
SortText string `json:"sortText,omitempty"`
444456
FilterText string `json:"filterText,omitempty"`
445457
InsertText string `json:"insertText,omitempty"`

langserver/internal/source/completion/builtin_function.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ func (c *completor) completeBuiltinFunction(ctx context.Context, parsedFile file
2525
for _, f := range function.BuiltInFunctions {
2626
if strings.HasPrefix(f.Name, incompleteColumnName) {
2727
result = append(result, CompletionItem{
28-
Kind: lsp.CIKFunction,
29-
NewText: f.Name,
30-
TypedPrefix: incompleteColumnName,
31-
Documentation: f.Description,
28+
Kind: lsp.CIKFunction,
29+
NewText: f.Name,
30+
TypedPrefix: incompleteColumnName,
31+
Documentation: lsp.MarkupContent{
32+
Kind: lsp.MKMarkdown,
33+
Value: f.Description,
34+
},
3235
})
3336
}
3437
}

langserver/internal/source/completion/completion.go

+42-24
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,13 @@ func (c *completor) completeTableScanField(ctx context.Context, tableScanNode *r
173173
if strings.HasPrefix(tableScanNode.Alias(), incompleteColumnName) {
174174
return []CompletionItem{
175175
{
176-
Kind: lsp.CIKField,
177-
NewText: tableScanNode.Alias(),
178-
Documentation: tableScanNode.Table().FullName(),
179-
TypedPrefix: incompleteColumnName,
176+
Kind: lsp.CIKField,
177+
NewText: tableScanNode.Alias(),
178+
Documentation: lsp.MarkupContent{
179+
Kind: lsp.MKPlainText,
180+
Value: tableScanNode.Table().FullName(),
181+
},
182+
TypedPrefix: incompleteColumnName,
180183
},
181184
}
182185
}
@@ -277,10 +280,13 @@ func (c *completor) completeProjectForTablePath(ctx context.Context, param table
277280
}
278281

279282
result = append(result, CompletionItem{
280-
Kind: lsp.CIKModule,
281-
NewText: p.ProjectId,
282-
Documentation: p.Name,
283-
TypedPrefix: param.ProjectID,
283+
Kind: lsp.CIKModule,
284+
NewText: p.ProjectId,
285+
Documentation: lsp.MarkupContent{
286+
Kind: lsp.MKPlainText,
287+
Value: p.Name,
288+
},
289+
TypedPrefix: param.ProjectID,
284290
})
285291
}
286292

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

302308
result = append(result, CompletionItem{
303-
Kind: lsp.CIKModule,
304-
NewText: d.DatasetID,
305-
Documentation: fmt.Sprintf("%s.%s", d.ProjectID, d.DatasetID),
306-
TypedPrefix: param.DatasetID,
309+
Kind: lsp.CIKModule,
310+
NewText: d.DatasetID,
311+
Documentation: lsp.MarkupContent{
312+
Kind: lsp.MKPlainText,
313+
Value: fmt.Sprintf("%s.%s", d.ProjectID, d.DatasetID),
314+
},
315+
TypedPrefix: param.DatasetID,
307316
})
308317
}
309318

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

325334
result = append(result, CompletionItem{
326-
Kind: lsp.CIKModule,
327-
NewText: t.TableID,
328-
Documentation: fmt.Sprintf("%s.%s.%s", t.ProjectID, t.DatasetID, t.TableID),
329-
TypedPrefix: param.TableID,
335+
Kind: lsp.CIKModule,
336+
NewText: t.TableID,
337+
Documentation: lsp.MarkupContent{
338+
Kind: lsp.MKPlainText,
339+
Value: fmt.Sprintf("%s.%s.%s", t.ProjectID, t.DatasetID, t.TableID),
340+
},
341+
TypedPrefix: param.TableID,
330342
})
331343
}
332344

@@ -426,10 +438,13 @@ type columnInterface interface {
426438

427439
func createCompletionItemFromColumn(column columnInterface, incompleteColumnName string) CompletionItem {
428440
return CompletionItem{
429-
Kind: lsp.CIKField,
430-
NewText: column.Name(),
431-
Documentation: column.Type().TypeName(types.ProductExternal),
432-
TypedPrefix: incompleteColumnName,
441+
Kind: lsp.CIKField,
442+
NewText: column.Name(),
443+
Documentation: lsp.MarkupContent{
444+
Kind: lsp.MKPlainText,
445+
Value: column.Type().TypeName(types.ProductExternal),
446+
},
447+
TypedPrefix: incompleteColumnName,
433448
}
434449
}
435450

@@ -439,9 +454,12 @@ func createCompletionItemFromSchema(schema *bq.FieldSchema, incompleteColumnName
439454
detail += "\n" + schema.Description
440455
}
441456
return CompletionItem{
442-
Kind: lsp.CIKField,
443-
NewText: schema.Name,
444-
Documentation: detail,
445-
TypedPrefix: incompleteColumnName,
457+
Kind: lsp.CIKField,
458+
NewText: schema.Name,
459+
Documentation: lsp.MarkupContent{
460+
Kind: lsp.MKPlainText,
461+
Value: detail,
462+
},
463+
TypedPrefix: incompleteColumnName,
446464
}
447465
}

0 commit comments

Comments
 (0)