Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to use Argument instead of Option on IndexCommand.Options.compilerargs #481

Merged
merged 1 commit into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

##### Bug Fixes

* None.
* Fix `index` command fails using filename with spaces in compiler arguments.
[Norio Nomura](https://github.com/norio-nomura)
[#480](https://github.com/jpsim/SourceKitten/issues/480)

## 0.19.1

Expand Down
16 changes: 9 additions & 7 deletions Source/sourcekitten/IndexCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ struct IndexCommand: CommandProtocol {

struct Options: OptionsProtocol {
let file: String
let compilerargs: String
let compilerargs: [String]

static func create(file: String) -> (_ compilerargs: String) -> Options {
return { compilerargs in
static func create(file: String) -> (_: Bool) -> (_ compilerargs: [String]) -> Options {
return { _ in { compilerargs in
self.init(file: file, compilerargs: compilerargs)
}
}}
}

static func evaluate(_ mode: CommandMode) -> Result<Options, CommandantError<SourceKittenError>> {
return create
<*> mode <| Option(key: "file", defaultValue: "", usage: "relative or absolute path of Swift file to index")
<*> mode <| Option(key: "compilerargs", defaultValue: "",
usage: "Compiler arguments to pass to SourceKit. This must be specified following the '--'")
<*> mode <| Switch(key: "compilerargs",
usage: "It remains for compatibility with older versions. It is simply ignored.")
<*> mode <| Argument(defaultValue: [],
usage: "Compiler arguments to pass to SourceKit. This must be specified following the '--'")
}
}

Expand All @@ -38,7 +40,7 @@ struct IndexCommand: CommandProtocol {
return .failure(.invalidArgument(description: "file must be set when calling index"))
}
let absoluteFile = options.file.bridge().absolutePathRepresentation()
let request = Request.index(file: absoluteFile, arguments: options.compilerargs.components(separatedBy: " "))
let request = Request.index(file: absoluteFile, arguments: options.compilerargs)
do {
print(toJSON(toNSDictionary(try request.send())))
return .success(())
Expand Down