|
33 | 33 | #include "swift/ClangImporter/ClangModule.h"
|
34 | 34 | #include "swift/Frontend/FrontendOptions.h"
|
35 | 35 | #include "swift/IDE/CodeCompletionCache.h"
|
| 36 | +#include "swift/IDE/CodeCompletionConsumer.h" |
36 | 37 | #include "swift/IDE/CodeCompletionResultPrinter.h"
|
37 | 38 | #include "swift/IDE/CodeCompletionStringPrinter.h"
|
38 | 39 | #include "swift/IDE/CompletionLookup.h"
|
@@ -1156,9 +1157,9 @@ static void addConditionalCompilationFlags(ASTContext &Ctx,
|
1156 | 1157 | /// If \p Sink is passed, the pointer of the each result may be replaced with a
|
1157 | 1158 | /// pointer to the new item allocated in \p Sink.
|
1158 | 1159 | /// If \p Sink is nullptr, the pointee of each result may be modified in place.
|
1159 |
| -static void postProcessResults(MutableArrayRef<CodeCompletionResult *> results, |
1160 |
| - CompletionKind Kind, DeclContext *DC, |
1161 |
| - CodeCompletionResultSink *Sink) { |
| 1160 | +void swift::ide::postProcessResults( |
| 1161 | + MutableArrayRef<CodeCompletionResult *> results, CompletionKind Kind, |
| 1162 | + DeclContext *DC, CodeCompletionResultSink *Sink) { |
1162 | 1163 | for (CodeCompletionResult *&result : results) {
|
1163 | 1164 | bool modified = false;
|
1164 | 1165 | auto flair = result->getFlair();
|
@@ -2065,132 +2066,6 @@ void swift::ide::lookupCodeCompletionResultsFromModule(
|
2065 | 2066 | Lookup.lookupExternalModuleDecls(module, accessPath, needLeadingDot);
|
2066 | 2067 | }
|
2067 | 2068 |
|
2068 |
| -static MutableArrayRef<CodeCompletionResult *> |
2069 |
| -copyCodeCompletionResults(CodeCompletionResultSink &targetSink, |
2070 |
| - CodeCompletionCache::Value &source, bool onlyTypes, |
2071 |
| - bool onlyPrecedenceGroups) { |
2072 |
| - |
2073 |
| - // We will be adding foreign results (from another sink) into TargetSink. |
2074 |
| - // TargetSink should have an owning pointer to the allocator that keeps the |
2075 |
| - // results alive. |
2076 |
| - targetSink.ForeignAllocators.push_back(source.Allocator); |
2077 |
| - auto startSize = targetSink.Results.size(); |
2078 |
| - |
2079 |
| - std::function<bool(const ContextFreeCodeCompletionResult *)> |
2080 |
| - shouldIncludeResult; |
2081 |
| - if (onlyTypes) { |
2082 |
| - shouldIncludeResult = [](const ContextFreeCodeCompletionResult *R) -> bool { |
2083 |
| - if (R->getKind() != CodeCompletionResultKind::Declaration) |
2084 |
| - return false; |
2085 |
| - switch (R->getAssociatedDeclKind()) { |
2086 |
| - case CodeCompletionDeclKind::Module: |
2087 |
| - case CodeCompletionDeclKind::Class: |
2088 |
| - case CodeCompletionDeclKind::Actor: |
2089 |
| - case CodeCompletionDeclKind::Struct: |
2090 |
| - case CodeCompletionDeclKind::Enum: |
2091 |
| - case CodeCompletionDeclKind::Protocol: |
2092 |
| - case CodeCompletionDeclKind::TypeAlias: |
2093 |
| - case CodeCompletionDeclKind::AssociatedType: |
2094 |
| - case CodeCompletionDeclKind::GenericTypeParam: |
2095 |
| - return true; |
2096 |
| - case CodeCompletionDeclKind::PrecedenceGroup: |
2097 |
| - case CodeCompletionDeclKind::EnumElement: |
2098 |
| - case CodeCompletionDeclKind::Constructor: |
2099 |
| - case CodeCompletionDeclKind::Destructor: |
2100 |
| - case CodeCompletionDeclKind::Subscript: |
2101 |
| - case CodeCompletionDeclKind::StaticMethod: |
2102 |
| - case CodeCompletionDeclKind::InstanceMethod: |
2103 |
| - case CodeCompletionDeclKind::PrefixOperatorFunction: |
2104 |
| - case CodeCompletionDeclKind::PostfixOperatorFunction: |
2105 |
| - case CodeCompletionDeclKind::InfixOperatorFunction: |
2106 |
| - case CodeCompletionDeclKind::FreeFunction: |
2107 |
| - case CodeCompletionDeclKind::StaticVar: |
2108 |
| - case CodeCompletionDeclKind::InstanceVar: |
2109 |
| - case CodeCompletionDeclKind::LocalVar: |
2110 |
| - case CodeCompletionDeclKind::GlobalVar: |
2111 |
| - return false; |
2112 |
| - } |
2113 |
| - |
2114 |
| - llvm_unreachable("Unhandled CodeCompletionDeclKind in switch."); |
2115 |
| - }; |
2116 |
| - } else if (onlyPrecedenceGroups) { |
2117 |
| - shouldIncludeResult = [](const ContextFreeCodeCompletionResult *R) -> bool { |
2118 |
| - return R->getAssociatedDeclKind() == |
2119 |
| - CodeCompletionDeclKind::PrecedenceGroup; |
2120 |
| - }; |
2121 |
| - } else { |
2122 |
| - shouldIncludeResult = [](const ContextFreeCodeCompletionResult *R) -> bool { |
2123 |
| - return true; |
2124 |
| - }; |
2125 |
| - } |
2126 |
| - for (auto contextFreeResult : source.Results) { |
2127 |
| - if (!shouldIncludeResult(contextFreeResult)) { |
2128 |
| - continue; |
2129 |
| - } |
2130 |
| - auto contextualResult = new (*targetSink.Allocator) CodeCompletionResult( |
2131 |
| - *contextFreeResult, SemanticContextKind::OtherModule, |
2132 |
| - CodeCompletionFlair(), |
2133 |
| - /*numBytesToErase=*/0, /*TypeContext=*/nullptr, /*DC=*/nullptr, |
2134 |
| - ContextualNotRecommendedReason::None, |
2135 |
| - CodeCompletionDiagnosticSeverity::None, /*DiagnosticMessage=*/""); |
2136 |
| - targetSink.Results.push_back(contextualResult); |
2137 |
| - } |
2138 |
| - |
2139 |
| - return llvm::makeMutableArrayRef(targetSink.Results.data() + startSize, |
2140 |
| - targetSink.Results.size() - startSize); |
2141 |
| -} |
2142 |
| - |
2143 |
| -void SimpleCachingCodeCompletionConsumer::handleResultsAndModules( |
2144 |
| - CodeCompletionContext &context, |
2145 |
| - ArrayRef<RequestedCachedModule> requestedModules, |
2146 |
| - DeclContext *DC) { |
2147 |
| - |
2148 |
| - // Use the current SourceFile as the DeclContext so that we can use it to |
2149 |
| - // perform qualified lookup, and to get the correct visibility for |
2150 |
| - // @testable imports. Also it cannot use 'DC' since it would apply decl |
2151 |
| - // context changes to cached results. |
2152 |
| - const SourceFile *SF = DC->getParentSourceFile(); |
2153 |
| - |
2154 |
| - for (auto &R : requestedModules) { |
2155 |
| - // FIXME(thread-safety): lock the whole AST context. We might load a |
2156 |
| - // module. |
2157 |
| - llvm::Optional<CodeCompletionCache::ValueRefCntPtr> V = |
2158 |
| - context.Cache.get(R.Key); |
2159 |
| - if (!V.hasValue()) { |
2160 |
| - // No cached results found. Fill the cache. |
2161 |
| - V = context.Cache.createValue(); |
2162 |
| - // Temporary sink in which we gather the result. The cache value retains |
2163 |
| - // the sink's allocator. |
2164 |
| - CodeCompletionResultSink Sink; |
2165 |
| - Sink.annotateResult = context.getAnnotateResult(); |
2166 |
| - Sink.addInitsToTopLevel = context.getAddInitsToTopLevel(); |
2167 |
| - Sink.enableCallPatternHeuristics = context.getCallPatternHeuristics(); |
2168 |
| - Sink.includeObjectLiterals = context.includeObjectLiterals(); |
2169 |
| - Sink.addCallWithNoDefaultArgs = context.addCallWithNoDefaultArgs(); |
2170 |
| - lookupCodeCompletionResultsFromModule(Sink, R.TheModule, R.Key.AccessPath, |
2171 |
| - R.Key.ResultsHaveLeadingDot, SF); |
2172 |
| - (*V)->Allocator = Sink.Allocator; |
2173 |
| - auto &CachedResults = (*V)->Results; |
2174 |
| - CachedResults.reserve(Sink.Results.size()); |
2175 |
| - // Instead of copying the context free results out of the sink's allocator |
2176 |
| - // retain the sink's entire allocator (which also includes the contextual |
2177 |
| - // properities) and simply store pointers to the context free results that |
2178 |
| - // back the contextual results. |
2179 |
| - for (auto Result : Sink.Results) { |
2180 |
| - CachedResults.push_back(Result->getContextFreeResultPtr()); |
2181 |
| - } |
2182 |
| - context.Cache.set(R.Key, *V); |
2183 |
| - } |
2184 |
| - assert(V.hasValue()); |
2185 |
| - auto newItems = copyCodeCompletionResults( |
2186 |
| - context.getResultSink(), **V, R.OnlyTypes, R.OnlyPrecedenceGroups); |
2187 |
| - postProcessResults(newItems, context.CodeCompletionKind, DC, |
2188 |
| - &context.getResultSink()); |
2189 |
| - } |
2190 |
| - |
2191 |
| - handleResults(context); |
2192 |
| -} |
2193 |
| - |
2194 | 2069 | //===----------------------------------------------------------------------===//
|
2195 | 2070 | // ImportDepth
|
2196 | 2071 | //===----------------------------------------------------------------------===//
|
|
0 commit comments