From 60e6ac22d318d9188715277ce6ba952f42f7149e Mon Sep 17 00:00:00 2001 From: Ryo Kitagawa Date: Fri, 11 Aug 2023 16:31:50 +0900 Subject: [PATCH 1/2] Add documentation --- langserver/internal/source/completion.go | 60 ++--- langserver/internal/source/completion_test.go | 230 +++++++++--------- 2 files changed, 145 insertions(+), 145 deletions(-) diff --git a/langserver/internal/source/completion.go b/langserver/internal/source/completion.go index 81b3156..2857cbf 100644 --- a/langserver/internal/source/completion.go +++ b/langserver/internal/source/completion.go @@ -14,10 +14,10 @@ import ( ) type CompletionItem struct { - Kind lsp.CompletionItemKind - NewText string - Detail string - TypedPrefix string + Kind lsp.CompletionItemKind + NewText string + Documentation string + TypedPrefix string } func (c CompletionItem) ToLspCompletionItem(position lsp.Position, supportSnippet bool) lsp.CompletionItem { @@ -26,7 +26,7 @@ func (c CompletionItem) ToLspCompletionItem(position lsp.Position, supportSnippe InsertTextFormat: lsp.ITFPlainText, Kind: c.Kind, Label: c.NewText, - Detail: c.Detail, + Documentation: c.Documentation, } } @@ -36,7 +36,7 @@ func (c CompletionItem) ToLspCompletionItem(position lsp.Position, supportSnippe InsertTextFormat: lsp.ITFSnippet, Kind: c.Kind, Label: c.NewText, - Detail: c.Detail, + Documentation: c.Documentation, TextEdit: &lsp.TextEdit{ NewText: c.NewText, Range: lsp.Range{ @@ -183,10 +183,10 @@ func (p *Project) completeTableScanField(ctx context.Context, tableScanNode *ras if strings.HasPrefix(tableScanNode.Alias(), incompleteColumnName) { return []CompletionItem{ { - Kind: lsp.CIKField, - NewText: tableScanNode.Alias(), - Detail: tableScanNode.Table().FullName(), - TypedPrefix: incompleteColumnName, + Kind: lsp.CIKField, + NewText: tableScanNode.Alias(), + Documentation: tableScanNode.Table().FullName(), + TypedPrefix: incompleteColumnName, }, } } @@ -287,10 +287,10 @@ func (p *Project) completeProjectForTablePath(ctx context.Context, param tablePa } result = append(result, CompletionItem{ - Kind: lsp.CIKModule, - NewText: p.ProjectId, - Detail: p.Name, - TypedPrefix: param.ProjectID, + Kind: lsp.CIKModule, + NewText: p.ProjectId, + Documentation: p.Name, + TypedPrefix: param.ProjectID, }) } @@ -310,10 +310,10 @@ func (p *Project) completeDatasetForTablePath(ctx context.Context, param tablePa } result = append(result, CompletionItem{ - Kind: lsp.CIKModule, - NewText: d.DatasetID, - Detail: fmt.Sprintf("%s.%s", d.ProjectID, d.DatasetID), - TypedPrefix: param.DatasetID, + Kind: lsp.CIKModule, + NewText: d.DatasetID, + Documentation: fmt.Sprintf("%s.%s", d.ProjectID, d.DatasetID), + TypedPrefix: param.DatasetID, }) } @@ -333,10 +333,10 @@ func (p *Project) completeTableForTablePath(ctx context.Context, param tablePath } result = append(result, CompletionItem{ - Kind: lsp.CIKModule, - NewText: t.TableID, - Detail: fmt.Sprintf("%s.%s.%s", t.ProjectID, t.DatasetID, t.TableID), - TypedPrefix: param.TableID, + Kind: lsp.CIKModule, + NewText: t.TableID, + Documentation: fmt.Sprintf("%s.%s.%s", t.ProjectID, t.DatasetID, t.TableID), + TypedPrefix: param.TableID, }) } @@ -436,10 +436,10 @@ type columnInterface interface { func createCompletionItemFromColumn(column columnInterface, incompleteColumnName string) CompletionItem { return CompletionItem{ - Kind: lsp.CIKField, - NewText: column.Name(), - Detail: column.Type().TypeName(types.ProductExternal), - TypedPrefix: incompleteColumnName, + Kind: lsp.CIKField, + NewText: column.Name(), + Documentation: column.Type().TypeName(types.ProductExternal), + TypedPrefix: incompleteColumnName, } } @@ -449,9 +449,9 @@ func createCompletionItemFromSchema(schema *bigquery.FieldSchema, incompleteColu detail += "\n" + schema.Description } return CompletionItem{ - Kind: lsp.CIKField, - NewText: schema.Name, - Detail: detail, - TypedPrefix: incompleteColumnName, + Kind: lsp.CIKField, + NewText: schema.Name, + Documentation: detail, + TypedPrefix: incompleteColumnName, } } diff --git a/langserver/internal/source/completion_test.go b/langserver/internal/source/completion_test.go index 0e2a23e..794fdca 100644 --- a/langserver/internal/source/completion_test.go +++ b/langserver/internal/source/completion_test.go @@ -48,14 +48,14 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", }, { - Kind: lsp.CIKField, - NewText: "name", - Detail: "STRING", + Kind: lsp.CIKField, + NewText: "name", + Documentation: "STRING", }, }, }, @@ -76,9 +76,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", }, }, }, @@ -108,9 +108,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "name", - Detail: "STRING", + Kind: lsp.CIKField, + NewText: "name", + Documentation: "STRING", }, }, }, @@ -132,9 +132,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INT64", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INT64", }, { // TODO: Refactoring test Kind: lsp.CIKField, @@ -159,10 +159,10 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", - TypedPrefix: "i", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", + TypedPrefix: "i", }, }, }, @@ -183,10 +183,10 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", - TypedPrefix: "i", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", + TypedPrefix: "i", }, }, }, @@ -213,9 +213,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", }, }, }, @@ -248,9 +248,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", }, }, }, @@ -277,10 +277,10 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", - TypedPrefix: "i", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", + TypedPrefix: "i", }, }, }, @@ -307,9 +307,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", }, }, }, @@ -336,9 +336,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INT64", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INT64", }, }, }, @@ -359,9 +359,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", }, }, }, @@ -382,9 +382,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", }, }, }, @@ -405,10 +405,10 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", - TypedPrefix: "i", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", + TypedPrefix: "i", }, }, }, @@ -429,9 +429,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INT64", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INT64", }, }, }, @@ -451,10 +451,10 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "table", - Detail: "project.dataset.table", - TypedPrefix: "t", + Kind: lsp.CIKField, + NewText: "table", + Documentation: "project.dataset.table", + TypedPrefix: "t", }, }, }, @@ -497,9 +497,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", }, }, }, @@ -520,9 +520,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", }, }, }, @@ -543,9 +543,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", }, }, }, @@ -566,9 +566,9 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", }, }, }, @@ -589,10 +589,10 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", - TypedPrefix: "i", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", + TypedPrefix: "i", }, }, }, @@ -613,10 +613,10 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", - TypedPrefix: "i", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", + TypedPrefix: "i", }, }, }, @@ -646,28 +646,28 @@ func TestProject_CompleteColumn(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description", - TypedPrefix: "", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description", + TypedPrefix: "", }, { - Kind: lsp.CIKField, - NewText: "id", - Detail: "INTEGER\nid description2", - TypedPrefix: "", + Kind: lsp.CIKField, + NewText: "id", + Documentation: "INTEGER\nid description2", + TypedPrefix: "", }, { - Kind: lsp.CIKField, - NewText: "t1", - Detail: "project.dataset.table", - TypedPrefix: "", + Kind: lsp.CIKField, + NewText: "t1", + Documentation: "project.dataset.table", + TypedPrefix: "", }, { - Kind: lsp.CIKField, - NewText: "t2", - Detail: "project.dataset.table2", - TypedPrefix: "", + Kind: lsp.CIKField, + NewText: "t2", + Documentation: "project.dataset.table2", + TypedPrefix: "", }, }, }, @@ -743,14 +743,14 @@ func TestProject_CompleteFromClause(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKModule, - NewText: "1table", - Detail: "project.dataset.1table", + Kind: lsp.CIKModule, + NewText: "1table", + Documentation: "project.dataset.1table", }, { - Kind: lsp.CIKModule, - NewText: "2table", - Detail: "project.dataset.2table", + Kind: lsp.CIKModule, + NewText: "2table", + Documentation: "project.dataset.2table", }, }, }, @@ -780,9 +780,9 @@ func TestProject_CompleteFromClause(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKModule, - NewText: "table20230622", - Detail: "project.dataset.table20230622", + Kind: lsp.CIKModule, + NewText: "table20230622", + Documentation: "project.dataset.table20230622", }, }, }, @@ -810,14 +810,14 @@ func TestProject_CompleteFromClause(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKModule, - NewText: "dataset1", - Detail: "project.dataset1", + Kind: lsp.CIKModule, + NewText: "dataset1", + Documentation: "project.dataset1", }, { - Kind: lsp.CIKModule, - NewText: "dataset2", - Detail: "project.dataset2", + Kind: lsp.CIKModule, + NewText: "dataset2", + Documentation: "project.dataset2", }, }, }, @@ -844,16 +844,16 @@ func TestProject_CompleteFromClause(t *testing.T) { }, expectCompletionItems: []source.CompletionItem{ { - Kind: lsp.CIKModule, - NewText: "project1", - Detail: "project name", - TypedPrefix: "p", + Kind: lsp.CIKModule, + NewText: "project1", + Documentation: "project name", + TypedPrefix: "p", }, { - Kind: lsp.CIKModule, - NewText: "project2", - Detail: "project name", - TypedPrefix: "p", + Kind: lsp.CIKModule, + NewText: "project2", + Documentation: "project name", + TypedPrefix: "p", }, }, }, From 0fefa4b1bc4501debf9f98fda93d8c660c5d704f Mon Sep 17 00:00:00 2001 From: Ryo Kitagawa Date: Sun, 13 Aug 2023 12:13:03 +0900 Subject: [PATCH 2/2] Disable completionItem/resolve --- langserver/initialize.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/langserver/initialize.go b/langserver/initialize.go index ec271c7..6c9d2a9 100644 --- a/langserver/initialize.go +++ b/langserver/initialize.go @@ -41,7 +41,7 @@ func (h *Handler) handleInitialize(ctx context.Context, conn *jsonrpc2.Conn, req HoverProvider: true, CodeActionProvider: true, CompletionProvider: &lsp.CompletionOptions{ - ResolveProvider: true, + ResolveProvider: false, TriggerCharacters: []string{"*", "."}, }, },