Skip to content

Commit 52e45e1

Browse files
authored
Enable SignatureHelp (#187)
1 parent c437020 commit 52e45e1

File tree

12 files changed

+282
-73
lines changed

12 files changed

+282
-73
lines changed

include/Feature/SignatureHelp.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cstdint>
55

66
#include "llvm/ADT/StringRef.h"
7+
#include "Protocol/Feature/SignatureHelp.h"
78

89
namespace clice {
910

@@ -17,12 +18,8 @@ struct SignatureHelpOption {};
1718

1819
namespace feature {
1920

20-
struct SignatureHelpItem {};
21-
22-
using SignatureHelpResult = std::vector<SignatureHelpItem>;
23-
24-
SignatureHelpResult signatureHelp(CompilationParams& params,
25-
const config::SignatureHelpOption& option);
21+
proto::SignatureHelp signature_help(CompilationParams& params,
22+
const config::SignatureHelpOption& option);
2623

2724
} // namespace feature
2825

include/Protocol/Basic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <array>
34
#include <string>
45
#include <vector>
56
#include <cstdint>

include/Protocol/Feature/SignatureHelp.h

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,47 @@
44

55
namespace clice::proto {
66

7-
struct SignatureHelpClientCapabilities {};
7+
struct SignatureHelpClientCapabilities {
8+
/**
9+
* The client supports the `activeParameter` property on
10+
* `SignatureInformation` literal.
11+
*
12+
* @since 3.16.0
13+
*/
14+
};
815

9-
struct SignatureHelpOptions {};
16+
struct SignatureHelpOptions {
17+
/// The characters that trigger signature help automatically.
18+
array<string> triggerCharacters;
19+
20+
/// List of characters that re-trigger signature help.
21+
///
22+
/// These trigger characters are only active when signature help is already
23+
/// showing. All trigger characters are also counted as re-trigger
24+
/// characters.
25+
array<string> retriggerCharacters;
26+
};
27+
28+
using SignatureHelpParams = TextDocumentPositionParams;
29+
30+
struct ParameterInformation {
31+
std::array<uinteger, 2> label;
32+
};
33+
34+
struct SignatureInformation {
35+
string label;
36+
37+
MarkupContent document;
38+
39+
array<ParameterInformation> parameters;
40+
41+
uinteger activeParameter;
42+
};
43+
44+
struct SignatureHelp {
45+
array<SignatureInformation> signatures;
46+
47+
uinteger activeSignature;
48+
};
1049

1150
} // namespace clice::proto

include/Protocol/Lifecycle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct ServerCapabilities {
8585
HoverOptions hoverProvider;
8686

8787
/// The server provides signature help support.
88-
/// FIXME: SignatureHelpOptions signatureHelpProvider;
88+
SignatureHelpOptions signatureHelpProvider;
8989

9090
/// The server provides go to declaration support.
9191
/// FIXME: DeclarationOptions declarationProvider;

include/Server/Server.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ class Server {
200200

201201
async::Task<json::Value> on_hover(proto::HoverParams params);
202202

203+
async::Task<json::Value> on_signature_help(proto::SignatureHelpParams params);
204+
203205
async::Task<json::Value> on_document_symbol(proto::DocumentSymbolParams params);
204206

205207
async::Task<json::Value> on_document_link(proto::DocumentLinkParams params);

include/Test/Tester.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct Tester {
3131
sources.add_sources(content);
3232
}
3333

34-
bool compile(llvm::StringRef standard = "-std=c++20") {
34+
void prepare(llvm::StringRef standard = "-std=c++20") {
3535
auto command = std::format("clang++ {} {} -fms-extensions", standard, src_path);
3636

3737
database.update_command("fake", src_path, command);
@@ -46,6 +46,10 @@ struct Tester {
4646
params.add_remapped_file(path, source.content);
4747
}
4848
}
49+
}
50+
51+
bool compile(llvm::StringRef standard = "-std=c++20") {
52+
prepare(standard);
4953

5054
auto info = clice::compile(params);
5155
if(!info) {

src/AST/Utility.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -281,34 +281,32 @@ const clang::NamedDecl* decl_of_impl(const void* T) {
281281
}
282282

283283
auto decl_of(clang::QualType type) -> const clang::NamedDecl* {
284+
if(auto TST = type->getAs<clang::TemplateSpecializationType>()) {
285+
auto decl = TST->getTemplateName().getAsTemplateDecl();
286+
if(type->isDependentType()) {
287+
return decl;
288+
}
289+
290+
/// For a template specialization type, the template name is possibly a `ClassTemplateDecl`
291+
/// `TypeAliasTemplateDecl` or `TemplateTemplateParmDecl` and `BuiltinTemplateDecl`.
292+
if(llvm::isa<clang::TypeAliasTemplateDecl>(decl)) {
293+
return decl->getTemplatedDecl();
294+
}
295+
296+
if(llvm::isa<clang::TemplateTemplateParmDecl, clang::BuiltinTemplateDecl>(decl)) {
297+
return decl;
298+
}
299+
300+
return instantiated_from(TST->getAsCXXRecordDecl());
301+
}
302+
284303
switch(type->getTypeClass()) {
285304
#define ABSTRACT_TYPE(TY, BASE)
286305
#define TYPE(TY, BASE) \
287306
case clang::Type::TY: return decl_of_impl(llvm::cast<clang::TY##Type>(type));
288307
#include "clang/AST/TypeNodes.inc"
289308
}
290309

291-
/// FIXME: Handle Template Specialization type in the future
292-
/// if(auto TST = type->getAs<clang::TemplateSpecializationType>()) {
293-
/// auto decl = TST->getTemplateName().getAsTemplateDecl();
294-
/// if(type->isDependentType()) {
295-
/// return decl;
296-
/// }
297-
///
298-
/// /// For a template specialization type, the template name is possibly a
299-
/// `ClassTemplateDecl`
300-
/// /// `TypeAliasTemplateDecl` or `TemplateTemplateParmDecl` and `BuiltinTemplateDecl`.
301-
/// if(llvm::isa<clang::TypeAliasTemplateDecl>(decl)) {
302-
/// return decl->getTemplatedDecl();
303-
/// }
304-
///
305-
/// if(llvm::isa<clang::TemplateTemplateParmDecl, clang::BuiltinTemplateDecl>(decl)) {
306-
/// return decl;
307-
/// }
308-
///
309-
/// return instantiated_from(TST->getAsCXXRecordDecl());
310-
///}
311-
312310
return nullptr;
313311
}
314312

0 commit comments

Comments
 (0)