Skip to content

Commit 6d55929

Browse files
committed
Fix signature help not working
Also fix markdown in completion item
1 parent d349c8c commit 6d55929

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- Fixed signature help not showing up
12+
- Fixed markdown in completion not working
13+
914
## [0.4.0] - 2022-05-17
1015

1116
### Added

src/Protocol.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,28 @@ enum struct CompletionItemKind
648648
TypeParameter = 25,
649649
};
650650

651+
enum struct MarkupKind
652+
{
653+
PlainText,
654+
Markdown,
655+
};
656+
NLOHMANN_JSON_SERIALIZE_ENUM(MarkupKind, {{MarkupKind::PlainText, "plaintext"}, {MarkupKind::Markdown, "markdown"}});
657+
658+
struct MarkupContent
659+
{
660+
MarkupKind kind;
661+
std::string value;
662+
};
663+
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(MarkupContent, kind, value);
664+
651665
struct CompletionItem
652666
{
653667
std::string label;
654668
std::optional<CompletionItemLabelDetails> labelDetails;
655669
std::optional<CompletionItemKind> kind;
656670
std::optional<std::vector<CompletionItemTag>> tags;
657671
std::optional<std::string> detail;
658-
std::optional<std::string> documentation;
672+
std::optional<MarkupContent> documentation;
659673
bool deprecated = false;
660674
bool preselect = false;
661675
std::optional<std::string> sortText;
@@ -692,20 +706,6 @@ struct HoverParams : TextDocumentPositionParams
692706
{
693707
};
694708

695-
enum struct MarkupKind
696-
{
697-
PlainText,
698-
Markdown,
699-
};
700-
NLOHMANN_JSON_SERIALIZE_ENUM(MarkupKind, {{MarkupKind::PlainText, "plaintext"}, {MarkupKind::Markdown, "markdown"}});
701-
702-
struct MarkupContent
703-
{
704-
MarkupKind kind;
705-
std::string value;
706-
};
707-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(MarkupContent, kind, value);
708-
709709
struct Hover
710710
{
711711
MarkupContent contents;

src/Workspace.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ class WorkspaceFolder
799799
item.deprecated = entry.deprecated;
800800

801801
if (entry.documentationSymbol)
802-
item.documentation = printDocumentation(client->documentation, *entry.documentationSymbol);
802+
item.documentation = {lsp::MarkupKind::Markdown, printDocumentation(client->documentation, *entry.documentationSymbol)};
803803

804804
switch (entry.kind)
805805
{
@@ -1086,7 +1086,7 @@ class WorkspaceFolder
10861086

10871087
// Create the whole label
10881088
std::string label = types::toStringNamedFunction(module, ftv, candidate->func);
1089-
std::optional<lsp::MarkupContent> documentation;
1089+
lsp::MarkupContent documentation{lsp::MarkupKind::PlainText, ""};
10901090

10911091
if (followedId->documentationSymbol)
10921092
documentation = {lsp::MarkupKind::Markdown, printDocumentation(client->documentation, *followedId->documentationSymbol)};
@@ -1107,17 +1107,19 @@ class WorkspaceFolder
11071107
}
11081108

11091109
std::string label;
1110+
lsp::MarkupContent parameterDocumentation{lsp::MarkupKind::PlainText, ""};
11101111
if (idx < ftv->argNames.size() && ftv->argNames[idx])
11111112
{
11121113
label = ftv->argNames[idx]->name + ": ";
11131114
}
11141115
label += Luau::toString(*it);
1115-
parameters.push_back(lsp::ParameterInformation{label});
1116+
1117+
parameters.push_back(lsp::ParameterInformation{label, parameterDocumentation});
11161118
it++;
11171119
idx++;
11181120
}
11191121

1120-
signatures.push_back(lsp::SignatureInformation{label, std::nullopt, parameters});
1122+
signatures.push_back(lsp::SignatureInformation{label, documentation, parameters});
11211123
};
11221124

11231125
if (auto ftv = Luau::get<Luau::FunctionTypeVar>(followedId))

src/main.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,17 +500,21 @@ class LanguageServer
500500
}
501501

502502
// TODO: can't type this as lsp::hover as it can return null
503-
std::optional<lsp::Hover> hover(const lsp::HoverParams& params)
503+
Response hover(const lsp::HoverParams& params)
504504
{
505505
auto workspace = findWorkspace(params.textDocument.uri);
506-
return workspace->hover(params);
506+
if (auto result = workspace->hover(params))
507+
return *result;
508+
return nullptr;
507509
}
508510

509511
// TODO: can't type this as lsp::SignatureHelp as it can return null
510-
std::optional<lsp::SignatureHelp> signatureHelp(const lsp::SignatureHelpParams& params)
512+
Response signatureHelp(const lsp::SignatureHelpParams& params)
511513
{
512514
auto workspace = findWorkspace(params.textDocument.uri);
513-
return workspace->signatureHelp(params);
515+
if (auto result = workspace->signatureHelp(params))
516+
return *result;
517+
return nullptr;
514518
}
515519

516520
Response gotoDefinition(const lsp::DefinitionParams& params)

0 commit comments

Comments
 (0)