diff --git a/Makefile b/Makefile index 77d0140a8..28369ba64 100644 --- a/Makefile +++ b/Makefile @@ -84,6 +84,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 +}