mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #77072 from hamishknight/complete-options
[IDE] Pass LangOptions to `ide::isSourceInputComplete`
This commit is contained in:
@@ -11,7 +11,6 @@ set(driver_sources_and_options
|
||||
modulewrap_main.cpp
|
||||
swift_api_digester_main.cpp
|
||||
swift_cache_tool_main.cpp
|
||||
swift_indent_main.cpp
|
||||
swift_symbolgraph_extract_main.cpp
|
||||
swift_synthesize_interface_main.cpp
|
||||
swift_parse_test_main.cpp)
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
//===--- swift_indent_main.cpp - Swift code formatting tool ---------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Formats Swift files or file ranges according to a set of parameters.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/AST/DiagnosticsFrontend.h"
|
||||
#include "swift/Basic/SourceManager.h"
|
||||
#include "swift/Frontend/Frontend.h"
|
||||
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
|
||||
#include "swift/IDE/Indenting.h"
|
||||
#include "swift/Option/Options.h"
|
||||
#include "swift/Subsystems.h"
|
||||
#include "llvm/Option/Arg.h"
|
||||
#include "llvm/Option/Option.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace swift;
|
||||
using namespace swift::ide;
|
||||
using namespace llvm::opt;
|
||||
|
||||
class FormatterDocument {
|
||||
private:
|
||||
SourceManager SM;
|
||||
unsigned BufferID;
|
||||
CompilerInvocation CompInv;
|
||||
std::unique_ptr<ParserUnit> Parser;
|
||||
class FormatterDiagConsumer : public swift::DiagnosticConsumer {
|
||||
void handleDiagnostic(SourceManager &SM,
|
||||
const swift::DiagnosticInfo &Info) override {
|
||||
llvm::errs() << "Parse error: ";
|
||||
DiagnosticEngine::formatDiagnosticText(llvm::errs(), Info.FormatString,
|
||||
Info.FormatArgs);
|
||||
llvm::errs() << "\n";
|
||||
}
|
||||
} DiagConsumer;
|
||||
|
||||
public:
|
||||
FormatterDocument(std::unique_ptr<llvm::MemoryBuffer> Buffer) {
|
||||
// Formatting logic requires tokens on source file.
|
||||
CompInv.getLangOptions().CollectParsedToken = true;
|
||||
updateCode(std::move(Buffer));
|
||||
}
|
||||
|
||||
void updateCode(std::unique_ptr<llvm::MemoryBuffer> Buffer) {
|
||||
BufferID = SM.addNewSourceBuffer(std::move(Buffer));
|
||||
Parser.reset(new ParserUnit(
|
||||
SM, SourceFileKind::Main, BufferID, CompInv.getLangOptions(),
|
||||
CompInv.getTypeCheckerOptions(), CompInv.getSILOptions(),
|
||||
CompInv.getModuleName()));
|
||||
Parser->getDiagnosticEngine().addConsumer(DiagConsumer);
|
||||
Parser->parse();
|
||||
}
|
||||
|
||||
std::pair<LineRange, std::string> reformat(LineRange Range,
|
||||
CodeFormatOptions Options) {
|
||||
return ::reformat(Range, Options, SM, Parser->getSourceFile());
|
||||
}
|
||||
|
||||
const llvm::MemoryBuffer &memBuffer() const {
|
||||
return *SM.getLLVMSourceMgr().getMemoryBuffer(BufferID);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user