Skip to content

Commit f124c2f

Browse files
authored
Merge pull request #41525 from ahoppen/pr/split-codecompletion-cpp
[CodeCompletion] Split CodeCompletion.cpp into multiple files
2 parents 90860b1 + 1fdfc6a commit f124c2f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+8810
-7731
lines changed

include/swift/IDE/CodeCompletion.h

Lines changed: 12 additions & 1265 deletions
Large diffs are not rendered by default.

include/swift/IDE/CodeCompletionCache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "swift/Basic/ThreadSafeRefCounted.h"
1717
#include "swift/IDE/CodeCompletion.h"
18+
#include "swift/IDE/CodeCompletionResult.h"
19+
#include "swift/IDE/CodeCompletionString.h"
1820
#include "llvm/ADT/Hashing.h"
1921
#include "llvm/ADT/IntrusiveRefCntPtr.h"
2022
#include "llvm/Support/Chrono.h"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//===--- CodeCompletionConsumer.h -----------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_IDE_CODECOMPLETIONCONSUMER
14+
#define SWIFT_IDE_CODECOMPLETIONCONSUMER
15+
16+
#include "swift/IDE/CodeCompletionContext.h"
17+
#include "swift/Parse/CodeCompletionCallbacks.h"
18+
19+
namespace swift {
20+
namespace ide {
21+
22+
struct RequestedCachedModule;
23+
24+
/// An abstract base class for consumers of code completion results.
25+
/// \see \c SimpleCachingCodeCompletionConsumer.
26+
class CodeCompletionConsumer {
27+
public:
28+
virtual ~CodeCompletionConsumer() {}
29+
virtual void
30+
handleResultsAndModules(CodeCompletionContext &context,
31+
ArrayRef<RequestedCachedModule> requestedModules,
32+
DeclContext *DC) = 0;
33+
};
34+
35+
/// A simplified code completion consumer interface that clients can use to get
36+
/// CodeCompletionResults with automatic caching of top-level completions from
37+
/// imported modules.
38+
struct SimpleCachingCodeCompletionConsumer : public CodeCompletionConsumer {
39+
40+
// Implement the CodeCompletionConsumer interface.
41+
void handleResultsAndModules(CodeCompletionContext &context,
42+
ArrayRef<RequestedCachedModule> requestedModules,
43+
DeclContext *DCForModules) override;
44+
45+
/// Clients should override this method to receive \p Results.
46+
virtual void handleResults(CodeCompletionContext &context) = 0;
47+
};
48+
49+
} // end namespace ide
50+
} // end namespace swift
51+
52+
#endif // SWIFT_IDE_CODECOMPLETIONCONSUMER
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//===--- CodeCompletionContext.h ------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_IDE_CODECOMPLETIONCONTEXT
14+
#define SWIFT_IDE_CODECOMPLETIONCONTEXT
15+
16+
#include "swift/IDE/CodeCompletionResult.h"
17+
#include "swift/IDE/CodeCompletionResultSink.h"
18+
19+
namespace swift {
20+
namespace ide {
21+
22+
class CodeCompletionCache;
23+
24+
class CodeCompletionContext {
25+
friend class CodeCompletionResultBuilder;
26+
27+
/// A set of current completion results.
28+
CodeCompletionResultSink CurrentResults;
29+
30+
public:
31+
CodeCompletionCache &Cache;
32+
CompletionKind CodeCompletionKind = CompletionKind::None;
33+
34+
enum class TypeContextKind {
35+
/// There is no known contextual type. All types are equally good.
36+
None,
37+
38+
/// There is a contextual type from a single-expression closure/function
39+
/// body. The context is a hint, and enables unresolved member completion,
40+
/// but should not hide any results.
41+
SingleExpressionBody,
42+
43+
/// There are known contextual types, or there aren't but a nonvoid type is
44+
/// expected.
45+
Required,
46+
};
47+
48+
TypeContextKind typeContextKind = TypeContextKind::None;
49+
50+
/// Whether there may be members that can use implicit member syntax,
51+
/// e.g. `x = .foo`.
52+
bool MayUseImplicitMemberExpr = false;
53+
54+
/// Flag to indicate that the completion is happening reusing ASTContext
55+
/// from the previous completion.
56+
/// NOTE: Do not use this to change the behavior. This is only for debugging.
57+
bool ReusingASTContext = false;
58+
59+
CodeCompletionContext(CodeCompletionCache &Cache) : Cache(Cache) {}
60+
61+
void setAnnotateResult(bool flag) { CurrentResults.annotateResult = flag; }
62+
bool getAnnotateResult() const { return CurrentResults.annotateResult; }
63+
64+
void setIncludeObjectLiterals(bool flag) {
65+
CurrentResults.includeObjectLiterals = flag;
66+
}
67+
bool includeObjectLiterals() const {
68+
return CurrentResults.includeObjectLiterals;
69+
}
70+
71+
void setAddInitsToTopLevel(bool flag) {
72+
CurrentResults.addInitsToTopLevel = flag;
73+
}
74+
bool getAddInitsToTopLevel() const {
75+
return CurrentResults.addInitsToTopLevel;
76+
}
77+
78+
void setCallPatternHeuristics(bool flag) {
79+
CurrentResults.enableCallPatternHeuristics = flag;
80+
}
81+
bool getCallPatternHeuristics() const {
82+
return CurrentResults.enableCallPatternHeuristics;
83+
}
84+
85+
void setAddCallWithNoDefaultArgs(bool flag) {
86+
CurrentResults.addCallWithNoDefaultArgs = flag;
87+
}
88+
bool addCallWithNoDefaultArgs() const {
89+
return CurrentResults.addCallWithNoDefaultArgs;
90+
}
91+
92+
/// Allocate a string owned by the code completion context.
93+
StringRef copyString(StringRef Str);
94+
95+
/// Sort code completion results in an implementation-defined order
96+
/// in place.
97+
static std::vector<CodeCompletionResult *>
98+
sortCompletionResults(ArrayRef<CodeCompletionResult *> Results);
99+
100+
CodeCompletionResultSink &getResultSink() { return CurrentResults; }
101+
};
102+
103+
} // end namespace ide
104+
} // end namespace swift
105+
106+
#endif // SWIFT_IDE_CODECOMPLETIONCONTEXT

0 commit comments

Comments
 (0)