From a0731aa84cdbaa8e4dc8655cefa4731e72d71d25 Mon Sep 17 00:00:00 2001 From: ainopara Date: Tue, 3 Oct 2017 21:35:04 +0800 Subject: [PATCH 01/15] Refactor `Request` to make it resilience. --- Source/SourceKittenFramework/Request.swift | 696 +++++-- .../RequestBuilder.swift | 88 + .../SourceKittenFramework/SourceKitDef.swift | 1654 +++++++++++++++++ Tests/LinuxMain.swift | 3 +- .../Fixtures/ProtocolVersion.json | 4 + .../Fixtures/SwiftAssertInterface.json | 1346 ++++++++++++++ .../Fixtures/SwiftModuleGroups.json | 58 + .../RequestTests.swift | 66 + .../SwiftDocsTests.swift | 2 +- sourcekitten.xcodeproj/project.pbxproj | 12 + 10 files changed, 3760 insertions(+), 169 deletions(-) create mode 100644 Source/SourceKittenFramework/RequestBuilder.swift create mode 100644 Source/SourceKittenFramework/SourceKitDef.swift create mode 100644 Tests/SourceKittenFrameworkTests/Fixtures/ProtocolVersion.json create mode 100644 Tests/SourceKittenFrameworkTests/Fixtures/SwiftAssertInterface.json create mode 100644 Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups.json create mode 100644 Tests/SourceKittenFrameworkTests/RequestTests.swift diff --git a/Source/SourceKittenFramework/Request.swift b/Source/SourceKittenFramework/Request.swift index ffd26f076..bddbaa578 100644 --- a/Source/SourceKittenFramework/Request.swift +++ b/Source/SourceKittenFramework/Request.swift @@ -189,176 +189,19 @@ private extension String { } } -/// Represents a SourceKit request. -public enum Request { - /// An `editor.open` request for the given File. - case editorOpen(file: File) - /// A `cursorinfo` request for an offset in the given file, using the `arguments` given. - case cursorInfo(file: String, offset: Int64, arguments: [String]) - /// A custom request by passing in the sourcekitd_object_t directly. - case customRequest(request: sourcekitd_object_t) - /// A request generated by sourcekit using the yaml representation. - case yamlRequest(yaml: String) - /// A `codecomplete` request by passing in the file name, contents, offset - /// for which to generate code completion options and array of compiler arguments. - case codeCompletionRequest(file: String, contents: String, offset: Int64, arguments: [String]) - /// ObjC Swift Interface - case interface(file: String, uuid: String, arguments: [String]) - /// Find USR - case findUSR(file: String, usr: String) - /// Index - case index(file: String, arguments: [String]) - /// Format - case format(file: String, line: Int64, useTabs: Bool, indentWidth: Int64) - /// ReplaceText - case replaceText(file: String, offset: Int64, length: Int64, sourceText: String) - /// A documentation request for the given source text. - case docInfo(text: String, arguments: [String]) - /// A documentation request for the given module. - case moduleInfo(module: String, arguments: [String]) - - fileprivate var sourcekitObject: sourcekitd_object_t { - let dict: [sourcekitd_uid_t: sourcekitd_object_t?] - switch self { - case .editorOpen(let file): - if let path = file.path { - dict = [ - sourcekitd_uid_get_from_cstr("key.request")!: sourcekitd_request_uid_create(sourcekitd_uid_get_from_cstr("source.request.editor.open")!), - sourcekitd_uid_get_from_cstr("key.name")!: sourcekitd_request_string_create(path), - sourcekitd_uid_get_from_cstr("key.sourcefile")!: sourcekitd_request_string_create(path) - ] - } else { - dict = [ - sourcekitd_uid_get_from_cstr("key.request")!: sourcekitd_request_uid_create(sourcekitd_uid_get_from_cstr("source.request.editor.open")!), - sourcekitd_uid_get_from_cstr("key.name")!: sourcekitd_request_string_create(String(file.contents.hash)), - sourcekitd_uid_get_from_cstr("key.sourcetext")!: sourcekitd_request_string_create(file.contents) - ] - } - case .cursorInfo(let file, let offset, let arguments): - var compilerargs = arguments.map({ sourcekitd_request_string_create($0) }) - dict = [ - sourcekitd_uid_get_from_cstr("key.request")!: sourcekitd_request_uid_create(sourcekitd_uid_get_from_cstr("source.request.cursorinfo")!), - sourcekitd_uid_get_from_cstr("key.name")!: sourcekitd_request_string_create(file), - sourcekitd_uid_get_from_cstr("key.sourcefile")!: sourcekitd_request_string_create(file), - sourcekitd_uid_get_from_cstr("key.offset")!: sourcekitd_request_int64_create(offset), - sourcekitd_uid_get_from_cstr("key.compilerargs")!: sourcekitd_request_array_create(&compilerargs, compilerargs.count) - ] - case .customRequest(let request): - return request - case .yamlRequest(let yaml): - return sourcekitd_request_create_from_yaml(yaml, nil)! - case .codeCompletionRequest(let file, let contents, let offset, let arguments): - var compilerargs = arguments.map({ sourcekitd_request_string_create($0) }) - dict = [ - sourcekitd_uid_get_from_cstr("key.request")!: sourcekitd_request_uid_create(sourcekitd_uid_get_from_cstr("source.request.codecomplete")!), - sourcekitd_uid_get_from_cstr("key.name")!: sourcekitd_request_string_create(file), - sourcekitd_uid_get_from_cstr("key.sourcefile")!: sourcekitd_request_string_create(file), - sourcekitd_uid_get_from_cstr("key.sourcetext")!: sourcekitd_request_string_create(contents), - sourcekitd_uid_get_from_cstr("key.offset")!: sourcekitd_request_int64_create(offset), - sourcekitd_uid_get_from_cstr("key.compilerargs")!: sourcekitd_request_array_create(&compilerargs, compilerargs.count) - ] - case .interface(let file, let uuid, var arguments): - if !arguments.contains("-x") { - arguments.append(contentsOf: ["-x", "objective-c"]) - } - if !arguments.contains("-isysroot") { - arguments.append(contentsOf: ["-isysroot", sdkPath()]) - } - var compilerargs = ([file] + arguments).map({ sourcekitd_request_string_create($0) }) - dict = [ - sourcekitd_uid_get_from_cstr("key.request")!: - sourcekitd_request_uid_create(sourcekitd_uid_get_from_cstr("source.request.editor.open.interface.header")!), - sourcekitd_uid_get_from_cstr("key.name")!: sourcekitd_request_string_create(uuid), - sourcekitd_uid_get_from_cstr("key.filepath")!: sourcekitd_request_string_create(file), - sourcekitd_uid_get_from_cstr("key.compilerargs")!: sourcekitd_request_array_create(&compilerargs, compilerargs.count) - ] - case .findUSR(let file, let usr): - dict = [ - sourcekitd_uid_get_from_cstr("key.request")!: sourcekitd_request_uid_create(sourcekitd_uid_get_from_cstr("source.request.editor.find_usr")!), - sourcekitd_uid_get_from_cstr("key.usr")!: sourcekitd_request_string_create(usr), - sourcekitd_uid_get_from_cstr("key.sourcefile")!: sourcekitd_request_string_create(file) - ] - case .index(let file, let arguments): - var compilerargs = arguments.map({ sourcekitd_request_string_create($0) }) - dict = [ - sourcekitd_uid_get_from_cstr("key.request")!: sourcekitd_request_uid_create(sourcekitd_uid_get_from_cstr("source.request.indexsource")!), - sourcekitd_uid_get_from_cstr("key.sourcefile")!: sourcekitd_request_string_create(file), - sourcekitd_uid_get_from_cstr("key.compilerargs")!: sourcekitd_request_array_create(&compilerargs, compilerargs.count) - ] - case .format(let file, let line, let useTabs, let indentWidth): - let formatOptions = [ - sourcekitd_uid_get_from_cstr("key.editor.format.indentwidth")!: sourcekitd_request_int64_create(indentWidth), - sourcekitd_uid_get_from_cstr("key.editor.format.tabwidth")!: sourcekitd_request_int64_create(indentWidth), - sourcekitd_uid_get_from_cstr("key.editor.format.usetabs")!: sourcekitd_request_int64_create(useTabs ? 1 : 0) - ] - var formatOptionsKeys = Array(formatOptions.keys.map({ $0 as sourcekitd_uid_t? })) - var formatOptionsValues = Array(formatOptions.values) - dict = [ - sourcekitd_uid_get_from_cstr("key.request")!: sourcekitd_request_uid_create(sourcekitd_uid_get_from_cstr("source.request.editor.formattext")!), - sourcekitd_uid_get_from_cstr("key.name")!: sourcekitd_request_string_create(file), - sourcekitd_uid_get_from_cstr("key.line")!: sourcekitd_request_int64_create(line), - sourcekitd_uid_get_from_cstr("key.editor.format.options")!: - sourcekitd_request_dictionary_create(&formatOptionsKeys, &formatOptionsValues, formatOptions.count) - ] - case .replaceText(let file, let offset, let length, let sourceText): - dict = [ - sourcekitd_uid_get_from_cstr("key.request")!: sourcekitd_request_uid_create(sourcekitd_uid_get_from_cstr("source.request.editor.replacetext")!), - sourcekitd_uid_get_from_cstr("key.name")!: sourcekitd_request_string_create(file), - sourcekitd_uid_get_from_cstr("key.offset")!: sourcekitd_request_int64_create(offset), - sourcekitd_uid_get_from_cstr("key.length")!: sourcekitd_request_int64_create(length), - sourcekitd_uid_get_from_cstr("key.sourcetext")!: sourcekitd_request_string_create(sourceText) - ] - case .docInfo(let text, let arguments): - var compilerargs = arguments.map({ sourcekitd_request_string_create($0) }) - dict = [ - sourcekitd_uid_get_from_cstr("key.request")!: sourcekitd_request_uid_create(sourcekitd_uid_get_from_cstr("source.request.docinfo")!), - sourcekitd_uid_get_from_cstr("key.name")!: sourcekitd_request_string_create(NSUUID().uuidString), - sourcekitd_uid_get_from_cstr("key.compilerargs")!: sourcekitd_request_array_create(&compilerargs, compilerargs.count), - sourcekitd_uid_get_from_cstr("key.sourcetext")!: sourcekitd_request_string_create(text) - ] - case .moduleInfo(let module, let arguments): - var compilerargs = arguments.map({ sourcekitd_request_string_create($0) }) - dict = [ - sourcekitd_uid_get_from_cstr("key.request")!: sourcekitd_request_uid_create(sourcekitd_uid_get_from_cstr("source.request.docinfo")!), - sourcekitd_uid_get_from_cstr("key.name")!: sourcekitd_request_string_create(NSUUID().uuidString), - sourcekitd_uid_get_from_cstr("key.compilerargs")!: sourcekitd_request_array_create(&compilerargs, compilerargs.count), - sourcekitd_uid_get_from_cstr("key.modulename")!: sourcekitd_request_string_create(module) - ] - } - var keys = Array(dict.keys.map({ $0 as sourcekitd_uid_t? })) - var values = Array(dict.values) - return sourcekitd_request_dictionary_create(&keys, &values, dict.count)! - } - - /** - Create a Request.CursorInfo.sourcekitObject() from a file path and compiler arguments. - - - parameter filePath: Path of the file to create request. - - parameter arguments: Compiler arguments. +let defaultArguments = { return ["-sdk", sdkPath()] }() - - returns: sourcekitd_object_t representation of the Request, if successful. - */ - internal static func cursorInfoRequest(filePath: String?, arguments: [String]) -> sourcekitd_object_t? { - if let path = filePath { - return Request.cursorInfo(file: path, offset: 0, arguments: arguments).sourcekitObject - } - return nil - } +public protocol RequestType { + func sourcekitObject() -> sourcekitd_object_t +} - /** - Send a Request.CursorInfo by updating its offset. Returns SourceKit response if successful. +/// Represents a SourceKit request. +public struct Request { - - parameter cursorInfoRequest: sourcekitd_object_t representation of Request.CursorInfo - - parameter offset: Offset to update request. + public let type: RequestType - - returns: SourceKit response if successful. - */ - internal static func send(cursorInfoRequest: sourcekitd_object_t, atOffset offset: Int64) -> [String: SourceKitRepresentable]? { - if offset == 0 { - return nil - } - sourcekitd_request_dictionary_set_int64(cursorInfoRequest, sourcekitd_uid_get_from_cstr(SwiftDocKey.offset.rawValue)!, offset) - return try? Request.customRequest(request: cursorInfoRequest).failableSend() + fileprivate var sourcekitObject: sourcekitd_object_t { + return type.sourcekitObject() } /** @@ -429,7 +272,526 @@ public enum Request { } } -// MARK: CustomStringConvertible +// MARK: - CursorInfo reuse + +extension Request { + + /** + Create a Request.CursorInfo.sourcekitObject() from a file path and compiler arguments. + + - parameter filePath: Path of the file to create request. + - parameter arguments: Compiler arguments. + + - returns: sourcekitd_object_t representation of the Request, if successful. + */ + internal static func cursorInfoRequest(filePath: String?, arguments: [String]) -> sourcekitd_object_t? { + if let path = filePath { + return Request.cursorInfo(file: path, offset: 0, arguments: arguments).sourcekitObject + } + return nil + } + + /** + Send a Request.CursorInfo by updating its offset. Returns SourceKit response if successful. + + - parameter cursorInfoRequest: sourcekitd_object_t representation of Request.CursorInfo + - parameter offset: Offset to update request. + + - returns: SourceKit response if successful. + */ + internal static func send(cursorInfoRequest: sourcekitd_object_t, atOffset offset: Int64) -> [String: SourceKitRepresentable]? { + if offset == 0 { + return nil + } + sourcekitd_request_dictionary_set_int64(cursorInfoRequest, sourcekitd_uid_get_from_cstr(SwiftDocKey.offset.rawValue), offset) + return try? Request.customRequest(request: cursorInfoRequest).failableSend() + } +} + +// MARK: - +// swiftlint:disable nesting +extension Request { + + /// An `editor.open` request for the given File. + public struct EditorOpen: RequestType { + public let name: String + + public struct Source { + public let sourceFile: String? + public let sourceText: String? + + public static func path(_ path: String) -> Source { + return Source(sourceFile: path, sourceText: nil) + } + + public static func text(_ text: String) -> Source { + return Source(sourceFile: nil, sourceText: text) + } + } + public let source: Source + public let enableSyntaxMap: Bool? + public let enableStructure: Bool? + public let enableDiagnostics: Bool? + public let syntacticOnly: Bool? + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .editorOpen) + requestBuilder[.name] = name + requestBuilder[.sourceFile] = source.sourceFile + requestBuilder[.sourceText] = source.sourceText + requestBuilder[.enableSyntaxMap] = enableSyntaxMap + requestBuilder[.enableStructure] = enableStructure + requestBuilder[.enableDiagnostics] = enableDiagnostics + requestBuilder[.syntacticOnly] = syntacticOnly + requestBuilder[.compilerArgs] = arguments + return requestBuilder.makeRequest() + } + } + + public static func editorOpen(file: File, arguments: [String] = defaultArguments) -> Request { + let name: String + let source: EditorOpen.Source + if let path = file.path { + name = path + source = .path(path) + } else { + name = String(file.contents.hash) + source = .text(file.contents) + } + + return .editorOpen(name: name, source: source, arguments: arguments) + } + + public static func editorOpen( + name: String, + source: EditorOpen.Source, + enableSyntaxMap: Bool? = nil, + enableStructure: Bool? = nil, + enableDiagnostics: Bool? = nil, + syntacticOnly: Bool? = nil, + arguments: [String] = defaultArguments + ) -> Request { + return Request(type: EditorOpen( + name: name, + source: source, + enableSyntaxMap: enableSyntaxMap, + enableStructure: enableStructure, + enableDiagnostics: enableDiagnostics, + syntacticOnly: syntacticOnly, + arguments: arguments + )) + } +} + +extension Request { + /// Generate interface for a swift module. + public struct EditorOpenInterface: RequestType { + public let name: String + public let moduleName: String + + public struct Group { + public let groupName: String? + public let interestedUSR: String? + + public static func name(_ name: String) -> Group { + return Group(groupName: name, interestedUSR: nil) + } + + public static func containsInterestedUSR(_ usr: String) -> Group { + return Group(groupName: nil, interestedUSR: usr) + } + } + public let group: Group? + public let synthesizedExtension: Bool? + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .editorOpenInterface) + requestBuilder[.name] = name + requestBuilder[.moduleName] = moduleName + requestBuilder[.synthesizedExtension] = synthesizedExtension + requestBuilder[.compilerArgs] = arguments + if let group = self.group { + requestBuilder[.groupName] = group.groupName + requestBuilder[.interestedUSR] = group.interestedUSR + } + return requestBuilder.makeRequest() + } + } + + public static func editorOpenInterface( + name: String, + moduleName: String, + group: EditorOpenInterface.Group? = nil, + synthesizedExtension: Bool? = nil, + arguments: [String] = defaultArguments + ) -> Request { + return Request(type: EditorOpenInterface( + name: name, + moduleName: moduleName, + group: group, + synthesizedExtension: synthesizedExtension, + arguments: arguments + )) + } +} + +extension Request { + /// A `cursorinfo` request for an offset or an usr in the given file, using the `arguments` given. + public struct CursorInfo: RequestType { + public let name: String + public let sourceFile: String + + public struct Location { + public let usr: String? + public let offset: Int64? + public let length: Int64? + public let retrieveRefactorActions: Bool? + + public static func offset(_ offset: Int64, length: Int64? = nil, retrieveRefactorActions: Bool? = nil) -> Location { + return Location(usr: nil, offset: offset, length: length, retrieveRefactorActions: retrieveRefactorActions) + } + + public static func usr(_ usr: String) -> Location { + return Location(usr: usr, offset: nil, length: nil, retrieveRefactorActions: nil) + } + } + public let location: Location + public let cancelOnSubsequentRequest: Bool? + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .cursorInfo) + requestBuilder[.name] = name + requestBuilder[.sourceFile] = sourceFile + requestBuilder[.cancelOnSubsequentRequest] = cancelOnSubsequentRequest + requestBuilder[.uSR] = location.usr + requestBuilder[.offset] = location.offset + requestBuilder[.length] = location.length + requestBuilder[.retrieveRefactorActions] = location.retrieveRefactorActions + requestBuilder[.compilerArgs] = arguments + return requestBuilder.makeRequest() + } + } + + public static func cursorInfo(file: String, offset: Int64, arguments: [String]) -> Request { + return .cursorInfo(name: file, file: file, location: .offset(offset), arguments: arguments) + } + + public static func cursorInfo( + name: String, + file: String, + location: CursorInfo.Location, + cancelOnSubsequentRequest: Bool? = nil, + arguments: [String] + ) -> Request { + return Request(type: CursorInfo( + name: name, + sourceFile: file, + location: location, + cancelOnSubsequentRequest: cancelOnSubsequentRequest, + arguments: arguments + )) + } +} + +extension Request { + /// A custom request by passing in the sourcekitd_object_t directly. + public struct Custom: RequestType { + public let request: sourcekitd_object_t + + public func sourcekitObject() -> sourcekitd_object_t { + return request + } + } + + public static func customRequest(request: sourcekitd_object_t) -> Request { + return Request(type: Custom(request: request)) + } +} + +extension Request { + /// A request generated by sourcekit using the yaml representation. + public struct Yaml: RequestType { + public let yaml: String + + public func sourcekitObject() -> sourcekitd_object_t { + return sourcekitd_request_create_from_yaml(yaml, nil) + } + } + + public static func yamlRequest(yaml: String) -> Request { + return Request(type: Yaml(yaml: yaml)) + } +} + +extension Request { + /// A `codecomplete` request by passing in the file name, contents, offset + /// for which to generate code completion options and array of compiler arguments. + public struct CodeComplete: RequestType { + public struct Source { + public let sourceFile: String? + public let sourceText: String? + + public static func path(_ path: String) -> Source { + return Source(sourceFile: path, sourceText: nil) + } + + public static func text(_ text: String, name: String? = nil) -> Source { + return Source(sourceFile: name, sourceText: text) + } + } + public let source: Source + public let offset: Int64 + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .codeComplete) + requestBuilder[.sourceFile] = source.sourceFile + requestBuilder[.sourceText] = source.sourceText + requestBuilder[.offset] = offset + requestBuilder[.compilerArgs] = arguments + return requestBuilder.makeRequest() + } + } + + public static func codeCompletionRequest(file: String, contents: String, offset: Int64, arguments: [String]) -> Request { + return .codeComplete(source: .text(contents, name: file), offset: offset, arguments: arguments) + } + + public static func codeComplete(source: CodeComplete.Source, offset: Int64, arguments: [String]) -> Request { + return Request(type: CodeComplete(source: source, offset: offset, arguments: arguments)) + } +} + +extension Request { + /// ObjC Swift Interface + public struct EditorOpenHeaderInterface: RequestType { + public let name: String + public let filePath: String + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .editorOpenHeaderInterface) + requestBuilder[.name] = name + requestBuilder[.filePath] = filePath + requestBuilder[.compilerArgs] = arguments + return requestBuilder.makeRequest() + } + } + + public static func interface(file: String, uuid: String, arguments: [String]) -> Request { + var arguments = arguments + if !arguments.contains("-x") { + arguments.append(contentsOf: ["-x", "objective-c"]) + } + if !arguments.contains("-isysroot") { + arguments.append(contentsOf: ["-isysroot", sdkPath()]) + } + + arguments = [file] + arguments + + return Request(type: EditorOpenHeaderInterface(name: uuid, filePath: file, arguments: arguments)) + } +} + +extension Request { + /// Find USR + public struct EditorFindUSR: RequestType { + public let sourceFile: String + public let usr: String + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .editorFindUSR) + requestBuilder[.sourceFile] = sourceFile + requestBuilder[.uSR] = usr + return requestBuilder.makeRequest() + } + } + + public static func findUSR(file: String, usr: String) -> Request { + return Request(type: EditorFindUSR(sourceFile: file, usr: usr)) + } +} + +extension Request { + /// Index + public struct Index: RequestType { + public let sourceFile: String + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .index) + requestBuilder[.sourceFile] = sourceFile + requestBuilder[.compilerArgs] = arguments + return requestBuilder.makeRequest() + } + } + + public static func index(file: String, arguments: [String]) -> Request { + return Request(type: Index(sourceFile: file, arguments: arguments)) + } +} + +extension Request { + /// Format + public struct EditorFormatText: RequestType { + public let name: String + public let line: Int64 + + public struct Options { + public let indentWidth: Int64 + public let tabWidth: Int64 + public let useTabs: Bool + } + public let options: Options + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .editorFormatText) + requestBuilder[.name] = name + requestBuilder[.line] = line + + let formatOptions: [String: Any] = [ + "key.editor.format.indentwidth": options.indentWidth, + "key.editor.format.tabwidth": options.tabWidth, + "key.editor.format.usetabs": options.useTabs + ] + requestBuilder[.formatOptions] = formatOptions + + return requestBuilder.makeRequest() + } + } + + public static func format(file: String, line: Int64, useTabs: Bool, indentWidth: Int64) -> Request { + let options = EditorFormatText.Options( + indentWidth: indentWidth, + tabWidth: indentWidth, + useTabs: useTabs + ) + return Request(type: EditorFormatText(name: file, line: line, options: options)) + } +} + +extension Request { + /// ReplaceText + public struct EditorReplaceText: RequestType { + public let name: String + public let offset: Int64 + public let length: Int64 + public let sourceText: String + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .editorReplaceText) + requestBuilder[.name] = name + requestBuilder[.offset] = offset + requestBuilder[.length] = length + requestBuilder[.sourceText] = sourceText + + return requestBuilder.makeRequest() + } + } + + public static func replaceText(file: String, offset: Int64, length: Int64, sourceText: String) -> Request { + return Request(type: EditorReplaceText(name: file, offset: offset, length: length, sourceText: sourceText)) + } +} + +extension Request { + /// A documentation request for the given source text. + /// Or a documentation request for the given module. + public struct DocInfo: RequestType { + public let name: String + + public struct Source { + public let sourceText: String? + public let moduleName: String? + + public static func text(_ sourceText: String) -> Source { + return Source(sourceText: sourceText, moduleName: nil) + } + + public static func module(name moduleName: String) -> Source { + return Source(sourceText: nil, moduleName: moduleName) + } + } + public let source: Source + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .docInfo) + requestBuilder[.name] = name + requestBuilder[.sourceText] = source.sourceText + requestBuilder[.moduleName] = source.moduleName + requestBuilder[.compilerArgs] = arguments + + return requestBuilder.makeRequest() + } + } + + public static func docInfo(text: String, arguments: [String]) -> Request { + return Request(type: DocInfo(name: NSUUID().uuidString, source: .text(text), arguments: arguments)) + } + + public static func moduleInfo(module: String, arguments: [String]) -> Request { + return Request(type: DocInfo(name: NSUUID().uuidString, source: .module(name: module), arguments: arguments)) + } +} + +extension Request { + /// Demangle swift names + public struct Demangle: RequestType { + public let names: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .demangle) + requestBuilder[.names] = names + + return requestBuilder.makeRequest() + } + } + + public static func demangle(names: [String]) -> Request { + return Request(type: Demangle(names: names)) + } +} + +extension Request { + /// Request groups for module + public struct ModuleGroups: RequestType { + public let moduleName: String + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .moduleGroups) + requestBuilder[.moduleName] = moduleName + requestBuilder[.compilerArgs] = arguments + + return requestBuilder.makeRequest() + } + } + + public static func moduleGroups(module: String, arguments: [String]) -> Request { + return Request(type: ModuleGroups(moduleName: module, arguments: arguments)) + } +} + +extension Request { + /// SourceKit protocol version + public struct ProtocolVersion: RequestType { + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .protocolVersion) + return requestBuilder.makeRequest() + } + } + + public static func protocolVersion() -> Request { + return Request(type: ProtocolVersion()) + } +} +// swiftlint:enable nesting + +// MARK: - CustomStringConvertible extension Request: CustomStringConvertible { /// A textual representation of `Request`. diff --git a/Source/SourceKittenFramework/RequestBuilder.swift b/Source/SourceKittenFramework/RequestBuilder.swift new file mode 100644 index 000000000..3bac0ebe6 --- /dev/null +++ b/Source/SourceKittenFramework/RequestBuilder.swift @@ -0,0 +1,88 @@ +// +// RequestBuilder.swift +// sourcekitten +// +// Created by Zheng Li on 06/10/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation +#if SWIFT_PACKAGE +import SourceKit +#endif + +public class RequestBuilder { + private var dict: [sourcekitd_uid_t: sourcekitd_object_t] = [:] + + public init(type: SourceKitDef.Request) { + dict[transform(key: "key.request")] = sourcekitd_request_uid_create(transform(key: type.stringRepresentation)) + } + + public subscript(_ key: SourceKitDef.Key) -> Any? { + get { return dict[transform(key: key.stringRepresentation)] } + set { set(newValue, for: key.stringRepresentation) } + } + + public func makeRequest() -> sourcekitd_object_t { + var keys = Array(dict.keys.map({ $0 as sourcekitd_uid_t? })) + var values = Array(dict.values.map({ $0 as sourcekitd_object_t? })) + return sourcekitd_request_dictionary_create(&keys, &values, dict.count) + } + + private func set(_ value: Any?, for key: String) { + if let value = value { + if let string = value as? String, key == "key.request" { + dict[transform(key: "key.request")] = sourcekitd_request_uid_create(transform(key: string)) + } else { + dict[transform(key: key)] = transform(any: value) + } + } else { + dict[transform(key: key)] = nil + } + } +} + +private func transform(key: String) -> sourcekitd_uid_t { + return sourcekitd_uid_get_from_cstr(key) +} + +private func transform(string: String) -> sourcekitd_object_t { + return sourcekitd_request_string_create(string) +} + +private func transform(bool: Bool) -> sourcekitd_object_t { + return sourcekitd_request_int64_create(bool ? 1 : 0) +} + +private func transform(integer: Int64) -> sourcekitd_object_t { + return sourcekitd_request_int64_create(integer) +} + +private func transform(array: [Any]) -> sourcekitd_object_t { + var array = array.map(transform(any:)).map { $0 as sourcekitd_object_t? } + return sourcekitd_request_array_create(&array, array.count) +} + +private func transform(dictionary: [String: Any]) -> sourcekitd_object_t { + var keys = Array(dictionary.keys).map(transform(key:)).map { $0 as sourcekitd_uid_t? } + var values = Array(dictionary.values).map(transform(any:)).map { $0 as sourcekitd_object_t? } + return sourcekitd_request_dictionary_create(&keys, &values, dictionary.count) +} + +private func transform(any: Any) -> sourcekitd_object_t { + switch any { + case let string as String: + return transform(string: string) + case let bool as Bool: + return transform(bool: bool) + case let integer as Int64: + return transform(integer: integer) + case let array as [Any]: + return transform(array: array) + case let dictionary as [String: Any]: + return transform(dictionary: dictionary) + default: + fatalError("RequestBuilder: Unsupported value type: \(type(of: any)) value: \(any)") + } +} + diff --git a/Source/SourceKittenFramework/SourceKitDef.swift b/Source/SourceKittenFramework/SourceKitDef.swift new file mode 100644 index 000000000..01c8b11ea --- /dev/null +++ b/Source/SourceKittenFramework/SourceKitDef.swift @@ -0,0 +1,1654 @@ +// Generated using Sourcery 0.8.0 — https://github.com/krzysztofzablocki/Sourcery +// DO NOT EDIT + +// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length +import Swift + +public struct SourceKitDef { + + public enum Key { + case versionMajor + case versionMinor + case results + case request + case notification + case kind + case accessLevel + case setterAccessLevel + case keyword + case name + case uSR + case originalUSR + case defaultImplementationOf + case interestedUSR + case genericParams + case genericRequirements + case docFullAsXML + case line + case column + case receiverUSR + case isDynamic + case filePath + case moduleInterfaceName + case hash + case compilerArgs + case severity + case offset + case length + case sourceFile + case sourceText + case enableSyntaxMap + case enableStructure + case description + case typeName + case runtimeName + case selectorName + case annotatedDecl + case fullyAnnotatedDecl + case docBrief + case context + case moduleImportDepth + case numBytesToErase + case notRecommended + case annotations + case diagnosticStage + case syntaxMap + case isSystem + case related + case inherits + case conforms + case extends + case dependencies + case entities + case nameOffset + case nameLength + case bodyOffset + case bodyLength + case throwOffset + case throwLength + case docOffset + case docLength + case isLocal + case inheritedTypes + case attributes + case attribute + case elements + case subStructure + case ranges + case fixits + case diagnostics + case formatOptions + case codeCompleteOptions + case filterRules + case nextRequestStart + case popular + case unpopular + case hide + case platform + case isDeprecated + case isUnavailable + case isOptional + case message + case introduced + case deprecated + case obsoleted + case removeCache + case typeInterface + case typeUsr + case containerTypeUsr + case moduleGroups + case baseName + case argNames + case selectorPieces + case nameKind + case localizationKey + case isZeroArgSelector + case swiftVersion + case enableDiagnostics + case groupName + case actionName + case synthesizedExtension + case usingSwiftArgs + case names + case uIDs + case syntacticOnly + case actionable + case parentLoc + case isTestCandidate + case overrides + case associatedUSRs + case moduleName + case relatedDecls + case simplified + case rangeContent + case cancelOnSubsequentRequest + case renameLocations + case locations + case nameType + case newName + case categorizedEdits + case categorizedRanges + case rangesWorthNote + case edits + case endLine + case endColumn + case argIndex + case text + case category + case isFunctionLike + case isNonProtocolType + case refactorActions + case retrieveRefactorActions + case actionUID + case actionUnavailableReason + case unrecognized(String) + + public init(string: String) { + switch string { + case "key.version_major": + self = .versionMajor + case "key.version_minor": + self = .versionMinor + case "key.results": + self = .results + case "key.request": + self = .request + case "key.notification": + self = .notification + case "key.kind": + self = .kind + case "key.accessibility": + self = .accessLevel + case "key.setter_accessibility": + self = .setterAccessLevel + case "key.keyword": + self = .keyword + case "key.name": + self = .name + case "key.usr": + self = .uSR + case "key.original_usr": + self = .originalUSR + case "key.default_implementation_of": + self = .defaultImplementationOf + case "key.interested_usr": + self = .interestedUSR + case "key.generic_params": + self = .genericParams + case "key.generic_requirements": + self = .genericRequirements + case "key.doc.full_as_xml": + self = .docFullAsXML + case "key.line": + self = .line + case "key.column": + self = .column + case "key.receiver_usr": + self = .receiverUSR + case "key.is_dynamic": + self = .isDynamic + case "key.filepath": + self = .filePath + case "key.module_interface_name": + self = .moduleInterfaceName + case "key.hash": + self = .hash + case "key.compilerargs": + self = .compilerArgs + case "key.severity": + self = .severity + case "key.offset": + self = .offset + case "key.length": + self = .length + case "key.sourcefile": + self = .sourceFile + case "key.sourcetext": + self = .sourceText + case "key.enablesyntaxmap": + self = .enableSyntaxMap + case "key.enablesubstructure": + self = .enableStructure + case "key.description": + self = .description + case "key.typename": + self = .typeName + case "key.runtime_name": + self = .runtimeName + case "key.selector_name": + self = .selectorName + case "key.annotated_decl": + self = .annotatedDecl + case "key.fully_annotated_decl": + self = .fullyAnnotatedDecl + case "key.doc.brief": + self = .docBrief + case "key.context": + self = .context + case "key.moduleimportdepth": + self = .moduleImportDepth + case "key.num_bytes_to_erase": + self = .numBytesToErase + case "key.not_recommended": + self = .notRecommended + case "key.annotations": + self = .annotations + case "key.diagnostic_stage": + self = .diagnosticStage + case "key.syntaxmap": + self = .syntaxMap + case "key.is_system": + self = .isSystem + case "key.related": + self = .related + case "key.inherits": + self = .inherits + case "key.conforms": + self = .conforms + case "key.extends": + self = .extends + case "key.dependencies": + self = .dependencies + case "key.entities": + self = .entities + case "key.nameoffset": + self = .nameOffset + case "key.namelength": + self = .nameLength + case "key.bodyoffset": + self = .bodyOffset + case "key.bodylength": + self = .bodyLength + case "key.throwoffset": + self = .throwOffset + case "key.throwlength": + self = .throwLength + case "key.docoffset": + self = .docOffset + case "key.doclength": + self = .docLength + case "key.is_local": + self = .isLocal + case "key.inheritedtypes": + self = .inheritedTypes + case "key.attributes": + self = .attributes + case "key.attribute": + self = .attribute + case "key.elements": + self = .elements + case "key.substructure": + self = .subStructure + case "key.ranges": + self = .ranges + case "key.fixits": + self = .fixits + case "key.diagnostics": + self = .diagnostics + case "key.editor.format.options": + self = .formatOptions + case "key.codecomplete.options": + self = .codeCompleteOptions + case "key.codecomplete.filterrules": + self = .filterRules + case "key.nextrequeststart": + self = .nextRequestStart + case "key.popular": + self = .popular + case "key.unpopular": + self = .unpopular + case "key.hide": + self = .hide + case "key.platform": + self = .platform + case "key.is_deprecated": + self = .isDeprecated + case "key.is_unavailable": + self = .isUnavailable + case "key.is_optional": + self = .isOptional + case "key.message": + self = .message + case "key.introduced": + self = .introduced + case "key.deprecated": + self = .deprecated + case "key.obsoleted": + self = .obsoleted + case "key.removecache": + self = .removeCache + case "key.typeinterface": + self = .typeInterface + case "key.typeusr": + self = .typeUsr + case "key.containertypeusr": + self = .containerTypeUsr + case "key.modulegroups": + self = .moduleGroups + case "key.basename": + self = .baseName + case "key.argnames": + self = .argNames + case "key.selectorpieces": + self = .selectorPieces + case "key.namekind": + self = .nameKind + case "key.localization_key": + self = .localizationKey + case "key.is_zero_arg_selector": + self = .isZeroArgSelector + case "key.swift_version": + self = .swiftVersion + case "key.enablediagnostics": + self = .enableDiagnostics + case "key.groupname": + self = .groupName + case "key.actionname": + self = .actionName + case "key.synthesizedextensions": + self = .synthesizedExtension + case "key.usingswiftargs": + self = .usingSwiftArgs + case "key.names": + self = .names + case "key.uids": + self = .uIDs + case "key.syntactic_only": + self = .syntacticOnly + case "key.actionable": + self = .actionable + case "key.parent_loc": + self = .parentLoc + case "key.is_test_candidate": + self = .isTestCandidate + case "key.overrides": + self = .overrides + case "key.associated_usrs": + self = .associatedUSRs + case "key.modulename": + self = .moduleName + case "key.related_decls": + self = .relatedDecls + case "key.simplified": + self = .simplified + case "key.rangecontent": + self = .rangeContent + case "key.cancel_on_subsequent_request": + self = .cancelOnSubsequentRequest + case "key.renamelocations": + self = .renameLocations + case "key.locations": + self = .locations + case "key.nametype": + self = .nameType + case "key.newname": + self = .newName + case "key.categorizededits": + self = .categorizedEdits + case "key.categorizedranges": + self = .categorizedRanges + case "key.rangesworthnote": + self = .rangesWorthNote + case "key.edits": + self = .edits + case "key.endline": + self = .endLine + case "key.endcolumn": + self = .endColumn + case "key.argindex": + self = .argIndex + case "key.text": + self = .text + case "key.category": + self = .category + case "key.is_function_like": + self = .isFunctionLike + case "key.is_non_protocol_type": + self = .isNonProtocolType + case "key.refactor_actions": + self = .refactorActions + case "key.retrieve_refactor_actions": + self = .retrieveRefactorActions + case "key.actionuid": + self = .actionUID + case "key.actionunavailablereason": + self = .actionUnavailableReason + default: + self = .unrecognized(string) + } + } + + public var stringRepresentation: String { + switch self { + case .versionMajor: + return "key.version_major" + case .versionMinor: + return "key.version_minor" + case .results: + return "key.results" + case .request: + return "key.request" + case .notification: + return "key.notification" + case .kind: + return "key.kind" + case .accessLevel: + return "key.accessibility" + case .setterAccessLevel: + return "key.setter_accessibility" + case .keyword: + return "key.keyword" + case .name: + return "key.name" + case .uSR: + return "key.usr" + case .originalUSR: + return "key.original_usr" + case .defaultImplementationOf: + return "key.default_implementation_of" + case .interestedUSR: + return "key.interested_usr" + case .genericParams: + return "key.generic_params" + case .genericRequirements: + return "key.generic_requirements" + case .docFullAsXML: + return "key.doc.full_as_xml" + case .line: + return "key.line" + case .column: + return "key.column" + case .receiverUSR: + return "key.receiver_usr" + case .isDynamic: + return "key.is_dynamic" + case .filePath: + return "key.filepath" + case .moduleInterfaceName: + return "key.module_interface_name" + case .hash: + return "key.hash" + case .compilerArgs: + return "key.compilerargs" + case .severity: + return "key.severity" + case .offset: + return "key.offset" + case .length: + return "key.length" + case .sourceFile: + return "key.sourcefile" + case .sourceText: + return "key.sourcetext" + case .enableSyntaxMap: + return "key.enablesyntaxmap" + case .enableStructure: + return "key.enablesubstructure" + case .description: + return "key.description" + case .typeName: + return "key.typename" + case .runtimeName: + return "key.runtime_name" + case .selectorName: + return "key.selector_name" + case .annotatedDecl: + return "key.annotated_decl" + case .fullyAnnotatedDecl: + return "key.fully_annotated_decl" + case .docBrief: + return "key.doc.brief" + case .context: + return "key.context" + case .moduleImportDepth: + return "key.moduleimportdepth" + case .numBytesToErase: + return "key.num_bytes_to_erase" + case .notRecommended: + return "key.not_recommended" + case .annotations: + return "key.annotations" + case .diagnosticStage: + return "key.diagnostic_stage" + case .syntaxMap: + return "key.syntaxmap" + case .isSystem: + return "key.is_system" + case .related: + return "key.related" + case .inherits: + return "key.inherits" + case .conforms: + return "key.conforms" + case .extends: + return "key.extends" + case .dependencies: + return "key.dependencies" + case .entities: + return "key.entities" + case .nameOffset: + return "key.nameoffset" + case .nameLength: + return "key.namelength" + case .bodyOffset: + return "key.bodyoffset" + case .bodyLength: + return "key.bodylength" + case .throwOffset: + return "key.throwoffset" + case .throwLength: + return "key.throwlength" + case .docOffset: + return "key.docoffset" + case .docLength: + return "key.doclength" + case .isLocal: + return "key.is_local" + case .inheritedTypes: + return "key.inheritedtypes" + case .attributes: + return "key.attributes" + case .attribute: + return "key.attribute" + case .elements: + return "key.elements" + case .subStructure: + return "key.substructure" + case .ranges: + return "key.ranges" + case .fixits: + return "key.fixits" + case .diagnostics: + return "key.diagnostics" + case .formatOptions: + return "key.editor.format.options" + case .codeCompleteOptions: + return "key.codecomplete.options" + case .filterRules: + return "key.codecomplete.filterrules" + case .nextRequestStart: + return "key.nextrequeststart" + case .popular: + return "key.popular" + case .unpopular: + return "key.unpopular" + case .hide: + return "key.hide" + case .platform: + return "key.platform" + case .isDeprecated: + return "key.is_deprecated" + case .isUnavailable: + return "key.is_unavailable" + case .isOptional: + return "key.is_optional" + case .message: + return "key.message" + case .introduced: + return "key.introduced" + case .deprecated: + return "key.deprecated" + case .obsoleted: + return "key.obsoleted" + case .removeCache: + return "key.removecache" + case .typeInterface: + return "key.typeinterface" + case .typeUsr: + return "key.typeusr" + case .containerTypeUsr: + return "key.containertypeusr" + case .moduleGroups: + return "key.modulegroups" + case .baseName: + return "key.basename" + case .argNames: + return "key.argnames" + case .selectorPieces: + return "key.selectorpieces" + case .nameKind: + return "key.namekind" + case .localizationKey: + return "key.localization_key" + case .isZeroArgSelector: + return "key.is_zero_arg_selector" + case .swiftVersion: + return "key.swift_version" + case .enableDiagnostics: + return "key.enablediagnostics" + case .groupName: + return "key.groupname" + case .actionName: + return "key.actionname" + case .synthesizedExtension: + return "key.synthesizedextensions" + case .usingSwiftArgs: + return "key.usingswiftargs" + case .names: + return "key.names" + case .uIDs: + return "key.uids" + case .syntacticOnly: + return "key.syntactic_only" + case .actionable: + return "key.actionable" + case .parentLoc: + return "key.parent_loc" + case .isTestCandidate: + return "key.is_test_candidate" + case .overrides: + return "key.overrides" + case .associatedUSRs: + return "key.associated_usrs" + case .moduleName: + return "key.modulename" + case .relatedDecls: + return "key.related_decls" + case .simplified: + return "key.simplified" + case .rangeContent: + return "key.rangecontent" + case .cancelOnSubsequentRequest: + return "key.cancel_on_subsequent_request" + case .renameLocations: + return "key.renamelocations" + case .locations: + return "key.locations" + case .nameType: + return "key.nametype" + case .newName: + return "key.newname" + case .categorizedEdits: + return "key.categorizededits" + case .categorizedRanges: + return "key.categorizedranges" + case .rangesWorthNote: + return "key.rangesworthnote" + case .edits: + return "key.edits" + case .endLine: + return "key.endline" + case .endColumn: + return "key.endcolumn" + case .argIndex: + return "key.argindex" + case .text: + return "key.text" + case .category: + return "key.category" + case .isFunctionLike: + return "key.is_function_like" + case .isNonProtocolType: + return "key.is_non_protocol_type" + case .refactorActions: + return "key.refactor_actions" + case .retrieveRefactorActions: + return "key.retrieve_refactor_actions" + case .actionUID: + return "key.actionuid" + case .actionUnavailableReason: + return "key.actionunavailablereason" + case let .unrecognized(string): + return string + } + } + } + + public enum Kind { + case declFunctionFree + case refFunctionFree + case declMethodInstance + case refMethodInstance + case declMethodStatic + case refMethodStatic + case declMethodClass + case refMethodClass + case declAccessorGetter + case refAccessorGetter + case declAccessorSetter + case refAccessorSetter + case declAccessorWillSet + case refAccessorWillSet + case declAccessorDidSet + case refAccessorDidSet + case declAccessorAddress + case refAccessorAddress + case declAccessorMutableAddress + case refAccessorMutableAddress + case declConstructor + case refConstructor + case declDestructor + case refDestructor + case declFunctionPrefixOperator + case declFunctionPostfixOperator + case declFunctionInfixOperator + case refFunctionPrefixOperator + case refFunctionPostfixOperator + case refFunctionInfixOperator + case declPrecedenceGroup + case refPrecedenceGroup + case declSubscript + case refSubscript + case declVarGlobal + case refVarGlobal + case declVarInstance + case refVarInstance + case declVarStatic + case refVarStatic + case declVarClass + case refVarClass + case declVarLocal + case refVarLocal + case declVarParam + case declModule + case declClass + case refClass + case declStruct + case refStruct + case declEnum + case refEnum + case declEnumCase + case declEnumElement + case refEnumElement + case declProtocol + case refProtocol + case declExtension + case declExtensionStruct + case declExtensionClass + case declExtensionEnum + case declExtensionProtocol + case declAssociatedType + case refAssociatedType + case declTypeAlias + case refTypeAlias + case declGenericTypeParam + case refGenericTypeParam + case refModule + case stmtForEach + case stmtFor + case stmtWhile + case stmtRepeatWhile + case stmtIf + case stmtGuard + case stmtSwitch + case stmtCase + case stmtBrace + case exprCall + case exprArg + case exprArray + case exprDictionary + case exprObjectLiteral + case structureElemId + case structureElemExpr + case structureElemInitExpr + case structureElemCondExpr + case structureElemPattern + case structureElemTypeRef + case rangeSingleStatement + case rangeSingleExpression + case rangeSingleDeclaration + case rangeMultiStatement + case rangeInvalid + case nameObjc + case nameSwift + case keyword + case identifier + case typeIdentifier + case buildConfigKeyword + case buildConfigId + case attributeId + case attributeBuiltin + case number + case string + case stringInterpolation + case comment + case docComment + case docCommentField + case commentMarker + case commentURL + case placeholder + case objectLiteral + case expr + case stmt + case type + case forEachSequence + case diagNote + case diagWarning + case diagError + case codeCompletionEverything + case codeCompletionModule + case codeCompletionKeyword + case codeCompletionLiteral + case codeCompletionCustom + case codeCompletionIdentifier + case codeCompletionDescription + case editActive + case editInactive + case editSelector + case editString + case editComment + case editMismatch + case editUnknown + case renameRangeBase + case renameRangeKeywordBase + case renameRangeParam + case renameRangeDeclArgLabel + case renameRangeCallArgLabel + case renameRangeCallArgColon + case renameRangeCallArgCombined + case renameRangeSelectorArgLabel + case definition + case reference + case call + case unknown + case unrecognized(String) + + public init(string: String) { + switch string { + case "source.lang.swift.decl.function.free": + self = .declFunctionFree + case "source.lang.swift.ref.function.free": + self = .refFunctionFree + case "source.lang.swift.decl.function.method.instance": + self = .declMethodInstance + case "source.lang.swift.ref.function.method.instance": + self = .refMethodInstance + case "source.lang.swift.decl.function.method.static": + self = .declMethodStatic + case "source.lang.swift.ref.function.method.static": + self = .refMethodStatic + case "source.lang.swift.decl.function.method.class": + self = .declMethodClass + case "source.lang.swift.ref.function.method.class": + self = .refMethodClass + case "source.lang.swift.decl.function.accessor.getter": + self = .declAccessorGetter + case "source.lang.swift.ref.function.accessor.getter": + self = .refAccessorGetter + case "source.lang.swift.decl.function.accessor.setter": + self = .declAccessorSetter + case "source.lang.swift.ref.function.accessor.setter": + self = .refAccessorSetter + case "source.lang.swift.decl.function.accessor.willset": + self = .declAccessorWillSet + case "source.lang.swift.ref.function.accessor.willset": + self = .refAccessorWillSet + case "source.lang.swift.decl.function.accessor.didset": + self = .declAccessorDidSet + case "source.lang.swift.ref.function.accessor.didset": + self = .refAccessorDidSet + case "source.lang.swift.decl.function.accessor.address": + self = .declAccessorAddress + case "source.lang.swift.ref.function.accessor.address": + self = .refAccessorAddress + case "source.lang.swift.decl.function.accessor.mutableaddress": + self = .declAccessorMutableAddress + case "source.lang.swift.ref.function.accessor.mutableaddress": + self = .refAccessorMutableAddress + case "source.lang.swift.decl.function.constructor": + self = .declConstructor + case "source.lang.swift.ref.function.constructor": + self = .refConstructor + case "source.lang.swift.decl.function.destructor": + self = .declDestructor + case "source.lang.swift.ref.function.destructor": + self = .refDestructor + case "source.lang.swift.decl.function.operator.prefix": + self = .declFunctionPrefixOperator + case "source.lang.swift.decl.function.operator.postfix": + self = .declFunctionPostfixOperator + case "source.lang.swift.decl.function.operator.infix": + self = .declFunctionInfixOperator + case "source.lang.swift.ref.function.operator.prefix": + self = .refFunctionPrefixOperator + case "source.lang.swift.ref.function.operator.postfix": + self = .refFunctionPostfixOperator + case "source.lang.swift.ref.function.operator.infix": + self = .refFunctionInfixOperator + case "source.lang.swift.decl.precedencegroup": + self = .declPrecedenceGroup + case "source.lang.swift.ref.precedencegroup": + self = .refPrecedenceGroup + case "source.lang.swift.decl.function.subscript": + self = .declSubscript + case "source.lang.swift.ref.function.subscript": + self = .refSubscript + case "source.lang.swift.decl.var.global": + self = .declVarGlobal + case "source.lang.swift.ref.var.global": + self = .refVarGlobal + case "source.lang.swift.decl.var.instance": + self = .declVarInstance + case "source.lang.swift.ref.var.instance": + self = .refVarInstance + case "source.lang.swift.decl.var.static": + self = .declVarStatic + case "source.lang.swift.ref.var.static": + self = .refVarStatic + case "source.lang.swift.decl.var.class": + self = .declVarClass + case "source.lang.swift.ref.var.class": + self = .refVarClass + case "source.lang.swift.decl.var.local": + self = .declVarLocal + case "source.lang.swift.ref.var.local": + self = .refVarLocal + case "source.lang.swift.decl.var.parameter": + self = .declVarParam + case "source.lang.swift.decl.module": + self = .declModule + case "source.lang.swift.decl.class": + self = .declClass + case "source.lang.swift.ref.class": + self = .refClass + case "source.lang.swift.decl.struct": + self = .declStruct + case "source.lang.swift.ref.struct": + self = .refStruct + case "source.lang.swift.decl.enum": + self = .declEnum + case "source.lang.swift.ref.enum": + self = .refEnum + case "source.lang.swift.decl.enumcase": + self = .declEnumCase + case "source.lang.swift.decl.enumelement": + self = .declEnumElement + case "source.lang.swift.ref.enumelement": + self = .refEnumElement + case "source.lang.swift.decl.protocol": + self = .declProtocol + case "source.lang.swift.ref.protocol": + self = .refProtocol + case "source.lang.swift.decl.extension": + self = .declExtension + case "source.lang.swift.decl.extension.struct": + self = .declExtensionStruct + case "source.lang.swift.decl.extension.class": + self = .declExtensionClass + case "source.lang.swift.decl.extension.enum": + self = .declExtensionEnum + case "source.lang.swift.decl.extension.protocol": + self = .declExtensionProtocol + case "source.lang.swift.decl.associatedtype": + self = .declAssociatedType + case "source.lang.swift.ref.associatedtype": + self = .refAssociatedType + case "source.lang.swift.decl.typealias": + self = .declTypeAlias + case "source.lang.swift.ref.typealias": + self = .refTypeAlias + case "source.lang.swift.decl.generic_type_param": + self = .declGenericTypeParam + case "source.lang.swift.ref.generic_type_param": + self = .refGenericTypeParam + case "source.lang.swift.ref.module": + self = .refModule + case "source.lang.swift.stmt.foreach": + self = .stmtForEach + case "source.lang.swift.stmt.for": + self = .stmtFor + case "source.lang.swift.stmt.while": + self = .stmtWhile + case "source.lang.swift.stmt.repeatwhile": + self = .stmtRepeatWhile + case "source.lang.swift.stmt.if": + self = .stmtIf + case "source.lang.swift.stmt.guard": + self = .stmtGuard + case "source.lang.swift.stmt.switch": + self = .stmtSwitch + case "source.lang.swift.stmt.case": + self = .stmtCase + case "source.lang.swift.stmt.brace": + self = .stmtBrace + case "source.lang.swift.expr.call": + self = .exprCall + case "source.lang.swift.expr.argument": + self = .exprArg + case "source.lang.swift.expr.array": + self = .exprArray + case "source.lang.swift.expr.dictionary": + self = .exprDictionary + case "source.lang.swift.expr.object_literal": + self = .exprObjectLiteral + case "source.lang.swift.structure.elem.id": + self = .structureElemId + case "source.lang.swift.structure.elem.expr": + self = .structureElemExpr + case "source.lang.swift.structure.elem.init_expr": + self = .structureElemInitExpr + case "source.lang.swift.structure.elem.condition_expr": + self = .structureElemCondExpr + case "source.lang.swift.structure.elem.pattern": + self = .structureElemPattern + case "source.lang.swift.structure.elem.typeref": + self = .structureElemTypeRef + case "source.lang.swift.range.singlestatement": + self = .rangeSingleStatement + case "source.lang.swift.range.singleexpression": + self = .rangeSingleExpression + case "source.lang.swift.range.singledeclaration": + self = .rangeSingleDeclaration + case "source.lang.swift.range.multistatement": + self = .rangeMultiStatement + case "source.lang.swift.range.invalid": + self = .rangeInvalid + case "source.lang.name.kind.objc": + self = .nameObjc + case "source.lang.name.kind.swift": + self = .nameSwift + case "source.lang.swift.syntaxtype.keyword": + self = .keyword + case "source.lang.swift.syntaxtype.identifier": + self = .identifier + case "source.lang.swift.syntaxtype.typeidentifier": + self = .typeIdentifier + case "source.lang.swift.syntaxtype.buildconfig.keyword": + self = .buildConfigKeyword + case "source.lang.swift.syntaxtype.buildconfig.id": + self = .buildConfigId + case "source.lang.swift.syntaxtype.attribute.id": + self = .attributeId + case "source.lang.swift.syntaxtype.attribute.builtin": + self = .attributeBuiltin + case "source.lang.swift.syntaxtype.number": + self = .number + case "source.lang.swift.syntaxtype.string": + self = .string + case "source.lang.swift.syntaxtype.string_interpolation_anchor": + self = .stringInterpolation + case "source.lang.swift.syntaxtype.comment": + self = .comment + case "source.lang.swift.syntaxtype.doccomment": + self = .docComment + case "source.lang.swift.syntaxtype.doccomment.field": + self = .docCommentField + case "source.lang.swift.syntaxtype.comment.mark": + self = .commentMarker + case "source.lang.swift.syntaxtype.comment.url": + self = .commentURL + case "source.lang.swift.syntaxtype.placeholder": + self = .placeholder + case "source.lang.swift.syntaxtype.objectliteral": + self = .objectLiteral + case "source.lang.swift.expr": + self = .expr + case "source.lang.swift.stmt": + self = .stmt + case "source.lang.swift.type": + self = .type + case "source.lang.swift.foreach.sequence": + self = .forEachSequence + case "source.diagnostic.severity.note": + self = .diagNote + case "source.diagnostic.severity.warning": + self = .diagWarning + case "source.diagnostic.severity.error": + self = .diagError + case "source.codecompletion.everything": + self = .codeCompletionEverything + case "source.codecompletion.module": + self = .codeCompletionModule + case "source.codecompletion.keyword": + self = .codeCompletionKeyword + case "source.codecompletion.literal": + self = .codeCompletionLiteral + case "source.codecompletion.custom": + self = .codeCompletionCustom + case "source.codecompletion.identifier": + self = .codeCompletionIdentifier + case "source.codecompletion.description": + self = .codeCompletionDescription + case "source.edit.kind.active": + self = .editActive + case "source.edit.kind.inactive": + self = .editInactive + case "source.edit.kind.selector": + self = .editSelector + case "source.edit.kind.string": + self = .editString + case "source.edit.kind.comment": + self = .editComment + case "source.edit.kind.mismatch": + self = .editMismatch + case "source.edit.kind.unknown": + self = .editUnknown + case "source.refactoring.range.kind.basename": + self = .renameRangeBase + case "source.refactoring.range.kind.keyword-basename": + self = .renameRangeKeywordBase + case "source.refactoring.range.kind.parameter-and-whitespace": + self = .renameRangeParam + case "source.refactoring.range.kind.decl-argument-label": + self = .renameRangeDeclArgLabel + case "source.refactoring.range.kind.call-argument-label": + self = .renameRangeCallArgLabel + case "source.refactoring.range.kind.call-argument-colon": + self = .renameRangeCallArgColon + case "source.refactoring.range.kind.call-argument-combined": + self = .renameRangeCallArgCombined + case "source.refactoring.range.kind.selector-argument-label": + self = .renameRangeSelectorArgLabel + case "source.syntacticrename.definition": + self = .definition + case "source.syntacticrename.reference": + self = .reference + case "source.syntacticrename.call": + self = .call + case "source.syntacticrename.unknown": + self = .unknown + default: + self = .unrecognized(string) + } + } + + public var stringRepresentation: String { + switch self { + case .declFunctionFree: + return "source.lang.swift.decl.function.free" + case .refFunctionFree: + return "source.lang.swift.ref.function.free" + case .declMethodInstance: + return "source.lang.swift.decl.function.method.instance" + case .refMethodInstance: + return "source.lang.swift.ref.function.method.instance" + case .declMethodStatic: + return "source.lang.swift.decl.function.method.static" + case .refMethodStatic: + return "source.lang.swift.ref.function.method.static" + case .declMethodClass: + return "source.lang.swift.decl.function.method.class" + case .refMethodClass: + return "source.lang.swift.ref.function.method.class" + case .declAccessorGetter: + return "source.lang.swift.decl.function.accessor.getter" + case .refAccessorGetter: + return "source.lang.swift.ref.function.accessor.getter" + case .declAccessorSetter: + return "source.lang.swift.decl.function.accessor.setter" + case .refAccessorSetter: + return "source.lang.swift.ref.function.accessor.setter" + case .declAccessorWillSet: + return "source.lang.swift.decl.function.accessor.willset" + case .refAccessorWillSet: + return "source.lang.swift.ref.function.accessor.willset" + case .declAccessorDidSet: + return "source.lang.swift.decl.function.accessor.didset" + case .refAccessorDidSet: + return "source.lang.swift.ref.function.accessor.didset" + case .declAccessorAddress: + return "source.lang.swift.decl.function.accessor.address" + case .refAccessorAddress: + return "source.lang.swift.ref.function.accessor.address" + case .declAccessorMutableAddress: + return "source.lang.swift.decl.function.accessor.mutableaddress" + case .refAccessorMutableAddress: + return "source.lang.swift.ref.function.accessor.mutableaddress" + case .declConstructor: + return "source.lang.swift.decl.function.constructor" + case .refConstructor: + return "source.lang.swift.ref.function.constructor" + case .declDestructor: + return "source.lang.swift.decl.function.destructor" + case .refDestructor: + return "source.lang.swift.ref.function.destructor" + case .declFunctionPrefixOperator: + return "source.lang.swift.decl.function.operator.prefix" + case .declFunctionPostfixOperator: + return "source.lang.swift.decl.function.operator.postfix" + case .declFunctionInfixOperator: + return "source.lang.swift.decl.function.operator.infix" + case .refFunctionPrefixOperator: + return "source.lang.swift.ref.function.operator.prefix" + case .refFunctionPostfixOperator: + return "source.lang.swift.ref.function.operator.postfix" + case .refFunctionInfixOperator: + return "source.lang.swift.ref.function.operator.infix" + case .declPrecedenceGroup: + return "source.lang.swift.decl.precedencegroup" + case .refPrecedenceGroup: + return "source.lang.swift.ref.precedencegroup" + case .declSubscript: + return "source.lang.swift.decl.function.subscript" + case .refSubscript: + return "source.lang.swift.ref.function.subscript" + case .declVarGlobal: + return "source.lang.swift.decl.var.global" + case .refVarGlobal: + return "source.lang.swift.ref.var.global" + case .declVarInstance: + return "source.lang.swift.decl.var.instance" + case .refVarInstance: + return "source.lang.swift.ref.var.instance" + case .declVarStatic: + return "source.lang.swift.decl.var.static" + case .refVarStatic: + return "source.lang.swift.ref.var.static" + case .declVarClass: + return "source.lang.swift.decl.var.class" + case .refVarClass: + return "source.lang.swift.ref.var.class" + case .declVarLocal: + return "source.lang.swift.decl.var.local" + case .refVarLocal: + return "source.lang.swift.ref.var.local" + case .declVarParam: + return "source.lang.swift.decl.var.parameter" + case .declModule: + return "source.lang.swift.decl.module" + case .declClass: + return "source.lang.swift.decl.class" + case .refClass: + return "source.lang.swift.ref.class" + case .declStruct: + return "source.lang.swift.decl.struct" + case .refStruct: + return "source.lang.swift.ref.struct" + case .declEnum: + return "source.lang.swift.decl.enum" + case .refEnum: + return "source.lang.swift.ref.enum" + case .declEnumCase: + return "source.lang.swift.decl.enumcase" + case .declEnumElement: + return "source.lang.swift.decl.enumelement" + case .refEnumElement: + return "source.lang.swift.ref.enumelement" + case .declProtocol: + return "source.lang.swift.decl.protocol" + case .refProtocol: + return "source.lang.swift.ref.protocol" + case .declExtension: + return "source.lang.swift.decl.extension" + case .declExtensionStruct: + return "source.lang.swift.decl.extension.struct" + case .declExtensionClass: + return "source.lang.swift.decl.extension.class" + case .declExtensionEnum: + return "source.lang.swift.decl.extension.enum" + case .declExtensionProtocol: + return "source.lang.swift.decl.extension.protocol" + case .declAssociatedType: + return "source.lang.swift.decl.associatedtype" + case .refAssociatedType: + return "source.lang.swift.ref.associatedtype" + case .declTypeAlias: + return "source.lang.swift.decl.typealias" + case .refTypeAlias: + return "source.lang.swift.ref.typealias" + case .declGenericTypeParam: + return "source.lang.swift.decl.generic_type_param" + case .refGenericTypeParam: + return "source.lang.swift.ref.generic_type_param" + case .refModule: + return "source.lang.swift.ref.module" + case .stmtForEach: + return "source.lang.swift.stmt.foreach" + case .stmtFor: + return "source.lang.swift.stmt.for" + case .stmtWhile: + return "source.lang.swift.stmt.while" + case .stmtRepeatWhile: + return "source.lang.swift.stmt.repeatwhile" + case .stmtIf: + return "source.lang.swift.stmt.if" + case .stmtGuard: + return "source.lang.swift.stmt.guard" + case .stmtSwitch: + return "source.lang.swift.stmt.switch" + case .stmtCase: + return "source.lang.swift.stmt.case" + case .stmtBrace: + return "source.lang.swift.stmt.brace" + case .exprCall: + return "source.lang.swift.expr.call" + case .exprArg: + return "source.lang.swift.expr.argument" + case .exprArray: + return "source.lang.swift.expr.array" + case .exprDictionary: + return "source.lang.swift.expr.dictionary" + case .exprObjectLiteral: + return "source.lang.swift.expr.object_literal" + case .structureElemId: + return "source.lang.swift.structure.elem.id" + case .structureElemExpr: + return "source.lang.swift.structure.elem.expr" + case .structureElemInitExpr: + return "source.lang.swift.structure.elem.init_expr" + case .structureElemCondExpr: + return "source.lang.swift.structure.elem.condition_expr" + case .structureElemPattern: + return "source.lang.swift.structure.elem.pattern" + case .structureElemTypeRef: + return "source.lang.swift.structure.elem.typeref" + case .rangeSingleStatement: + return "source.lang.swift.range.singlestatement" + case .rangeSingleExpression: + return "source.lang.swift.range.singleexpression" + case .rangeSingleDeclaration: + return "source.lang.swift.range.singledeclaration" + case .rangeMultiStatement: + return "source.lang.swift.range.multistatement" + case .rangeInvalid: + return "source.lang.swift.range.invalid" + case .nameObjc: + return "source.lang.name.kind.objc" + case .nameSwift: + return "source.lang.name.kind.swift" + case .keyword: + return "source.lang.swift.syntaxtype.keyword" + case .identifier: + return "source.lang.swift.syntaxtype.identifier" + case .typeIdentifier: + return "source.lang.swift.syntaxtype.typeidentifier" + case .buildConfigKeyword: + return "source.lang.swift.syntaxtype.buildconfig.keyword" + case .buildConfigId: + return "source.lang.swift.syntaxtype.buildconfig.id" + case .attributeId: + return "source.lang.swift.syntaxtype.attribute.id" + case .attributeBuiltin: + return "source.lang.swift.syntaxtype.attribute.builtin" + case .number: + return "source.lang.swift.syntaxtype.number" + case .string: + return "source.lang.swift.syntaxtype.string" + case .stringInterpolation: + return "source.lang.swift.syntaxtype.string_interpolation_anchor" + case .comment: + return "source.lang.swift.syntaxtype.comment" + case .docComment: + return "source.lang.swift.syntaxtype.doccomment" + case .docCommentField: + return "source.lang.swift.syntaxtype.doccomment.field" + case .commentMarker: + return "source.lang.swift.syntaxtype.comment.mark" + case .commentURL: + return "source.lang.swift.syntaxtype.comment.url" + case .placeholder: + return "source.lang.swift.syntaxtype.placeholder" + case .objectLiteral: + return "source.lang.swift.syntaxtype.objectliteral" + case .expr: + return "source.lang.swift.expr" + case .stmt: + return "source.lang.swift.stmt" + case .type: + return "source.lang.swift.type" + case .forEachSequence: + return "source.lang.swift.foreach.sequence" + case .diagNote: + return "source.diagnostic.severity.note" + case .diagWarning: + return "source.diagnostic.severity.warning" + case .diagError: + return "source.diagnostic.severity.error" + case .codeCompletionEverything: + return "source.codecompletion.everything" + case .codeCompletionModule: + return "source.codecompletion.module" + case .codeCompletionKeyword: + return "source.codecompletion.keyword" + case .codeCompletionLiteral: + return "source.codecompletion.literal" + case .codeCompletionCustom: + return "source.codecompletion.custom" + case .codeCompletionIdentifier: + return "source.codecompletion.identifier" + case .codeCompletionDescription: + return "source.codecompletion.description" + case .editActive: + return "source.edit.kind.active" + case .editInactive: + return "source.edit.kind.inactive" + case .editSelector: + return "source.edit.kind.selector" + case .editString: + return "source.edit.kind.string" + case .editComment: + return "source.edit.kind.comment" + case .editMismatch: + return "source.edit.kind.mismatch" + case .editUnknown: + return "source.edit.kind.unknown" + case .renameRangeBase: + return "source.refactoring.range.kind.basename" + case .renameRangeKeywordBase: + return "source.refactoring.range.kind.keyword-basename" + case .renameRangeParam: + return "source.refactoring.range.kind.parameter-and-whitespace" + case .renameRangeDeclArgLabel: + return "source.refactoring.range.kind.decl-argument-label" + case .renameRangeCallArgLabel: + return "source.refactoring.range.kind.call-argument-label" + case .renameRangeCallArgColon: + return "source.refactoring.range.kind.call-argument-colon" + case .renameRangeCallArgCombined: + return "source.refactoring.range.kind.call-argument-combined" + case .renameRangeSelectorArgLabel: + return "source.refactoring.range.kind.selector-argument-label" + case .definition: + return "source.syntacticrename.definition" + case .reference: + return "source.syntacticrename.reference" + case .call: + return "source.syntacticrename.call" + case .unknown: + return "source.syntacticrename.unknown" + case let .unrecognized(string): + return string + } + } + } + + public enum Request { + case protocolVersion + case crashWithExit + case demangle + case mangleSimpleClass + case index + case docInfo + case codeComplete + case codeCompleteOpen + case codeCompleteClose + case codeCompleteUpdate + case codeCompleteCacheOnDisk + case codeCompleteSetPopularAPI + case codeCompleteSetCustom + case cursorInfo + case rangeInfo + case relatedIdents + case editorOpen + case editorOpenInterface + case editorOpenHeaderInterface + case editorOpenSwiftSourceInterface + case editorOpenSwiftTypeInterface + case editorExtractTextFromComment + case editorClose + case editorReplaceText + case editorFormatText + case editorExpandPlaceholder + case editorFindUSR + case editorFindInterfaceDoc + case buildSettingsRegister + case moduleGroups + case nameTranslation + case markupToXML + case syntacticRename + case findRenameRanges + case findLocalRenameRanges + case semanticRefactoring + case unrecognized(String) + + public init(string: String) { + switch string { + case "source.request.protocol_version": + self = .protocolVersion + case "source.request.crash_exit": + self = .crashWithExit + case "source.request.demangle": + self = .demangle + case "source.request.mangle_simple_class": + self = .mangleSimpleClass + case "source.request.indexsource": + self = .index + case "source.request.docinfo": + self = .docInfo + case "source.request.codecomplete": + self = .codeComplete + case "source.request.codecomplete.open": + self = .codeCompleteOpen + case "source.request.codecomplete.close": + self = .codeCompleteClose + case "source.request.codecomplete.update": + self = .codeCompleteUpdate + case "source.request.codecomplete.cache.ondisk": + self = .codeCompleteCacheOnDisk + case "source.request.codecomplete.setpopularapi": + self = .codeCompleteSetPopularAPI + case "source.request.codecomplete.setcustom": + self = .codeCompleteSetCustom + case "source.request.cursorinfo": + self = .cursorInfo + case "source.request.rangeinfo": + self = .rangeInfo + case "source.request.relatedidents": + self = .relatedIdents + case "source.request.editor.open": + self = .editorOpen + case "source.request.editor.open.interface": + self = .editorOpenInterface + case "source.request.editor.open.interface.header": + self = .editorOpenHeaderInterface + case "source.request.editor.open.interface.swiftsource": + self = .editorOpenSwiftSourceInterface + case "source.request.editor.open.interface.swifttype": + self = .editorOpenSwiftTypeInterface + case "source.request.editor.extract.comment": + self = .editorExtractTextFromComment + case "source.request.editor.close": + self = .editorClose + case "source.request.editor.replacetext": + self = .editorReplaceText + case "source.request.editor.formattext": + self = .editorFormatText + case "source.request.editor.expand_placeholder": + self = .editorExpandPlaceholder + case "source.request.editor.find_usr": + self = .editorFindUSR + case "source.request.editor.find_interface_doc": + self = .editorFindInterfaceDoc + case "source.request.buildsettings.register": + self = .buildSettingsRegister + case "source.request.module.groups": + self = .moduleGroups + case "source.request.name.translation": + self = .nameTranslation + case "source.request.convert.markup.xml": + self = .markupToXML + case "source.request.syntacticrename": + self = .syntacticRename + case "source.request.find-syntactic-rename-ranges": + self = .findRenameRanges + case "source.request.find-local-rename-ranges": + self = .findLocalRenameRanges + case "source.request.semantic.refactoring": + self = .semanticRefactoring + default: + self = .unrecognized(string) + } + } + + public var stringRepresentation: String { + switch self { + case .protocolVersion: + return "source.request.protocol_version" + case .crashWithExit: + return "source.request.crash_exit" + case .demangle: + return "source.request.demangle" + case .mangleSimpleClass: + return "source.request.mangle_simple_class" + case .index: + return "source.request.indexsource" + case .docInfo: + return "source.request.docinfo" + case .codeComplete: + return "source.request.codecomplete" + case .codeCompleteOpen: + return "source.request.codecomplete.open" + case .codeCompleteClose: + return "source.request.codecomplete.close" + case .codeCompleteUpdate: + return "source.request.codecomplete.update" + case .codeCompleteCacheOnDisk: + return "source.request.codecomplete.cache.ondisk" + case .codeCompleteSetPopularAPI: + return "source.request.codecomplete.setpopularapi" + case .codeCompleteSetCustom: + return "source.request.codecomplete.setcustom" + case .cursorInfo: + return "source.request.cursorinfo" + case .rangeInfo: + return "source.request.rangeinfo" + case .relatedIdents: + return "source.request.relatedidents" + case .editorOpen: + return "source.request.editor.open" + case .editorOpenInterface: + return "source.request.editor.open.interface" + case .editorOpenHeaderInterface: + return "source.request.editor.open.interface.header" + case .editorOpenSwiftSourceInterface: + return "source.request.editor.open.interface.swiftsource" + case .editorOpenSwiftTypeInterface: + return "source.request.editor.open.interface.swifttype" + case .editorExtractTextFromComment: + return "source.request.editor.extract.comment" + case .editorClose: + return "source.request.editor.close" + case .editorReplaceText: + return "source.request.editor.replacetext" + case .editorFormatText: + return "source.request.editor.formattext" + case .editorExpandPlaceholder: + return "source.request.editor.expand_placeholder" + case .editorFindUSR: + return "source.request.editor.find_usr" + case .editorFindInterfaceDoc: + return "source.request.editor.find_interface_doc" + case .buildSettingsRegister: + return "source.request.buildsettings.register" + case .moduleGroups: + return "source.request.module.groups" + case .nameTranslation: + return "source.request.name.translation" + case .markupToXML: + return "source.request.convert.markup.xml" + case .syntacticRename: + return "source.request.syntacticrename" + case .findRenameRanges: + return "source.request.find-syntactic-rename-ranges" + case .findLocalRenameRanges: + return "source.request.find-local-rename-ranges" + case .semanticRefactoring: + return "source.request.semantic.refactoring" + case let .unrecognized(string): + return string + } + } + } +} + +public extension SourceKitDef.Key { + public static let count: Int = 134 +} + +public extension SourceKitDef.Kind { + public static let count: Int = 146 +} + +public extension SourceKitDef.Request { + public static let count: Int = 36 +} diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index 7e18fd776..93da5dc62 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -12,5 +12,6 @@ XCTMain([ testCase(StringTests.allTests), testCase(StructureTests.allTests), testCase(SwiftDocsTests.allTests), - testCase(SyntaxTests.allTests) + testCase(SyntaxTests.allTests), + testCase(RequestTests.allTests) ]) diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/ProtocolVersion.json b/Tests/SourceKittenFrameworkTests/Fixtures/ProtocolVersion.json new file mode 100644 index 000000000..f61272de9 --- /dev/null +++ b/Tests/SourceKittenFrameworkTests/Fixtures/ProtocolVersion.json @@ -0,0 +1,4 @@ +{ + "key.version_major" : 1, + "key.version_minor" : 0 +} \ No newline at end of file diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/SwiftAssertInterface.json b/Tests/SourceKittenFrameworkTests/Fixtures/SwiftAssertInterface.json new file mode 100644 index 000000000..c0eeb065f --- /dev/null +++ b/Tests/SourceKittenFrameworkTests/Fixtures/SwiftAssertInterface.json @@ -0,0 +1,1346 @@ +{ + "key.annotations" : [ + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 1476, + "key.length" : 4, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 1512, + "key.length" : 6, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 1536, + "key.length" : 12, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 1564, + "key.length" : 4, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 3004, + "key.length" : 4, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 3040, + "key.length" : 6, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 3064, + "key.length" : 12, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 3092, + "key.length" : 4, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 4405, + "key.length" : 6, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 4429, + "key.length" : 12, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 4457, + "key.length" : 4, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 5653, + "key.length" : 6, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 5677, + "key.length" : 12, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 5705, + "key.length" : 4, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.enum", + "key.offset" : 5722, + "key.length" : 5, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 6211, + "key.length" : 6, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 6235, + "key.length" : 12, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.struct", + "key.offset" : 6263, + "key.length" : 4, + "key.is_system" : true + }, + { + "key.kind" : "source.lang.swift.ref.enum", + "key.offset" : 6280, + "key.length" : 5, + "key.is_system" : true + } + ], + "key.syntaxmap" : [ + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 0, + "key.length" : 68 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 68, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 72, + "key.length" : 80 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 152, + "key.length" : 79 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 231, + "key.length" : 59 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 290, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 294, + "key.length" : 72 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 366, + "key.length" : 72 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 438, + "key.length" : 64 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 502, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 506, + "key.length" : 70 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 576, + "key.length" : 62 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 638, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 642, + "key.length" : 79 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 721, + "key.length" : 79 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 800, + "key.length" : 49 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 849, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 853, + "key.length" : 18 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment.field", + "key.offset" : 859, + "key.length" : 10 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 871, + "key.length" : 75 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 946, + "key.length" : 41 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 987, + "key.length" : 79 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1066, + "key.length" : 36 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1102, + "key.length" : 80 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1182, + "key.length" : 70 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1252, + "key.length" : 77 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1329, + "key.length" : 77 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1406, + "key.length" : 19 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.builtin", + "key.offset" : 1425, + "key.length" : 6 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 1432, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 1437, + "key.length" : 6 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 1444, + "key.length" : 1 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 1446, + "key.length" : 9 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.id", + "key.offset" : 1457, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.builtin", + "key.offset" : 1458, + "key.length" : 11 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 1476, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 1482, + "key.length" : 1 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 1484, + "key.length" : 7 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.id", + "key.offset" : 1493, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.builtin", + "key.offset" : 1494, + "key.length" : 11 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 1512, + "key.length" : 6 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 1521, + "key.length" : 7 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 1530, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 1536, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 1551, + "key.length" : 5 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 1558, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 1564, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 1571, + "key.length" : 5 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1579, + "key.length" : 62 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1641, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1645, + "key.length" : 78 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1723, + "key.length" : 39 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1762, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1766, + "key.length" : 72 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1838, + "key.length" : 72 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1910, + "key.length" : 64 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1974, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 1978, + "key.length" : 73 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2051, + "key.length" : 64 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2115, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2119, + "key.length" : 79 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2198, + "key.length" : 79 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2277, + "key.length" : 49 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2326, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2330, + "key.length" : 18 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment.field", + "key.offset" : 2336, + "key.length" : 10 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2348, + "key.length" : 74 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2422, + "key.length" : 30 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2452, + "key.length" : 79 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2531, + "key.length" : 70 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2601, + "key.length" : 79 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2680, + "key.length" : 72 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2752, + "key.length" : 16 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2768, + "key.length" : 77 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2845, + "key.length" : 52 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 2897, + "key.length" : 50 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.builtin", + "key.offset" : 2947, + "key.length" : 6 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 2954, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 2959, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 2972, + "key.length" : 1 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 2974, + "key.length" : 9 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.id", + "key.offset" : 2985, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.builtin", + "key.offset" : 2986, + "key.length" : 11 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 3004, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 3010, + "key.length" : 1 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 3012, + "key.length" : 7 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.id", + "key.offset" : 3021, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.builtin", + "key.offset" : 3022, + "key.length" : 11 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 3040, + "key.length" : 6 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 3049, + "key.length" : 7 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 3058, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 3064, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 3079, + "key.length" : 5 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 3086, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 3092, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 3099, + "key.length" : 5 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3107, + "key.length" : 52 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3159, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3163, + "key.length" : 80 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3243, + "key.length" : 77 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3320, + "key.length" : 79 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3399, + "key.length" : 75 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3474, + "key.length" : 70 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3544, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3548, + "key.length" : 70 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3618, + "key.length" : 73 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3691, + "key.length" : 26 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3717, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3721, + "key.length" : 35 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3756, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3760, + "key.length" : 76 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3836, + "key.length" : 68 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3904, + "key.length" : 25 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3929, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3933, + "key.length" : 18 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment.field", + "key.offset" : 3939, + "key.length" : 10 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 3951, + "key.length" : 74 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4025, + "key.length" : 36 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4061, + "key.length" : 77 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4138, + "key.length" : 58 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4196, + "key.length" : 80 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4276, + "key.length" : 70 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.builtin", + "key.offset" : 4346, + "key.length" : 6 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 4353, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 4358, + "key.length" : 16 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 4375, + "key.length" : 1 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 4377, + "key.length" : 7 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.id", + "key.offset" : 4386, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.builtin", + "key.offset" : 4387, + "key.length" : 11 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 4405, + "key.length" : 6 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 4414, + "key.length" : 7 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 4423, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 4429, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 4444, + "key.length" : 5 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 4451, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 4457, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 4464, + "key.length" : 5 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4472, + "key.length" : 48 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4520, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4524, + "key.length" : 79 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4603, + "key.length" : 71 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4674, + "key.length" : 38 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4712, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4716, + "key.length" : 72 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4788, + "key.length" : 74 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4862, + "key.length" : 26 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4888, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4892, + "key.length" : 76 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4968, + "key.length" : 25 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4993, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 4997, + "key.length" : 78 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5075, + "key.length" : 68 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5143, + "key.length" : 25 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5168, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5172, + "key.length" : 18 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment.field", + "key.offset" : 5178, + "key.length" : 10 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5190, + "key.length" : 74 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5264, + "key.length" : 36 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5300, + "key.length" : 77 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5377, + "key.length" : 61 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5438, + "key.length" : 80 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5518, + "key.length" : 73 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.builtin", + "key.offset" : 5591, + "key.length" : 6 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 5598, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 5603, + "key.length" : 19 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 5623, + "key.length" : 1 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 5625, + "key.length" : 7 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.id", + "key.offset" : 5634, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.builtin", + "key.offset" : 5635, + "key.length" : 11 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 5653, + "key.length" : 6 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 5662, + "key.length" : 7 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 5671, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 5677, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 5692, + "key.length" : 5 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 5699, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 5705, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 5712, + "key.length" : 5 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 5722, + "key.length" : 5 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5729, + "key.length" : 64 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5793, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5797, + "key.length" : 18 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment.field", + "key.offset" : 5803, + "key.length" : 10 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5815, + "key.length" : 70 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5885, + "key.length" : 77 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 5962, + "key.length" : 52 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 6014, + "key.length" : 80 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.doccomment", + "key.offset" : 6094, + "key.length" : 64 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.builtin", + "key.offset" : 6158, + "key.length" : 6 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 6165, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 6170, + "key.length" : 10 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 6181, + "key.length" : 1 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 6183, + "key.length" : 7 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.id", + "key.offset" : 6192, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.attribute.builtin", + "key.offset" : 6193, + "key.length" : 11 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 6211, + "key.length" : 6 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 6220, + "key.length" : 7 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 6229, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 6235, + "key.length" : 12 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 6250, + "key.length" : 5 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.identifier", + "key.offset" : 6257, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 6263, + "key.length" : 4 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.keyword", + "key.offset" : 6270, + "key.length" : 5 + }, + { + "key.kind" : "source.lang.swift.syntaxtype.typeidentifier", + "key.offset" : 6280, + "key.length" : 5 + } + ], + "key.substructure" : [ + { + "key.nameoffset" : 1437, + "key.accessibility" : "source.lang.swift.accessibility.public", + "key.length" : 145, + "key.substructure" : [ + { + "key.nameoffset" : 0, + "key.typename" : "@autoclosure () -> Bool", + "key.length" : 36, + "key.name" : "condition", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 1444, + "key.namelength" : 0 + }, + { + "key.nameoffset" : 0, + "key.typename" : "@autoclosure () -> String", + "key.length" : 36, + "key.name" : "message", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 1482, + "key.namelength" : 0 + }, + { + "key.nameoffset" : 1530, + "key.typename" : "StaticString", + "key.length" : 26, + "key.name" : "file", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 1530, + "key.namelength" : 4 + }, + { + "key.nameoffset" : 1558, + "key.typename" : "UInt", + "key.length" : 18, + "key.name" : "line", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 1558, + "key.namelength" : 4 + } + ], + "key.name" : "assert(_:_:file:line:)", + "key.kind" : "source.lang.swift.decl.function.free", + "key.namelength" : 140, + "key.offset" : 1432 + }, + { + "key.nameoffset" : 2959, + "key.accessibility" : "source.lang.swift.accessibility.public", + "key.length" : 151, + "key.substructure" : [ + { + "key.nameoffset" : 0, + "key.typename" : "@autoclosure () -> Bool", + "key.length" : 36, + "key.name" : "condition", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 2972, + "key.namelength" : 0 + }, + { + "key.nameoffset" : 0, + "key.typename" : "@autoclosure () -> String", + "key.length" : 36, + "key.name" : "message", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 3010, + "key.namelength" : 0 + }, + { + "key.nameoffset" : 3058, + "key.typename" : "StaticString", + "key.length" : 26, + "key.name" : "file", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 3058, + "key.namelength" : 4 + }, + { + "key.nameoffset" : 3086, + "key.typename" : "UInt", + "key.length" : 18, + "key.name" : "line", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 3086, + "key.namelength" : 4 + } + ], + "key.name" : "precondition(_:_:file:line:)", + "key.kind" : "source.lang.swift.decl.function.free", + "key.namelength" : 146, + "key.offset" : 2954 + }, + { + "key.nameoffset" : 4358, + "key.accessibility" : "source.lang.swift.accessibility.public", + "key.length" : 117, + "key.substructure" : [ + { + "key.nameoffset" : 0, + "key.typename" : "@autoclosure () -> String", + "key.length" : 36, + "key.name" : "message", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 4375, + "key.namelength" : 0 + }, + { + "key.nameoffset" : 4423, + "key.typename" : "StaticString", + "key.length" : 26, + "key.name" : "file", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 4423, + "key.namelength" : 4 + }, + { + "key.nameoffset" : 4451, + "key.typename" : "UInt", + "key.length" : 18, + "key.name" : "line", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 4451, + "key.namelength" : 4 + } + ], + "key.name" : "assertionFailure(_:file:line:)", + "key.kind" : "source.lang.swift.decl.function.free", + "key.namelength" : 112, + "key.offset" : 4353 + }, + { + "key.nameoffset" : 5603, + "key.accessibility" : "source.lang.swift.accessibility.public", + "key.length" : 129, + "key.substructure" : [ + { + "key.nameoffset" : 0, + "key.typename" : "@autoclosure () -> String", + "key.length" : 36, + "key.name" : "message", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 5623, + "key.namelength" : 0 + }, + { + "key.nameoffset" : 5671, + "key.typename" : "StaticString", + "key.length" : 26, + "key.name" : "file", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 5671, + "key.namelength" : 4 + }, + { + "key.nameoffset" : 5699, + "key.typename" : "UInt", + "key.length" : 18, + "key.name" : "line", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 5699, + "key.namelength" : 4 + } + ], + "key.name" : "preconditionFailure(_:file:line:)", + "key.kind" : "source.lang.swift.decl.function.free", + "key.namelength" : 115, + "key.offset" : 5598 + }, + { + "key.nameoffset" : 6170, + "key.accessibility" : "source.lang.swift.accessibility.public", + "key.length" : 120, + "key.substructure" : [ + { + "key.nameoffset" : 0, + "key.typename" : "@autoclosure () -> String", + "key.length" : 36, + "key.name" : "message", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 6181, + "key.namelength" : 0 + }, + { + "key.nameoffset" : 6229, + "key.typename" : "StaticString", + "key.length" : 26, + "key.name" : "file", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 6229, + "key.namelength" : 4 + }, + { + "key.nameoffset" : 6257, + "key.typename" : "UInt", + "key.length" : 18, + "key.name" : "line", + "key.kind" : "source.lang.swift.decl.var.parameter", + "key.offset" : 6257, + "key.namelength" : 4 + } + ], + "key.name" : "fatalError(_:file:line:)", + "key.kind" : "source.lang.swift.decl.function.free", + "key.namelength" : 106, + "key.offset" : 6165 + } + ], + "key.sourcetext" : "\/\/\/ Performs a traditional C-style assert with an optional message.\n\/\/\/\n\/\/\/ Use this function for internal sanity checks that are active during testing\n\/\/\/ but do not impact performance of shipping code. To check for invalid usage\n\/\/\/ in Release builds, see `precondition(_:_:file:line:)`.\n\/\/\/\n\/\/\/ * In playgrounds and `-Onone` builds (the default for Xcode's Debug\n\/\/\/ configuration): If `condition` evaluates to `false`, stop program\n\/\/\/ execution in a debuggable state after printing `message`.\n\/\/\/\n\/\/\/ * In `-O` builds (the default for Xcode's Release configuration),\n\/\/\/ `condition` is not evaluated, and there are no effects.\n\/\/\/\n\/\/\/ * In `-Ounchecked` builds, `condition` is not evaluated, but the optimizer\n\/\/\/ may assume that it *always* evaluates to `true`. Failure to satisfy that\n\/\/\/ assumption is a serious programming error.\n\/\/\/\n\/\/\/ - Parameters:\n\/\/\/ - condition: The condition to test. `condition` is only evaluated in\n\/\/\/ playgrounds and `-Onone` builds.\n\/\/\/ - message: A string to print if `condition` is evaluated to `false`. The\n\/\/\/ default is an empty string.\n\/\/\/ - file: The file name to print with `message` if the assertion fails. The\n\/\/\/ default is the file where `assert(_:_:file:line:)` is called.\n\/\/\/ - line: The line number to print along with `message` if the assertion\n\/\/\/ fails. The default is the line number where `assert(_:_:file:line:)`\n\/\/\/ is called.\npublic func assert(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = default, file: StaticString = #file, line: UInt = #line)\n\n\/\/\/ Checks a necessary condition for making forward progress.\n\/\/\/\n\/\/\/ Use this function to detect conditions that must prevent the program from\n\/\/\/ proceeding, even in shipping code.\n\/\/\/\n\/\/\/ * In playgrounds and `-Onone` builds (the default for Xcode's Debug\n\/\/\/ configuration): If `condition` evaluates to `false`, stop program\n\/\/\/ execution in a debuggable state after printing `message`.\n\/\/\/\n\/\/\/ * In `-O` builds (the default for Xcode's Release configuration): If\n\/\/\/ `condition` evaluates to `false`, stop program execution.\n\/\/\/\n\/\/\/ * In `-Ounchecked` builds, `condition` is not evaluated, but the optimizer\n\/\/\/ may assume that it *always* evaluates to `true`. Failure to satisfy that\n\/\/\/ assumption is a serious programming error.\n\/\/\/\n\/\/\/ - Parameters:\n\/\/\/ - condition: The condition to test. `condition` is not evaluated in\n\/\/\/ `-Ounchecked` builds.\n\/\/\/ - message: A string to print if `condition` is evaluated to `false` in a\n\/\/\/ playground or `-Onone` build. The default is an empty string.\n\/\/\/ - file: The file name to print with `message` if the precondition fails.\n\/\/\/ The default is the file where `precondition(_:_:file:line:)` is\n\/\/\/ called.\n\/\/\/ - line: The line number to print along with `message` if the assertion\n\/\/\/ fails. The default is the line number where\n\/\/\/ `precondition(_:_:file:line:)` is called.\npublic func precondition(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = default, file: StaticString = #file, line: UInt = #line)\n\n\/\/\/ Indicates that an internal sanity check failed.\n\/\/\/\n\/\/\/ Use this function to stop the program, without impacting the performance of\n\/\/\/ shipping code, when control flow is not expected to reach the call---for\n\/\/\/ example, in the `default` case of a `switch` where you have knowledge that\n\/\/\/ one of the other cases must be satisfied. To protect code from invalid\n\/\/\/ usage in Release builds, see `preconditionFailure(_:file:line:)`.\n\/\/\/\n\/\/\/ * In playgrounds and -Onone builds (the default for Xcode's Debug\n\/\/\/ configuration), stop program execution in a debuggable state after\n\/\/\/ printing `message`.\n\/\/\/\n\/\/\/ * In -O builds, has no effect.\n\/\/\/\n\/\/\/ * In -Ounchecked builds, the optimizer may assume that this function is\n\/\/\/ never called. Failure to satisfy that assumption is a serious\n\/\/\/ programming error.\n\/\/\/\n\/\/\/ - Parameters:\n\/\/\/ - message: A string to print in a playground or `-Onone` build. The\n\/\/\/ default is an empty string.\n\/\/\/ - file: The file name to print with `message`. The default is the file\n\/\/\/ where `assertionFailure(_:file:line:)` is called.\n\/\/\/ - line: The line number to print along with `message`. The default is the\n\/\/\/ line number where `assertionFailure(_:file:line:)` is called.\npublic func assertionFailure(_ message: @autoclosure () -> String = default, file: StaticString = #file, line: UInt = #line)\n\n\/\/\/ Indicates that a precondition was violated.\n\/\/\/\n\/\/\/ Use this function to stop the program when control flow can only reach the\n\/\/\/ call if your API was improperly used. This function's effects vary\n\/\/\/ depending on the build flag used:\n\/\/\/\n\/\/\/ * In playgrounds and `-Onone` builds (the default for Xcode's Debug\n\/\/\/ configuration), stops program execution in a debuggable state after\n\/\/\/ printing `message`.\n\/\/\/\n\/\/\/ * In `-O` builds (the default for Xcode's Release configuration), stops\n\/\/\/ program execution.\n\/\/\/\n\/\/\/ * In `-Ounchecked` builds, the optimizer may assume that this function is\n\/\/\/ never called. Failure to satisfy that assumption is a serious\n\/\/\/ programming error.\n\/\/\/\n\/\/\/ - Parameters:\n\/\/\/ - message: A string to print in a playground or `-Onone` build. The\n\/\/\/ default is an empty string.\n\/\/\/ - file: The file name to print with `message`. The default is the file\n\/\/\/ where `preconditionFailure(_:file:line:)` is called.\n\/\/\/ - line: The line number to print along with `message`. The default is the\n\/\/\/ line number where `preconditionFailure(_:file:line:)` is called.\npublic func preconditionFailure(_ message: @autoclosure () -> String = default, file: StaticString = #file, line: UInt = #line) -> Never\n\n\/\/\/ Unconditionally prints a given message and stops execution.\n\/\/\/\n\/\/\/ - Parameters:\n\/\/\/ - message: The string to print. The default is an empty string.\n\/\/\/ - file: The file name to print with `message`. The default is the file\n\/\/\/ where `fatalError(_:file:line:)` is called.\n\/\/\/ - line: The line number to print along with `message`. The default is the\n\/\/\/ line number where `fatalError(_:file:line:)` is called.\npublic func fatalError(_ message: @autoclosure () -> String = default, file: StaticString = #file, line: UInt = #line) -> Never\n\n" +} \ No newline at end of file diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups.json b/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups.json new file mode 100644 index 000000000..6074ce39b --- /dev/null +++ b/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups.json @@ -0,0 +1,58 @@ +{ + "key.modulegroups" : [ + { + "key.groupname" : "Assert" + }, + { + "key.groupname" : "Bool" + }, + { + "key.groupname" : "C" + }, + { + "key.groupname" : "Collection" + }, + { + "key.groupname" : "Collection\/Array" + }, + { + "key.groupname" : "Collection\/HashedCollections" + }, + { + "key.groupname" : "Collection\/Lazy Views" + }, + { + "key.groupname" : "Collection\/Type-erased" + }, + { + "key.groupname" : "KeyPaths" + }, + { + "key.groupname" : "Math" + }, + { + "key.groupname" : "Math\/Floating" + }, + { + "key.groupname" : "Math\/Integers" + }, + { + "key.groupname" : "Misc" + }, + { + "key.groupname" : "Optional" + }, + { + "key.groupname" : "Pointer" + }, + { + "key.groupname" : "Protocols" + }, + { + "key.groupname" : "Reflection" + }, + { + "key.groupname" : "String" + } + ] +} \ No newline at end of file diff --git a/Tests/SourceKittenFrameworkTests/RequestTests.swift b/Tests/SourceKittenFrameworkTests/RequestTests.swift new file mode 100644 index 000000000..a70b2369b --- /dev/null +++ b/Tests/SourceKittenFrameworkTests/RequestTests.swift @@ -0,0 +1,66 @@ +// +// RequestTests.swift +// SourceKittenFrameworkTests +// +// Created by Zheng Li on 05/10/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation +import SourceKittenFramework +import XCTest + +class RequestTests: XCTestCase { + func testProtocolVersion() { + let version = Request.protocolVersion().send() + compareJSONString(withFixtureNamed: "ProtocolVersion", jsonString: toJSON(toNSDictionary(version))) + } + + func testSwiftModuleGroups() { + let groups = Request.moduleGroups(module: "Swift", arguments: ["-sdk", sdkPath()]).send() + compareJSONString(withFixtureNamed: "SwiftModuleGroups", jsonString: toJSON(toNSDictionary(groups))) + } + + func testDemangle() { + let mangledNames = [ + "_T0SSD", + "_T0SC7NSRangeamD", + "_T0So7ProcessCD", + "_T021SourceKittenFramework7RequestOD", + "_T0s10DictionaryVySS9Structure22SourceKitRepresentable_pGD" + ] + + let expectedResult: NSDictionary = [ + "key.results": [ + ["key.name": "Swift.String"], + ["key.name": "__C.NSRange.Type"], + ["key.name": "__ObjC.Process"], + ["key.name": "SourceKittenFramework.Request"], + ["key.name": "Swift.Dictionary"] + ] + ] + let result = Request.demangle(names: mangledNames).send() + XCTAssertEqual(toNSDictionary(result), expectedResult, "should demange names.") + } + + func testEditorOpenInterface() { + let result = Request.editorOpenInterface( + name: UUID().uuidString, + moduleName: "Swift", + group: .name("Assert"), // Choose a relative small group. + synthesizedExtension: true, + arguments: ["-sdk", sdkPath()] + ).send() + compareJSONString(withFixtureNamed: "SwiftAssertInterface", jsonString: toJSON(toNSDictionary(result))) + } +} + +extension RequestTests { + static var allTests: [(String, (RequestTests) -> () throws -> Void)] { + return [ + ("testProtocolVersion", testProtocolVersion), + ("testSwiftModuleGroups", testSwiftModuleGroups), + ("testEditorOpenInterface", testEditorOpenInterface) + ] + } +} diff --git a/Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift b/Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift index 64d1cd8e8..4cf20a488 100644 --- a/Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift +++ b/Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift @@ -13,6 +13,7 @@ import XCTest func compareJSONString(withFixtureNamed name: String, jsonString: CustomStringConvertible, rootDirectory: String = fixturesDirectory, + overwrite: Bool = false, file: StaticString = #file, line: UInt = #line) { #if os(Linux) @@ -32,7 +33,6 @@ func compareJSONString(withFixtureNamed name: String, let expectedFile = File(path: versionedExpectedFilename(for: name))! - let overwrite = false if overwrite && actualContent != expectedFile.contents { _ = try? actualContent.data(using: .utf8)?.write(to: URL(fileURLWithPath: expectedFile.path!), options: []) return diff --git a/sourcekitten.xcodeproj/project.pbxproj b/sourcekitten.xcodeproj/project.pbxproj index 0a5a4d08e..f7573b0b0 100644 --- a/sourcekitten.xcodeproj/project.pbxproj +++ b/sourcekitten.xcodeproj/project.pbxproj @@ -23,6 +23,9 @@ 6CCFCE8C1CFECFF1003239EB /* Yams.framework in Embed Frameworks into SourceKittenFramework.framework */ = {isa = PBXBuildFile; fileRef = E80678041CF2749300AFC816 /* Yams.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 6CCFCE8E1CFED000003239EB /* Commandant.framework in Embed Frameworks into SourceKittenFramework.framework */ = {isa = PBXBuildFile; fileRef = E8EBAA5D1A5D374B002F1B8E /* Commandant.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 6CCFCE901CFED005003239EB /* Result.framework in Embed Frameworks into SourceKittenFramework.framework */ = {isa = PBXBuildFile; fileRef = E834D61D1B2D054B002AA1FE /* Result.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 861E9D431F87574A001F182C /* SourceKitDef.swift in Sources */ = {isa = PBXBuildFile; fileRef = 861E9D421F87574A001F182C /* SourceKitDef.swift */; }; + 866176221F85F31B00B9DF14 /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 866176211F85F31B00B9DF14 /* RequestTests.swift */; }; + 866EDB011F87C79E00EC198A /* RequestBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 866EDAFF1F87C74600EC198A /* RequestBuilder.swift */; }; B2FA87E26BC9C5F774FD694C /* SwiftLangSyntax.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2FA804AA9D4427FF571EFB2 /* SwiftLangSyntax.swift */; }; C236E84B1DFF5120003807D2 /* YamlRequestCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C236E84A1DFF5120003807D2 /* YamlRequestCommand.swift */; }; D0AAAB5019FB0960007B24B3 /* SourceKittenFramework.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D0D1216D19E87B05005E4BAA /* SourceKittenFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -144,6 +147,9 @@ 6C7F0A841EDB0AAD008EC581 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; 6CC381621ECACB50000C6F81 /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = ""; }; 6CFC18F01C7F2FB900CD70E1 /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; + 861E9D421F87574A001F182C /* SourceKitDef.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceKitDef.swift; sourceTree = ""; }; + 866176211F85F31B00B9DF14 /* RequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestTests.swift; sourceTree = ""; }; + 866EDAFF1F87C74600EC198A /* RequestBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestBuilder.swift; sourceTree = ""; }; B2FA804AA9D4427FF571EFB2 /* SwiftLangSyntax.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftLangSyntax.swift; sourceTree = ""; }; C236E84A1DFF5120003807D2 /* YamlRequestCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YamlRequestCommand.swift; sourceTree = ""; }; D0D1211B19E87861005E4BAA /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; usesTabs = 0; }; @@ -384,6 +390,7 @@ isa = PBXGroup; children = ( E86F588D1C4DC49000426E78 /* sourcekitd.h */, + 861E9D421F87574A001F182C /* SourceKitDef.swift */, E8D4742B1A648ED10011A49C /* clang-c */, D0D1216F19E87B05005E4BAA /* Supporting Files */, 3F0CBB401BAAFF160015BBA8 /* Clang+SourceKitten.swift */, @@ -421,6 +428,7 @@ 6CC381621ECACB50000C6F81 /* Version.swift */, E8A9B88F1B56CB5500CD17D4 /* Xcode.swift */, B2FA804AA9D4427FF571EFB2 /* SwiftLangSyntax.swift */, + 866EDAFF1F87C74600EC198A /* RequestBuilder.swift */, ); name = SourceKittenFramework; path = Source/SourceKittenFramework; @@ -454,6 +462,7 @@ E8C9EA031A5C986A00A6D4D1 /* StructureTests.swift */, E80F23661A5CADD900FD2352 /* SwiftDocsTests.swift */, D0DB09A319EA354200234B16 /* SyntaxTests.swift */, + 866176211F85F31B00B9DF14 /* RequestTests.swift */, ); name = SourceKittenFrameworkTests; path = Tests/SourceKittenFrameworkTests; @@ -660,6 +669,7 @@ E82882541DAEEDD1002E0564 /* LinuxCompatibility.swift in Sources */, E806D2931BE058D600D1BE41 /* Documentation.swift in Sources */, 3F0CBB411BAAFF160015BBA8 /* Clang+SourceKitten.swift in Sources */, + 866EDB011F87C79E00EC198A /* RequestBuilder.swift in Sources */, 2E8FF7101C6268C100F280F0 /* StatementKind.swift in Sources */, 6C4CF6551C798086008532C5 /* library_wrapper_Documentation.swift in Sources */, E8D4743B1A648F290011A49C /* ClangTranslationUnit.swift in Sources */, @@ -667,6 +677,7 @@ E852418F1A5F4FB3007099FB /* Dictionary+Merge.swift in Sources */, 6CC381641ECACB6F000C6F81 /* Version.swift in Sources */, E847636A1A5A0651000EAE22 /* File.swift in Sources */, + 861E9D431F87574A001F182C /* SourceKitDef.swift in Sources */, 6C4CF5771C78B47F008532C5 /* library_wrapper.swift in Sources */, 3F56EAD01BAB251C006433D0 /* JSONOutput.swift in Sources */, E8A18A3B1A58971D000362B7 /* Language.swift in Sources */, @@ -703,6 +714,7 @@ E805A04A1B560FCA00EA654A /* FileTests.swift in Sources */, E8241CA31A5E01840047687E /* ModuleTests.swift in Sources */, 3DEF4C591DBF9C2D00B3B54A /* DocInfoTests.swift in Sources */, + 866176221F85F31B00B9DF14 /* RequestTests.swift in Sources */, E8C9EA0A1A5C9A2900A6D4D1 /* OffsetMapTests.swift in Sources */, E805A0481B55CBAF00EA654A /* SourceKitTests.swift in Sources */, E8C9EA081A5C99C400A6D4D1 /* StringTests.swift in Sources */, From 70d8611c1442bd38efda723fae891946207e04de Mon Sep 17 00:00:00 2001 From: ainopara Date: Sat, 7 Oct 2017 00:36:03 +0800 Subject: [PATCH 02/15] Fix CI issues. --- Source/SourceKittenFramework/Request.swift | 8 +-- .../RequestBuilder.swift | 1 - .../Fixtures/LinuxSwiftModuleGroups.json | 58 +++++++++++++++++++ .../LinuxSwiftModuleGroups@swift-3.2.json | 55 ++++++++++++++++++ .../Fixtures/SwiftModuleGroups@swift-3.2.json | 55 ++++++++++++++++++ .../RequestTests.swift | 13 ++++- 6 files changed, 184 insertions(+), 6 deletions(-) create mode 100644 Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups.json create mode 100644 Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.2.json create mode 100644 Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.2.json diff --git a/Source/SourceKittenFramework/Request.swift b/Source/SourceKittenFramework/Request.swift index bddbaa578..e9c97a60e 100644 --- a/Source/SourceKittenFramework/Request.swift +++ b/Source/SourceKittenFramework/Request.swift @@ -189,7 +189,7 @@ private extension String { } } -let defaultArguments = { return ["-sdk", sdkPath()] }() +public let defaultRequestArguments = { return ["-sdk", sdkPath()] }() public protocol RequestType { func sourcekitObject() -> sourcekitd_object_t @@ -349,7 +349,7 @@ extension Request { } } - public static func editorOpen(file: File, arguments: [String] = defaultArguments) -> Request { + public static func editorOpen(file: File, arguments: [String] = defaultRequestArguments) -> Request { let name: String let source: EditorOpen.Source if let path = file.path { @@ -370,7 +370,7 @@ extension Request { enableStructure: Bool? = nil, enableDiagnostics: Bool? = nil, syntacticOnly: Bool? = nil, - arguments: [String] = defaultArguments + arguments: [String] = defaultRequestArguments ) -> Request { return Request(type: EditorOpen( name: name, @@ -425,7 +425,7 @@ extension Request { moduleName: String, group: EditorOpenInterface.Group? = nil, synthesizedExtension: Bool? = nil, - arguments: [String] = defaultArguments + arguments: [String] = defaultRequestArguments ) -> Request { return Request(type: EditorOpenInterface( name: name, diff --git a/Source/SourceKittenFramework/RequestBuilder.swift b/Source/SourceKittenFramework/RequestBuilder.swift index 3bac0ebe6..14ebc44a2 100644 --- a/Source/SourceKittenFramework/RequestBuilder.swift +++ b/Source/SourceKittenFramework/RequestBuilder.swift @@ -85,4 +85,3 @@ private func transform(any: Any) -> sourcekitd_object_t { fatalError("RequestBuilder: Unsupported value type: \(type(of: any)) value: \(any)") } } - diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups.json b/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups.json new file mode 100644 index 000000000..82fa1e998 --- /dev/null +++ b/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups.json @@ -0,0 +1,58 @@ +{ + "key.modulegroups" : [ + { + "key.groupname" : "Assert" + }, + { + "key.groupname" : "Bool" + }, + { + "key.groupname" : "C" + }, + { + "key.groupname" : "Collection" + }, + { + "key.groupname" : "Collection/Array" + }, + { + "key.groupname" : "Collection/HashedCollections" + }, + { + "key.groupname" : "Collection/Lazy Views" + }, + { + "key.groupname" : "Collection/Type-erased" + }, + { + "key.groupname" : "KeyPaths" + }, + { + "key.groupname" : "Math" + }, + { + "key.groupname" : "Math/Floating" + }, + { + "key.groupname" : "Math/Integers" + }, + { + "key.groupname" : "Misc" + }, + { + "key.groupname" : "Optional" + }, + { + "key.groupname" : "Pointer" + }, + { + "key.groupname" : "Protocols" + }, + { + "key.groupname" : "Reflection" + }, + { + "key.groupname" : "String" + } + ] +} \ No newline at end of file diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.2.json b/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.2.json new file mode 100644 index 000000000..1f0ea2e5e --- /dev/null +++ b/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.2.json @@ -0,0 +1,55 @@ +{ + "key.modulegroups" : [ + { + "key.groupname" : "Assert" + }, + { + "key.groupname" : "Bool" + }, + { + "key.groupname" : "C" + }, + { + "key.groupname" : "Collection" + }, + { + "key.groupname" : "Collection/Array" + }, + { + "key.groupname" : "Collection/HashedCollections" + }, + { + "key.groupname" : "Collection/Lazy Views" + }, + { + "key.groupname" : "Collection/Type-erased" + }, + { + "key.groupname" : "Math" + }, + { + "key.groupname" : "Math/Floating" + }, + { + "key.groupname" : "Math/Integers" + }, + { + "key.groupname" : "Misc" + }, + { + "key.groupname" : "Optional" + }, + { + "key.groupname" : "Pointer" + }, + { + "key.groupname" : "Protocols" + }, + { + "key.groupname" : "Reflection" + }, + { + "key.groupname" : "String" + } + ] +} \ No newline at end of file diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.2.json b/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.2.json new file mode 100644 index 000000000..f9e8e53c1 --- /dev/null +++ b/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.2.json @@ -0,0 +1,55 @@ +{ + "key.modulegroups" : [ + { + "key.groupname" : "Assert" + }, + { + "key.groupname" : "Bool" + }, + { + "key.groupname" : "C" + }, + { + "key.groupname" : "Collection" + }, + { + "key.groupname" : "Collection\/Array" + }, + { + "key.groupname" : "Collection\/HashedCollections" + }, + { + "key.groupname" : "Collection\/Lazy Views" + }, + { + "key.groupname" : "Collection\/Type-erased" + }, + { + "key.groupname" : "Math" + }, + { + "key.groupname" : "Math\/Floating" + }, + { + "key.groupname" : "Math\/Integers" + }, + { + "key.groupname" : "Misc" + }, + { + "key.groupname" : "Optional" + }, + { + "key.groupname" : "Pointer" + }, + { + "key.groupname" : "Protocols" + }, + { + "key.groupname" : "Reflection" + }, + { + "key.groupname" : "String" + } + ] +} diff --git a/Tests/SourceKittenFrameworkTests/RequestTests.swift b/Tests/SourceKittenFrameworkTests/RequestTests.swift index a70b2369b..faa5c0ad7 100644 --- a/Tests/SourceKittenFrameworkTests/RequestTests.swift +++ b/Tests/SourceKittenFrameworkTests/RequestTests.swift @@ -29,7 +29,7 @@ class RequestTests: XCTestCase { "_T021SourceKittenFramework7RequestOD", "_T0s10DictionaryVySS9Structure22SourceKitRepresentable_pGD" ] - +#if swift(>=4.0) let expectedResult: NSDictionary = [ "key.results": [ ["key.name": "Swift.String"], @@ -39,6 +39,17 @@ class RequestTests: XCTestCase { ["key.name": "Swift.Dictionary"] ] ] +#else + let expectedResult: NSDictionary = [ + "key.results": [ + ["key.name": "Swift.String"], + ["key.name": "__C.NSRange with unmangled suffix \"mD\""], + ["key.name": "__ObjC.Process"], + ["key.name": "SourceKittenFramework.Request"], + ["key.name": "Swift.Dictionary"] + ] + ] +#endif let result = Request.demangle(names: mangledNames).send() XCTAssertEqual(toNSDictionary(result), expectedResult, "should demange names.") } From d5a52e76917b35e3b3f93accb8c7ac25051c6dfb Mon Sep 17 00:00:00 2001 From: ainopara Date: Sat, 7 Oct 2017 00:36:03 +0800 Subject: [PATCH 03/15] Move linux fixture to Linux folder. --- .../{LinuxSwiftModuleGroups.json => Linux/SwiftModuleGroups.json} | 0 .../SwiftModuleGroups@swift-3.2.json} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Tests/SourceKittenFrameworkTests/Fixtures/{LinuxSwiftModuleGroups.json => Linux/SwiftModuleGroups.json} (100%) rename Tests/SourceKittenFrameworkTests/Fixtures/{LinuxSwiftModuleGroups@swift-3.2.json => Linux/SwiftModuleGroups@swift-3.2.json} (100%) diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups.json b/Tests/SourceKittenFrameworkTests/Fixtures/Linux/SwiftModuleGroups.json similarity index 100% rename from Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups.json rename to Tests/SourceKittenFrameworkTests/Fixtures/Linux/SwiftModuleGroups.json diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.2.json b/Tests/SourceKittenFrameworkTests/Fixtures/Linux/SwiftModuleGroups@swift-3.2.json similarity index 100% rename from Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.2.json rename to Tests/SourceKittenFrameworkTests/Fixtures/Linux/SwiftModuleGroups@swift-3.2.json From d43550858b983890c8a37f2e166cf54ec175b9ac Mon Sep 17 00:00:00 2001 From: ainopara Date: Sat, 7 Oct 2017 01:25:45 +0800 Subject: [PATCH 04/15] Finally figure out how this works. --- ...roups@swift-3.2.json => LinuxSwiftModuleGroups@swift-3.1.json} | 0 ...iftModuleGroups.json => LinuxSwiftModuleGroups@swift-4.0.json} | 0 ...duleGroups@swift-3.2.json => SwiftModuleGroups@swift-3.1.json} | 0 .../{SwiftModuleGroups.json => SwiftModuleGroups@swift-4.0.json} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename Tests/SourceKittenFrameworkTests/Fixtures/{Linux/SwiftModuleGroups@swift-3.2.json => LinuxSwiftModuleGroups@swift-3.1.json} (100%) rename Tests/SourceKittenFrameworkTests/Fixtures/{Linux/SwiftModuleGroups.json => LinuxSwiftModuleGroups@swift-4.0.json} (100%) rename Tests/SourceKittenFrameworkTests/Fixtures/{SwiftModuleGroups@swift-3.2.json => SwiftModuleGroups@swift-3.1.json} (100%) rename Tests/SourceKittenFrameworkTests/Fixtures/{SwiftModuleGroups.json => SwiftModuleGroups@swift-4.0.json} (100%) diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/Linux/SwiftModuleGroups@swift-3.2.json b/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.1.json similarity index 100% rename from Tests/SourceKittenFrameworkTests/Fixtures/Linux/SwiftModuleGroups@swift-3.2.json rename to Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.1.json diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/Linux/SwiftModuleGroups.json b/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-4.0.json similarity index 100% rename from Tests/SourceKittenFrameworkTests/Fixtures/Linux/SwiftModuleGroups.json rename to Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-4.0.json diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.2.json b/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.1.json similarity index 100% rename from Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.2.json rename to Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.1.json diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups.json b/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-4.0.json similarity index 100% rename from Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups.json rename to Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-4.0.json From 2629b128b01268d57c3f70265023a0eb1ca355d0 Mon Sep 17 00:00:00 2001 From: ainopara Date: Sat, 7 Oct 2017 07:30:10 +0800 Subject: [PATCH 05/15] Print which version of fixture we are loading. --- Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift b/Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift index 4cf20a488..249f6c8b7 100644 --- a/Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift +++ b/Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift @@ -80,11 +80,14 @@ private func versionedExpectedFilename(for name: String) -> String { for platform in platforms { let versionedFilename = "\(fixturesDirectory)\(platform)\(name)@\(version).json" if FileManager.default.fileExists(atPath: versionedFilename) { + print("Loading \(versionedFilename)") return versionedFilename } } } - return "\(fixturesDirectory)\(name).json" + let fallbackFilename = "\(fixturesDirectory)\(name).json" + print("Loading \(fallbackFilename)") + return fallbackFilename } class SwiftDocsTests: XCTestCase { From fb1fb5f8c5ff00d1da71da6b01c67e2183a37ed3 Mon Sep 17 00:00:00 2001 From: ainopara Date: Sat, 7 Oct 2017 07:31:50 +0800 Subject: [PATCH 06/15] swift 3.2 has same output with swift 4.0 rather than swift 3.1. --- ...ups@swift-4.0.json => LinuxSwiftModuleGroups@swift-3.2.json} | 0 ...leGroups@swift-4.0.json => SwiftModuleGroups@swift-3.2.json} | 0 Tests/SourceKittenFrameworkTests/RequestTests.swift | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename Tests/SourceKittenFrameworkTests/Fixtures/{LinuxSwiftModuleGroups@swift-4.0.json => LinuxSwiftModuleGroups@swift-3.2.json} (100%) rename Tests/SourceKittenFrameworkTests/Fixtures/{SwiftModuleGroups@swift-4.0.json => SwiftModuleGroups@swift-3.2.json} (100%) diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-4.0.json b/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.2.json similarity index 100% rename from Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-4.0.json rename to Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.2.json diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-4.0.json b/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.2.json similarity index 100% rename from Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-4.0.json rename to Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.2.json diff --git a/Tests/SourceKittenFrameworkTests/RequestTests.swift b/Tests/SourceKittenFrameworkTests/RequestTests.swift index faa5c0ad7..cc47c2c11 100644 --- a/Tests/SourceKittenFrameworkTests/RequestTests.swift +++ b/Tests/SourceKittenFrameworkTests/RequestTests.swift @@ -29,7 +29,7 @@ class RequestTests: XCTestCase { "_T021SourceKittenFramework7RequestOD", "_T0s10DictionaryVySS9Structure22SourceKitRepresentable_pGD" ] -#if swift(>=4.0) +#if swift(>=3.2) let expectedResult: NSDictionary = [ "key.results": [ ["key.name": "Swift.String"], From e17c51db2250ea05658075cd8d3440d2c0bcd01e Mon Sep 17 00:00:00 2001 From: ainopara Date: Sat, 7 Oct 2017 07:42:16 +0800 Subject: [PATCH 07/15] Side effect should be placed in `compareJSONString` rather than `versionedExpectedFilename`. --- Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift b/Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift index 249f6c8b7..3d38ce790 100644 --- a/Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift +++ b/Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift @@ -31,7 +31,9 @@ func compareJSONString(withFixtureNamed name: String, withTemplate: "\"key\\.filepath\" : \"\",") #endif - let expectedFile = File(path: versionedExpectedFilename(for: name))! + let versionedFilename = versionedExpectedFilename(for: name) + print("Loading \(versionedFilename)") + let expectedFile = File(path: versionedFilename)! if overwrite && actualContent != expectedFile.contents { _ = try? actualContent.data(using: .utf8)?.write(to: URL(fileURLWithPath: expectedFile.path!), options: []) @@ -80,14 +82,11 @@ private func versionedExpectedFilename(for name: String) -> String { for platform in platforms { let versionedFilename = "\(fixturesDirectory)\(platform)\(name)@\(version).json" if FileManager.default.fileExists(atPath: versionedFilename) { - print("Loading \(versionedFilename)") return versionedFilename } } } - let fallbackFilename = "\(fixturesDirectory)\(name).json" - print("Loading \(fallbackFilename)") - return fallbackFilename + return "\(fixturesDirectory)\(name).json" } class SwiftDocsTests: XCTestCase { From b5db3c2f2321b383cabda9a1db9807fa3ea3a346 Mon Sep 17 00:00:00 2001 From: ainopara Date: Fri, 3 Nov 2017 12:09:59 +0800 Subject: [PATCH 08/15] Add make command to generate sourcekit type defines. --- Makefile | 5 + .../SourceKittenFramework/SourceKitDef.swift | 6 +- Templates/AutoEnumNameFix.stencil | 40 ++ Templates/ProtocolUIDs.def | 344 ++++++++++++++++++ Templates/TypeDefs.h | 17 + 5 files changed, 410 insertions(+), 2 deletions(-) create mode 100644 Templates/AutoEnumNameFix.stencil create mode 100644 Templates/ProtocolUIDs.def create mode 100644 Templates/TypeDefs.h diff --git a/Makefile b/Makefile index 2b00388d7..bf8499f7e 100644 --- a/Makefile +++ b/Makefile @@ -85,6 +85,11 @@ docker_test: docker_test_4: docker run -v `pwd`:`pwd` -w `pwd` --rm norionomura/swift:40 swift test +generate_sourcekit_defines: + clang -E -P Templates/TypeDefs.h -o Templates/SourceKitDef.swift + sourcery --sources Templates/SourceKitDef.swift --templates Templates/AutoEnumNameFix.stencil --output Templates/SourceKitDef.swift + mv Templates/SourceKitDef.swift Source/SourceKittenFramework + # http://irace.me/swift-profiling/ display_compilation_time: $(BUILD_TOOL) $(XCODEFLAGS) OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" clean build-for-testing | grep -E ^[1-9]{1}[0-9]*.[0-9]+ms | sort -n diff --git a/Source/SourceKittenFramework/SourceKitDef.swift b/Source/SourceKittenFramework/SourceKitDef.swift index 01c8b11ea..36a88ecb4 100644 --- a/Source/SourceKittenFramework/SourceKitDef.swift +++ b/Source/SourceKittenFramework/SourceKitDef.swift @@ -1,9 +1,10 @@ -// Generated using Sourcery 0.8.0 — https://github.com/krzysztofzablocki/Sourcery +// Generated using Sourcery 0.9.0 — https://github.com/krzysztofzablocki/Sourcery // DO NOT EDIT -// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length + import Swift +// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length public struct SourceKitDef { public enum Key { @@ -1641,6 +1642,7 @@ public struct SourceKitDef { } } + public extension SourceKitDef.Key { public static let count: Int = 134 } diff --git a/Templates/AutoEnumNameFix.stencil b/Templates/AutoEnumNameFix.stencil new file mode 100644 index 000000000..9004b914c --- /dev/null +++ b/Templates/AutoEnumNameFix.stencil @@ -0,0 +1,40 @@ +import Swift + +// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length +public struct SourceKitDef { + {% for enum in types.all %} + + public enum {{ enum.name }} { + {% for case in enum.cases %}case {{ case.name|lowerFirst }} + {% endfor %} + case unrecognized(String) + + public init(string: String) { + switch string { + {% for case in enum.cases %}case "{{ case.rawValue }}": + self = .{{ case.name|lowerFirst }} + {% endfor %} + default: + self = .unrecognized(string) + } + } + + public var stringRepresentation: String { + switch self { + {% for case in enum.cases %}case .{{ case.name|lowerFirst }}: + return "{{ case.rawValue }}" + {% endfor %} + case let .unrecognized(string): + return string + } + } + } + {% endfor %} +} + +{% for enum in types.all %} + +public extension SourceKitDef.{{ enum.name }} { + public static let count: Int = {{ enum.cases.count }} +} +{% endfor %} diff --git a/Templates/ProtocolUIDs.def b/Templates/ProtocolUIDs.def new file mode 100644 index 000000000..8f019c717 --- /dev/null +++ b/Templates/ProtocolUIDs.def @@ -0,0 +1,344 @@ +#ifndef KEY +#define KEY(NAME, CONTENT) +#endif + +#ifndef REQUEST +#define REQUEST(NAME, CONTENT) +#endif + +#ifndef KIND +#define KIND(NAME, CONTENT) +#endif + +KEY(VersionMajor, "key.version_major") +KEY(VersionMinor, "key.version_minor") +KEY(Results, "key.results") +KEY(Request, "key.request") +KEY(Notification, "key.notification") +KEY(Kind, "key.kind") +KEY(AccessLevel, "key.accessibility") +KEY(SetterAccessLevel, "key.setter_accessibility") +KEY(Keyword, "key.keyword") +KEY(Name, "key.name") +KEY(USR, "key.usr") +KEY(OriginalUSR, "key.original_usr") +KEY(DefaultImplementationOf, "key.default_implementation_of") +KEY(InterestedUSR, "key.interested_usr") +KEY(GenericParams, "key.generic_params") +KEY(GenericRequirements, "key.generic_requirements") +KEY(DocFullAsXML, "key.doc.full_as_xml") +KEY(Line, "key.line") +KEY(Column, "key.column") +KEY(ReceiverUSR, "key.receiver_usr") +KEY(IsDynamic, "key.is_dynamic") +KEY(FilePath, "key.filepath") +KEY(ModuleInterfaceName, "key.module_interface_name") +KEY(Hash, "key.hash") +KEY(CompilerArgs, "key.compilerargs") +KEY(Severity, "key.severity") +KEY(Offset, "key.offset") +KEY(Length, "key.length") +KEY(SourceFile, "key.sourcefile") +KEY(SourceText, "key.sourcetext") +KEY(EnableSyntaxMap, "key.enablesyntaxmap") +KEY(EnableStructure, "key.enablesubstructure") +KEY(Description, "key.description") +KEY(TypeName, "key.typename") +KEY(RuntimeName, "key.runtime_name") +KEY(SelectorName, "key.selector_name") +KEY(AnnotatedDecl, "key.annotated_decl") +KEY(FullyAnnotatedDecl, "key.fully_annotated_decl") +KEY(DocBrief, "key.doc.brief") +KEY(Context, "key.context") +KEY(ModuleImportDepth, "key.moduleimportdepth") +KEY(NumBytesToErase, "key.num_bytes_to_erase") +KEY(NotRecommended, "key.not_recommended") +KEY(Annotations, "key.annotations") +KEY(DiagnosticStage, "key.diagnostic_stage") +KEY(SyntaxMap, "key.syntaxmap") +KEY(IsSystem, "key.is_system") +KEY(Related, "key.related") +KEY(Inherits, "key.inherits") +KEY(Conforms, "key.conforms") +KEY(Extends, "key.extends") +KEY(Dependencies, "key.dependencies") +KEY(Entities, "key.entities") +KEY(NameOffset, "key.nameoffset") +KEY(NameLength, "key.namelength") +KEY(BodyOffset, "key.bodyoffset") +KEY(BodyLength, "key.bodylength") +KEY(ThrowOffset, "key.throwoffset") +KEY(ThrowLength, "key.throwlength") +KEY(DocOffset, "key.docoffset") +KEY(DocLength, "key.doclength") +KEY(IsLocal, "key.is_local") +KEY(InheritedTypes, "key.inheritedtypes") +KEY(Attributes, "key.attributes") +KEY(Attribute, "key.attribute") +KEY(Elements, "key.elements") +KEY(SubStructure, "key.substructure") +KEY(Ranges, "key.ranges") +KEY(Fixits, "key.fixits") +KEY(Diagnostics, "key.diagnostics") +KEY(FormatOptions, "key.editor.format.options") +KEY(CodeCompleteOptions, "key.codecomplete.options") +KEY(FilterRules, "key.codecomplete.filterrules") +KEY(NextRequestStart, "key.nextrequeststart") +KEY(Popular, "key.popular") +KEY(Unpopular, "key.unpopular") +KEY(Hide, "key.hide") +KEY(Platform, "key.platform") +KEY(IsDeprecated, "key.is_deprecated") +KEY(IsUnavailable, "key.is_unavailable") +KEY(IsOptional, "key.is_optional") +KEY(Message, "key.message") +KEY(Introduced, "key.introduced") +KEY(Deprecated, "key.deprecated") +KEY(Obsoleted, "key.obsoleted") +KEY(RemoveCache, "key.removecache") +KEY(TypeInterface, "key.typeinterface") +KEY(TypeUsr, "key.typeusr") +KEY(ContainerTypeUsr, "key.containertypeusr") +KEY(ModuleGroups, "key.modulegroups") +KEY(BaseName, "key.basename") +KEY(ArgNames, "key.argnames") +KEY(SelectorPieces, "key.selectorpieces") +KEY(NameKind, "key.namekind") +KEY(LocalizationKey, "key.localization_key") +KEY(IsZeroArgSelector, "key.is_zero_arg_selector") +KEY(SwiftVersion, "key.swift_version") + +KEY(EnableDiagnostics, "key.enablediagnostics") +KEY(GroupName, "key.groupname") +KEY(ActionName, "key.actionname") +KEY(SynthesizedExtension, "key.synthesizedextensions") +KEY(UsingSwiftArgs, "key.usingswiftargs") + +KEY(Names, "key.names") +KEY(UIDs, "key.uids") +KEY(SyntacticOnly, "key.syntactic_only") +KEY(Actionable, "key.actionable") +KEY(ParentLoc, "key.parent_loc") +KEY(IsTestCandidate, "key.is_test_candidate") +KEY(Overrides, "key.overrides") +KEY(AssociatedUSRs, "key.associated_usrs") +KEY(ModuleName, "key.modulename") +KEY(RelatedDecls, "key.related_decls") +KEY(Simplified, "key.simplified") +KEY(RangeContent, "key.rangecontent") +KEY(CancelOnSubsequentRequest, "key.cancel_on_subsequent_request") + +KEY(RenameLocations, "key.renamelocations") +KEY(Locations, "key.locations") +KEY(NameType, "key.nametype") +KEY(NewName, "key.newname") +KEY(CategorizedEdits, "key.categorizededits") +KEY(CategorizedRanges, "key.categorizedranges") +KEY(RangesWorthNote, "key.rangesworthnote") +KEY(Edits, "key.edits") +KEY(EndLine, "key.endline") +KEY(EndColumn, "key.endcolumn") +KEY(ArgIndex, "key.argindex") +KEY(Text, "key.text") +KEY(Category, "key.category") +KEY(IsFunctionLike, "key.is_function_like") +KEY(IsNonProtocolType, "key.is_non_protocol_type") + +KEY(RefactorActions, "key.refactor_actions") +KEY(RetrieveRefactorActions, "key.retrieve_refactor_actions") +KEY(ActionUID, "key.actionuid") +KEY(ActionUnavailableReason, "key.actionunavailablereason") + +REQUEST(ProtocolVersion, "source.request.protocol_version") +REQUEST(CrashWithExit, "source.request.crash_exit") +REQUEST(Demangle, "source.request.demangle") +REQUEST(MangleSimpleClass, "source.request.mangle_simple_class") +REQUEST(Index, "source.request.indexsource") +REQUEST(DocInfo, "source.request.docinfo") +REQUEST(CodeComplete, "source.request.codecomplete") +REQUEST(CodeCompleteOpen, "source.request.codecomplete.open") +REQUEST(CodeCompleteClose, "source.request.codecomplete.close") +REQUEST(CodeCompleteUpdate, "source.request.codecomplete.update") +REQUEST(CodeCompleteCacheOnDisk, "source.request.codecomplete.cache.ondisk") +REQUEST(CodeCompleteSetPopularAPI, "source.request.codecomplete.setpopularapi") +REQUEST(CodeCompleteSetCustom, "source.request.codecomplete.setcustom") +REQUEST(CursorInfo, "source.request.cursorinfo") +REQUEST(RangeInfo, "source.request.rangeinfo") +REQUEST(RelatedIdents, "source.request.relatedidents") +REQUEST(EditorOpen, "source.request.editor.open") +REQUEST(EditorOpenInterface, "source.request.editor.open.interface") +REQUEST(EditorOpenHeaderInterface, "source.request.editor.open.interface.header") +REQUEST(EditorOpenSwiftSourceInterface, "source.request.editor.open.interface.swiftsource") +REQUEST(EditorOpenSwiftTypeInterface, "source.request.editor.open.interface.swifttype") +REQUEST(EditorExtractTextFromComment, "source.request.editor.extract.comment") +REQUEST(EditorClose, "source.request.editor.close") +REQUEST(EditorReplaceText, "source.request.editor.replacetext") +REQUEST(EditorFormatText, "source.request.editor.formattext") +REQUEST(EditorExpandPlaceholder, "source.request.editor.expand_placeholder") +REQUEST(EditorFindUSR, "source.request.editor.find_usr") +REQUEST(EditorFindInterfaceDoc, "source.request.editor.find_interface_doc") +REQUEST(BuildSettingsRegister, "source.request.buildsettings.register") +REQUEST(ModuleGroups, "source.request.module.groups") +REQUEST(NameTranslation, "source.request.name.translation") +REQUEST(MarkupToXML, "source.request.convert.markup.xml") + +REQUEST(SyntacticRename, "source.request.syntacticrename") +REQUEST(FindRenameRanges, "source.request.find-syntactic-rename-ranges") +REQUEST(FindLocalRenameRanges, "source.request.find-local-rename-ranges") +REQUEST(SemanticRefactoring, "source.request.semantic.refactoring") + +KIND(DeclFunctionFree, "source.lang.swift.decl.function.free") +KIND(RefFunctionFree, "source.lang.swift.ref.function.free") +KIND(DeclMethodInstance, "source.lang.swift.decl.function.method.instance") +KIND(RefMethodInstance, "source.lang.swift.ref.function.method.instance") +KIND(DeclMethodStatic, "source.lang.swift.decl.function.method.static") +KIND(RefMethodStatic, "source.lang.swift.ref.function.method.static") +KIND(DeclMethodClass, "source.lang.swift.decl.function.method.class") +KIND(RefMethodClass, "source.lang.swift.ref.function.method.class") +KIND(DeclAccessorGetter, "source.lang.swift.decl.function.accessor.getter") +KIND(RefAccessorGetter, "source.lang.swift.ref.function.accessor.getter") +KIND(DeclAccessorSetter, "source.lang.swift.decl.function.accessor.setter") +KIND(RefAccessorSetter, "source.lang.swift.ref.function.accessor.setter") +KIND(DeclAccessorWillSet, "source.lang.swift.decl.function.accessor.willset") +KIND(RefAccessorWillSet, "source.lang.swift.ref.function.accessor.willset") +KIND(DeclAccessorDidSet, "source.lang.swift.decl.function.accessor.didset") +KIND(RefAccessorDidSet, "source.lang.swift.ref.function.accessor.didset") +KIND(DeclAccessorAddress, "source.lang.swift.decl.function.accessor.address") +KIND(RefAccessorAddress, "source.lang.swift.ref.function.accessor.address") +KIND(DeclAccessorMutableAddress, "source.lang.swift.decl.function.accessor.mutableaddress") +KIND(RefAccessorMutableAddress, "source.lang.swift.ref.function.accessor.mutableaddress") +KIND(DeclConstructor, "source.lang.swift.decl.function.constructor") +KIND(RefConstructor, "source.lang.swift.ref.function.constructor") +KIND(DeclDestructor, "source.lang.swift.decl.function.destructor") +KIND(RefDestructor, "source.lang.swift.ref.function.destructor") +KIND(DeclFunctionPrefixOperator, "source.lang.swift.decl.function.operator.prefix") +KIND(DeclFunctionPostfixOperator, "source.lang.swift.decl.function.operator.postfix") +KIND(DeclFunctionInfixOperator, "source.lang.swift.decl.function.operator.infix") +KIND(RefFunctionPrefixOperator, "source.lang.swift.ref.function.operator.prefix") +KIND(RefFunctionPostfixOperator, "source.lang.swift.ref.function.operator.postfix") +KIND(RefFunctionInfixOperator, "source.lang.swift.ref.function.operator.infix") +KIND(DeclPrecedenceGroup, "source.lang.swift.decl.precedencegroup") +KIND(RefPrecedenceGroup, "source.lang.swift.ref.precedencegroup") +KIND(DeclSubscript, "source.lang.swift.decl.function.subscript") +KIND(RefSubscript, "source.lang.swift.ref.function.subscript") +KIND(DeclVarGlobal, "source.lang.swift.decl.var.global") +KIND(RefVarGlobal, "source.lang.swift.ref.var.global") +KIND(DeclVarInstance, "source.lang.swift.decl.var.instance") +KIND(RefVarInstance, "source.lang.swift.ref.var.instance") +KIND(DeclVarStatic, "source.lang.swift.decl.var.static") +KIND(RefVarStatic, "source.lang.swift.ref.var.static") +KIND(DeclVarClass, "source.lang.swift.decl.var.class") +KIND(RefVarClass, "source.lang.swift.ref.var.class") +KIND(DeclVarLocal, "source.lang.swift.decl.var.local") +KIND(RefVarLocal, "source.lang.swift.ref.var.local") +KIND(DeclVarParam, "source.lang.swift.decl.var.parameter") +KIND(DeclModule, "source.lang.swift.decl.module") +KIND(DeclClass, "source.lang.swift.decl.class") +KIND(RefClass, "source.lang.swift.ref.class") +KIND(DeclStruct, "source.lang.swift.decl.struct") +KIND(RefStruct, "source.lang.swift.ref.struct") +KIND(DeclEnum, "source.lang.swift.decl.enum") +KIND(RefEnum, "source.lang.swift.ref.enum") +KIND(DeclEnumCase, "source.lang.swift.decl.enumcase") +KIND(DeclEnumElement, "source.lang.swift.decl.enumelement") +KIND(RefEnumElement, "source.lang.swift.ref.enumelement") +KIND(DeclProtocol, "source.lang.swift.decl.protocol") +KIND(RefProtocol, "source.lang.swift.ref.protocol") +KIND(DeclExtension, "source.lang.swift.decl.extension") +KIND(DeclExtensionStruct, "source.lang.swift.decl.extension.struct") +KIND(DeclExtensionClass, "source.lang.swift.decl.extension.class") +KIND(DeclExtensionEnum, "source.lang.swift.decl.extension.enum") +KIND(DeclExtensionProtocol, "source.lang.swift.decl.extension.protocol") +KIND(DeclAssociatedType, "source.lang.swift.decl.associatedtype") +KIND(RefAssociatedType, "source.lang.swift.ref.associatedtype") +KIND(DeclTypeAlias, "source.lang.swift.decl.typealias") +KIND(RefTypeAlias, "source.lang.swift.ref.typealias") +KIND(DeclGenericTypeParam, "source.lang.swift.decl.generic_type_param") +KIND(RefGenericTypeParam, "source.lang.swift.ref.generic_type_param") +KIND(RefModule, "source.lang.swift.ref.module") +KIND(StmtForEach, "source.lang.swift.stmt.foreach") +KIND(StmtFor, "source.lang.swift.stmt.for") +KIND(StmtWhile, "source.lang.swift.stmt.while") +KIND(StmtRepeatWhile, "source.lang.swift.stmt.repeatwhile") +KIND(StmtIf, "source.lang.swift.stmt.if") +KIND(StmtGuard, "source.lang.swift.stmt.guard") +KIND(StmtSwitch, "source.lang.swift.stmt.switch") +KIND(StmtCase, "source.lang.swift.stmt.case") +KIND(StmtBrace, "source.lang.swift.stmt.brace") +KIND(ExprCall, "source.lang.swift.expr.call") +KIND(ExprArg, "source.lang.swift.expr.argument") +KIND(ExprArray, "source.lang.swift.expr.array") +KIND(ExprDictionary, "source.lang.swift.expr.dictionary") +KIND(ExprObjectLiteral, "source.lang.swift.expr.object_literal") +KIND(StructureElemId, "source.lang.swift.structure.elem.id") +KIND(StructureElemExpr, "source.lang.swift.structure.elem.expr") +KIND(StructureElemInitExpr, "source.lang.swift.structure.elem.init_expr") +KIND(StructureElemCondExpr, "source.lang.swift.structure.elem.condition_expr") +KIND(StructureElemPattern, "source.lang.swift.structure.elem.pattern") +KIND(StructureElemTypeRef, "source.lang.swift.structure.elem.typeref") +KIND(RangeSingleStatement, "source.lang.swift.range.singlestatement") +KIND(RangeSingleExpression, "source.lang.swift.range.singleexpression") +KIND(RangeSingleDeclaration, "source.lang.swift.range.singledeclaration") +KIND(RangeMultiStatement, "source.lang.swift.range.multistatement") +KIND(RangeInvalid, "source.lang.swift.range.invalid") +KIND(NameObjc, "source.lang.name.kind.objc") +KIND(NameSwift, "source.lang.name.kind.swift") +KIND(Keyword, "source.lang.swift.syntaxtype.keyword") +KIND(Identifier, "source.lang.swift.syntaxtype.identifier") +KIND(TypeIdentifier, "source.lang.swift.syntaxtype.typeidentifier") +KIND(BuildConfigKeyword, "source.lang.swift.syntaxtype.buildconfig.keyword") +KIND(BuildConfigId, "source.lang.swift.syntaxtype.buildconfig.id") +KIND(AttributeId, "source.lang.swift.syntaxtype.attribute.id") +KIND(AttributeBuiltin, "source.lang.swift.syntaxtype.attribute.builtin") +KIND(Number, "source.lang.swift.syntaxtype.number") +KIND(String, "source.lang.swift.syntaxtype.string") +KIND(StringInterpolation, "source.lang.swift.syntaxtype.string_interpolation_anchor") +KIND(Comment, "source.lang.swift.syntaxtype.comment") +KIND(DocComment, "source.lang.swift.syntaxtype.doccomment") +KIND(DocCommentField, "source.lang.swift.syntaxtype.doccomment.field") +KIND(CommentMarker, "source.lang.swift.syntaxtype.comment.mark") +KIND(CommentURL, "source.lang.swift.syntaxtype.comment.url") +KIND(Placeholder, "source.lang.swift.syntaxtype.placeholder") +KIND(ObjectLiteral, "source.lang.swift.syntaxtype.objectliteral") + +KIND(Expr, "source.lang.swift.expr") +KIND(Stmt, "source.lang.swift.stmt") +KIND(Type, "source.lang.swift.type") +KIND(ForEachSequence, "source.lang.swift.foreach.sequence") + +KIND(DiagNote, "source.diagnostic.severity.note") +KIND(DiagWarning, "source.diagnostic.severity.warning") +KIND(DiagError, "source.diagnostic.severity.error") + +KIND(CodeCompletionEverything, "source.codecompletion.everything") +KIND(CodeCompletionModule, "source.codecompletion.module") +KIND(CodeCompletionKeyword, "source.codecompletion.keyword") +KIND(CodeCompletionLiteral, "source.codecompletion.literal") +KIND(CodeCompletionCustom, "source.codecompletion.custom") +KIND(CodeCompletionIdentifier, "source.codecompletion.identifier") +KIND(CodeCompletionDescription, "source.codecompletion.description") + +KIND(EditActive, "source.edit.kind.active") +KIND(EditInactive, "source.edit.kind.inactive") +KIND(EditSelector, "source.edit.kind.selector") +KIND(EditString, "source.edit.kind.string") +KIND(EditComment, "source.edit.kind.comment") +KIND(EditMismatch, "source.edit.kind.mismatch") +KIND(EditUnknown, "source.edit.kind.unknown") +KIND(RenameRangeBase, "source.refactoring.range.kind.basename") +KIND(RenameRangeKeywordBase, "source.refactoring.range.kind.keyword-basename") +KIND(RenameRangeParam, "source.refactoring.range.kind.parameter-and-whitespace") +KIND(RenameRangeDeclArgLabel, "source.refactoring.range.kind.decl-argument-label") +KIND(RenameRangeCallArgLabel, "source.refactoring.range.kind.call-argument-label") +KIND(RenameRangeCallArgColon, "source.refactoring.range.kind.call-argument-colon") +KIND(RenameRangeCallArgCombined, "source.refactoring.range.kind.call-argument-combined") +KIND(RenameRangeSelectorArgLabel, "source.refactoring.range.kind.selector-argument-label") + +KIND(Definition, "source.syntacticrename.definition") +KIND(Reference, "source.syntacticrename.reference") +KIND(Call, "source.syntacticrename.call") +KIND(Unknown, "source.syntacticrename.unknown") + +#undef KIND +#undef REQUEST +#undef KEY diff --git a/Templates/TypeDefs.h b/Templates/TypeDefs.h new file mode 100644 index 000000000..ad648c3f0 --- /dev/null +++ b/Templates/TypeDefs.h @@ -0,0 +1,17 @@ +enum Key: String { +#define KEY(NAME, CONTENT) case NAME = CONTENT +#include "ProtocolUIDs.def" +#undef KEY +} + +enum Request: String { +#define REQUEST(NAME, CONTENT) case NAME = CONTENT +#include "ProtocolUIDs.def" +#undef REQUEST +} + +enum Kind: String { +#define KIND(NAME, CONTENT) case NAME = CONTENT +#include "ProtocolUIDs.def" +#undef KIND +} From 27f77f8a575ca81f64072b44c428d9c3ff2d2e32 Mon Sep 17 00:00:00 2001 From: ainopara Date: Fri, 3 Nov 2017 12:53:54 +0800 Subject: [PATCH 09/15] Tell swiftlint to ignore `SourceKitDef.swift`. --- .swiftlint.yml | 1 + Templates/AutoEnumNameFix.stencil | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index f951bfd25..48364e15e 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -7,6 +7,7 @@ excluded: - Source/SourceKittenFramework/library_wrapper_Documentation.swift - Source/SourceKittenFramework/library_wrapper_Index.swift - Source/SourceKittenFramework/library_wrapper_sourcekitd.swift + - Source/SourceKittenFramework/SourceKitDef.swift opt_in_rules: - attributes - closure_end_indentation diff --git a/Templates/AutoEnumNameFix.stencil b/Templates/AutoEnumNameFix.stencil index 9004b914c..bcb72e58f 100644 --- a/Templates/AutoEnumNameFix.stencil +++ b/Templates/AutoEnumNameFix.stencil @@ -1,6 +1,5 @@ import Swift -// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length public struct SourceKitDef { {% for enum in types.all %} From ae15a99458780aa8ce88d0bbaa22101cd9c2fdf7 Mon Sep 17 00:00:00 2001 From: ainopara Date: Fri, 3 Nov 2017 13:07:20 +0800 Subject: [PATCH 10/15] And regenerate the defination file. --- Source/SourceKittenFramework/SourceKitDef.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/SourceKittenFramework/SourceKitDef.swift b/Source/SourceKittenFramework/SourceKitDef.swift index 36a88ecb4..f7242e972 100644 --- a/Source/SourceKittenFramework/SourceKitDef.swift +++ b/Source/SourceKittenFramework/SourceKitDef.swift @@ -4,7 +4,6 @@ import Swift -// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length public struct SourceKitDef { public enum Key { From bfa7dfc4ebb80819670bd7f19fd2ff130daf834c Mon Sep 17 00:00:00 2001 From: ainopara Date: Sat, 25 Nov 2017 18:22:08 +0800 Subject: [PATCH 11/15] Adapt IUO change. --- Source/SourceKittenFramework/Request.swift | 4 ++-- Source/SourceKittenFramework/RequestBuilder.swift | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/SourceKittenFramework/Request.swift b/Source/SourceKittenFramework/Request.swift index e9c97a60e..b659e0031 100644 --- a/Source/SourceKittenFramework/Request.swift +++ b/Source/SourceKittenFramework/Request.swift @@ -303,7 +303,7 @@ extension Request { if offset == 0 { return nil } - sourcekitd_request_dictionary_set_int64(cursorInfoRequest, sourcekitd_uid_get_from_cstr(SwiftDocKey.offset.rawValue), offset) + sourcekitd_request_dictionary_set_int64(cursorInfoRequest, sourcekitd_uid_get_from_cstr(SwiftDocKey.offset.rawValue)!, offset) return try? Request.customRequest(request: cursorInfoRequest).failableSend() } } @@ -517,7 +517,7 @@ extension Request { public let yaml: String public func sourcekitObject() -> sourcekitd_object_t { - return sourcekitd_request_create_from_yaml(yaml, nil) + return sourcekitd_request_create_from_yaml(yaml, nil)! } } diff --git a/Source/SourceKittenFramework/RequestBuilder.swift b/Source/SourceKittenFramework/RequestBuilder.swift index 14ebc44a2..11de91b98 100644 --- a/Source/SourceKittenFramework/RequestBuilder.swift +++ b/Source/SourceKittenFramework/RequestBuilder.swift @@ -26,7 +26,7 @@ public class RequestBuilder { public func makeRequest() -> sourcekitd_object_t { var keys = Array(dict.keys.map({ $0 as sourcekitd_uid_t? })) var values = Array(dict.values.map({ $0 as sourcekitd_object_t? })) - return sourcekitd_request_dictionary_create(&keys, &values, dict.count) + return sourcekitd_request_dictionary_create(&keys, &values, dict.count)! } private func set(_ value: Any?, for key: String) { @@ -43,30 +43,30 @@ public class RequestBuilder { } private func transform(key: String) -> sourcekitd_uid_t { - return sourcekitd_uid_get_from_cstr(key) + return sourcekitd_uid_get_from_cstr(key)! } private func transform(string: String) -> sourcekitd_object_t { - return sourcekitd_request_string_create(string) + return sourcekitd_request_string_create(string)! } private func transform(bool: Bool) -> sourcekitd_object_t { - return sourcekitd_request_int64_create(bool ? 1 : 0) + return sourcekitd_request_int64_create(bool ? 1 : 0)! } private func transform(integer: Int64) -> sourcekitd_object_t { - return sourcekitd_request_int64_create(integer) + return sourcekitd_request_int64_create(integer)! } private func transform(array: [Any]) -> sourcekitd_object_t { var array = array.map(transform(any:)).map { $0 as sourcekitd_object_t? } - return sourcekitd_request_array_create(&array, array.count) + return sourcekitd_request_array_create(&array, array.count)! } private func transform(dictionary: [String: Any]) -> sourcekitd_object_t { var keys = Array(dictionary.keys).map(transform(key:)).map { $0 as sourcekitd_uid_t? } var values = Array(dictionary.values).map(transform(any:)).map { $0 as sourcekitd_object_t? } - return sourcekitd_request_dictionary_create(&keys, &values, dictionary.count) + return sourcekitd_request_dictionary_create(&keys, &values, dictionary.count)! } private func transform(any: Any) -> sourcekitd_object_t { From 77409839ad16be0a5443da134392ddfd00f2093e Mon Sep 17 00:00:00 2001 From: ainopara Date: Sat, 25 Nov 2017 19:26:21 +0800 Subject: [PATCH 12/15] Split up `Request.swift`. --- Source/SourceKittenFramework/Request.swift | 524 ------------------ .../Requests/Request+CodeComplete.swift | 49 ++ .../Requests/Request+CursorInfo.swift | 105 ++++ .../Requests/Request+Custom.swift | 24 + .../Requests/Request+Demangle.swift | 27 + .../Requests/Request+DocInfo.swift | 50 ++ .../Requests/Request+EditorFindUSR.swift | 28 + .../Requests/Request+EditorFormatText.swift | 48 ++ .../Requests/Request+EditorOpen.swift | 84 +++ .../Request+EditorOpenHeaderInterface.swift | 40 ++ .../Request+EditorOpenInterface.swift | 61 ++ .../Requests/Request+EditorReplaceText.swift | 33 ++ .../Requests/Request+Index.swift | 28 + .../Requests/Request+ModuleGroups.swift | 29 + .../Requests/Request+YAML.swift | 24 + sourcekitten.xcodeproj/project.pbxproj | 66 ++- 16 files changed, 695 insertions(+), 525 deletions(-) create mode 100644 Source/SourceKittenFramework/Requests/Request+CodeComplete.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+CursorInfo.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+Custom.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+Demangle.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+DocInfo.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+EditorFindUSR.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+EditorFormatText.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+EditorOpen.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+EditorOpenHeaderInterface.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+EditorOpenInterface.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+EditorReplaceText.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+Index.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+ModuleGroups.swift create mode 100644 Source/SourceKittenFramework/Requests/Request+YAML.swift diff --git a/Source/SourceKittenFramework/Request.swift b/Source/SourceKittenFramework/Request.swift index b659e0031..3c386b076 100644 --- a/Source/SourceKittenFramework/Request.swift +++ b/Source/SourceKittenFramework/Request.swift @@ -12,9 +12,6 @@ import Foundation import SourceKit #endif -// swiftlint:disable file_length -// This file could easily be split up - public protocol SourceKitRepresentable { func isEqualTo(_ rhs: SourceKitRepresentable) -> Bool } @@ -189,8 +186,6 @@ private extension String { } } -public let defaultRequestArguments = { return ["-sdk", sdkPath()] }() - public protocol RequestType { func sourcekitObject() -> sourcekitd_object_t } @@ -272,525 +267,6 @@ public struct Request { } } -// MARK: - CursorInfo reuse - -extension Request { - - /** - Create a Request.CursorInfo.sourcekitObject() from a file path and compiler arguments. - - - parameter filePath: Path of the file to create request. - - parameter arguments: Compiler arguments. - - - returns: sourcekitd_object_t representation of the Request, if successful. - */ - internal static func cursorInfoRequest(filePath: String?, arguments: [String]) -> sourcekitd_object_t? { - if let path = filePath { - return Request.cursorInfo(file: path, offset: 0, arguments: arguments).sourcekitObject - } - return nil - } - - /** - Send a Request.CursorInfo by updating its offset. Returns SourceKit response if successful. - - - parameter cursorInfoRequest: sourcekitd_object_t representation of Request.CursorInfo - - parameter offset: Offset to update request. - - - returns: SourceKit response if successful. - */ - internal static func send(cursorInfoRequest: sourcekitd_object_t, atOffset offset: Int64) -> [String: SourceKitRepresentable]? { - if offset == 0 { - return nil - } - sourcekitd_request_dictionary_set_int64(cursorInfoRequest, sourcekitd_uid_get_from_cstr(SwiftDocKey.offset.rawValue)!, offset) - return try? Request.customRequest(request: cursorInfoRequest).failableSend() - } -} - -// MARK: - -// swiftlint:disable nesting -extension Request { - - /// An `editor.open` request for the given File. - public struct EditorOpen: RequestType { - public let name: String - - public struct Source { - public let sourceFile: String? - public let sourceText: String? - - public static func path(_ path: String) -> Source { - return Source(sourceFile: path, sourceText: nil) - } - - public static func text(_ text: String) -> Source { - return Source(sourceFile: nil, sourceText: text) - } - } - public let source: Source - public let enableSyntaxMap: Bool? - public let enableStructure: Bool? - public let enableDiagnostics: Bool? - public let syntacticOnly: Bool? - public let arguments: [String] - - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .editorOpen) - requestBuilder[.name] = name - requestBuilder[.sourceFile] = source.sourceFile - requestBuilder[.sourceText] = source.sourceText - requestBuilder[.enableSyntaxMap] = enableSyntaxMap - requestBuilder[.enableStructure] = enableStructure - requestBuilder[.enableDiagnostics] = enableDiagnostics - requestBuilder[.syntacticOnly] = syntacticOnly - requestBuilder[.compilerArgs] = arguments - return requestBuilder.makeRequest() - } - } - - public static func editorOpen(file: File, arguments: [String] = defaultRequestArguments) -> Request { - let name: String - let source: EditorOpen.Source - if let path = file.path { - name = path - source = .path(path) - } else { - name = String(file.contents.hash) - source = .text(file.contents) - } - - return .editorOpen(name: name, source: source, arguments: arguments) - } - - public static func editorOpen( - name: String, - source: EditorOpen.Source, - enableSyntaxMap: Bool? = nil, - enableStructure: Bool? = nil, - enableDiagnostics: Bool? = nil, - syntacticOnly: Bool? = nil, - arguments: [String] = defaultRequestArguments - ) -> Request { - return Request(type: EditorOpen( - name: name, - source: source, - enableSyntaxMap: enableSyntaxMap, - enableStructure: enableStructure, - enableDiagnostics: enableDiagnostics, - syntacticOnly: syntacticOnly, - arguments: arguments - )) - } -} - -extension Request { - /// Generate interface for a swift module. - public struct EditorOpenInterface: RequestType { - public let name: String - public let moduleName: String - - public struct Group { - public let groupName: String? - public let interestedUSR: String? - - public static func name(_ name: String) -> Group { - return Group(groupName: name, interestedUSR: nil) - } - - public static func containsInterestedUSR(_ usr: String) -> Group { - return Group(groupName: nil, interestedUSR: usr) - } - } - public let group: Group? - public let synthesizedExtension: Bool? - public let arguments: [String] - - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .editorOpenInterface) - requestBuilder[.name] = name - requestBuilder[.moduleName] = moduleName - requestBuilder[.synthesizedExtension] = synthesizedExtension - requestBuilder[.compilerArgs] = arguments - if let group = self.group { - requestBuilder[.groupName] = group.groupName - requestBuilder[.interestedUSR] = group.interestedUSR - } - return requestBuilder.makeRequest() - } - } - - public static func editorOpenInterface( - name: String, - moduleName: String, - group: EditorOpenInterface.Group? = nil, - synthesizedExtension: Bool? = nil, - arguments: [String] = defaultRequestArguments - ) -> Request { - return Request(type: EditorOpenInterface( - name: name, - moduleName: moduleName, - group: group, - synthesizedExtension: synthesizedExtension, - arguments: arguments - )) - } -} - -extension Request { - /// A `cursorinfo` request for an offset or an usr in the given file, using the `arguments` given. - public struct CursorInfo: RequestType { - public let name: String - public let sourceFile: String - - public struct Location { - public let usr: String? - public let offset: Int64? - public let length: Int64? - public let retrieveRefactorActions: Bool? - - public static func offset(_ offset: Int64, length: Int64? = nil, retrieveRefactorActions: Bool? = nil) -> Location { - return Location(usr: nil, offset: offset, length: length, retrieveRefactorActions: retrieveRefactorActions) - } - - public static func usr(_ usr: String) -> Location { - return Location(usr: usr, offset: nil, length: nil, retrieveRefactorActions: nil) - } - } - public let location: Location - public let cancelOnSubsequentRequest: Bool? - public let arguments: [String] - - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .cursorInfo) - requestBuilder[.name] = name - requestBuilder[.sourceFile] = sourceFile - requestBuilder[.cancelOnSubsequentRequest] = cancelOnSubsequentRequest - requestBuilder[.uSR] = location.usr - requestBuilder[.offset] = location.offset - requestBuilder[.length] = location.length - requestBuilder[.retrieveRefactorActions] = location.retrieveRefactorActions - requestBuilder[.compilerArgs] = arguments - return requestBuilder.makeRequest() - } - } - - public static func cursorInfo(file: String, offset: Int64, arguments: [String]) -> Request { - return .cursorInfo(name: file, file: file, location: .offset(offset), arguments: arguments) - } - - public static func cursorInfo( - name: String, - file: String, - location: CursorInfo.Location, - cancelOnSubsequentRequest: Bool? = nil, - arguments: [String] - ) -> Request { - return Request(type: CursorInfo( - name: name, - sourceFile: file, - location: location, - cancelOnSubsequentRequest: cancelOnSubsequentRequest, - arguments: arguments - )) - } -} - -extension Request { - /// A custom request by passing in the sourcekitd_object_t directly. - public struct Custom: RequestType { - public let request: sourcekitd_object_t - - public func sourcekitObject() -> sourcekitd_object_t { - return request - } - } - - public static func customRequest(request: sourcekitd_object_t) -> Request { - return Request(type: Custom(request: request)) - } -} - -extension Request { - /// A request generated by sourcekit using the yaml representation. - public struct Yaml: RequestType { - public let yaml: String - - public func sourcekitObject() -> sourcekitd_object_t { - return sourcekitd_request_create_from_yaml(yaml, nil)! - } - } - - public static func yamlRequest(yaml: String) -> Request { - return Request(type: Yaml(yaml: yaml)) - } -} - -extension Request { - /// A `codecomplete` request by passing in the file name, contents, offset - /// for which to generate code completion options and array of compiler arguments. - public struct CodeComplete: RequestType { - public struct Source { - public let sourceFile: String? - public let sourceText: String? - - public static func path(_ path: String) -> Source { - return Source(sourceFile: path, sourceText: nil) - } - - public static func text(_ text: String, name: String? = nil) -> Source { - return Source(sourceFile: name, sourceText: text) - } - } - public let source: Source - public let offset: Int64 - public let arguments: [String] - - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .codeComplete) - requestBuilder[.sourceFile] = source.sourceFile - requestBuilder[.sourceText] = source.sourceText - requestBuilder[.offset] = offset - requestBuilder[.compilerArgs] = arguments - return requestBuilder.makeRequest() - } - } - - public static func codeCompletionRequest(file: String, contents: String, offset: Int64, arguments: [String]) -> Request { - return .codeComplete(source: .text(contents, name: file), offset: offset, arguments: arguments) - } - - public static func codeComplete(source: CodeComplete.Source, offset: Int64, arguments: [String]) -> Request { - return Request(type: CodeComplete(source: source, offset: offset, arguments: arguments)) - } -} - -extension Request { - /// ObjC Swift Interface - public struct EditorOpenHeaderInterface: RequestType { - public let name: String - public let filePath: String - public let arguments: [String] - - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .editorOpenHeaderInterface) - requestBuilder[.name] = name - requestBuilder[.filePath] = filePath - requestBuilder[.compilerArgs] = arguments - return requestBuilder.makeRequest() - } - } - - public static func interface(file: String, uuid: String, arguments: [String]) -> Request { - var arguments = arguments - if !arguments.contains("-x") { - arguments.append(contentsOf: ["-x", "objective-c"]) - } - if !arguments.contains("-isysroot") { - arguments.append(contentsOf: ["-isysroot", sdkPath()]) - } - - arguments = [file] + arguments - - return Request(type: EditorOpenHeaderInterface(name: uuid, filePath: file, arguments: arguments)) - } -} - -extension Request { - /// Find USR - public struct EditorFindUSR: RequestType { - public let sourceFile: String - public let usr: String - - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .editorFindUSR) - requestBuilder[.sourceFile] = sourceFile - requestBuilder[.uSR] = usr - return requestBuilder.makeRequest() - } - } - - public static func findUSR(file: String, usr: String) -> Request { - return Request(type: EditorFindUSR(sourceFile: file, usr: usr)) - } -} - -extension Request { - /// Index - public struct Index: RequestType { - public let sourceFile: String - public let arguments: [String] - - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .index) - requestBuilder[.sourceFile] = sourceFile - requestBuilder[.compilerArgs] = arguments - return requestBuilder.makeRequest() - } - } - - public static func index(file: String, arguments: [String]) -> Request { - return Request(type: Index(sourceFile: file, arguments: arguments)) - } -} - -extension Request { - /// Format - public struct EditorFormatText: RequestType { - public let name: String - public let line: Int64 - - public struct Options { - public let indentWidth: Int64 - public let tabWidth: Int64 - public let useTabs: Bool - } - public let options: Options - - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .editorFormatText) - requestBuilder[.name] = name - requestBuilder[.line] = line - - let formatOptions: [String: Any] = [ - "key.editor.format.indentwidth": options.indentWidth, - "key.editor.format.tabwidth": options.tabWidth, - "key.editor.format.usetabs": options.useTabs - ] - requestBuilder[.formatOptions] = formatOptions - - return requestBuilder.makeRequest() - } - } - - public static func format(file: String, line: Int64, useTabs: Bool, indentWidth: Int64) -> Request { - let options = EditorFormatText.Options( - indentWidth: indentWidth, - tabWidth: indentWidth, - useTabs: useTabs - ) - return Request(type: EditorFormatText(name: file, line: line, options: options)) - } -} - -extension Request { - /// ReplaceText - public struct EditorReplaceText: RequestType { - public let name: String - public let offset: Int64 - public let length: Int64 - public let sourceText: String - - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .editorReplaceText) - requestBuilder[.name] = name - requestBuilder[.offset] = offset - requestBuilder[.length] = length - requestBuilder[.sourceText] = sourceText - - return requestBuilder.makeRequest() - } - } - - public static func replaceText(file: String, offset: Int64, length: Int64, sourceText: String) -> Request { - return Request(type: EditorReplaceText(name: file, offset: offset, length: length, sourceText: sourceText)) - } -} - -extension Request { - /// A documentation request for the given source text. - /// Or a documentation request for the given module. - public struct DocInfo: RequestType { - public let name: String - - public struct Source { - public let sourceText: String? - public let moduleName: String? - - public static func text(_ sourceText: String) -> Source { - return Source(sourceText: sourceText, moduleName: nil) - } - - public static func module(name moduleName: String) -> Source { - return Source(sourceText: nil, moduleName: moduleName) - } - } - public let source: Source - public let arguments: [String] - - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .docInfo) - requestBuilder[.name] = name - requestBuilder[.sourceText] = source.sourceText - requestBuilder[.moduleName] = source.moduleName - requestBuilder[.compilerArgs] = arguments - - return requestBuilder.makeRequest() - } - } - - public static func docInfo(text: String, arguments: [String]) -> Request { - return Request(type: DocInfo(name: NSUUID().uuidString, source: .text(text), arguments: arguments)) - } - - public static func moduleInfo(module: String, arguments: [String]) -> Request { - return Request(type: DocInfo(name: NSUUID().uuidString, source: .module(name: module), arguments: arguments)) - } -} - -extension Request { - /// Demangle swift names - public struct Demangle: RequestType { - public let names: [String] - - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .demangle) - requestBuilder[.names] = names - - return requestBuilder.makeRequest() - } - } - - public static func demangle(names: [String]) -> Request { - return Request(type: Demangle(names: names)) - } -} - -extension Request { - /// Request groups for module - public struct ModuleGroups: RequestType { - public let moduleName: String - public let arguments: [String] - - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .moduleGroups) - requestBuilder[.moduleName] = moduleName - requestBuilder[.compilerArgs] = arguments - - return requestBuilder.makeRequest() - } - } - - public static func moduleGroups(module: String, arguments: [String]) -> Request { - return Request(type: ModuleGroups(moduleName: module, arguments: arguments)) - } -} - -extension Request { - /// SourceKit protocol version - public struct ProtocolVersion: RequestType { - public func sourcekitObject() -> sourcekitd_object_t { - let requestBuilder = RequestBuilder(type: .protocolVersion) - return requestBuilder.makeRequest() - } - } - - public static func protocolVersion() -> Request { - return Request(type: ProtocolVersion()) - } -} -// swiftlint:enable nesting - // MARK: - CustomStringConvertible extension Request: CustomStringConvertible { diff --git a/Source/SourceKittenFramework/Requests/Request+CodeComplete.swift b/Source/SourceKittenFramework/Requests/Request+CodeComplete.swift new file mode 100644 index 000000000..91e22106e --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+CodeComplete.swift @@ -0,0 +1,49 @@ +// +// Request+CodeCompletion.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +// swiftlint:disable nesting +extension Request { + /// A `codecomplete` request by passing in the file name, contents, offset + /// for which to generate code completion options and array of compiler arguments. + public struct CodeComplete: RequestType { + public struct Source { + public let sourceFile: String? + public let sourceText: String? + + public static func path(_ path: String) -> Source { + return Source(sourceFile: path, sourceText: nil) + } + + public static func text(_ text: String, name: String? = nil) -> Source { + return Source(sourceFile: name, sourceText: text) + } + } + public let source: Source + public let offset: Int64 + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .codeComplete) + requestBuilder[.sourceFile] = source.sourceFile + requestBuilder[.sourceText] = source.sourceText + requestBuilder[.offset] = offset + requestBuilder[.compilerArgs] = arguments + return requestBuilder.makeRequest() + } + } + + public static func codeCompletionRequest(file: String, contents: String, offset: Int64, arguments: [String]) -> Request { + return .codeComplete(source: .text(contents, name: file), offset: offset, arguments: arguments) + } + + public static func codeComplete(source: CodeComplete.Source, offset: Int64, arguments: [String]) -> Request { + return Request(type: CodeComplete(source: source, offset: offset, arguments: arguments)) + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+CursorInfo.swift b/Source/SourceKittenFramework/Requests/Request+CursorInfo.swift new file mode 100644 index 000000000..b5bf251e0 --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+CursorInfo.swift @@ -0,0 +1,105 @@ +// +// Request+CursorInfo.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +// swiftlint:disable nesting +extension Request { + /// A `cursorinfo` request for an offset or an usr in the given file, using the `arguments` given. + public struct CursorInfo: RequestType { + public let name: String + public let sourceFile: String + + public struct Location { + public let usr: String? + public let offset: Int64? + public let length: Int64? + public let retrieveRefactorActions: Bool? + + public static func offset(_ offset: Int64, length: Int64? = nil, retrieveRefactorActions: Bool? = nil) -> Location { + return Location(usr: nil, offset: offset, length: length, retrieveRefactorActions: retrieveRefactorActions) + } + + public static func usr(_ usr: String) -> Location { + return Location(usr: usr, offset: nil, length: nil, retrieveRefactorActions: nil) + } + } + public let location: Location + public let cancelOnSubsequentRequest: Bool? + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .cursorInfo) + requestBuilder[.name] = name + requestBuilder[.sourceFile] = sourceFile + requestBuilder[.cancelOnSubsequentRequest] = cancelOnSubsequentRequest + requestBuilder[.uSR] = location.usr + requestBuilder[.offset] = location.offset + requestBuilder[.length] = location.length + requestBuilder[.retrieveRefactorActions] = location.retrieveRefactorActions + requestBuilder[.compilerArgs] = arguments + return requestBuilder.makeRequest() + } + } + + public static func cursorInfo(file: String, offset: Int64, arguments: [String]) -> Request { + return .cursorInfo(name: file, file: file, location: .offset(offset), arguments: arguments) + } + + public static func cursorInfo( + name: String, + file: String, + location: CursorInfo.Location, + cancelOnSubsequentRequest: Bool? = nil, + arguments: [String] + ) -> Request { + return Request(type: CursorInfo( + name: name, + sourceFile: file, + location: location, + cancelOnSubsequentRequest: cancelOnSubsequentRequest, + arguments: arguments + )) + } +} + +// MARK: - CursorInfo reuse + +extension Request { + + /** + Create a Request.CursorInfo.sourcekitObject() from a file path and compiler arguments. + + - parameter filePath: Path of the file to create request. + - parameter arguments: Compiler arguments. + + - returns: sourcekitd_object_t representation of the Request, if successful. + */ + internal static func cursorInfoRequest(filePath: String?, arguments: [String]) -> sourcekitd_object_t? { + if let path = filePath { + return Request.cursorInfo(file: path, offset: 0, arguments: arguments).type.sourcekitObject() + } + return nil + } + + /** + Send a Request.CursorInfo by updating its offset. Returns SourceKit response if successful. + + - parameter cursorInfoRequest: sourcekitd_object_t representation of Request.CursorInfo + - parameter offset: Offset to update request. + + - returns: SourceKit response if successful. + */ + internal static func send(cursorInfoRequest: sourcekitd_object_t, atOffset offset: Int64) -> [String: SourceKitRepresentable]? { + if offset == 0 { + return nil + } + sourcekitd_request_dictionary_set_int64(cursorInfoRequest, sourcekitd_uid_get_from_cstr(SwiftDocKey.offset.rawValue)!, offset) + return try? Request.customRequest(request: cursorInfoRequest).failableSend() + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+Custom.swift b/Source/SourceKittenFramework/Requests/Request+Custom.swift new file mode 100644 index 000000000..e91bdfbde --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+Custom.swift @@ -0,0 +1,24 @@ +// +// Request+Custom.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +extension Request { + /// A custom request by passing in the sourcekitd_object_t directly. + public struct Custom: RequestType { + public let request: sourcekitd_object_t + + public func sourcekitObject() -> sourcekitd_object_t { + return request + } + } + + public static func customRequest(request: sourcekitd_object_t) -> Request { + return Request(type: Custom(request: request)) + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+Demangle.swift b/Source/SourceKittenFramework/Requests/Request+Demangle.swift new file mode 100644 index 000000000..4088f90d7 --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+Demangle.swift @@ -0,0 +1,27 @@ +// +// Request+Demangle.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +extension Request { + /// Demangle swift names + public struct Demangle: RequestType { + public let names: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .demangle) + requestBuilder[.names] = names + + return requestBuilder.makeRequest() + } + } + + public static func demangle(names: [String]) -> Request { + return Request(type: Demangle(names: names)) + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+DocInfo.swift b/Source/SourceKittenFramework/Requests/Request+DocInfo.swift new file mode 100644 index 000000000..b6921d0f7 --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+DocInfo.swift @@ -0,0 +1,50 @@ +// +// Request+DocInfo.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +extension Request { + /// A documentation request for the given source text. + /// Or a documentation request for the given module. + public struct DocInfo: RequestType { + public let name: String + + public struct Source { + public let sourceText: String? + public let moduleName: String? + + public static func text(_ sourceText: String) -> Source { + return Source(sourceText: sourceText, moduleName: nil) + } + + public static func module(name moduleName: String) -> Source { + return Source(sourceText: nil, moduleName: moduleName) + } + } + public let source: Source + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .docInfo) + requestBuilder[.name] = name + requestBuilder[.sourceText] = source.sourceText + requestBuilder[.moduleName] = source.moduleName + requestBuilder[.compilerArgs] = arguments + + return requestBuilder.makeRequest() + } + } + + public static func docInfo(text: String, arguments: [String]) -> Request { + return Request(type: DocInfo(name: NSUUID().uuidString, source: .text(text), arguments: arguments)) + } + + public static func moduleInfo(module: String, arguments: [String]) -> Request { + return Request(type: DocInfo(name: NSUUID().uuidString, source: .module(name: module), arguments: arguments)) + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+EditorFindUSR.swift b/Source/SourceKittenFramework/Requests/Request+EditorFindUSR.swift new file mode 100644 index 000000000..c116fc34c --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+EditorFindUSR.swift @@ -0,0 +1,28 @@ +// +// Request+EditorFindUSR.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +extension Request { + /// Find USR + public struct EditorFindUSR: RequestType { + public let sourceFile: String + public let usr: String + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .editorFindUSR) + requestBuilder[.sourceFile] = sourceFile + requestBuilder[.uSR] = usr + return requestBuilder.makeRequest() + } + } + + public static func findUSR(file: String, usr: String) -> Request { + return Request(type: EditorFindUSR(sourceFile: file, usr: usr)) + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+EditorFormatText.swift b/Source/SourceKittenFramework/Requests/Request+EditorFormatText.swift new file mode 100644 index 000000000..c90991fdb --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+EditorFormatText.swift @@ -0,0 +1,48 @@ +// +// Request+EditorFormat.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +extension Request { + /// Format + public struct EditorFormatText: RequestType { + public let name: String + public let line: Int64 + + public struct Options { + public let indentWidth: Int64 + public let tabWidth: Int64 + public let useTabs: Bool + } + public let options: Options + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .editorFormatText) + requestBuilder[.name] = name + requestBuilder[.line] = line + + let formatOptions: [String: Any] = [ + "key.editor.format.indentwidth": options.indentWidth, + "key.editor.format.tabwidth": options.tabWidth, + "key.editor.format.usetabs": options.useTabs + ] + requestBuilder[.formatOptions] = formatOptions + + return requestBuilder.makeRequest() + } + } + + public static func format(file: String, line: Int64, useTabs: Bool, indentWidth: Int64) -> Request { + let options = EditorFormatText.Options( + indentWidth: indentWidth, + tabWidth: indentWidth, + useTabs: useTabs + ) + return Request(type: EditorFormatText(name: file, line: line, options: options)) + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+EditorOpen.swift b/Source/SourceKittenFramework/Requests/Request+EditorOpen.swift new file mode 100644 index 000000000..bc60b2695 --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+EditorOpen.swift @@ -0,0 +1,84 @@ +// +// Request+EditorOpen.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +// swiftlint:disable nesting +extension Request { + + /// An `editor.open` request for the given File. + public struct EditorOpen: RequestType { + public let name: String + + public struct Source { + public let sourceFile: String? + public let sourceText: String? + + public static func path(_ path: String) -> Source { + return Source(sourceFile: path, sourceText: nil) + } + + public static func text(_ text: String) -> Source { + return Source(sourceFile: nil, sourceText: text) + } + } + public let source: Source + public let enableSyntaxMap: Bool? + public let enableStructure: Bool? + public let enableDiagnostics: Bool? + public let syntacticOnly: Bool? + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .editorOpen) + requestBuilder[.name] = name + requestBuilder[.sourceFile] = source.sourceFile + requestBuilder[.sourceText] = source.sourceText + requestBuilder[.enableSyntaxMap] = enableSyntaxMap + requestBuilder[.enableStructure] = enableStructure + requestBuilder[.enableDiagnostics] = enableDiagnostics + requestBuilder[.syntacticOnly] = syntacticOnly + requestBuilder[.compilerArgs] = arguments + return requestBuilder.makeRequest() + } + } + + public static func editorOpen(file: File, arguments: [String] = []) -> Request { + let name: String + let source: EditorOpen.Source + if let path = file.path { + name = path + source = .path(path) + } else { + name = String(file.contents.hash) + source = .text(file.contents) + } + + return .editorOpen(name: name, source: source, arguments: arguments) + } + + public static func editorOpen( + name: String, + source: EditorOpen.Source, + enableSyntaxMap: Bool? = nil, + enableStructure: Bool? = nil, + enableDiagnostics: Bool? = nil, + syntacticOnly: Bool? = nil, + arguments: [String] = [] + ) -> Request { + return Request(type: EditorOpen( + name: name, + source: source, + enableSyntaxMap: enableSyntaxMap, + enableStructure: enableStructure, + enableDiagnostics: enableDiagnostics, + syntacticOnly: syntacticOnly, + arguments: arguments + )) + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+EditorOpenHeaderInterface.swift b/Source/SourceKittenFramework/Requests/Request+EditorOpenHeaderInterface.swift new file mode 100644 index 000000000..aec1b2f4c --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+EditorOpenHeaderInterface.swift @@ -0,0 +1,40 @@ +// +// Request+EditorOpenHeaderInterface.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +extension Request { + /// ObjC Swift Interface + public struct EditorOpenHeaderInterface: RequestType { + public let name: String + public let filePath: String + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .editorOpenHeaderInterface) + requestBuilder[.name] = name + requestBuilder[.filePath] = filePath + requestBuilder[.compilerArgs] = arguments + return requestBuilder.makeRequest() + } + } + + public static func interface(file: String, uuid: String, arguments: [String]) -> Request { + var arguments = arguments + if !arguments.contains("-x") { + arguments.append(contentsOf: ["-x", "objective-c"]) + } + if !arguments.contains("-isysroot") { + arguments.append(contentsOf: ["-isysroot", sdkPath()]) + } + + arguments = [file] + arguments + + return Request(type: EditorOpenHeaderInterface(name: uuid, filePath: file, arguments: arguments)) + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+EditorOpenInterface.swift b/Source/SourceKittenFramework/Requests/Request+EditorOpenInterface.swift new file mode 100644 index 000000000..116f574a2 --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+EditorOpenInterface.swift @@ -0,0 +1,61 @@ +// +// Request+EditorOpenInterface.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +// swiftlint:disable nesting +extension Request { + /// Generate interface for a swift module. + public struct EditorOpenInterface: RequestType { + public let name: String + public let moduleName: String + + public struct Group { + public let groupName: String? + public let interestedUSR: String? + + public static func name(_ name: String) -> Group { + return Group(groupName: name, interestedUSR: nil) + } + + public static func containsInterestedUSR(_ usr: String) -> Group { + return Group(groupName: nil, interestedUSR: usr) + } + } + public let group: Group? + public let synthesizedExtension: Bool? + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .editorOpenInterface) + requestBuilder[.name] = name + requestBuilder[.moduleName] = moduleName + requestBuilder[.synthesizedExtension] = synthesizedExtension + requestBuilder[.compilerArgs] = arguments + requestBuilder[.groupName] = group?.groupName + requestBuilder[.interestedUSR] = group?.interestedUSR + return requestBuilder.makeRequest() + } + } + + public static func editorOpenInterface( + name: String, + moduleName: String, + group: EditorOpenInterface.Group? = nil, + synthesizedExtension: Bool? = nil, + arguments: [String] = [] + ) -> Request { + return Request(type: EditorOpenInterface( + name: name, + moduleName: moduleName, + group: group, + synthesizedExtension: synthesizedExtension, + arguments: arguments + )) + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+EditorReplaceText.swift b/Source/SourceKittenFramework/Requests/Request+EditorReplaceText.swift new file mode 100644 index 000000000..5c5370307 --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+EditorReplaceText.swift @@ -0,0 +1,33 @@ +// +// Request+EditorReplaceText.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +extension Request { + /// ReplaceText + public struct EditorReplaceText: RequestType { + public let name: String + public let offset: Int64 + public let length: Int64 + public let sourceText: String + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .editorReplaceText) + requestBuilder[.name] = name + requestBuilder[.offset] = offset + requestBuilder[.length] = length + requestBuilder[.sourceText] = sourceText + + return requestBuilder.makeRequest() + } + } + + public static func replaceText(file: String, offset: Int64, length: Int64, sourceText: String) -> Request { + return Request(type: EditorReplaceText(name: file, offset: offset, length: length, sourceText: sourceText)) + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+Index.swift b/Source/SourceKittenFramework/Requests/Request+Index.swift new file mode 100644 index 000000000..0353600e0 --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+Index.swift @@ -0,0 +1,28 @@ +// +// Request+Index.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +extension Request { + /// Index + public struct Index: RequestType { + public let sourceFile: String + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .index) + requestBuilder[.sourceFile] = sourceFile + requestBuilder[.compilerArgs] = arguments + return requestBuilder.makeRequest() + } + } + + public static func index(file: String, arguments: [String]) -> Request { + return Request(type: Index(sourceFile: file, arguments: arguments)) + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+ModuleGroups.swift b/Source/SourceKittenFramework/Requests/Request+ModuleGroups.swift new file mode 100644 index 000000000..38fd7c206 --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+ModuleGroups.swift @@ -0,0 +1,29 @@ +// +// Request+ModuleGroups.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +extension Request { + /// Request groups for module + public struct ModuleGroups: RequestType { + public let moduleName: String + public let arguments: [String] + + public func sourcekitObject() -> sourcekitd_object_t { + let requestBuilder = RequestBuilder(type: .moduleGroups) + requestBuilder[.moduleName] = moduleName + requestBuilder[.compilerArgs] = arguments + + return requestBuilder.makeRequest() + } + } + + public static func moduleGroups(module: String, arguments: [String]) -> Request { + return Request(type: ModuleGroups(moduleName: module, arguments: arguments)) + } +} diff --git a/Source/SourceKittenFramework/Requests/Request+YAML.swift b/Source/SourceKittenFramework/Requests/Request+YAML.swift new file mode 100644 index 000000000..7600a22d8 --- /dev/null +++ b/Source/SourceKittenFramework/Requests/Request+YAML.swift @@ -0,0 +1,24 @@ +// +// Request+YAML.swift +// SourceKittenFramework +// +// Created by Zheng Li on 25/11/2017. +// Copyright © 2017 SourceKitten. All rights reserved. +// + +import Foundation + +extension Request { + /// A request generated by sourcekit using the yaml representation. + public struct YAML: RequestType { + public let yaml: String + + public func sourcekitObject() -> sourcekitd_object_t { + return sourcekitd_request_create_from_yaml(yaml, nil)! + } + } + + public static func yamlRequest(yaml: String) -> Request { + return Request(type: YAML(yaml: yaml)) + } +} diff --git a/sourcekitten.xcodeproj/project.pbxproj b/sourcekitten.xcodeproj/project.pbxproj index f7573b0b0..5c630b1e8 100644 --- a/sourcekitten.xcodeproj/project.pbxproj +++ b/sourcekitten.xcodeproj/project.pbxproj @@ -26,6 +26,20 @@ 861E9D431F87574A001F182C /* SourceKitDef.swift in Sources */ = {isa = PBXBuildFile; fileRef = 861E9D421F87574A001F182C /* SourceKitDef.swift */; }; 866176221F85F31B00B9DF14 /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 866176211F85F31B00B9DF14 /* RequestTests.swift */; }; 866EDB011F87C79E00EC198A /* RequestBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 866EDAFF1F87C74600EC198A /* RequestBuilder.swift */; }; + 869C8D491FC97C800067FF0E /* Request+EditorOpen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D481FC97C800067FF0E /* Request+EditorOpen.swift */; }; + 869C8D4B1FC97EEB0067FF0E /* Request+EditorOpenInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D4A1FC97EEB0067FF0E /* Request+EditorOpenInterface.swift */; }; + 869C8D4D1FC97F8E0067FF0E /* Request+CursorInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D4C1FC97F8E0067FF0E /* Request+CursorInfo.swift */; }; + 869C8D4F1FC981BC0067FF0E /* Request+Custom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D4E1FC981BC0067FF0E /* Request+Custom.swift */; }; + 869C8D511FC981DB0067FF0E /* Request+YAML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D501FC981DB0067FF0E /* Request+YAML.swift */; }; + 869C8D531FC9831C0067FF0E /* Request+CodeComplete.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D521FC9831C0067FF0E /* Request+CodeComplete.swift */; }; + 869C8D551FC986110067FF0E /* Request+EditorOpenHeaderInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D541FC986110067FF0E /* Request+EditorOpenHeaderInterface.swift */; }; + 869C8D571FC9869A0067FF0E /* Request+EditorFindUSR.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D561FC9869A0067FF0E /* Request+EditorFindUSR.swift */; }; + 869C8D591FC986D60067FF0E /* Request+EditorFormatText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D581FC986D60067FF0E /* Request+EditorFormatText.swift */; }; + 869C8D5B1FC9874F0067FF0E /* Request+EditorReplaceText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D5A1FC9874F0067FF0E /* Request+EditorReplaceText.swift */; }; + 869C8D5D1FC9877D0067FF0E /* Request+Index.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D5C1FC9877D0067FF0E /* Request+Index.swift */; }; + 869C8D5F1FC988B80067FF0E /* Request+DocInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D5E1FC988B80067FF0E /* Request+DocInfo.swift */; }; + 869C8D611FC989030067FF0E /* Request+Demangle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D601FC989030067FF0E /* Request+Demangle.swift */; }; + 869C8D631FC9896E0067FF0E /* Request+ModuleGroups.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D621FC9896E0067FF0E /* Request+ModuleGroups.swift */; }; B2FA87E26BC9C5F774FD694C /* SwiftLangSyntax.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2FA804AA9D4427FF571EFB2 /* SwiftLangSyntax.swift */; }; C236E84B1DFF5120003807D2 /* YamlRequestCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C236E84A1DFF5120003807D2 /* YamlRequestCommand.swift */; }; D0AAAB5019FB0960007B24B3 /* SourceKittenFramework.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D0D1216D19E87B05005E4BAA /* SourceKittenFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -150,6 +164,20 @@ 861E9D421F87574A001F182C /* SourceKitDef.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceKitDef.swift; sourceTree = ""; }; 866176211F85F31B00B9DF14 /* RequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestTests.swift; sourceTree = ""; }; 866EDAFF1F87C74600EC198A /* RequestBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestBuilder.swift; sourceTree = ""; }; + 869C8D481FC97C800067FF0E /* Request+EditorOpen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+EditorOpen.swift"; sourceTree = ""; }; + 869C8D4A1FC97EEB0067FF0E /* Request+EditorOpenInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+EditorOpenInterface.swift"; sourceTree = ""; }; + 869C8D4C1FC97F8E0067FF0E /* Request+CursorInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+CursorInfo.swift"; sourceTree = ""; }; + 869C8D4E1FC981BC0067FF0E /* Request+Custom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+Custom.swift"; sourceTree = ""; }; + 869C8D501FC981DB0067FF0E /* Request+YAML.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+YAML.swift"; sourceTree = ""; }; + 869C8D521FC9831C0067FF0E /* Request+CodeComplete.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+CodeComplete.swift"; sourceTree = ""; }; + 869C8D541FC986110067FF0E /* Request+EditorOpenHeaderInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+EditorOpenHeaderInterface.swift"; sourceTree = ""; }; + 869C8D561FC9869A0067FF0E /* Request+EditorFindUSR.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+EditorFindUSR.swift"; sourceTree = ""; }; + 869C8D581FC986D60067FF0E /* Request+EditorFormatText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+EditorFormatText.swift"; sourceTree = ""; }; + 869C8D5A1FC9874F0067FF0E /* Request+EditorReplaceText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+EditorReplaceText.swift"; sourceTree = ""; }; + 869C8D5C1FC9877D0067FF0E /* Request+Index.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+Index.swift"; sourceTree = ""; }; + 869C8D5E1FC988B80067FF0E /* Request+DocInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+DocInfo.swift"; sourceTree = ""; }; + 869C8D601FC989030067FF0E /* Request+Demangle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+Demangle.swift"; sourceTree = ""; }; + 869C8D621FC9896E0067FF0E /* Request+ModuleGroups.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+ModuleGroups.swift"; sourceTree = ""; }; B2FA804AA9D4427FF571EFB2 /* SwiftLangSyntax.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftLangSyntax.swift; sourceTree = ""; }; C236E84A1DFF5120003807D2 /* YamlRequestCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YamlRequestCommand.swift; sourceTree = ""; }; D0D1211B19E87861005E4BAA /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; usesTabs = 0; }; @@ -277,6 +305,27 @@ name = "Supporting Files"; sourceTree = ""; }; + 869C8D641FC98A670067FF0E /* Requests */ = { + isa = PBXGroup; + children = ( + 869C8D481FC97C800067FF0E /* Request+EditorOpen.swift */, + 869C8D4A1FC97EEB0067FF0E /* Request+EditorOpenInterface.swift */, + 869C8D541FC986110067FF0E /* Request+EditorOpenHeaderInterface.swift */, + 869C8D561FC9869A0067FF0E /* Request+EditorFindUSR.swift */, + 869C8D581FC986D60067FF0E /* Request+EditorFormatText.swift */, + 869C8D5A1FC9874F0067FF0E /* Request+EditorReplaceText.swift */, + 869C8D5C1FC9877D0067FF0E /* Request+Index.swift */, + 869C8D4C1FC97F8E0067FF0E /* Request+CursorInfo.swift */, + 869C8D521FC9831C0067FF0E /* Request+CodeComplete.swift */, + 869C8D4E1FC981BC0067FF0E /* Request+Custom.swift */, + 869C8D501FC981DB0067FF0E /* Request+YAML.swift */, + 869C8D5E1FC988B80067FF0E /* Request+DocInfo.swift */, + 869C8D601FC989030067FF0E /* Request+Demangle.swift */, + 869C8D621FC9896E0067FF0E /* Request+ModuleGroups.swift */, + ); + path = Requests; + sourceTree = ""; + }; D0D1210F19E87861005E4BAA = { isa = PBXGroup; children = ( @@ -411,7 +460,6 @@ E877D9261B5693E70095BB2B /* ObjCDeclarationKind.swift */, E83748C21A5BCD7900862B1B /* OffsetMap.swift */, E806D2901BE058C400D1BE41 /* Parameter.swift */, - E86847391A587B4D0043DC65 /* Request.swift */, E8A9B8911B56D1B100CD17D4 /* SourceDeclaration.swift */, D0D1217119E87B05005E4BAA /* SourceKittenFramework.h */, E806D28C1BE0589B00D1BE41 /* SourceLocation.swift */, @@ -428,7 +476,9 @@ 6CC381621ECACB50000C6F81 /* Version.swift */, E8A9B88F1B56CB5500CD17D4 /* Xcode.swift */, B2FA804AA9D4427FF571EFB2 /* SwiftLangSyntax.swift */, + E86847391A587B4D0043DC65 /* Request.swift */, 866EDAFF1F87C74600EC198A /* RequestBuilder.swift */, + 869C8D641FC98A670067FF0E /* Requests */, ); name = SourceKittenFramework; path = Source/SourceKittenFramework; @@ -671,23 +721,34 @@ 3F0CBB411BAAFF160015BBA8 /* Clang+SourceKitten.swift in Sources */, 866EDB011F87C79E00EC198A /* RequestBuilder.swift in Sources */, 2E8FF7101C6268C100F280F0 /* StatementKind.swift in Sources */, + 869C8D511FC981DB0067FF0E /* Request+YAML.swift in Sources */, 6C4CF6551C798086008532C5 /* library_wrapper_Documentation.swift in Sources */, E8D4743B1A648F290011A49C /* ClangTranslationUnit.swift in Sources */, E8EE34BF1B9A502F00947605 /* CodeCompletionItem.swift in Sources */, + 869C8D611FC989030067FF0E /* Request+Demangle.swift in Sources */, E852418F1A5F4FB3007099FB /* Dictionary+Merge.swift in Sources */, 6CC381641ECACB6F000C6F81 /* Version.swift in Sources */, E847636A1A5A0651000EAE22 /* File.swift in Sources */, + 869C8D591FC986D60067FF0E /* Request+EditorFormatText.swift in Sources */, + 869C8D5D1FC9877D0067FF0E /* Request+Index.swift in Sources */, + 869C8D551FC986110067FF0E /* Request+EditorOpenHeaderInterface.swift in Sources */, 861E9D431F87574A001F182C /* SourceKitDef.swift in Sources */, + 869C8D631FC9896E0067FF0E /* Request+ModuleGroups.swift in Sources */, 6C4CF5771C78B47F008532C5 /* library_wrapper.swift in Sources */, 3F56EAD01BAB251C006433D0 /* JSONOutput.swift in Sources */, + 869C8D571FC9869A0067FF0E /* Request+EditorFindUSR.swift in Sources */, E8A18A3B1A58971D000362B7 /* Language.swift in Sources */, + 869C8D531FC9831C0067FF0E /* Request+CodeComplete.swift in Sources */, E806D28F1BE058B100D1BE41 /* Text.swift in Sources */, + 869C8D5F1FC988B80067FF0E /* Request+DocInfo.swift in Sources */, E8241CA51A5E01A10047687E /* Module.swift in Sources */, E877D9271B5693E70095BB2B /* ObjCDeclarationKind.swift in Sources */, 6C4CF6521C798082008532C5 /* library_wrapper_CXString.swift in Sources */, E83748C31A5BCD7900862B1B /* OffsetMap.swift in Sources */, E806D2911BE058C400D1BE41 /* Parameter.swift in Sources */, E868473A1A587B4D0043DC65 /* Request.swift in Sources */, + 869C8D491FC97C800067FF0E /* Request+EditorOpen.swift in Sources */, + 869C8D4D1FC97F8E0067FF0E /* Request+CursorInfo.swift in Sources */, E8A9B8921B56D1B100CD17D4 /* SourceDeclaration.swift in Sources */, E806D28D1BE0589B00D1BE41 /* SourceLocation.swift in Sources */, E8AE53C71A5B5FCA0092D24A /* String+SourceKitten.swift in Sources */, @@ -695,12 +756,15 @@ E89291A91A5B800300D91568 /* SwiftDeclarationKind.swift in Sources */, E89291A71A5B7FF800D91568 /* SwiftDocKey.swift in Sources */, E8A18A3F1A592246000362B7 /* SwiftDocs.swift in Sources */, + 869C8D5B1FC9874F0067FF0E /* Request+EditorReplaceText.swift in Sources */, E80F23691A5CB01A00FD2352 /* SyntaxKind.swift in Sources */, 6C4CF5761C78B47F008532C5 /* library_wrapper_sourcekitd.swift in Sources */, E8CC8A2D1A587FD300D1FEC7 /* SyntaxMap.swift in Sources */, 6C4CF6581C79808C008532C5 /* library_wrapper_Index.swift in Sources */, E80F236B1A5CB04100FD2352 /* SyntaxToken.swift in Sources */, E8A9B8901B56CB5500CD17D4 /* Xcode.swift in Sources */, + 869C8D4B1FC97EEB0067FF0E /* Request+EditorOpenInterface.swift in Sources */, + 869C8D4F1FC981BC0067FF0E /* Request+Custom.swift in Sources */, B2FA87E26BC9C5F774FD694C /* SwiftLangSyntax.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; From 05e45a8fba600bace7550d06d6bd718024a36d12 Mon Sep 17 00:00:00 2001 From: ainopara Date: Sat, 25 Nov 2017 19:30:17 +0800 Subject: [PATCH 13/15] Update test case to drop swift 3.1 support. --- .../LinuxSwiftModuleGroups@swift-3.1.json | 55 ------------------- .../Fixtures/SwiftModuleGroups@swift-3.1.json | 55 ------------------- .../RequestTests.swift | 21 +------ 3 files changed, 2 insertions(+), 129 deletions(-) delete mode 100644 Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.1.json delete mode 100644 Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.1.json diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.1.json b/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.1.json deleted file mode 100644 index 1f0ea2e5e..000000000 --- a/Tests/SourceKittenFrameworkTests/Fixtures/LinuxSwiftModuleGroups@swift-3.1.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "key.modulegroups" : [ - { - "key.groupname" : "Assert" - }, - { - "key.groupname" : "Bool" - }, - { - "key.groupname" : "C" - }, - { - "key.groupname" : "Collection" - }, - { - "key.groupname" : "Collection/Array" - }, - { - "key.groupname" : "Collection/HashedCollections" - }, - { - "key.groupname" : "Collection/Lazy Views" - }, - { - "key.groupname" : "Collection/Type-erased" - }, - { - "key.groupname" : "Math" - }, - { - "key.groupname" : "Math/Floating" - }, - { - "key.groupname" : "Math/Integers" - }, - { - "key.groupname" : "Misc" - }, - { - "key.groupname" : "Optional" - }, - { - "key.groupname" : "Pointer" - }, - { - "key.groupname" : "Protocols" - }, - { - "key.groupname" : "Reflection" - }, - { - "key.groupname" : "String" - } - ] -} \ No newline at end of file diff --git a/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.1.json b/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.1.json deleted file mode 100644 index f9e8e53c1..000000000 --- a/Tests/SourceKittenFrameworkTests/Fixtures/SwiftModuleGroups@swift-3.1.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "key.modulegroups" : [ - { - "key.groupname" : "Assert" - }, - { - "key.groupname" : "Bool" - }, - { - "key.groupname" : "C" - }, - { - "key.groupname" : "Collection" - }, - { - "key.groupname" : "Collection\/Array" - }, - { - "key.groupname" : "Collection\/HashedCollections" - }, - { - "key.groupname" : "Collection\/Lazy Views" - }, - { - "key.groupname" : "Collection\/Type-erased" - }, - { - "key.groupname" : "Math" - }, - { - "key.groupname" : "Math\/Floating" - }, - { - "key.groupname" : "Math\/Integers" - }, - { - "key.groupname" : "Misc" - }, - { - "key.groupname" : "Optional" - }, - { - "key.groupname" : "Pointer" - }, - { - "key.groupname" : "Protocols" - }, - { - "key.groupname" : "Reflection" - }, - { - "key.groupname" : "String" - } - ] -} diff --git a/Tests/SourceKittenFrameworkTests/RequestTests.swift b/Tests/SourceKittenFrameworkTests/RequestTests.swift index cc47c2c11..2f1b2e3e7 100644 --- a/Tests/SourceKittenFrameworkTests/RequestTests.swift +++ b/Tests/SourceKittenFrameworkTests/RequestTests.swift @@ -11,11 +11,6 @@ import SourceKittenFramework import XCTest class RequestTests: XCTestCase { - func testProtocolVersion() { - let version = Request.protocolVersion().send() - compareJSONString(withFixtureNamed: "ProtocolVersion", jsonString: toJSON(toNSDictionary(version))) - } - func testSwiftModuleGroups() { let groups = Request.moduleGroups(module: "Swift", arguments: ["-sdk", sdkPath()]).send() compareJSONString(withFixtureNamed: "SwiftModuleGroups", jsonString: toJSON(toNSDictionary(groups))) @@ -29,7 +24,6 @@ class RequestTests: XCTestCase { "_T021SourceKittenFramework7RequestOD", "_T0s10DictionaryVySS9Structure22SourceKitRepresentable_pGD" ] -#if swift(>=3.2) let expectedResult: NSDictionary = [ "key.results": [ ["key.name": "Swift.String"], @@ -39,17 +33,7 @@ class RequestTests: XCTestCase { ["key.name": "Swift.Dictionary"] ] ] -#else - let expectedResult: NSDictionary = [ - "key.results": [ - ["key.name": "Swift.String"], - ["key.name": "__C.NSRange with unmangled suffix \"mD\""], - ["key.name": "__ObjC.Process"], - ["key.name": "SourceKittenFramework.Request"], - ["key.name": "Swift.Dictionary"] - ] - ] -#endif + let result = Request.demangle(names: mangledNames).send() XCTAssertEqual(toNSDictionary(result), expectedResult, "should demange names.") } @@ -58,7 +42,7 @@ class RequestTests: XCTestCase { let result = Request.editorOpenInterface( name: UUID().uuidString, moduleName: "Swift", - group: .name("Assert"), // Choose a relative small group. + group: .name("Assert"), // Choose a relatively small group. synthesizedExtension: true, arguments: ["-sdk", sdkPath()] ).send() @@ -69,7 +53,6 @@ class RequestTests: XCTestCase { extension RequestTests { static var allTests: [(String, (RequestTests) -> () throws -> Void)] { return [ - ("testProtocolVersion", testProtocolVersion), ("testSwiftModuleGroups", testSwiftModuleGroups), ("testEditorOpenInterface", testEditorOpenInterface) ] From 1ad8ed97249e6d2a8efa0434aba823bf1587f0f4 Mon Sep 17 00:00:00 2001 From: ainopara Date: Sun, 26 Nov 2017 12:19:24 +0800 Subject: [PATCH 14/15] Rename `SourceKitDef` to `UID`. --- Makefile | 6 +- .../RequestBuilder.swift | 10 +- .../Requests/Request+CursorInfo.swift | 2 +- .../Requests/Request+EditorFindUSR.swift | 2 +- .../{SourceKitDef.swift => UID.swift} | 348 +++++++++++++++++- Templates/AutoEnumNameFix.stencil | 20 +- sourcekitten.xcodeproj/project.pbxproj | 8 +- 7 files changed, 358 insertions(+), 38 deletions(-) rename Source/SourceKittenFramework/{SourceKitDef.swift => UID.swift} (82%) diff --git a/Makefile b/Makefile index bf8499f7e..3f92d7518 100644 --- a/Makefile +++ b/Makefile @@ -86,9 +86,9 @@ docker_test_4: docker run -v `pwd`:`pwd` -w `pwd` --rm norionomura/swift:40 swift test generate_sourcekit_defines: - clang -E -P Templates/TypeDefs.h -o Templates/SourceKitDef.swift - sourcery --sources Templates/SourceKitDef.swift --templates Templates/AutoEnumNameFix.stencil --output Templates/SourceKitDef.swift - mv Templates/SourceKitDef.swift Source/SourceKittenFramework + clang -E -P Templates/TypeDefs.h -o Templates/UID.swift + sourcery --sources Templates/UID.swift --templates Templates/AutoEnumNameFix.stencil --output Templates/UID.swift + mv Templates/UID.swift Source/SourceKittenFramework # http://irace.me/swift-profiling/ display_compilation_time: diff --git a/Source/SourceKittenFramework/RequestBuilder.swift b/Source/SourceKittenFramework/RequestBuilder.swift index 11de91b98..6daa7742e 100644 --- a/Source/SourceKittenFramework/RequestBuilder.swift +++ b/Source/SourceKittenFramework/RequestBuilder.swift @@ -14,13 +14,13 @@ import SourceKit public class RequestBuilder { private var dict: [sourcekitd_uid_t: sourcekitd_object_t] = [:] - public init(type: SourceKitDef.Request) { - dict[transform(key: "key.request")] = sourcekitd_request_uid_create(transform(key: type.stringRepresentation)) + public init(type: UID.Request) { + dict[transform(key: "key.request")] = sourcekitd_request_uid_create(transform(key: type.description)) } - public subscript(_ key: SourceKitDef.Key) -> Any? { - get { return dict[transform(key: key.stringRepresentation)] } - set { set(newValue, for: key.stringRepresentation) } + public subscript(_ key: UID.Key) -> Any? { + get { return dict[transform(key: key.description)] } + set { set(newValue, for: key.description) } } public func makeRequest() -> sourcekitd_object_t { diff --git a/Source/SourceKittenFramework/Requests/Request+CursorInfo.swift b/Source/SourceKittenFramework/Requests/Request+CursorInfo.swift index b5bf251e0..c5225363e 100644 --- a/Source/SourceKittenFramework/Requests/Request+CursorInfo.swift +++ b/Source/SourceKittenFramework/Requests/Request+CursorInfo.swift @@ -38,7 +38,7 @@ extension Request { requestBuilder[.name] = name requestBuilder[.sourceFile] = sourceFile requestBuilder[.cancelOnSubsequentRequest] = cancelOnSubsequentRequest - requestBuilder[.uSR] = location.usr + requestBuilder[.usr] = location.usr requestBuilder[.offset] = location.offset requestBuilder[.length] = location.length requestBuilder[.retrieveRefactorActions] = location.retrieveRefactorActions diff --git a/Source/SourceKittenFramework/Requests/Request+EditorFindUSR.swift b/Source/SourceKittenFramework/Requests/Request+EditorFindUSR.swift index c116fc34c..75764d7f9 100644 --- a/Source/SourceKittenFramework/Requests/Request+EditorFindUSR.swift +++ b/Source/SourceKittenFramework/Requests/Request+EditorFindUSR.swift @@ -17,7 +17,7 @@ extension Request { public func sourcekitObject() -> sourcekitd_object_t { let requestBuilder = RequestBuilder(type: .editorFindUSR) requestBuilder[.sourceFile] = sourceFile - requestBuilder[.uSR] = usr + requestBuilder[.usr] = usr return requestBuilder.makeRequest() } } diff --git a/Source/SourceKittenFramework/SourceKitDef.swift b/Source/SourceKittenFramework/UID.swift similarity index 82% rename from Source/SourceKittenFramework/SourceKitDef.swift rename to Source/SourceKittenFramework/UID.swift index f7242e972..f76eda88f 100644 --- a/Source/SourceKittenFramework/SourceKitDef.swift +++ b/Source/SourceKittenFramework/UID.swift @@ -4,142 +4,276 @@ import Swift -public struct SourceKitDef { +public struct UID { - public enum Key { + public enum Key: CustomStringConvertible { + /// key.version_major case versionMajor + /// key.version_minor case versionMinor + /// key.results case results + /// key.request case request + /// key.notification case notification + /// key.kind case kind + /// key.accessibility case accessLevel + /// key.setter_accessibility case setterAccessLevel + /// key.keyword case keyword + /// key.name case name - case uSR + /// key.usr + case usr + /// key.original_usr case originalUSR + /// key.default_implementation_of case defaultImplementationOf + /// key.interested_usr case interestedUSR + /// key.generic_params case genericParams + /// key.generic_requirements case genericRequirements + /// key.doc.full_as_xml case docFullAsXML + /// key.line case line + /// key.column case column + /// key.receiver_usr case receiverUSR + /// key.is_dynamic case isDynamic + /// key.filepath case filePath + /// key.module_interface_name case moduleInterfaceName + /// key.hash case hash + /// key.compilerargs case compilerArgs + /// key.severity case severity + /// key.offset case offset + /// key.length case length + /// key.sourcefile case sourceFile + /// key.sourcetext case sourceText + /// key.enablesyntaxmap case enableSyntaxMap + /// key.enablesubstructure case enableStructure + /// key.description case description + /// key.typename case typeName + /// key.runtime_name case runtimeName + /// key.selector_name case selectorName + /// key.annotated_decl case annotatedDecl + /// key.fully_annotated_decl case fullyAnnotatedDecl + /// key.doc.brief case docBrief + /// key.context case context + /// key.moduleimportdepth case moduleImportDepth + /// key.num_bytes_to_erase case numBytesToErase + /// key.not_recommended case notRecommended + /// key.annotations case annotations + /// key.diagnostic_stage case diagnosticStage + /// key.syntaxmap case syntaxMap + /// key.is_system case isSystem + /// key.related case related + /// key.inherits case inherits + /// key.conforms case conforms + /// key.extends case extends + /// key.dependencies case dependencies + /// key.entities case entities + /// key.nameoffset case nameOffset + /// key.namelength case nameLength + /// key.bodyoffset case bodyOffset + /// key.bodylength case bodyLength + /// key.throwoffset case throwOffset + /// key.throwlength case throwLength + /// key.docoffset case docOffset + /// key.doclength case docLength + /// key.is_local case isLocal + /// key.inheritedtypes case inheritedTypes + /// key.attributes case attributes + /// key.attribute case attribute + /// key.elements case elements + /// key.substructure case subStructure + /// key.ranges case ranges + /// key.fixits case fixits + /// key.diagnostics case diagnostics + /// key.editor.format.options case formatOptions + /// key.codecomplete.options case codeCompleteOptions + /// key.codecomplete.filterrules case filterRules + /// key.nextrequeststart case nextRequestStart + /// key.popular case popular + /// key.unpopular case unpopular + /// key.hide case hide + /// key.platform case platform + /// key.is_deprecated case isDeprecated + /// key.is_unavailable case isUnavailable + /// key.is_optional case isOptional + /// key.message case message + /// key.introduced case introduced + /// key.deprecated case deprecated + /// key.obsoleted case obsoleted + /// key.removecache case removeCache + /// key.typeinterface case typeInterface + /// key.typeusr case typeUsr + /// key.containertypeusr case containerTypeUsr + /// key.modulegroups case moduleGroups + /// key.basename case baseName + /// key.argnames case argNames + /// key.selectorpieces case selectorPieces + /// key.namekind case nameKind + /// key.localization_key case localizationKey + /// key.is_zero_arg_selector case isZeroArgSelector + /// key.swift_version case swiftVersion + /// key.enablediagnostics case enableDiagnostics + /// key.groupname case groupName + /// key.actionname case actionName + /// key.synthesizedextensions case synthesizedExtension + /// key.usingswiftargs case usingSwiftArgs + /// key.names case names - case uIDs + /// key.uids + case uids + /// key.syntactic_only case syntacticOnly + /// key.actionable case actionable + /// key.parent_loc case parentLoc + /// key.is_test_candidate case isTestCandidate + /// key.overrides case overrides + /// key.associated_usrs case associatedUSRs + /// key.modulename case moduleName + /// key.related_decls case relatedDecls + /// key.simplified case simplified + /// key.rangecontent case rangeContent + /// key.cancel_on_subsequent_request case cancelOnSubsequentRequest + /// key.renamelocations case renameLocations + /// key.locations case locations + /// key.nametype case nameType + /// key.newname case newName + /// key.categorizededits case categorizedEdits + /// key.categorizedranges case categorizedRanges + /// key.rangesworthnote case rangesWorthNote + /// key.edits case edits + /// key.endline case endLine + /// key.endcolumn case endColumn + /// key.argindex case argIndex + /// key.text case text + /// key.category case category + /// key.is_function_like case isFunctionLike + /// key.is_non_protocol_type case isNonProtocolType + /// key.refactor_actions case refactorActions + /// key.retrieve_refactor_actions case retrieveRefactorActions + /// key.actionuid case actionUID + /// key.actionunavailablereason case actionUnavailableReason case unrecognized(String) @@ -166,7 +300,7 @@ public struct SourceKitDef { case "key.name": self = .name case "key.usr": - self = .uSR + self = .usr case "key.original_usr": self = .originalUSR case "key.default_implementation_of": @@ -352,7 +486,7 @@ public struct SourceKitDef { case "key.names": self = .names case "key.uids": - self = .uIDs + self = .uiDs case "key.syntactic_only": self = .syntacticOnly case "key.actionable": @@ -418,7 +552,7 @@ public struct SourceKitDef { } } - public var stringRepresentation: String { + public var description: String { switch self { case .versionMajor: return "key.version_major" @@ -440,7 +574,7 @@ public struct SourceKitDef { return "key.keyword" case .name: return "key.name" - case .uSR: + case .usr: return "key.usr" case .originalUSR: return "key.original_usr" @@ -626,7 +760,7 @@ public struct SourceKitDef { return "key.usingswiftargs" case .names: return "key.names" - case .uIDs: + case .uiDs: return "key.uids" case .syntacticOnly: return "key.syntactic_only" @@ -694,152 +828,298 @@ public struct SourceKitDef { } } - public enum Kind { + public enum Kind: CustomStringConvertible { + /// source.lang.swift.decl.function.free case declFunctionFree + /// source.lang.swift.ref.function.free case refFunctionFree + /// source.lang.swift.decl.function.method.instance case declMethodInstance + /// source.lang.swift.ref.function.method.instance case refMethodInstance + /// source.lang.swift.decl.function.method.static case declMethodStatic + /// source.lang.swift.ref.function.method.static case refMethodStatic + /// source.lang.swift.decl.function.method.class case declMethodClass + /// source.lang.swift.ref.function.method.class case refMethodClass + /// source.lang.swift.decl.function.accessor.getter case declAccessorGetter + /// source.lang.swift.ref.function.accessor.getter case refAccessorGetter + /// source.lang.swift.decl.function.accessor.setter case declAccessorSetter + /// source.lang.swift.ref.function.accessor.setter case refAccessorSetter + /// source.lang.swift.decl.function.accessor.willset case declAccessorWillSet + /// source.lang.swift.ref.function.accessor.willset case refAccessorWillSet + /// source.lang.swift.decl.function.accessor.didset case declAccessorDidSet + /// source.lang.swift.ref.function.accessor.didset case refAccessorDidSet + /// source.lang.swift.decl.function.accessor.address case declAccessorAddress + /// source.lang.swift.ref.function.accessor.address case refAccessorAddress + /// source.lang.swift.decl.function.accessor.mutableaddress case declAccessorMutableAddress + /// source.lang.swift.ref.function.accessor.mutableaddress case refAccessorMutableAddress + /// source.lang.swift.decl.function.constructor case declConstructor + /// source.lang.swift.ref.function.constructor case refConstructor + /// source.lang.swift.decl.function.destructor case declDestructor + /// source.lang.swift.ref.function.destructor case refDestructor + /// source.lang.swift.decl.function.operator.prefix case declFunctionPrefixOperator + /// source.lang.swift.decl.function.operator.postfix case declFunctionPostfixOperator + /// source.lang.swift.decl.function.operator.infix case declFunctionInfixOperator + /// source.lang.swift.ref.function.operator.prefix case refFunctionPrefixOperator + /// source.lang.swift.ref.function.operator.postfix case refFunctionPostfixOperator + /// source.lang.swift.ref.function.operator.infix case refFunctionInfixOperator + /// source.lang.swift.decl.precedencegroup case declPrecedenceGroup + /// source.lang.swift.ref.precedencegroup case refPrecedenceGroup + /// source.lang.swift.decl.function.subscript case declSubscript + /// source.lang.swift.ref.function.subscript case refSubscript + /// source.lang.swift.decl.var.global case declVarGlobal + /// source.lang.swift.ref.var.global case refVarGlobal + /// source.lang.swift.decl.var.instance case declVarInstance + /// source.lang.swift.ref.var.instance case refVarInstance + /// source.lang.swift.decl.var.static case declVarStatic + /// source.lang.swift.ref.var.static case refVarStatic + /// source.lang.swift.decl.var.class case declVarClass + /// source.lang.swift.ref.var.class case refVarClass + /// source.lang.swift.decl.var.local case declVarLocal + /// source.lang.swift.ref.var.local case refVarLocal + /// source.lang.swift.decl.var.parameter case declVarParam + /// source.lang.swift.decl.module case declModule + /// source.lang.swift.decl.class case declClass + /// source.lang.swift.ref.class case refClass + /// source.lang.swift.decl.struct case declStruct + /// source.lang.swift.ref.struct case refStruct + /// source.lang.swift.decl.enum case declEnum + /// source.lang.swift.ref.enum case refEnum + /// source.lang.swift.decl.enumcase case declEnumCase + /// source.lang.swift.decl.enumelement case declEnumElement + /// source.lang.swift.ref.enumelement case refEnumElement + /// source.lang.swift.decl.protocol case declProtocol + /// source.lang.swift.ref.protocol case refProtocol + /// source.lang.swift.decl.extension case declExtension + /// source.lang.swift.decl.extension.struct case declExtensionStruct + /// source.lang.swift.decl.extension.class case declExtensionClass + /// source.lang.swift.decl.extension.enum case declExtensionEnum + /// source.lang.swift.decl.extension.protocol case declExtensionProtocol + /// source.lang.swift.decl.associatedtype case declAssociatedType + /// source.lang.swift.ref.associatedtype case refAssociatedType + /// source.lang.swift.decl.typealias case declTypeAlias + /// source.lang.swift.ref.typealias case refTypeAlias + /// source.lang.swift.decl.generic_type_param case declGenericTypeParam + /// source.lang.swift.ref.generic_type_param case refGenericTypeParam + /// source.lang.swift.ref.module case refModule + /// source.lang.swift.stmt.foreach case stmtForEach + /// source.lang.swift.stmt.for case stmtFor + /// source.lang.swift.stmt.while case stmtWhile + /// source.lang.swift.stmt.repeatwhile case stmtRepeatWhile + /// source.lang.swift.stmt.if case stmtIf + /// source.lang.swift.stmt.guard case stmtGuard + /// source.lang.swift.stmt.switch case stmtSwitch + /// source.lang.swift.stmt.case case stmtCase + /// source.lang.swift.stmt.brace case stmtBrace + /// source.lang.swift.expr.call case exprCall + /// source.lang.swift.expr.argument case exprArg + /// source.lang.swift.expr.array case exprArray + /// source.lang.swift.expr.dictionary case exprDictionary + /// source.lang.swift.expr.object_literal case exprObjectLiteral + /// source.lang.swift.structure.elem.id case structureElemId + /// source.lang.swift.structure.elem.expr case structureElemExpr + /// source.lang.swift.structure.elem.init_expr case structureElemInitExpr + /// source.lang.swift.structure.elem.condition_expr case structureElemCondExpr + /// source.lang.swift.structure.elem.pattern case structureElemPattern + /// source.lang.swift.structure.elem.typeref case structureElemTypeRef + /// source.lang.swift.range.singlestatement case rangeSingleStatement + /// source.lang.swift.range.singleexpression case rangeSingleExpression + /// source.lang.swift.range.singledeclaration case rangeSingleDeclaration + /// source.lang.swift.range.multistatement case rangeMultiStatement + /// source.lang.swift.range.invalid case rangeInvalid + /// source.lang.name.kind.objc case nameObjc + /// source.lang.name.kind.swift case nameSwift + /// source.lang.swift.syntaxtype.keyword case keyword + /// source.lang.swift.syntaxtype.identifier case identifier + /// source.lang.swift.syntaxtype.typeidentifier case typeIdentifier + /// source.lang.swift.syntaxtype.buildconfig.keyword case buildConfigKeyword + /// source.lang.swift.syntaxtype.buildconfig.id case buildConfigId + /// source.lang.swift.syntaxtype.attribute.id case attributeId + /// source.lang.swift.syntaxtype.attribute.builtin case attributeBuiltin + /// source.lang.swift.syntaxtype.number case number + /// source.lang.swift.syntaxtype.string case string + /// source.lang.swift.syntaxtype.string_interpolation_anchor case stringInterpolation + /// source.lang.swift.syntaxtype.comment case comment + /// source.lang.swift.syntaxtype.doccomment case docComment + /// source.lang.swift.syntaxtype.doccomment.field case docCommentField + /// source.lang.swift.syntaxtype.comment.mark case commentMarker + /// source.lang.swift.syntaxtype.comment.url case commentURL + /// source.lang.swift.syntaxtype.placeholder case placeholder + /// source.lang.swift.syntaxtype.objectliteral case objectLiteral + /// source.lang.swift.expr case expr + /// source.lang.swift.stmt case stmt + /// source.lang.swift.type case type + /// source.lang.swift.foreach.sequence case forEachSequence + /// source.diagnostic.severity.note case diagNote + /// source.diagnostic.severity.warning case diagWarning + /// source.diagnostic.severity.error case diagError + /// source.codecompletion.everything case codeCompletionEverything + /// source.codecompletion.module case codeCompletionModule + /// source.codecompletion.keyword case codeCompletionKeyword + /// source.codecompletion.literal case codeCompletionLiteral + /// source.codecompletion.custom case codeCompletionCustom + /// source.codecompletion.identifier case codeCompletionIdentifier + /// source.codecompletion.description case codeCompletionDescription + /// source.edit.kind.active case editActive + /// source.edit.kind.inactive case editInactive + /// source.edit.kind.selector case editSelector + /// source.edit.kind.string case editString + /// source.edit.kind.comment case editComment + /// source.edit.kind.mismatch case editMismatch + /// source.edit.kind.unknown case editUnknown + /// source.refactoring.range.kind.basename case renameRangeBase + /// source.refactoring.range.kind.keyword-basename case renameRangeKeywordBase + /// source.refactoring.range.kind.parameter-and-whitespace case renameRangeParam + /// source.refactoring.range.kind.decl-argument-label case renameRangeDeclArgLabel + /// source.refactoring.range.kind.call-argument-label case renameRangeCallArgLabel + /// source.refactoring.range.kind.call-argument-colon case renameRangeCallArgColon + /// source.refactoring.range.kind.call-argument-combined case renameRangeCallArgCombined + /// source.refactoring.range.kind.selector-argument-label case renameRangeSelectorArgLabel + /// source.syntacticrename.definition case definition + /// source.syntacticrename.reference case reference + /// source.syntacticrename.call case call + /// source.syntacticrename.unknown case unknown case unrecognized(String) @@ -1142,7 +1422,7 @@ public struct SourceKitDef { } } - public var stringRepresentation: String { + public var description: String { switch self { case .declFunctionFree: return "source.lang.swift.decl.function.free" @@ -1442,42 +1722,78 @@ public struct SourceKitDef { } } - public enum Request { + public enum Request: CustomStringConvertible { + /// source.request.protocol_version case protocolVersion + /// source.request.crash_exit case crashWithExit + /// source.request.demangle case demangle + /// source.request.mangle_simple_class case mangleSimpleClass + /// source.request.indexsource case index + /// source.request.docinfo case docInfo + /// source.request.codecomplete case codeComplete + /// source.request.codecomplete.open case codeCompleteOpen + /// source.request.codecomplete.close case codeCompleteClose + /// source.request.codecomplete.update case codeCompleteUpdate + /// source.request.codecomplete.cache.ondisk case codeCompleteCacheOnDisk + /// source.request.codecomplete.setpopularapi case codeCompleteSetPopularAPI + /// source.request.codecomplete.setcustom case codeCompleteSetCustom + /// source.request.cursorinfo case cursorInfo + /// source.request.rangeinfo case rangeInfo + /// source.request.relatedidents case relatedIdents + /// source.request.editor.open case editorOpen + /// source.request.editor.open.interface case editorOpenInterface + /// source.request.editor.open.interface.header case editorOpenHeaderInterface + /// source.request.editor.open.interface.swiftsource case editorOpenSwiftSourceInterface + /// source.request.editor.open.interface.swifttype case editorOpenSwiftTypeInterface + /// source.request.editor.extract.comment case editorExtractTextFromComment + /// source.request.editor.close case editorClose + /// source.request.editor.replacetext case editorReplaceText + /// source.request.editor.formattext case editorFormatText + /// source.request.editor.expand_placeholder case editorExpandPlaceholder + /// source.request.editor.find_usr case editorFindUSR + /// source.request.editor.find_interface_doc case editorFindInterfaceDoc + /// source.request.buildsettings.register case buildSettingsRegister + /// source.request.module.groups case moduleGroups + /// source.request.name.translation case nameTranslation + /// source.request.convert.markup.xml case markupToXML + /// source.request.syntacticrename case syntacticRename + /// source.request.find-syntactic-rename-ranges case findRenameRanges + /// source.request.find-local-rename-ranges case findLocalRenameRanges + /// source.request.semantic.refactoring case semanticRefactoring case unrecognized(String) @@ -1560,7 +1876,7 @@ public struct SourceKitDef { } } - public var stringRepresentation: String { + public var description: String { switch self { case .protocolVersion: return "source.request.protocol_version" @@ -1642,14 +1958,14 @@ public struct SourceKitDef { } -public extension SourceKitDef.Key { +public extension UID.Key { public static let count: Int = 134 } -public extension SourceKitDef.Kind { +public extension UID.Kind { public static let count: Int = 146 } -public extension SourceKitDef.Request { +public extension UID.Request { public static let count: Int = 36 } diff --git a/Templates/AutoEnumNameFix.stencil b/Templates/AutoEnumNameFix.stencil index bcb72e58f..ec37a521a 100644 --- a/Templates/AutoEnumNameFix.stencil +++ b/Templates/AutoEnumNameFix.stencil @@ -1,26 +1,30 @@ import Swift -public struct SourceKitDef { +public struct UID { {% for enum in types.all %} - public enum {{ enum.name }} { - {% for case in enum.cases %}case {{ case.name|lowerFirst }} + public enum {{ enum.name }}: CustomStringConvertible { + {% for case in enum.cases %} + /// {{ case.rawValue }} + case {{ case.name|lowerFirstWord|replace:"uiDs","uids" }} {% endfor %} case unrecognized(String) public init(string: String) { switch string { - {% for case in enum.cases %}case "{{ case.rawValue }}": - self = .{{ case.name|lowerFirst }} + {% for case in enum.cases %} + case "{{ case.rawValue }}": + self = .{{ case.name|lowerFirstWord }} {% endfor %} default: self = .unrecognized(string) } } - public var stringRepresentation: String { + public var description: String { switch self { - {% for case in enum.cases %}case .{{ case.name|lowerFirst }}: + {% for case in enum.cases %} + case .{{ case.name|lowerFirstWord }}: return "{{ case.rawValue }}" {% endfor %} case let .unrecognized(string): @@ -33,7 +37,7 @@ public struct SourceKitDef { {% for enum in types.all %} -public extension SourceKitDef.{{ enum.name }} { +public extension UID.{{ enum.name }} { public static let count: Int = {{ enum.cases.count }} } {% endfor %} diff --git a/sourcekitten.xcodeproj/project.pbxproj b/sourcekitten.xcodeproj/project.pbxproj index 5c630b1e8..85f7ff09a 100644 --- a/sourcekitten.xcodeproj/project.pbxproj +++ b/sourcekitten.xcodeproj/project.pbxproj @@ -23,7 +23,6 @@ 6CCFCE8C1CFECFF1003239EB /* Yams.framework in Embed Frameworks into SourceKittenFramework.framework */ = {isa = PBXBuildFile; fileRef = E80678041CF2749300AFC816 /* Yams.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 6CCFCE8E1CFED000003239EB /* Commandant.framework in Embed Frameworks into SourceKittenFramework.framework */ = {isa = PBXBuildFile; fileRef = E8EBAA5D1A5D374B002F1B8E /* Commandant.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 6CCFCE901CFED005003239EB /* Result.framework in Embed Frameworks into SourceKittenFramework.framework */ = {isa = PBXBuildFile; fileRef = E834D61D1B2D054B002AA1FE /* Result.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 861E9D431F87574A001F182C /* SourceKitDef.swift in Sources */ = {isa = PBXBuildFile; fileRef = 861E9D421F87574A001F182C /* SourceKitDef.swift */; }; 866176221F85F31B00B9DF14 /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 866176211F85F31B00B9DF14 /* RequestTests.swift */; }; 866EDB011F87C79E00EC198A /* RequestBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 866EDAFF1F87C74600EC198A /* RequestBuilder.swift */; }; 869C8D491FC97C800067FF0E /* Request+EditorOpen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D481FC97C800067FF0E /* Request+EditorOpen.swift */; }; @@ -40,6 +39,7 @@ 869C8D5F1FC988B80067FF0E /* Request+DocInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D5E1FC988B80067FF0E /* Request+DocInfo.swift */; }; 869C8D611FC989030067FF0E /* Request+Demangle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D601FC989030067FF0E /* Request+Demangle.swift */; }; 869C8D631FC9896E0067FF0E /* Request+ModuleGroups.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869C8D621FC9896E0067FF0E /* Request+ModuleGroups.swift */; }; + 86F578AF1FCA60DE00D47B78 /* UID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86F578AD1FCA5BC000D47B78 /* UID.swift */; }; B2FA87E26BC9C5F774FD694C /* SwiftLangSyntax.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2FA804AA9D4427FF571EFB2 /* SwiftLangSyntax.swift */; }; C236E84B1DFF5120003807D2 /* YamlRequestCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C236E84A1DFF5120003807D2 /* YamlRequestCommand.swift */; }; D0AAAB5019FB0960007B24B3 /* SourceKittenFramework.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D0D1216D19E87B05005E4BAA /* SourceKittenFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -161,7 +161,6 @@ 6C7F0A841EDB0AAD008EC581 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; 6CC381621ECACB50000C6F81 /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = ""; }; 6CFC18F01C7F2FB900CD70E1 /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; - 861E9D421F87574A001F182C /* SourceKitDef.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceKitDef.swift; sourceTree = ""; }; 866176211F85F31B00B9DF14 /* RequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestTests.swift; sourceTree = ""; }; 866EDAFF1F87C74600EC198A /* RequestBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestBuilder.swift; sourceTree = ""; }; 869C8D481FC97C800067FF0E /* Request+EditorOpen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+EditorOpen.swift"; sourceTree = ""; }; @@ -178,6 +177,7 @@ 869C8D5E1FC988B80067FF0E /* Request+DocInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+DocInfo.swift"; sourceTree = ""; }; 869C8D601FC989030067FF0E /* Request+Demangle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+Demangle.swift"; sourceTree = ""; }; 869C8D621FC9896E0067FF0E /* Request+ModuleGroups.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Request+ModuleGroups.swift"; sourceTree = ""; }; + 86F578AD1FCA5BC000D47B78 /* UID.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UID.swift; sourceTree = ""; }; B2FA804AA9D4427FF571EFB2 /* SwiftLangSyntax.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftLangSyntax.swift; sourceTree = ""; }; C236E84A1DFF5120003807D2 /* YamlRequestCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YamlRequestCommand.swift; sourceTree = ""; }; D0D1211B19E87861005E4BAA /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; usesTabs = 0; }; @@ -438,8 +438,8 @@ D0D1216E19E87B05005E4BAA /* SourceKittenFramework */ = { isa = PBXGroup; children = ( + 86F578AD1FCA5BC000D47B78 /* UID.swift */, E86F588D1C4DC49000426E78 /* sourcekitd.h */, - 861E9D421F87574A001F182C /* SourceKitDef.swift */, E8D4742B1A648ED10011A49C /* clang-c */, D0D1216F19E87B05005E4BAA /* Supporting Files */, 3F0CBB401BAAFF160015BBA8 /* Clang+SourceKitten.swift */, @@ -732,7 +732,6 @@ 869C8D591FC986D60067FF0E /* Request+EditorFormatText.swift in Sources */, 869C8D5D1FC9877D0067FF0E /* Request+Index.swift in Sources */, 869C8D551FC986110067FF0E /* Request+EditorOpenHeaderInterface.swift in Sources */, - 861E9D431F87574A001F182C /* SourceKitDef.swift in Sources */, 869C8D631FC9896E0067FF0E /* Request+ModuleGroups.swift in Sources */, 6C4CF5771C78B47F008532C5 /* library_wrapper.swift in Sources */, 3F56EAD01BAB251C006433D0 /* JSONOutput.swift in Sources */, @@ -747,6 +746,7 @@ E83748C31A5BCD7900862B1B /* OffsetMap.swift in Sources */, E806D2911BE058C400D1BE41 /* Parameter.swift in Sources */, E868473A1A587B4D0043DC65 /* Request.swift in Sources */, + 86F578AF1FCA60DE00D47B78 /* UID.swift in Sources */, 869C8D491FC97C800067FF0E /* Request+EditorOpen.swift in Sources */, 869C8D4D1FC97F8E0067FF0E /* Request+CursorInfo.swift in Sources */, E8A9B8921B56D1B100CD17D4 /* SourceDeclaration.swift in Sources */, From ab72f26de7fe5acc99ab163693a5463144c32e48 Mon Sep 17 00:00:00 2001 From: ainopara Date: Sun, 26 Nov 2017 13:46:19 +0800 Subject: [PATCH 15/15] Fix issue about lower first word filter for `UIDs`. Add Hashable conformance. --- Source/SourceKittenFramework/UID.swift | 37 ++++++++++++++++++++++++-- Templates/AutoEnumNameFix.stencil | 19 +++++++++++-- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Source/SourceKittenFramework/UID.swift b/Source/SourceKittenFramework/UID.swift index f76eda88f..24ca5b6bb 100644 --- a/Source/SourceKittenFramework/UID.swift +++ b/Source/SourceKittenFramework/UID.swift @@ -486,7 +486,7 @@ public struct UID { case "key.names": self = .names case "key.uids": - self = .uiDs + self = .uids case "key.syntactic_only": self = .syntacticOnly case "key.actionable": @@ -760,7 +760,7 @@ public struct UID { return "key.usingswiftargs" case .names: return "key.names" - case .uiDs: + case .uids: return "key.uids" case .syntacticOnly: return "key.syntactic_only" @@ -1957,6 +1957,39 @@ public struct UID { } } +// MARK: - Hashable + +extension UID.Key: Hashable { + public var hashValue: Int { + return description.hashValue + } + + public static func == (lhs: UID.Key, rhs: UID.Key) -> Bool { + return lhs.description == rhs.description + } +} + +extension UID.Kind: Hashable { + public var hashValue: Int { + return description.hashValue + } + + public static func == (lhs: UID.Kind, rhs: UID.Kind) -> Bool { + return lhs.description == rhs.description + } +} + +extension UID.Request: Hashable { + public var hashValue: Int { + return description.hashValue + } + + public static func == (lhs: UID.Request, rhs: UID.Request) -> Bool { + return lhs.description == rhs.description + } +} + +// MARK: - public extension UID.Key { public static let count: Int = 134 diff --git a/Templates/AutoEnumNameFix.stencil b/Templates/AutoEnumNameFix.stencil index ec37a521a..b8d8217d2 100644 --- a/Templates/AutoEnumNameFix.stencil +++ b/Templates/AutoEnumNameFix.stencil @@ -14,7 +14,7 @@ public struct UID { switch string { {% for case in enum.cases %} case "{{ case.rawValue }}": - self = .{{ case.name|lowerFirstWord }} + self = .{{ case.name|lowerFirstWord|replace:"uiDs","uids" }} {% endfor %} default: self = .unrecognized(string) @@ -24,7 +24,7 @@ public struct UID { public var description: String { switch self { {% for case in enum.cases %} - case .{{ case.name|lowerFirstWord }}: + case .{{ case.name|lowerFirstWord|replace:"uiDs","uids" }}: return "{{ case.rawValue }}" {% endfor %} case let .unrecognized(string): @@ -35,6 +35,21 @@ public struct UID { {% endfor %} } +// MARK: - Hashable +{% for enum in types.all %} + +extension UID.{{ enum.name }}: Hashable { + public var hashValue: Int { + return description.hashValue + } + + public static func == (lhs: UID.{{ enum.name }}, rhs: UID.{{ enum.name }}) -> Bool { + return lhs.description == rhs.description + } +} +{% endfor %} + +// MARK: - {% for enum in types.all %} public extension UID.{{ enum.name }} {