Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show documentation on hover and completion #101

Merged
merged 8 commits into from
Jan 25, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
return docs as markdown upon completion
PgBiel committed Jan 25, 2025
commit ed25e9c7a079a306dab8c3cdfc10834bdbff7685
11 changes: 7 additions & 4 deletions server/internal/lsp/search/search_completion_list.go
Original file line number Diff line number Diff line change
@@ -127,15 +127,18 @@ func extractExplicitModulePath(possibleModulePath string) option.Option[symbols.
return option.None[symbols.ModulePath]()
}

// TODO: Consider only returning the body text, not contracts here
// Returns: nil | string
// Obtains a doc comment's representation as markup, or nil.
// Only the body is included (not contracts) for brevity.
// Returns: nil | MarkupContent
func GetCompletableDocComment(s symbols.Indexable) any {
docComment := s.GetDocComment()
if docComment == nil || docComment.GetBody() == "" {
return nil
} else {
// Don't include contract information in completion, for brevity
return docComment.GetBody()
return protocol.MarkupContent{
Kind: protocol.MarkupKindMarkdown,
Value: docComment.GetBody(),
}
}
}

25 changes: 16 additions & 9 deletions server/internal/lsp/search/search_completion_list_test.go
Original file line number Diff line number Diff line change
@@ -27,6 +27,13 @@ func filterOutKeywordSuggestions(completionList []protocol.CompletionItem) []pro
return filteredCompletionList
}

func asMarkdown(text string) protocol.MarkupContent {
return protocol.MarkupContent{
Kind: protocol.MarkupKindMarkdown,
Value: text,
}
}

func Test_isCompletingAChain(t *testing.T) {
cases := []struct {
name string
@@ -354,8 +361,8 @@ func TestBuildCompletionList(t *testing.T) {
{"v", protocol.CompletionItem{Label: "variable", Kind: &expectedVarKind}},
{"va", protocol.CompletionItem{Label: "variable", Kind: &expectedVarKind}},
{"x", protocol.CompletionItem{Label: "xanadu", Kind: &expectedVarKind}},
{"docu", protocol.CompletionItem{Label: "documented", Kind: &expectedVarKind, Documentation: "doc"}},
{"MY_C", protocol.CompletionItem{Label: "MY_CONST", Kind: &expectedConstKind, Documentation: "const doc"}},
{"docu", protocol.CompletionItem{Label: "documented", Kind: &expectedVarKind, Documentation: asMarkdown("doc")}},
{"MY_C", protocol.CompletionItem{Label: "MY_CONST", Kind: &expectedConstKind, Documentation: asMarkdown("const doc")}},
}

for n, tt := range cases {
@@ -479,10 +486,10 @@ func TestBuildCompletionList(t *testing.T) {
expected []protocol.CompletionItem
}{
{"p", []protocol.CompletionItem{
{Label: "process", Kind: &expectedKind, Documentation: "abc"},
{Label: "process", Kind: &expectedKind, Documentation: asMarkdown("abc")},
}},
{"proc", []protocol.CompletionItem{
{Label: "process", Kind: &expectedKind, Documentation: "abc"},
{Label: "process", Kind: &expectedKind, Documentation: asMarkdown("abc")},
}},
}

@@ -522,7 +529,7 @@ func TestBuildCompletionList(t *testing.T) {
}`

// Contracts are excluded
expectedDoc := "abc"
expectedDoc := asMarkdown("abc")

expectedKind := protocol.CompletionItemKindFunction
cases := []struct {
@@ -639,7 +646,7 @@ func TestBuildCompletionList_struct_suggest_all_its_members(t *testing.T) {
NewText: "toCircle",
Range: protocol_utils.NewLSPRange(6, 7, 6, 8),
},
Documentation: "member doc",
Documentation: asMarkdown("member doc"),
},
{Label: "width", Kind: &expectedKind},
}, completionList)
@@ -1024,7 +1031,7 @@ func TestBuildCompletionList_modules(t *testing.T) {
NewText: "app",
Range: protocol_utils.NewLSPRange(3, 4, 3, 5),
},
Documentation: "doc",
Documentation: asMarkdown("doc"),
},
},
true,
@@ -1231,7 +1238,7 @@ func TestBuildCompletionList_interfaces(t *testing.T) {
{
Label: "EmulatorConsole",
Kind: cast.ToPtr(protocol.CompletionItemKindInterface),
Documentation: "doc",
Documentation: asMarkdown("doc"),
},
},
completionList,
@@ -1244,7 +1251,7 @@ func CreateCompletionItem(label string, kind protocol.CompletionItemKind) protoc
}

func CreateCompletionItemWithDoc(label string, kind protocol.CompletionItemKind, doc string) protocol.CompletionItem {
return protocol.CompletionItem{Label: label, Kind: &kind, Documentation: doc}
return protocol.CompletionItem{Label: label, Kind: &kind, Documentation: asMarkdown(doc)}
}

func TestBuildCompletionList_should_resolve_(t *testing.T) {