Skip to content

Commit 974829e

Browse files
committed
[swift-ide-test] Use dedicated method for conformingMethodList on CompletionInstance instead of generic performOperation
1 parent 4ee9b0d commit 974829e

File tree

3 files changed

+59
-60
lines changed

3 files changed

+59
-60
lines changed

include/swift/IDE/ConformingMethodList.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ class ConformingMethodListConsumer {
4444
virtual void handleResult(const ConformingMethodListResult &result) = 0;
4545
};
4646

47-
/// Printing consumer
48-
class PrintingConformingMethodListConsumer
49-
: public ConformingMethodListConsumer {
50-
llvm::raw_ostream &OS;
51-
52-
public:
53-
PrintingConformingMethodListConsumer(llvm::raw_ostream &OS) : OS(OS) {}
54-
55-
void handleResult(const ConformingMethodListResult &result) override;
56-
};
57-
5847
/// Create a factory for code completion callbacks.
5948
CodeCompletionCallbacksFactory *makeConformingMethodListCallbacksFactory(
6049
ArrayRef<const char *> expectedTypeNames,

lib/IDE/ConformingMethodList.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -172,43 +172,6 @@ void ConformingMethodListCallbacks::getMatchingMethods(
172172

173173
} // anonymous namespace.
174174

175-
void PrintingConformingMethodListConsumer::handleResult(
176-
const ConformingMethodListResult &result) {
177-
OS << "-----BEGIN CONFORMING METHOD LIST-----\n";
178-
179-
OS << "- TypeName: ";
180-
result.ExprType.print(OS);
181-
OS << "\n";
182-
183-
OS << "- Members: ";
184-
if (result.Members.empty())
185-
OS << " []";
186-
OS << "\n";
187-
for (auto VD : result.Members) {
188-
auto funcTy = cast<FuncDecl>(VD)->getMethodInterfaceType();
189-
funcTy = result.ExprType->getTypeOfMember(result.DC->getParentModule(), VD,
190-
funcTy);
191-
auto resultTy = funcTy->castTo<FunctionType>()->getResult();
192-
193-
OS << " - Name: ";
194-
VD->getName().print(OS);
195-
OS << "\n";
196-
197-
OS << " TypeName: ";
198-
resultTy.print(OS);
199-
OS << "\n";
200-
201-
StringRef BriefDoc = VD->getBriefComment();
202-
if (!BriefDoc.empty()) {
203-
OS << " DocBrief: \"";
204-
OS << VD->getBriefComment();
205-
OS << "\"\n";
206-
}
207-
}
208-
209-
OS << "-----END CONFORMING METHOD LIST-----\n";
210-
}
211-
212175
CodeCompletionCallbacksFactory *
213176
swift::ide::makeConformingMethodListCallbacksFactory(
214177
ArrayRef<const char *> expectedTypeNames,

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,51 @@ static int doTypeContextInfo(const CompilerInvocation &InitInvok,
10241024
});
10251025
}
10261026

1027+
static int printConformingMethodList(
1028+
CancellableResult<ConformingMethodListResults> CancellableResult) {
1029+
return printResult<ConformingMethodListResults>(
1030+
CancellableResult, [](ConformingMethodListResults &Results) {
1031+
auto Result = Results.Result;
1032+
if (!Result) {
1033+
return 0;
1034+
}
1035+
llvm::outs() << "-----BEGIN CONFORMING METHOD LIST-----\n";
1036+
1037+
llvm::outs() << "- TypeName: ";
1038+
Result->ExprType.print(llvm::outs());
1039+
llvm::outs() << "\n";
1040+
1041+
llvm::outs() << "- Members: ";
1042+
if (Result->Members.empty())
1043+
llvm::outs() << " []";
1044+
llvm::outs() << "\n";
1045+
for (auto VD : Result->Members) {
1046+
auto funcTy = cast<FuncDecl>(VD)->getMethodInterfaceType();
1047+
funcTy = Result->ExprType->getTypeOfMember(
1048+
Result->DC->getParentModule(), VD, funcTy);
1049+
auto resultTy = funcTy->castTo<FunctionType>()->getResult();
1050+
1051+
llvm::outs() << " - Name: ";
1052+
VD->getName().print(llvm::outs());
1053+
llvm::outs() << "\n";
1054+
1055+
llvm::outs() << " TypeName: ";
1056+
resultTy.print(llvm::outs());
1057+
llvm::outs() << "\n";
1058+
1059+
StringRef BriefDoc = VD->getBriefComment();
1060+
if (!BriefDoc.empty()) {
1061+
llvm::outs() << " DocBrief: \"";
1062+
llvm::outs() << VD->getBriefComment();
1063+
llvm::outs() << "\"\n";
1064+
}
1065+
}
1066+
1067+
llvm::outs() << "-----END CONFORMING METHOD LIST-----\n";
1068+
return 0;
1069+
});
1070+
}
1071+
10271072
static int
10281073
doConformingMethodList(const CompilerInvocation &InitInvok,
10291074
StringRef SourceFilename, StringRef SecondSourceFileName,
@@ -1034,18 +1079,20 @@ doConformingMethodList(const CompilerInvocation &InitInvok,
10341079
for (auto &name : expectedTypeNames)
10351080
typeNames.push_back(name.c_str());
10361081

1037-
// Create a CodeCompletionConsumer.
1038-
std::unique_ptr<ide::ConformingMethodListConsumer> Consumer(
1039-
new ide::PrintingConformingMethodListConsumer(llvm::outs()));
1040-
1041-
// Create a factory for code completion callbacks that will feed the
1042-
// Consumer.
1043-
std::unique_ptr<CodeCompletionCallbacksFactory> callbacksFactory(
1044-
ide::makeConformingMethodListCallbacksFactory(typeNames, *Consumer));
1045-
1046-
return doCodeCompletionImpl(callbacksFactory.get(), InitInvok, SourceFilename,
1047-
SecondSourceFileName, CodeCompletionToken,
1048-
CodeCompletionDiagnostics);
1082+
return performWithCompletionLikeOperationParams(
1083+
InitInvok, SourceFilename, SecondSourceFileName, CodeCompletionToken,
1084+
CodeCompletionDiagnostics,
1085+
[&](CompletionLikeOperationParams Params) -> bool {
1086+
CompletionInstance CompletionInst;
1087+
int ExitCode = 2;
1088+
CompletionInst.conformingMethodList(
1089+
Params.Invocation, Params.Args, Params.FileSystem,
1090+
Params.CompletionBuffer, Params.Offset, Params.DiagC, typeNames,
1091+
[&](CancellableResult<ConformingMethodListResults> Result) {
1092+
ExitCode = printConformingMethodList(Result);
1093+
});
1094+
return ExitCode;
1095+
});
10491096
}
10501097

10511098
static int doCodeCompletion(const CompilerInvocation &InitInvok,

0 commit comments

Comments
 (0)