diff --git a/Source/sourcekitten/CompleteCommand.swift b/Source/sourcekitten/CompleteCommand.swift index dad17a4ef..232dd43d4 100644 --- a/Source/sourcekitten/CompleteCommand.swift +++ b/Source/sourcekitten/CompleteCommand.swift @@ -19,12 +19,13 @@ 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> { @@ -32,6 +33,7 @@ struct CompleteCommand: CommandProtocol { <*> 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 '--'") } } @@ -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 {