ParameterInformation: use label: [number, number]

Don't bother checking signatureHelp.signatureInformationparameterInformation.labelOffsetSupport
This commit is contained in:
Fangrui Song 2018-12-16 20:47:14 -08:00
parent 49ae9e8912
commit 836caba19b

View File

@ -12,7 +12,7 @@ using namespace clang;
namespace { namespace {
struct ParameterInformation { struct ParameterInformation {
std::string label; std::vector<int> label;
}; };
struct SignatureInformation { struct SignatureInformation {
std::string label; std::string label;
@ -28,13 +28,12 @@ REFLECT_STRUCT(ParameterInformation, label);
REFLECT_STRUCT(SignatureInformation, label, documentation, parameters); REFLECT_STRUCT(SignatureInformation, label, documentation, parameters);
REFLECT_STRUCT(SignatureHelp, signatures, activeSignature, activeParameter); REFLECT_STRUCT(SignatureHelp, signatures, activeSignature, activeParameter);
std::string BuildOptional(const CodeCompletionString &CCS, void BuildOptional(const CodeCompletionString &CCS, std::string &label,
std::vector<ParameterInformation> &ls_params) { std::vector<ParameterInformation> &ls_params) {
std::string ret;
for (const auto &Chunk : CCS) { for (const auto &Chunk : CCS) {
switch (Chunk.Kind) { switch (Chunk.Kind) {
case CodeCompletionString::CK_Optional: case CodeCompletionString::CK_Optional:
ret += BuildOptional(*Chunk.Optional, ls_params); BuildOptional(*Chunk.Optional, label, ls_params);
break; break;
case CodeCompletionString::CK_Placeholder: case CodeCompletionString::CK_Placeholder:
// A string that acts as a placeholder for, e.g., a function call // A string that acts as a placeholder for, e.g., a function call
@ -44,18 +43,18 @@ std::string BuildOptional(const CodeCompletionString &CCS,
// A piece of text that describes the parameter that corresponds to // A piece of text that describes the parameter that corresponds to
// the code-completion location within a function call, message send, // the code-completion location within a function call, message send,
// macro invocation, etc. // macro invocation, etc.
ret += Chunk.Text; int off = (int)label.size();
ls_params.push_back({Chunk.Text}); label += Chunk.Text;
ls_params.push_back({{off, (int)label.size()}});
break; break;
} }
case CodeCompletionString::CK_VerticalSpace: case CodeCompletionString::CK_VerticalSpace:
break; break;
default: default:
ret += Chunk.Text; label += Chunk.Text;
break; break;
} }
} }
return ret;
} }
class SignatureHelpConsumer : public CodeCompleteConsumer { class SignatureHelpConsumer : public CodeCompleteConsumer {
@ -103,12 +102,13 @@ public:
break; break;
case CodeCompletionString::CK_Placeholder: case CodeCompletionString::CK_Placeholder:
case CodeCompletionString::CK_CurrentParameter: { case CodeCompletionString::CK_CurrentParameter: {
int off = (int)ls_sig.label.size();
ls_sig.label += Chunk.Text; ls_sig.label += Chunk.Text;
ls_sig.parameters.push_back({Chunk.Text}); ls_sig.parameters.push_back({{off, (int)ls_sig.label.size()}});
break; break;
} }
case CodeCompletionString::CK_Optional: case CodeCompletionString::CK_Optional:
ls_sig.label += BuildOptional(*Chunk.Optional, ls_sig.parameters); BuildOptional(*Chunk.Optional, ls_sig.label, ls_sig.parameters);
break; break;
case CodeCompletionString::CK_VerticalSpace: case CodeCompletionString::CK_VerticalSpace:
break; break;