Skip to content

Commit 5f092e3

Browse files
committedJul 8, 2019
[clangd] Use -completion-style=bundled by default if signature help is available
Summary: I didn't manage to find something nicer than optional<bool>, but at least I found a sneakier comment. Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64216 llvm-svn: 365356
1 parent b736969 commit 5f092e3

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed
 

‎clang-tools-extra/clangd/ClangdLSPServer.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
366366

367367
CCOpts.EnableSnippets = Params.capabilities.CompletionSnippets;
368368
CCOpts.IncludeFixIts = Params.capabilities.CompletionFixes;
369+
if (!CCOpts.BundleOverloads.hasValue())
370+
CCOpts.BundleOverloads = Params.capabilities.HasSignatureHelp;
369371
DiagOpts.EmbedFixesInDiagnostics = Params.capabilities.DiagnosticFixes;
370372
DiagOpts.SendDiagnosticCategory = Params.capabilities.DiagnosticCategory;
371373
DiagOpts.EmitRelatedLocations =

‎clang-tools-extra/clangd/CodeComplete.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct CompletionCandidate {
169169
// Returns a token identifying the overload set this is part of.
170170
// 0 indicates it's not part of any overload set.
171171
size_t overloadSet(const CodeCompleteOptions &Opts) const {
172-
if (!Opts.BundleOverloads)
172+
if (!Opts.BundleOverloads.getValueOr(false))
173173
return 0;
174174
llvm::SmallString<256> Scratch;
175175
if (IndexResult) {

‎clang-tools-extra/clangd/CodeComplete.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ struct CodeCompleteOptions {
6262
bool IncludeIneligibleResults = false;
6363

6464
/// Combine overloads into a single completion item where possible.
65-
bool BundleOverloads = false;
65+
/// If none, the the implementation may choose an appropriate behavior.
66+
/// (In practice, ClangdLSPServer enables bundling if the client claims
67+
/// to supports signature help).
68+
llvm::Optional<bool> BundleOverloads;
6669

6770
/// Limit the number of results returned (0 means no limit).
6871
/// If more results are available, we set CompletionList.isIncomplete.

‎clang-tools-extra/clangd/Protocol.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ bool fromJSON(const llvm::json::Value &Params, ClientCapabilities &R) {
323323
}
324324
}
325325
if (auto *Help = TextDocument->getObject("signatureHelp")) {
326+
R.HasSignatureHelp = true;
326327
if (auto *Info = Help->getObject("signatureInformation")) {
327328
if (auto *Parameter = Info->getObject("parameterInformation")) {
328329
if (auto OffsetSupport = Parameter->getBoolean("labelOffsetSupport"))

‎clang-tools-extra/clangd/Protocol.h

+8
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,15 @@ struct ClientCapabilities {
393393
bool CompletionFixes = false;
394394

395395
/// Client supports hierarchical document symbols.
396+
/// textDocument.documentSymbol.hierarchicalDocumentSymbolSupport
396397
bool HierarchicalDocumentSymbol = false;
397398

399+
/// Client supports signature help.
400+
/// textDocument.signatureHelp
401+
bool HasSignatureHelp = false;
402+
398403
/// Client supports processing label offsets instead of a simple label string.
404+
/// textDocument.signatureHelp.signatureInformation.parameterInformation.labelOffsetSupport
399405
bool OffsetsInSignatureHelp = false;
400406

401407
/// The supported set of CompletionItemKinds for textDocument/completion.
@@ -407,12 +413,14 @@ struct ClientCapabilities {
407413
bool CodeActionStructure = false;
408414

409415
/// Client supports semantic highlighting.
416+
/// textDocument.semanticHighlightingCapabilities.semanticHighlighting
410417
bool SemanticHighlighting = false;
411418

412419
/// Supported encodings for LSP character offsets. (clangd extension).
413420
llvm::Optional<std::vector<OffsetEncoding>> offsetEncoding;
414421

415422
/// The content format that should be used for Hover requests.
423+
/// textDocument.hover.contentEncoding
416424
MarkupKind HoverContentFormat = MarkupKind::PlainText;
417425
};
418426
bool fromJSON(const llvm::json::Value &, ClientCapabilities &);

‎clang-tools-extra/clangd/tool/ClangdMain.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ static llvm::cl::opt<CompletionStyleFlag> CompletionStyle(
5858
"completion, with full type information"),
5959
clEnumValN(Bundled, "bundled",
6060
"Similar completion items (e.g. function overloads) are "
61-
"combined. Type information shown where possible")),
62-
llvm::cl::init(Detailed));
61+
"combined. Type information shown where possible")));
6362

6463
// FIXME: Flags are the wrong mechanism for user preferences.
6564
// We should probably read a dotfile or similar.
@@ -487,7 +486,8 @@ int main(int argc, char *argv[]) {
487486
clangd::CodeCompleteOptions CCOpts;
488487
CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
489488
CCOpts.Limit = LimitResults;
490-
CCOpts.BundleOverloads = CompletionStyle != Detailed;
489+
if (CompletionStyle.getNumOccurrences())
490+
CCOpts.BundleOverloads = CompletionStyle != Detailed;
491491
CCOpts.ShowOrigins = ShowOrigins;
492492
CCOpts.InsertIncludes = HeaderInsertion;
493493
if (!HeaderInsertionDecorators) {

0 commit comments

Comments
 (0)