Skip to content

Commit

Permalink
add spm-module to complete command
Browse files Browse the repository at this point in the history
Adds support for reading the build commands from the `build.yaml` file
closes jpsim#270
  • Loading branch information
vdka committed Oct 18, 2016
1 parent 5bc7cc9 commit ef27e05
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Source/sourcekitten/CompleteCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ struct CompleteCommand: CommandProtocol {
let file: String
let text: String
let offset: Int
let spmModule: String
let compilerargs: [String]

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

static func evaluate(_ m: CommandMode) -> Result<Options, CommandantError<SourceKittenError>> {
return create
<*> m <| Option(key: "file", defaultValue: "", usage: "relative or absolute path of Swift file to parse")
<*> m <| Option(key: "text", defaultValue: "", usage: "Swift code text to parse")
<*> m <| Option(key: "offset", defaultValue: 0, usage: "Offset for which to generate code completion options.")
<*> m <| Option(key: "spm-module", defaultValue: "", usage: "Read compiler flags from a Swift Package Manager module")
<*> m <| Argument(defaultValue: [String](), usage: "Compiler arguments to pass to SourceKit. This must be specified following the '--'")
}
}
Expand All @@ -51,6 +53,13 @@ struct CompleteCommand: CommandProtocol {
}

var args = ["-c", path]
if !options.spmModule.isEmpty {
guard let module = Module(spmName: options.spmModule) else {
return .failure(.invalidArgument(description: "Bad module name"))
}
args.append(contentsOf: module.compilerArguments)
}

args.append(contentsOf: options.compilerargs)

if args.index(of: "-sdk") == nil {
Expand Down

0 comments on commit ef27e05

Please sign in to comment.