[IDE] Add swift-refactor option to output as plain text

Current modes are:
  1. output the whole rewritten buffer, with RUN and CHECK lines removed
  2. output each replacement in JSON

To make each refactoring (rather than the whole file) easier to test,
add a plain text output option that can be easily checked with
FileCheck.
This commit is contained in:
Ben Barham
2021-01-20 16:12:57 +10:00
parent aa7d010c79
commit 83915ccc4a
3 changed files with 67 additions and 9 deletions

View File

@@ -112,10 +112,21 @@ static llvm::cl::opt<bool>
IsNonProtocolType("is-non-protocol-type",
llvm::cl::desc("The symbol being renamed is a type and not a protocol"));
static llvm::cl::opt<bool>
DumpInJson("dump-json",
llvm::cl::desc("Whether to dump refactoring edits in json"),
llvm::cl::init(false));
enum class DumpType {
REWRITTEN,
JSON,
TEXT
};
static llvm::cl::opt<DumpType> DumpIn(
llvm::cl::desc("Dump edits to stdout as:"),
llvm::cl::init(DumpType::REWRITTEN),
llvm::cl::values(
clEnumValN(DumpType::REWRITTEN, "dump-rewritten",
"rewritten file"),
clEnumValN(DumpType::JSON, "dump-json",
"JSON"),
clEnumValN(DumpType::TEXT, "dump-text",
"text")));
static llvm::cl::opt<bool>
AvailableActions("actions",
@@ -373,12 +384,19 @@ int main(int argc, char *argv[]) {
RefactoringConfig.PreferredName = options::NewName;
std::string Error;
std::unique_ptr<SourceEditConsumer> pConsumer;
if (options::DumpInJson)
pConsumer.reset(new SourceEditJsonConsumer(llvm::outs()));
else
switch (options::DumpIn) {
case options::DumpType::REWRITTEN:
pConsumer.reset(new SourceEditOutputConsumer(SF->getASTContext().SourceMgr,
BufferID,
llvm::outs()));
BufferID,
llvm::outs()));
break;
case options::DumpType::JSON:
pConsumer.reset(new SourceEditJsonConsumer(llvm::outs()));
break;
case options::DumpType::TEXT:
pConsumer.reset(new SourceEditTextConsumer(llvm::outs()));
break;
}
return refactorSwiftModule(CI.getMainModule(), RefactoringConfig, *pConsumer,
PrintDiags);