mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Rename the swift-format utility to swift-indent
This is to distinguish the C++ indenting functionality from the new formatter that is written in Swift.
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
|
||||
# Swift-format
|
||||
|
||||
## Introduction
|
||||
|
||||
Note: This tool is still a work in progress.
|
||||
|
||||
swift-format is a tool for automatically format your Swift files according to a
|
||||
set of rules. It is implemented as another driver kind, like swiftc, the batch
|
||||
compiler, so swift-format is actually a symbolic link to swift. This tool uses
|
||||
libIDE to format code, so it can be leveraged from multiple systems and editors.
|
||||
|
||||
## Usage
|
||||
|
||||
To print all the available options:
|
||||
|
||||
swift-format -help
|
||||
|
||||
By default, swift-format will output the formatted file to the standard output:
|
||||
|
||||
swift-format sample.swift
|
||||
|
||||
You can either output the result to a separate file:
|
||||
|
||||
swift-format sample.swift -o result.swift
|
||||
|
||||
Or you can format in-place (the original file will be overwritten):
|
||||
|
||||
swift-format -in-place sample.swift
|
||||
|
||||
If you want to indent using tabs instead of spaces, use the `-use-tabs` option:
|
||||
|
||||
swift-format -use-tabs sample.swift
|
||||
|
||||
You can set the number of tabs or spaces using the `-tab-width` and
|
||||
`-indent-width` options, respectively.
|
||||
|
||||
If you want to indent cases in switch statements, use the "-indent-switch-case"
|
||||
option. The result would be something like this:
|
||||
|
||||
switch aSwitch {
|
||||
case .some(let s):
|
||||
print(s)
|
||||
|
||||
swift-format supports formatting a range of lines from a file:
|
||||
|
||||
swift-format -line-range 2:45 sample.swift
|
||||
|
||||
This will format the file from lines 2 to 45, inclusive.
|
||||
|
||||
You can format several files, but the `-line-range` option is not supported in
|
||||
that case.
|
||||
|
||||
You can also provide several line ranges by using multiple `-line-range` options:
|
||||
|
||||
swift-format -line-range 2:45 -line-range 100:120 sample.swift
|
||||
56
docs/SwiftIndent.md
Normal file
56
docs/SwiftIndent.md
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
# Swift-indent
|
||||
|
||||
## Introduction
|
||||
|
||||
Note: This tool is still a work in progress.
|
||||
|
||||
swift-indent is a tool for automatically indenting your Swift files according to a
|
||||
set of rules. It is implemented as another driver kind, like swiftc, the batch
|
||||
compiler, so swift-indent is actually a symbolic link to swift. This tool uses
|
||||
libIDE to indent code, so it can be leveraged from multiple systems and editors.
|
||||
|
||||
## Usage
|
||||
|
||||
To print all the available options:
|
||||
|
||||
swift-indent -help
|
||||
|
||||
By default, swift-indent will output the indented file to the standard output:
|
||||
|
||||
swift-indent sample.swift
|
||||
|
||||
You can either output the result to a separate file:
|
||||
|
||||
swift-indent sample.swift -o result.swift
|
||||
|
||||
Or you can indent in-place (the original file will be overwritten):
|
||||
|
||||
swift-indent -in-place sample.swift
|
||||
|
||||
If you want to indent using tabs instead of spaces, use the `-use-tabs` option:
|
||||
|
||||
swift-indent -use-tabs sample.swift
|
||||
|
||||
You can set the number of tabs or spaces using the `-tab-width` and
|
||||
`-indent-width` options, respectively.
|
||||
|
||||
If you want to indent cases in switch statements, use the "-indent-switch-case"
|
||||
option. The result would be something like this:
|
||||
|
||||
switch aSwitch {
|
||||
case .some(let s):
|
||||
print(s)
|
||||
|
||||
swift-indent supports indenting a range of lines from a file:
|
||||
|
||||
swift-indent -line-range 2:45 sample.swift
|
||||
|
||||
This will indent the file from lines 2 to 45, inclusive.
|
||||
|
||||
You can indent several files, but the `-line-range` option is not supported in
|
||||
that case.
|
||||
|
||||
You can also provide several line ranges by using multiple `-line-range` options:
|
||||
|
||||
swift-indent -line-range 2:45 -line-range 100:120 sample.swift
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
Interactive, // swift
|
||||
Batch, // swiftc
|
||||
AutolinkExtract, // swift-autolink-extract
|
||||
SwiftFormat // swift-format
|
||||
SwiftIndent // swift-indent
|
||||
};
|
||||
|
||||
class InputInfoMap;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//===--- Formatting.h -------------------------------------------*- C++ -*-===//
|
||||
//===--- Indenting.h --------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
@@ -10,8 +10,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SWIFT_FORMATTING_H
|
||||
#define SWIFT_FORMATTING_H
|
||||
#ifndef SWIFT_INDENTING_H
|
||||
#define SWIFT_INDENTING_H
|
||||
|
||||
namespace swift {
|
||||
namespace ide {
|
||||
@@ -101,4 +101,4 @@ std::pair<LineRange, std::string> reformat(LineRange Range,
|
||||
} // namespace ide
|
||||
} // namespace swift
|
||||
|
||||
#endif // LLVM_SWIFT_FORMATTING_H
|
||||
#endif // SWIFT_INDENTING_H
|
||||
@@ -33,7 +33,7 @@ namespace options {
|
||||
DoesNotAffectIncrementalBuild = (1 << 8),
|
||||
AutolinkExtractOption = (1 << 9),
|
||||
ModuleWrapOption = (1 << 10),
|
||||
SwiftFormatOption = (1 << 11),
|
||||
SwiftIndentOption = (1 << 11),
|
||||
ArgumentIsPath = (1 << 12),
|
||||
ModuleInterfaceOption = (1 << 13),
|
||||
};
|
||||
|
||||
@@ -29,8 +29,8 @@ def AutolinkExtractOption : OptionFlag;
|
||||
// The option should be accepted by swift -modulewrap
|
||||
def ModuleWrapOption : OptionFlag;
|
||||
|
||||
// The option should be accepted by swift-format
|
||||
def SwiftFormatOption : OptionFlag;
|
||||
// The option should be accepted by swift-indent
|
||||
def SwiftIndentOption : OptionFlag;
|
||||
|
||||
// The option should not be accepted by the driver.
|
||||
def NoDriverOption : OptionFlag;
|
||||
@@ -152,7 +152,7 @@ def driver_mode : Joined<["--"], "driver-mode=">, Flags<[HelpHidden]>,
|
||||
HelpText<"Set the driver mode to either 'swift' or 'swiftc'">;
|
||||
|
||||
def help : Flag<["-", "--"], "help">,
|
||||
Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption, SwiftFormatOption]>,
|
||||
Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption, SwiftIndentOption]>,
|
||||
HelpText<"Display available options">;
|
||||
def h : Flag<["-"], "h">, Alias<help>;
|
||||
def help_hidden : Flag<["-", "--"], "help-hidden">,
|
||||
@@ -174,7 +174,7 @@ def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>,
|
||||
|
||||
def o : JoinedOrSeparate<["-"], "o">,
|
||||
Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption,
|
||||
NoInteractiveOption, SwiftFormatOption, ArgumentIsPath]>,
|
||||
NoInteractiveOption, SwiftIndentOption, ArgumentIsPath]>,
|
||||
HelpText<"Write output to <file>">, MetaVarName<"<file>">;
|
||||
|
||||
def j : JoinedOrSeparate<["-"], "j">, Flags<[DoesNotAffectIncrementalBuild]>,
|
||||
@@ -588,28 +588,28 @@ def AssertConfig : Separate<["-"], "assert-config">,
|
||||
def code_formatting_Group : OptionGroup<"<code formatting options>">;
|
||||
|
||||
def use_tabs : Flag<["-"], "use-tabs">, Group<code_formatting_Group>,
|
||||
Flags<[NoInteractiveOption, NoBatchOption, SwiftFormatOption]>,
|
||||
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
|
||||
HelpText<"Use tabs for indentation.">;
|
||||
|
||||
def indent_switch_case : Flag<["-"], "indent-switch-case">,
|
||||
Group<code_formatting_Group>,
|
||||
Flags<[NoInteractiveOption, NoBatchOption, SwiftFormatOption]>,
|
||||
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
|
||||
HelpText<"Indent cases in switch statements.">;
|
||||
|
||||
def in_place : Flag<["-"], "in-place">, Group<code_formatting_Group>,
|
||||
Flags<[NoInteractiveOption, NoBatchOption, SwiftFormatOption]>,
|
||||
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
|
||||
HelpText<"Overwrite input file with formatted file.">;
|
||||
|
||||
def tab_width : Separate<["-"], "tab-width">, Group<code_formatting_Group>,
|
||||
Flags<[NoInteractiveOption, NoBatchOption, SwiftFormatOption]>,
|
||||
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
|
||||
HelpText<"Width of tab character.">, MetaVarName<"<n>">;
|
||||
|
||||
def indent_width : Separate<["-"], "indent-width">, Group<code_formatting_Group>,
|
||||
Flags<[NoInteractiveOption, NoBatchOption, SwiftFormatOption]>,
|
||||
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
|
||||
HelpText<"Number of characters to indent.">, MetaVarName<"<n>">;
|
||||
|
||||
def line_range : Separate<["-"], "line-range">, Group<code_formatting_Group>,
|
||||
Flags<[NoInteractiveOption, NoBatchOption, SwiftFormatOption]>,
|
||||
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
|
||||
HelpText<"<start line>:<end line>. Formats a range of lines (1-based). "
|
||||
"Can only be used with one input file.">, MetaVarName<"<n:n>">;
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ void Driver::parseDriverKind(ArrayRef<const char *> Args) {
|
||||
.Case("swift", DriverKind::Interactive)
|
||||
.Case("swiftc", DriverKind::Batch)
|
||||
.Case("swift-autolink-extract", DriverKind::AutolinkExtract)
|
||||
.Case("swift-format", DriverKind::SwiftFormat)
|
||||
.Case("swift-indent", DriverKind::SwiftIndent)
|
||||
.Default(None);
|
||||
|
||||
if (Kind.hasValue())
|
||||
@@ -3053,7 +3053,7 @@ void Driver::printHelp(bool ShowHidden) const {
|
||||
break;
|
||||
case DriverKind::Batch:
|
||||
case DriverKind::AutolinkExtract:
|
||||
case DriverKind::SwiftFormat:
|
||||
case DriverKind::SwiftIndent:
|
||||
ExcludedFlagsBitmask |= options::NoBatchOption;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "swift/Parse/Parser.h"
|
||||
#include "swift/Frontend/Frontend.h"
|
||||
#include "swift/Basic/SourceManager.h"
|
||||
#include "swift/IDE/Formatting.h"
|
||||
#include "swift/IDE/Indenting.h"
|
||||
#include "swift/Subsystems.h"
|
||||
|
||||
using namespace swift;
|
||||
|
||||
@@ -274,7 +274,7 @@ if 'syntax_parser_lib' in config.available_features:
|
||||
config.swift_syntax_parser_test = inferSwiftBinary('swift-syntax-parser-test')
|
||||
config.swift_reflection_dump = inferSwiftBinary('swift-reflection-dump')
|
||||
config.swift_remoteast_test = inferSwiftBinary('swift-remoteast-test')
|
||||
config.swift_format = inferSwiftBinary('swift-format')
|
||||
config.swift_indent = inferSwiftBinary('swift-indent')
|
||||
config.clang = inferSwiftBinary('clang')
|
||||
config.llvm_link = inferSwiftBinary('llvm-link')
|
||||
config.swift_llvm_opt = inferSwiftBinary('swift-llvm-opt')
|
||||
@@ -403,7 +403,7 @@ if '-enable-astscope-lookup' in config.swift_test_options:
|
||||
config.available_features.add("enable-astscope-lookup")
|
||||
if '-disable-parser-lookup' in config.swift_test_options:
|
||||
config.available_features.add("disable-parser-lookup")
|
||||
config.substitutions.append( ('%swift-format', config.swift_format) )
|
||||
config.substitutions.append( ('%swift-indent', config.swift_indent) )
|
||||
config.substitutions.append( ('%llvm-link', config.llvm_link) )
|
||||
config.substitutions.append( ('%swift-llvm-opt', config.swift_llvm_opt) )
|
||||
config.substitutions.append( ('%llvm-dwarfdump', config.llvm_dwarfdump) )
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// RUN: %swift-format %s >%t.response
|
||||
// RUN: %swift-indent %s >%t.response
|
||||
// RUN: diff -u %s.response %t.response
|
||||
// RUN: %swift-format -indent-width 2 %s >%t.response
|
||||
// RUN: %swift-indent -indent-width 2 %s >%t.response
|
||||
// RUN: diff -u %s.indent2.response %t.response
|
||||
// RUN: %swift-format -use-tabs %s >%t.response
|
||||
// RUN: %swift-indent -use-tabs %s >%t.response
|
||||
// RUN: diff -u %s.tabs.response %t.response
|
||||
// RUN: %swift-format -line-range 24:29 %s >%t.response
|
||||
// RUN: %swift-indent -line-range 24:29 %s >%t.response
|
||||
// RUN: diff -u %s.lines.response %t.response
|
||||
// RUN: %swift-format -indent-switch-case %s >%t.response
|
||||
// RUN: %swift-indent -indent-switch-case %s >%t.response
|
||||
// RUN: diff -u %s.indentswitch.response %t.response
|
||||
|
||||
import Foundation
|
||||
@@ -1,12 +1,12 @@
|
||||
// RUN: %swift-format %s >%t.response
|
||||
// RUN: %swift-indent %s >%t.response
|
||||
// RUN: diff -u %s.response %t.response
|
||||
// RUN: %swift-format -indent-width 2 %s >%t.response
|
||||
// RUN: %swift-indent -indent-width 2 %s >%t.response
|
||||
// RUN: diff -u %s.indent2.response %t.response
|
||||
// RUN: %swift-format -use-tabs %s >%t.response
|
||||
// RUN: %swift-indent -use-tabs %s >%t.response
|
||||
// RUN: diff -u %s.tabs.response %t.response
|
||||
// RUN: %swift-format -line-range 24:29 %s >%t.response
|
||||
// RUN: %swift-indent -line-range 24:29 %s >%t.response
|
||||
// RUN: diff -u %s.lines.response %t.response
|
||||
// RUN: %swift-format -indent-switch-case %s >%t.response
|
||||
// RUN: %swift-indent -indent-switch-case %s >%t.response
|
||||
// RUN: diff -u %s.indentswitch.response %t.response
|
||||
|
||||
import Foundation
|
||||
@@ -1,12 +1,12 @@
|
||||
// RUN: %swift-format %s >%t.response
|
||||
// RUN: %swift-indent %s >%t.response
|
||||
// RUN: diff -u %s.response %t.response
|
||||
// RUN: %swift-format -indent-width 2 %s >%t.response
|
||||
// RUN: %swift-indent -indent-width 2 %s >%t.response
|
||||
// RUN: diff -u %s.indent2.response %t.response
|
||||
// RUN: %swift-format -use-tabs %s >%t.response
|
||||
// RUN: %swift-indent -use-tabs %s >%t.response
|
||||
// RUN: diff -u %s.tabs.response %t.response
|
||||
// RUN: %swift-format -line-range 24:29 %s >%t.response
|
||||
// RUN: %swift-indent -line-range 24:29 %s >%t.response
|
||||
// RUN: diff -u %s.lines.response %t.response
|
||||
// RUN: %swift-format -indent-switch-case %s >%t.response
|
||||
// RUN: %swift-indent -indent-switch-case %s >%t.response
|
||||
// RUN: diff -u %s.indentswitch.response %t.response
|
||||
|
||||
import Foundation
|
||||
@@ -1,12 +1,12 @@
|
||||
// RUN: %swift-format %s >%t.response
|
||||
// RUN: %swift-indent %s >%t.response
|
||||
// RUN: diff -u %s.response %t.response
|
||||
// RUN: %swift-format -indent-width 2 %s >%t.response
|
||||
// RUN: %swift-indent -indent-width 2 %s >%t.response
|
||||
// RUN: diff -u %s.indent2.response %t.response
|
||||
// RUN: %swift-format -use-tabs %s >%t.response
|
||||
// RUN: %swift-indent -use-tabs %s >%t.response
|
||||
// RUN: diff -u %s.tabs.response %t.response
|
||||
// RUN: %swift-format -line-range 24:29 %s >%t.response
|
||||
// RUN: %swift-indent -line-range 24:29 %s >%t.response
|
||||
// RUN: diff -u %s.lines.response %t.response
|
||||
// RUN: %swift-format -indent-switch-case %s >%t.response
|
||||
// RUN: %swift-indent -indent-switch-case %s >%t.response
|
||||
// RUN: diff -u %s.indentswitch.response %t.response
|
||||
|
||||
import Foundation
|
||||
@@ -1,12 +1,12 @@
|
||||
// RUN: %swift-format %s >%t.response
|
||||
// RUN: %swift-indent %s >%t.response
|
||||
// RUN: diff -u %s.response %t.response
|
||||
// RUN: %swift-format -indent-width 2 %s >%t.response
|
||||
// RUN: %swift-indent -indent-width 2 %s >%t.response
|
||||
// RUN: diff -u %s.indent2.response %t.response
|
||||
// RUN: %swift-format -use-tabs %s >%t.response
|
||||
// RUN: %swift-indent -use-tabs %s >%t.response
|
||||
// RUN: diff -u %s.tabs.response %t.response
|
||||
// RUN: %swift-format -line-range 24:29 %s >%t.response
|
||||
// RUN: %swift-indent -line-range 24:29 %s >%t.response
|
||||
// RUN: diff -u %s.lines.response %t.response
|
||||
// RUN: %swift-format -indent-switch-case %s >%t.response
|
||||
// RUN: %swift-indent -indent-switch-case %s >%t.response
|
||||
// RUN: diff -u %s.indentswitch.response %t.response
|
||||
|
||||
import Foundation
|
||||
@@ -1,12 +1,12 @@
|
||||
// RUN: %swift-format %s >%t.response
|
||||
// RUN: %swift-indent %s >%t.response
|
||||
// RUN: diff -u %s.response %t.response
|
||||
// RUN: %swift-format -indent-width 2 %s >%t.response
|
||||
// RUN: %swift-indent -indent-width 2 %s >%t.response
|
||||
// RUN: diff -u %s.indent2.response %t.response
|
||||
// RUN: %swift-format -use-tabs %s >%t.response
|
||||
// RUN: %swift-indent -use-tabs %s >%t.response
|
||||
// RUN: diff -u %s.tabs.response %t.response
|
||||
// RUN: %swift-format -line-range 24:29 %s >%t.response
|
||||
// RUN: %swift-indent -line-range 24:29 %s >%t.response
|
||||
// RUN: diff -u %s.lines.response %t.response
|
||||
// RUN: %swift-format -indent-switch-case %s >%t.response
|
||||
// RUN: %swift-indent -indent-switch-case %s >%t.response
|
||||
// RUN: diff -u %s.indentswitch.response %t.response
|
||||
|
||||
import Foundation
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
|
||||
#include "swift/IDE/CodeCompletion.h"
|
||||
#include "swift/IDE/CommentConversion.h"
|
||||
#include "swift/IDE/Formatting.h"
|
||||
#include "swift/IDE/Indenting.h"
|
||||
#include "swift/IDE/SourceEntityWalker.h"
|
||||
#include "swift/IDE/SyntaxModel.h"
|
||||
#include "swift/Subsystems.h"
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "SourceKit/Support/ThreadSafeRefCntPtr.h"
|
||||
#include "SourceKit/Support/Tracing.h"
|
||||
#include "swift/Basic/ThreadSafeRefCounted.h"
|
||||
#include "swift/IDE/Formatting.h"
|
||||
#include "swift/IDE/Indenting.h"
|
||||
#include "swift/IDE/Refactoring.h"
|
||||
#include "swift/Index/IndexSymbol.h"
|
||||
#include "llvm/ADT/IntrusiveRefCntPtr.h"
|
||||
|
||||
@@ -2,7 +2,7 @@ add_swift_host_tool(swift
|
||||
driver.cpp
|
||||
autolink_extract_main.cpp
|
||||
modulewrap_main.cpp
|
||||
swift_format_main.cpp
|
||||
swift_indent_main.cpp
|
||||
SWIFT_COMPONENT compiler
|
||||
)
|
||||
target_link_libraries(swift
|
||||
@@ -20,7 +20,7 @@ swift_create_post_build_symlink(swift
|
||||
|
||||
swift_create_post_build_symlink(swift
|
||||
SOURCE "swift${CMAKE_EXECUTABLE_SUFFIX}"
|
||||
DESTINATION "swift-format${CMAKE_EXECUTABLE_SUFFIX}"
|
||||
DESTINATION "swift-indent${CMAKE_EXECUTABLE_SUFFIX}"
|
||||
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
|
||||
|
||||
swift_create_post_build_symlink(swift
|
||||
@@ -30,7 +30,7 @@ swift_create_post_build_symlink(swift
|
||||
|
||||
add_swift_tool_symlink(swiftc swift compiler)
|
||||
add_swift_tool_symlink(swift-autolink-extract swift autolink-driver)
|
||||
add_swift_tool_symlink(swift-format swift editor-integration)
|
||||
add_swift_tool_symlink(swift-indent swift editor-integration)
|
||||
|
||||
# If building as part of clang, make sure the headers are installed.
|
||||
if(NOT SWIFT_BUILT_STANDALONE)
|
||||
@@ -43,6 +43,6 @@ swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swiftc${CMAKE_E
|
||||
swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-autolink-extract${CMAKE_EXECUTABLE_SUFFIX}"
|
||||
DESTINATION "bin"
|
||||
COMPONENT autolink-driver)
|
||||
swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-format${CMAKE_EXECUTABLE_SUFFIX}"
|
||||
swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-indent${CMAKE_EXECUTABLE_SUFFIX}"
|
||||
DESTINATION "bin"
|
||||
COMPONENT editor-integration)
|
||||
|
||||
@@ -66,8 +66,8 @@ extern int autolink_extract_main(ArrayRef<const char *> Args, const char *Argv0,
|
||||
extern int modulewrap_main(ArrayRef<const char *> Args, const char *Argv0,
|
||||
void *MainAddr);
|
||||
|
||||
/// Run 'swift-format'
|
||||
extern int swift_format_main(ArrayRef<const char *> Args, const char *Argv0,
|
||||
/// Run 'swift-indent'
|
||||
extern int swift_indent_main(ArrayRef<const char *> Args, const char *Argv0,
|
||||
void *MainAddr);
|
||||
|
||||
/// Determine if the given invocation should run as a subcommand.
|
||||
@@ -148,8 +148,8 @@ static int run_driver(StringRef ExecName,
|
||||
return autolink_extract_main(
|
||||
TheDriver.getArgsWithoutProgramNameAndDriverMode(argv),
|
||||
argv[0], (void *)(intptr_t)getExecutablePath);
|
||||
case Driver::DriverKind::SwiftFormat:
|
||||
return swift_format_main(
|
||||
case Driver::DriverKind::SwiftIndent:
|
||||
return swift_indent_main(
|
||||
TheDriver.getArgsWithoutProgramNameAndDriverMode(argv),
|
||||
argv[0], (void *)(intptr_t)getExecutablePath);
|
||||
default:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//===--- swift_format_main.cpp - Swift code formatting tool ---------------===//
|
||||
//===--- swift_indent_main.cpp - Swift code formatting tool ---------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "swift/Basic/SourceManager.h"
|
||||
#include "swift/Frontend/Frontend.h"
|
||||
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
|
||||
#include "swift/IDE/Formatting.h"
|
||||
#include "swift/IDE/Indenting.h"
|
||||
#include "swift/Option/Options.h"
|
||||
#include "swift/Subsystems.h"
|
||||
#include "llvm/Option/Arg.h"
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class SwiftFormatInvocation {
|
||||
class SwiftIndentInvocation {
|
||||
private:
|
||||
std::string MainExecutablePath;
|
||||
std::string OutputFilename = "-";
|
||||
@@ -95,7 +95,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
SwiftFormatInvocation(const std::string &ExecPath)
|
||||
SwiftIndentInvocation(const std::string &ExecPath)
|
||||
: MainExecutablePath(ExecPath) {}
|
||||
|
||||
const std::string &getOutputFilename() { return OutputFilename; }
|
||||
@@ -111,7 +111,7 @@ public:
|
||||
unsigned MissingIndex;
|
||||
unsigned MissingCount;
|
||||
llvm::opt::InputArgList ParsedArgs =
|
||||
Table->ParseArgs(Args, MissingIndex, MissingCount, SwiftFormatOption);
|
||||
Table->ParseArgs(Args, MissingIndex, MissingCount, SwiftIndentOption);
|
||||
if (MissingCount) {
|
||||
Diags.diagnose(SourceLoc(), diag::error_missing_arg_value,
|
||||
ParsedArgs.getArgString(MissingIndex), MissingCount);
|
||||
@@ -151,7 +151,7 @@ public:
|
||||
if (ParsedArgs.getLastArg(OPT_help)) {
|
||||
std::string ExecutableName = llvm::sys::path::stem(MainExecutablePath);
|
||||
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(),
|
||||
"Swift Format Tool", options::SwiftFormatOption, 0,
|
||||
"Swift Format Tool", options::SwiftIndentOption, 0,
|
||||
/*ShowAllAliases*/false);
|
||||
return 1;
|
||||
}
|
||||
@@ -234,13 +234,13 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
int swift_format_main(ArrayRef<const char *> Args, const char *Argv0,
|
||||
int swift_indent_main(ArrayRef<const char *> Args, const char *Argv0,
|
||||
void *MainAddr) {
|
||||
CompilerInstance Instance;
|
||||
PrintingDiagnosticConsumer PDC;
|
||||
Instance.addDiagnosticConsumer(&PDC);
|
||||
|
||||
SwiftFormatInvocation Invocation(
|
||||
SwiftIndentInvocation Invocation(
|
||||
llvm::sys::fs::getMainExecutable(Argv0, MainAddr));
|
||||
|
||||
DiagnosticEngine &Diags = Instance.getDiags();
|
||||
@@ -1,31 +1,31 @@
|
||||
# This file is a minimal swift-format vim-integration. To install:
|
||||
# - Change 'binary' if swift-format is not on the path (see below).
|
||||
# This file is a minimal swift-indent vim-integration. To install:
|
||||
# - Change 'binary' if swift-indent is not on the path (see below).
|
||||
# - Add to your .vimrc:
|
||||
#
|
||||
# map <C-I> :pyf <path-to-this-file>/swift-format.py<cr>
|
||||
# imap <C-I> <c-o>:pyf <path-to-this-file>/swift-format.py<cr>
|
||||
# map <C-I> :pyf <path-to-this-file>/swift-indent.py<cr>
|
||||
# imap <C-I> <c-o>:pyf <path-to-this-file>/swift-indent.py<cr>
|
||||
#
|
||||
# The first line enables swift-format for NORMAL and VISUAL mode, the second
|
||||
# The first line enables swift-indent for NORMAL and VISUAL mode, the second
|
||||
# line adds support for INSERT mode. Change "C-I" to another binding if you
|
||||
# need swift-format on a different key (C-I stands for Ctrl+i).
|
||||
# need swift-indent on a different key (C-I stands for Ctrl+i).
|
||||
#
|
||||
# With this integration you can press the bound key and swift-format will
|
||||
# format the current line in NORMAL and INSERT mode or the selected region in
|
||||
# With this integration you can press the bound key and swift-indent will
|
||||
# indent the current line in NORMAL and INSERT mode or the selected region in
|
||||
# VISUAL mode. The line or region is extended to the next bigger syntactic
|
||||
# entity.
|
||||
#
|
||||
# You can also pass in the variable "l:lines" to choose the range for
|
||||
# formatting. This variable can either contain "<start line>:<end line> or
|
||||
# "all" to format the full file. So, to format the full file, write a function
|
||||
# indenting. This variable can either contain "<start line>:<end line> or
|
||||
# "all" to indent the full file. So, to indent the full file, write a function
|
||||
# like:
|
||||
#
|
||||
# :function FormatFile()
|
||||
# :function IndentFile()
|
||||
# : let l:lines="all"
|
||||
# : pyf <path-to-this-file>/swift-format.py
|
||||
# : pyf <path-to-this-file>/swift-indent.py
|
||||
# :endfunction
|
||||
#
|
||||
# It operates on the current, potentially unsaved buffer and does not create or
|
||||
# save any files. To revert a formatting, just undo.
|
||||
# save any files. To revert a indenting, just undo.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
@@ -36,9 +36,9 @@ import sys
|
||||
|
||||
import vim
|
||||
|
||||
binary = 'swift-format'
|
||||
if vim.eval('exists("g:swift_format_path")') == "1":
|
||||
binary = vim.eval('g:swift_format_path')
|
||||
binary = 'swift-indent'
|
||||
if vim.eval('exists("g:swift_indent_path")') == "1":
|
||||
binary = vim.eval('g:swift_indent_path')
|
||||
|
||||
|
||||
def get_buffer(encoding):
|
||||
@@ -82,7 +82,7 @@ def main(argc, argv):
|
||||
print(stderr)
|
||||
|
||||
if not stdout:
|
||||
print('No output from swift-format (crashed?).')
|
||||
print('No output from swift-indent (crashed?).')
|
||||
return
|
||||
|
||||
lines = stdout.decode(encoding).split('\n')
|
||||
Reference in New Issue
Block a user