Skip to content

Commit c126d7a

Browse files
committed
Merge branch 'main' of https://github.com/clice-project/clice into pr/Guo-Shiyu/184-1
2 parents c8e4271 + 5f8a577 commit c126d7a

35 files changed

+2940
-913
lines changed

include/AST/SourceCode.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ struct LocalSourceRange {
4646

4747
constexpr bool operator== (const LocalSourceRange& other) const = default;
4848

49+
constexpr auto length() {
50+
return end - begin;
51+
}
52+
4953
constexpr bool contains(uint32_t offset) const {
5054
return offset >= begin && offset <= end;
5155
}

include/AST/Utility.h

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,71 +12,58 @@ bool is_definition(const clang::Decl* decl);
1212
/// we consider it as a template while clang does not.
1313
bool is_templated(const clang::Decl* decl);
1414

15+
/// Check whether the decl is anonymous.
16+
bool is_anonymous(const clang::NamedDecl* decl);
17+
1518
/// Return the decl where it is instantiated from. If could be a template decl
1619
/// or a member of a class template. If the decl is a full specialization, return
1720
/// itself.
1821
const clang::NamedDecl* instantiated_from(const clang::NamedDecl* decl);
1922

2023
const clang::NamedDecl* normalize(const clang::NamedDecl* decl);
2124

25+
llvm::StringRef identifier_of(const clang::NamedDecl& D);
26+
27+
llvm::StringRef identifier_of(clang::QualType T);
28+
2229
/// Get the name of the decl.
2330
std::string name_of(const clang::NamedDecl* decl);
2431

32+
std::string display_name_of(const clang::NamedDecl* decl);
33+
2534
/// To response go-to-type-definition request. Some decls actually have a type
2635
/// for example the result of `typeof(var)` is the type of `var`. This function
2736
/// returns the type for the decl if any.
2837
clang::QualType type_of(const clang::NamedDecl* decl);
2938

30-
const clang::NamedDecl* get_decl_for_type(const clang::Type* T);
31-
3239
/// Get the underlying decl for a type if any.
33-
const clang::NamedDecl* decl_of(clang::QualType type);
34-
35-
/// Check whether the decl is anonymous.
36-
bool is_anonymous(const clang::NamedDecl* decl);
37-
38-
clang::NestedNameSpecifierLoc get_qualifier_loc(const clang::NamedDecl* decl);
39-
40-
auto get_template_specialization_args(const clang::NamedDecl* decl)
41-
-> std::optional<llvm::ArrayRef<clang::TemplateArgumentLoc>>;
40+
auto decl_of(clang::QualType type) -> const clang::NamedDecl*;
4241

43-
std::string print_template_specialization_args(const clang::NamedDecl* decl);
42+
/// Recursively strips all pointers, references, and array extents from
43+
/// a TypeLoc. e.g., for "const int*(&)[3]", the result will be location
44+
/// "for int".
45+
auto unwrap_type(clang::TypeLoc type, bool unwrap_function_type = true) -> clang::TypeLoc;
4446

45-
std::string print_name(const clang::NamedDecl* decl);
47+
auto get_only_instantiation(clang::NamedDecl* templated_decl) -> clang::NamedDecl*;
4648

47-
clang::TemplateTypeParmTypeLoc get_contained_auto_param_type(clang::TypeLoc TL);
49+
auto get_only_instantiation(clang::ParmVarDecl* param) -> clang::ParmVarDecl*;
4850

49-
clang::NamedDecl* get_only_instantiation(clang::NamedDecl* TemplatedDecl);
50-
51-
/// getSimpleName() returns the plain identifier for an entity, if any.
52-
llvm::StringRef getSimpleName(const clang::DeclarationName& DN);
53-
llvm::StringRef getSimpleName(const clang::NamedDecl& D);
54-
llvm::StringRef getSimpleName(clang::QualType T);
55-
56-
std::string summarizeExpr(const clang::Expr* E);
57-
58-
// Returns the template parameter pack type from an instantiated function
59-
// template, if it exists, nullptr otherwise.
60-
const clang::TemplateTypeParmType* getFunctionPackType(const clang::FunctionDecl* Callee);
51+
std::string summarize_expr(const clang::Expr* E);
6152

6253
// Returns the template parameter pack type that this parameter was expanded
6354
// from (if in the Args... or Args&... or Args&&... form), if this is the case,
6455
// nullptr otherwise.
65-
const clang::TemplateTypeParmType* getUnderlyingPackType(const clang::ParmVarDecl* Param);
56+
const clang::TemplateTypeParmType* underlying_pack_type(const clang::ParmVarDecl* param);
6657

6758
// Returns the parameters that are forwarded from the template parameters.
6859
// For example, `template <typename... Args> void foo(Args... args)` will return
6960
// the `args` parameters.
70-
llvm::SmallVector<const clang::ParmVarDecl*>
71-
resolveForwardingParameters(const clang::FunctionDecl* D, unsigned MaxDepth = 10);
72-
73-
// Determines if any intermediate type in desugaring QualType QT is of
74-
// substituted template parameter type. Ignore pointer or reference wrappers.
75-
bool isSugaredTemplateParameter(clang::QualType QT);
61+
auto resolve_forwarding_params(const clang::FunctionDecl* decl, unsigned max_depth = 10)
62+
-> llvm::SmallVector<const clang::ParmVarDecl*>;
7663

7764
// A simple wrapper for `clang::desugarForDiagnostic` that provides optional
7865
// semantic.
79-
std::optional<clang::QualType> desugar(clang::ASTContext& AST, clang::QualType QT);
66+
std::optional<clang::QualType> desugar(clang::ASTContext& context, clang::QualType type);
8067

8168
// Apply a series of heuristic methods to determine whether or not a QualType QT
8269
// is suitable for desugaring (e.g. getting the real name behind the using-alias
@@ -85,12 +72,12 @@ std::optional<clang::QualType> desugar(clang::ASTContext& AST, clang::QualType Q
8572
//
8673
// This could be refined further. See
8774
// https://github.com/clangd/clangd/issues/1298.
88-
clang::QualType maybeDesugar(clang::ASTContext& AST, clang::QualType QT);
75+
clang::QualType maybe_desugar(clang::ASTContext& context, clang::QualType type);
8976

9077
// Given a callee expression `Fn`, if the call is through a function pointer,
9178
// try to find the declaration of the corresponding function pointer type,
9279
// so that we can recover argument names from it.
9380
// FIXME: This function is mostly duplicated in SemaCodeComplete.cpp; unify.
94-
clang::FunctionProtoTypeLoc getPrototypeLoc(clang::Expr* Fn);
81+
clang::FunctionProtoTypeLoc proto_type_loc(clang::Expr* expr);
9582

9683
} // namespace clice::ast

include/Async/Task.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ class Task {
317317
void stacktrace() {
318318
promise_base* handle = core;
319319
while(handle) {
320-
clice::println("{}:{}:{}",
321-
handle->location.file_name(),
322-
handle->location.line(),
323-
handle->location.function_name());
320+
std::println("{}:{}:{}",
321+
handle->location.file_name(),
322+
handle->location.line(),
323+
handle->location.function_name());
324324
handle = handle->continuation;
325325
}
326326
}

include/Compiler/CompilationUnit.h

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,32 @@ class CompilationUnit {
122122
/// Create a file location with given file id and offset.
123123
auto create_location(clang::FileID fid, std::uint32_t offset) -> clang::SourceLocation;
124124

125+
using TokenRange = llvm::ArrayRef<clang::syntax::Token>;
126+
125127
/// Get the spelled tokens(raw token) of the file id.
126-
auto spelled_tokens(clang::FileID fid) -> llvm::ArrayRef<clang::syntax::Token>;
128+
auto spelled_tokens(clang::FileID fid) -> TokenRange;
129+
130+
/// Return the spelled tokens corresponding to the range.
131+
auto spelled_tokens(clang::SourceRange range) -> TokenRange;
127132

128133
/// The spelled tokens that overlap or touch a spelling location Loc.
129134
/// This always returns 0-2 tokens.
130-
auto spelled_tokens_touch(clang::SourceLocation location)
131-
-> llvm::ArrayRef<clang::syntax::Token>;
132-
133-
auto expanded_tokens() -> llvm::ArrayRef<clang::syntax::Token>;
134-
135-
/// Get the expanded tokens(after preprocessing) of the file id.
136-
auto expanded_tokens(clang::SourceRange range) -> llvm::ArrayRef<clang::syntax::Token>;
137-
138-
auto expansions_overlapping(llvm::ArrayRef<clang::syntax::Token>)
139-
-> std::vector<clang::syntax::TokenBuffer::Expansion>;
135+
auto spelled_tokens_touch(clang::SourceLocation location) -> TokenRange;
136+
137+
/// All tokens produced by the preprocessor after all macro replacements,
138+
/// directives, etc. Source locations found in the clang AST will always
139+
/// point to one of these tokens.
140+
/// Tokens are in TU order (per SourceManager::isBeforeInTranslationUnit()).
141+
/// FIXME: figure out how to handle token splitting, e.g. '>>' can be split
142+
/// into two '>' tokens by the parser. However, TokenBuffer currently
143+
/// keeps it as a single '>>' token.
144+
auto expanded_tokens() -> TokenRange;
145+
146+
/// Returns the subrange of expandedTokens() corresponding to the closed
147+
/// token range R.
148+
auto expanded_tokens(clang::SourceRange range) -> TokenRange;
149+
150+
auto expansions_overlapping(TokenRange) -> std::vector<clang::syntax::TokenBuffer::Expansion>;
140151

141152
/// Get the token length.
142153
auto token_length(clang::SourceLocation location) -> std::uint32_t;

include/Feature/Formatting.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
#pragma once
2+
3+
#include "AST/SourceCode.h"
4+
#include "Protocol/Feature/Formatting.h"
5+
#include "llvm/ADT/StringRef.h"
6+
7+
namespace clice::feature {
8+
9+
std::vector<proto::TextEdit> document_format(llvm::StringRef file,
10+
llvm::StringRef content,
11+
std::optional<LocalSourceRange>);
12+
13+
}

include/Feature/InlayHint.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ struct InlayHint {
5050
std::vector<index::SymbolID> parts;
5151
};
5252

53-
using InlayHints = std::vector<InlayHint>;
54-
55-
InlayHints inlay_hints(CompilationUnit& unit, LocalSourceRange target);
53+
auto inlay_hint(CompilationUnit& unit,
54+
LocalSourceRange target,
55+
const config::InlayHintsOptions& options) -> std::vector<InlayHint>;
5656

5757
} // namespace clice::feature

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/Formatting.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ struct DocumentFormattingClientCapabilities {};
88

99
using DocumentFormattingOptions = bool;
1010

11+
struct DocumentFormattingParams {
12+
/// The document to format.
13+
TextDocumentIdentifier textDocument;
14+
};
15+
16+
struct DocumentRangeFormattingParams {
17+
/// The document to format.
18+
TextDocumentIdentifier textDocument;
19+
20+
/// The range to format
21+
Range range;
22+
};
23+
1124
struct DocumentRangeFormattingClientCapabilities {};
1225

1326
using DocumentRangeFormattingOptions = bool;

include/Protocol/Feature/InlayHint.h

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,71 @@
44

55
namespace clice::proto {
66

7-
struct InlayHintClientCapabilities {};
7+
struct InlayHintClientCapabilities {
8+
/// Indicates which properties a client can resolve lazily on an inlay hint.
9+
struct {
10+
/// The properties that a client can resolve lazily.
11+
array<string> properties;
12+
} resolveSupport;
13+
};
814

915
struct InlayHintOptions {
1016
/// The server provides support to resolve additional
1117
/// information for an inlay hint item.
1218
bool resolveProvider;
1319
};
1420

21+
struct InlayHintParams {
22+
/// The text document.
23+
TextDocumentIdentifier textDocument;
24+
25+
/// The visible document range for which inlay hints should be computed.
26+
Range range;
27+
};
28+
29+
enum class InlayHintKind {
30+
/// An inlay hint that for a type annotation.
31+
Type = 1,
32+
33+
/// An inlay hint that is for a parameter.
34+
Parameter = 2,
35+
};
36+
37+
struct InlayHintLabelPart {
38+
/// The value of this label part.
39+
string value;
40+
41+
/// An optional source code location that represents this
42+
/// label part.
43+
///
44+
/// The editor will use this location for the hover and for code navigation
45+
/// features: This part will become a clickable link that resolves to the
46+
/// definition of the symbol at the given location (not necessarily the
47+
/// location itself), it shows the hover that shows at the given location,
48+
/// and it shows a context menu with further code navigation commands.
49+
///
50+
/// Depending on the client capability `inlayHint.resolveSupport` clients
51+
/// might resolve this property late using the resolve request.
52+
/// FIXME: Location location;
53+
};
54+
55+
struct InlayHint {
56+
/// The position of this hint.
57+
///
58+
/// If multiple hints have the same position, they will be shown in the order
59+
/// they appear in the response.
60+
Position position;
61+
62+
/// The label of this hint. A human readable string or an array of
63+
/// InlayHintLabelPart label parts.
64+
///
65+
/// *Note* that neither the string nor the label part can be empty.
66+
/// TODO: Use label
67+
array<InlayHintLabelPart> label;
68+
69+
/// The kind of this hint. Can be omitted in which case the client
70+
/// should fall back to a reasonable default.
71+
InlayHintKind kind;
72+
};
73+
1574
} // namespace clice::proto

0 commit comments

Comments
 (0)