diff --git a/Configurations/EditIntents.xcconfig b/Configurations/EditIntents.xcconfig new file mode 100644 index 0000000..02a46b8 --- /dev/null +++ b/Configurations/EditIntents.xcconfig @@ -0,0 +1,7 @@ +CODE_SIGN_ENTITLEMENTS = ${TARGET_NAME}/${TARGET_NAME}.entitlements +INFOPLIST_FILE = ${TARGET_NAME}/Info.plist +INFOPLIST_KEY_CFBundleDisplayName = ${TARGET_NAME} +LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks +PRODUCT_BUNDLE_IDENTIFIER = $(BUNDLE_ID_PREFIX).Edit.${TARGET_NAME} +PRODUCT_NAME = EditIntents +SKIP_INSTALL = YES diff --git a/Configurations/Project.xcconfig b/Configurations/Project.xcconfig index 15ba5d3..213f78c 100644 --- a/Configurations/Project.xcconfig +++ b/Configurations/Project.xcconfig @@ -37,7 +37,7 @@ CODE_SIGN_STYLE = Automatic COMBINE_HIDPI_IMAGES = YES COPY_PHASE_STRIP = NO CURRENT_PROJECT_DISPLAY_VERSION = 3.0.0 -CURRENT_PROJECT_VERSION = 200 +CURRENT_PROJECT_VERSION = 201 DEAD_CODE_STRIPPING = YES DEBUG_INFORMATION_FORMAT = dwarf-with-dsym ENABLE_HARDENED_RUNTIME = YES diff --git a/Edit.xcodeproj/project.pbxproj b/Edit.xcodeproj/project.pbxproj index cb4c648..bcf51c1 100644 --- a/Edit.xcodeproj/project.pbxproj +++ b/Edit.xcodeproj/project.pbxproj @@ -28,6 +28,9 @@ C929316F2B822BB800C64DDE /* TreeSitterSwift in Frameworks */ = {isa = PBXBuildFile; productRef = C929316E2B822BB800C64DDE /* TreeSitterSwift */; }; C92931712B822BBD00C64DDE /* TreeSitterMarkdown in Frameworks */ = {isa = PBXBuildFile; productRef = C92931702B822BBD00C64DDE /* TreeSitterMarkdown */; }; C93F72272BF0F9290021ACF3 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = C93F72262BF0F9290021ACF3 /* Sparkle */; }; + C93F724B2BF26BDC0021ACF3 /* EditIntentsExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93F724A2BF26BDC0021ACF3 /* EditIntentsExtension.swift */; }; + C93F724D2BF26BDC0021ACF3 /* HighlightIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93F724C2BF26BDC0021ACF3 /* HighlightIntent.swift */; }; + C93F72582BF26E9C0021ACF3 /* EditIntents.appex in Copy Extensions */ = {isa = PBXBuildFile; fileRef = C93F72482BF26BDC0021ACF3 /* EditIntents.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; C9409C662A98CC9800B5D898 /* Outline in Frameworks */ = {isa = PBXBuildFile; productRef = C9409C652A98CC9800B5D898 /* Outline */; }; C9409C6C2A99059C00B5D898 /* ProjectState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9409C6A2A99047000B5D898 /* ProjectState.swift */; }; C941F09C2B6AD4AF0003B640 /* DocumentContentAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C941F09B2B6AD4AF0003B640 /* DocumentContentAdapter.swift */; }; @@ -48,6 +51,8 @@ C942E6AE2B69889F00792DD4 /* UserScriptExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C942E6782B67B78F00792DD4 /* UserScriptExtension.swift */; }; C94450572BE561FA004E244E /* CodableTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = C94450562BE561FA004E244E /* CodableTheme.swift */; }; C94F7EC12A7D8C1900E0361A /* ProjectContentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C94F7EC02A7D8C1900E0361A /* ProjectContentViewController.swift */; }; + C95248C82BF3AFD400F55E71 /* EditKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C92931422B80CC6700C64DDE /* EditKit.framework */; }; + C95248C92BF3AFD700F55E71 /* ChimeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9FE52F42A7539B100CACA1A /* ChimeKit.framework */; }; C958C7812BC5A82900EC95F8 /* ConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C958C7802BC5A82900EC95F8 /* ConfigurationTests.swift */; }; C958C7842BC7019100EC95F8 /* LineNumberView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C958C7832BC7019100EC95F8 /* LineNumberView.swift */; }; C95B91052BD8275E006FDD00 /* ThemeModifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = C95B91032BD825EE006FDD00 /* ThemeModifiers.swift */; }; @@ -298,6 +303,13 @@ remoteGlobalIDString = C92931412B80CC6700C64DDE; remoteInfo = EditKit; }; + C93F72502BF26BDC0021ACF3 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C9FE52912A7525D000CACA1A /* Project object */; + proxyType = 1; + remoteGlobalIDString = C93F72472BF26BDC0021ACF3; + remoteInfo = EditIntents; + }; C942E67C2B67B78F00792DD4 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C9FE52912A7525D000CACA1A /* Project object */; @@ -312,6 +324,20 @@ remoteGlobalIDString = C9FE52F32A7539B100CACA1A; remoteInfo = ChimeKit; }; + C95248C42BF3AFC600F55E71 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C9FE52912A7525D000CACA1A /* Project object */; + proxyType = 1; + remoteGlobalIDString = C92931412B80CC6700C64DDE; + remoteInfo = EditKit; + }; + C95248C62BF3AFCE00F55E71 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C9FE52912A7525D000CACA1A /* Project object */; + proxyType = 1; + remoteGlobalIDString = C9FE52F32A7539B100CACA1A; + remoteInfo = ChimeKit; + }; C95B911D2BD98B2E006FDD00 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C9FE52912A7525D000CACA1A /* Project object */; @@ -832,6 +858,7 @@ dstPath = "$(EXTENSIONS_FOLDER_PATH)"; dstSubfolderSpec = 16; files = ( + C93F72582BF26E9C0021ACF3 /* EditIntents.appex in Copy Extensions */, C9E878092A9F53530018340C /* UIPlaceholderExtension.appex in Copy Extensions */, C9BDB5502B00FD89009225FB /* SwiftExtension.appex in Copy Extensions */, C942E67E2B67B78F00792DD4 /* UserScriptExtension.appex in Copy Extensions */, @@ -883,6 +910,12 @@ C92931422B80CC6700C64DDE /* EditKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = EditKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C92931722B822BFF00C64DDE /* EditKit.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = EditKit.xcconfig; sourceTree = ""; }; C93791A32AD5E02C00665F50 /* Project-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Project-Debug.xcconfig"; sourceTree = ""; }; + C93F72482BF26BDC0021ACF3 /* EditIntents.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.extensionkit-extension"; includeInIndex = 0; path = EditIntents.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + C93F724A2BF26BDC0021ACF3 /* EditIntentsExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditIntentsExtension.swift; sourceTree = ""; }; + C93F724C2BF26BDC0021ACF3 /* HighlightIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighlightIntent.swift; sourceTree = ""; }; + C93F724E2BF26BDC0021ACF3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + C93F724F2BF26BDC0021ACF3 /* EditIntents.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = EditIntents.entitlements; sourceTree = ""; }; + C93F72562BF26CB80021ACF3 /* EditIntents.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = EditIntents.xcconfig; sourceTree = ""; }; C9409C6A2A99047000B5D898 /* ProjectState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectState.swift; sourceTree = ""; }; C941F09B2B6AD4AF0003B640 /* DocumentContentAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentContentAdapter.swift; sourceTree = ""; }; C941F09E2B6C4CD90003B640 /* Dictionary+Fill.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dictionary+Fill.swift"; sourceTree = ""; }; @@ -1121,6 +1154,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + C93F72452BF26BDC0021ACF3 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + C95248C92BF3AFD700F55E71 /* ChimeKit.framework in Frameworks */, + C95248C82BF3AFD400F55E71 /* EditKit.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; C942E6732B67B78E00792DD4 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -1344,6 +1386,17 @@ path = PreferencesWindow; sourceTree = ""; }; + C93F72492BF26BDC0021ACF3 /* EditIntents */ = { + isa = PBXGroup; + children = ( + C93F724F2BF26BDC0021ACF3 /* EditIntents.entitlements */, + C93F724A2BF26BDC0021ACF3 /* EditIntentsExtension.swift */, + C93F724C2BF26BDC0021ACF3 /* HighlightIntent.swift */, + C93F724E2BF26BDC0021ACF3 /* Info.plist */, + ); + path = EditIntents; + sourceTree = ""; + }; C941F0AE2B6E67AC0003B640 /* Sources */ = { isa = PBXGroup; children = ( @@ -1600,6 +1653,7 @@ children = ( C9FE538E2A76674600CACA1A /* Configurations */, C9FE529B2A7525D000CACA1A /* Edit */, + C93F72492BF26BDC0021ACF3 /* EditIntents */, C9FE52B12A7525D300CACA1A /* EditTests */, C9FE52BB2A7525D300CACA1A /* EditUITests */, C9E8780D2A9F535C0018340C /* Extensions */, @@ -1641,6 +1695,7 @@ C942E6762B67B78E00792DD4 /* UserScriptExtension.appex */, C92931422B80CC6700C64DDE /* EditKit.framework */, C9E0B9FC2BD27F0F007AF034 /* libDiagnostics.a */, + C93F72482BF26BDC0021ACF3 /* EditIntents.appex */, ); name = Products; sourceTree = ""; @@ -1819,6 +1874,7 @@ children = ( C92673282B04046700B3CE2F /* Edit-Debug.xcconfig */, C9FE52CC2A752B4D00CACA1A /* Edit.xcconfig */, + C93F72562BF26CB80021ACF3 /* EditIntents.xcconfig */, C92931722B822BFF00C64DDE /* EditKit.xcconfig */, C9FE54082A7A625300CACA1A /* EditTests.xcconfig */, C92673432B05244600B3CE2F /* EditUITests.xcconfig */, @@ -2126,6 +2182,25 @@ productReference = C92931422B80CC6700C64DDE /* EditKit.framework */; productType = "com.apple.product-type.framework"; }; + C93F72472BF26BDC0021ACF3 /* EditIntents */ = { + isa = PBXNativeTarget; + buildConfigurationList = C93F72552BF26BDC0021ACF3 /* Build configuration list for PBXNativeTarget "EditIntents" */; + buildPhases = ( + C93F72442BF26BDC0021ACF3 /* Sources */, + C93F72452BF26BDC0021ACF3 /* Frameworks */, + C93F72462BF26BDC0021ACF3 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + C95248C72BF3AFCE00F55E71 /* PBXTargetDependency */, + C95248C52BF3AFC600F55E71 /* PBXTargetDependency */, + ); + name = EditIntents; + productName = EditIntents; + productReference = C93F72482BF26BDC0021ACF3 /* EditIntents.appex */; + productType = "com.apple.product-type.extensionkit-extension"; + }; C942E6752B67B78E00792DD4 /* UserScript */ = { isa = PBXNativeTarget; buildConfigurationList = C942E67F2B67B78F00792DD4 /* Build configuration list for PBXNativeTarget "UserScript" */; @@ -2406,6 +2481,7 @@ C9B8AA262B362DDE00C79606 /* PBXTargetDependency */, C942E67D2B67B78F00792DD4 /* PBXTargetDependency */, C92931472B80CC6700C64DDE /* PBXTargetDependency */, + C93F72512BF26BDC0021ACF3 /* PBXTargetDependency */, ); name = Edit; packageProductDependencies = ( @@ -2727,6 +2803,9 @@ C92931412B80CC6700C64DDE = { CreatedOnToolsVersion = 15.3; }; + C93F72472BF26BDC0021ACF3 = { + CreatedOnToolsVersion = 15.3; + }; C942E6752B67B78E00792DD4 = { CreatedOnToolsVersion = 15.3; }; @@ -2884,6 +2963,7 @@ C973DFFF2B62BDB3000998F7 /* Highlighting */, C942E6752B67B78E00792DD4 /* UserScript */, C9E0B9FB2BD27F0F007AF034 /* Diagnostics */, + C93F72472BF26BDC0021ACF3 /* EditIntents */, ); }; /* End PBXProject section */ @@ -2897,6 +2977,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + C93F72462BF26BDC0021ACF3 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; C942E6742B67B78E00792DD4 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -2999,6 +3086,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + C93F72442BF26BDC0021ACF3 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C93F724B2BF26BDC0021ACF3 /* EditIntentsExtension.swift in Sources */, + C93F724D2BF26BDC0021ACF3 /* HighlightIntent.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; C942E6722B67B78E00792DD4 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -3411,6 +3507,11 @@ target = C92931412B80CC6700C64DDE /* EditKit */; targetProxy = C929315E2B80DA1000C64DDE /* PBXContainerItemProxy */; }; + C93F72512BF26BDC0021ACF3 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = C93F72472BF26BDC0021ACF3 /* EditIntents */; + targetProxy = C93F72502BF26BDC0021ACF3 /* PBXContainerItemProxy */; + }; C941F0B32B7102E80003B640 /* PBXTargetDependency */ = { isa = PBXTargetDependency; productRef = C941F0B22B7102E80003B640 /* TreeSitterGo */; @@ -3425,6 +3526,16 @@ target = C9FE52F32A7539B100CACA1A /* ChimeKit */; targetProxy = C942E6832B67B9A100792DD4 /* PBXContainerItemProxy */; }; + C95248C52BF3AFC600F55E71 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = C92931412B80CC6700C64DDE /* EditKit */; + targetProxy = C95248C42BF3AFC600F55E71 /* PBXContainerItemProxy */; + }; + C95248C72BF3AFCE00F55E71 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = C9FE52F32A7539B100CACA1A /* ChimeKit */; + targetProxy = C95248C62BF3AFCE00F55E71 /* PBXContainerItemProxy */; + }; C95B90FD2BD80C71006FDD00 /* PBXTargetDependency */ = { isa = PBXTargetDependency; productRef = C95B90FC2BD80C71006FDD00 /* ThemePark */; @@ -3990,6 +4101,20 @@ }; name = Release; }; + C93F72532BF26BDC0021ACF3 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = C93F72562BF26CB80021ACF3 /* EditIntents.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + C93F72542BF26BDC0021ACF3 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = C93F72562BF26CB80021ACF3 /* EditIntents.xcconfig */; + buildSettings = { + }; + name = Release; + }; C942E6802B67B78F00792DD4 /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = C9E878112A9F53BB0018340C /* Extension.xcconfig */; @@ -4389,6 +4514,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + C93F72552BF26BDC0021ACF3 /* Build configuration list for PBXNativeTarget "EditIntents" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C93F72532BF26BDC0021ACF3 /* Debug */, + C93F72542BF26BDC0021ACF3 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; C942E67F2B67B78F00792DD4 /* Build configuration list for PBXNativeTarget "UserScript" */ = { isa = XCConfigurationList; buildConfigurations = ( @@ -4640,7 +4774,7 @@ repositoryURL = "https://github.com/ChimeHQ/Neon.git"; requirement = { kind = revision; - revision = 834fed55c04bab1e3894070b9b5939700284e4c8; + revision = 709683a2e2f3a2e502e8383f9aa5c725bf7d85e6; }; }; C93F72252BF0F9290021ACF3 /* XCRemoteSwiftPackageReference "Sparkle" */ = { @@ -4800,7 +4934,7 @@ repositoryURL = "https://github.com/ChimeHQ/ThemePark"; requirement = { kind = revision; - revision = 0838bd1db8be40aa87233f8351955bf84876f83d; + revision = fff8ae0521d76e81acd5c72ad39144ad10f1d489; }; }; C9FE52E62A75375300CACA1A /* XCRemoteSwiftPackageReference "ContainedDocument" */ = { diff --git a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index b61d7bd..f507c9a 100644 --- a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -127,7 +127,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/ChimeHQ/Neon.git", "state" : { - "revision" : "834fed55c04bab1e3894070b9b5939700284e4c8" + "revision" : "709683a2e2f3a2e502e8383f9aa5c725bf7d85e6" } }, { @@ -237,7 +237,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/ChimeHQ/ThemePark", "state" : { - "revision" : "0838bd1db8be40aa87233f8351955bf84876f83d" + "revision" : "fff8ae0521d76e81acd5c72ad39144ad10f1d489" } }, { diff --git a/Edit.xcodeproj/xcshareddata/xcschemes/EditIntents.xcscheme b/Edit.xcodeproj/xcshareddata/xcschemes/EditIntents.xcscheme new file mode 100644 index 0000000..5b6bdc2 --- /dev/null +++ b/Edit.xcodeproj/xcshareddata/xcschemes/EditIntents.xcscheme @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Edit.xcodeproj/xcshareddata/xcschemes/SwiftExtension.xcscheme b/Edit.xcodeproj/xcshareddata/xcschemes/SwiftExtension.xcscheme index 98db00b..8d24d50 100644 --- a/Edit.xcodeproj/xcshareddata/xcschemes/SwiftExtension.xcscheme +++ b/Edit.xcodeproj/xcshareddata/xcschemes/SwiftExtension.xcscheme @@ -17,7 +17,7 @@ diff --git a/Edit/Modules/SyntaxService/LanguageDataStore.swift b/Edit/Modules/SyntaxService/LanguageDataStore.swift index 84ead78..dea2df0 100644 --- a/Edit/Modules/SyntaxService/LanguageDataStore.swift +++ b/Edit/Modules/SyntaxService/LanguageDataStore.swift @@ -61,7 +61,7 @@ extension LanguageDataStore { return profile(for: utType) } - public func languageConfiguration(with identifier: String) -> LanguageConfiguration? { + public func languageConfiguration(with identifier: String, background: Bool = true) -> LanguageConfiguration? { let utType = LanguageDataStore.languageDocumentType(from: identifier) // shortcut this @@ -73,6 +73,20 @@ extension LanguageDataStore { return value } + if background == false { + if let value = configurationCache[utType] { + return value + } + + let profile = profile(for: utType) + + let config = try? profile.load() + + self.configurationCache[utType] = config + + return config + } + Task { _ = try! await loadLanguageConfiguration(with: utType, identifier: identifier) } @@ -95,4 +109,10 @@ extension LanguageDataStore { return config } + + public func loadLanguageConfiguration(with utType: UTType) async throws -> LanguageConfiguration? { + let profile = profile(for: utType) + + return try await loadLanguageConfiguration(with: utType, identifier: profile.name) + } } diff --git a/Edit/Modules/SyntaxService/LanguageProfile.swift b/Edit/Modules/SyntaxService/LanguageProfile.swift index 8e9e989..5bd473d 100644 --- a/Edit/Modules/SyntaxService/LanguageProfile.swift +++ b/Edit/Modules/SyntaxService/LanguageProfile.swift @@ -29,6 +29,16 @@ public struct LanguageProfile: Sendable { extension LanguageProfile { public func loadLanguageConfiguration() async throws -> LanguageConfiguration { + try await withUnsafeThrowingContinuation { continuation in + DispatchQueue.global().async { + let result = Result(catching: { try load() }) + + continuation.resume(with: result) + } + } + } + + public func load() throws -> LanguageConfiguration { guard let language = language, let bundleName = bundleName @@ -36,17 +46,9 @@ extension LanguageProfile { throw LanguageProfileError.treeSitterUnsupported } - return try await withUnsafeThrowingContinuation { [language, name, bundleName] continuation in - DispatchQueue.global().async { - let result = Result(catching: { - let queryURL = try LanguageProfile.languageQueryDirectory(for: name, bundleName: bundleName) - - return try LanguageConfiguration(language, name: name, queriesURL: queryURL) - }) + let queryURL = try LanguageProfile.languageQueryDirectory(for: name, bundleName: bundleName) - continuation.resume(with: result) - } - } + return try LanguageConfiguration(language, name: name, queriesURL: queryURL) } private static func languageQueryDirectory(for name: String, bundleName: String) throws -> URL { diff --git a/Edit/Modules/SyntaxService/SyntaxService.swift b/Edit/Modules/SyntaxService/SyntaxService.swift index 8ecf2d5..97d0ce4 100644 --- a/Edit/Modules/SyntaxService/SyntaxService.swift +++ b/Edit/Modules/SyntaxService/SyntaxService.swift @@ -69,7 +69,7 @@ public final class SyntaxService { guard profile.language != nil else { return } let config = TreeSitterClient.Configuration( - languageProvider: languageDataStore.languageConfiguration(with:), + languageProvider: { [languageDataStore] in languageDataStore.languageConfiguration(with: $0) }, contentProvider: { [textSystem] in textSystem.storage.layerContent(for: $0) }, lengthProvider: { [textSystem] in textSystem.storage.currentLength }, invalidationHandler: { [unowned self] in self.invalidationHandler(.set($0)) }, diff --git a/Edit/Sources/AppDelegate.swift b/Edit/Sources/AppDelegate.swift index 4358e3f..58f0602 100644 --- a/Edit/Sources/AppDelegate.swift +++ b/Edit/Sources/AppDelegate.swift @@ -57,7 +57,8 @@ extension AppDelegate { } @IBAction func checkForUpdates(_ sender: Any?) { - updaterController.checkForUpdates(sender) +// updaterController.checkForUpdates(sender) + tryThing() } } @@ -66,3 +67,49 @@ extension AppDelegate: SPUUpdaterDelegate { ["beta"] } } + +import SyntaxService +import TreeSitterClient +import Neon +import ThemePark + +enum HighlightIntentError: Error { + case languageConfigurationUnavailable +} + +extension AppDelegate { + func tryThing() { + Task { + let source = "let value = \"hello\" " + let theme = ThemeStore.currentTheme ?? Theme.fallback + let store = LanguageDataStore.global + guard let rootConfig = try await store.loadLanguageConfiguration(with: .swiftSource) else { + throw HighlightIntentError.languageConfigurationUnavailable + } + + let variant = theme.supportedVariants.first! + + for value in theme.supportedVariants { + print("variant:", variant) + } + let context = Query.Context(controlState: .active, variant: variant) + + let attrProvider: TokenAttributeProvider = { token in + let style = theme.highlightsQueryCaptureStyle(for: token.name, context: context) + + print(token.name, "=>", style.color) + + return [.foregroundColor: style.color] + } + + let highlightedSource = try await TreeSitterClient.highlight( + string: source, + attributeProvider: attrProvider, + rootLanguageConfig: rootConfig, + languageProvider: { store.languageConfiguration(with: $0, background: false) } + ) + + print(highlightedSource) + } + } +} diff --git a/EditIntents/EditIntents.entitlements b/EditIntents/EditIntents.entitlements new file mode 100644 index 0000000..c341b40 --- /dev/null +++ b/EditIntents/EditIntents.entitlements @@ -0,0 +1,12 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.application-groups + + $(APP_GROUP) + + + diff --git a/EditIntents/EditIntentsExtension.swift b/EditIntents/EditIntentsExtension.swift new file mode 100644 index 0000000..18279d2 --- /dev/null +++ b/EditIntents/EditIntentsExtension.swift @@ -0,0 +1,5 @@ +import AppIntents + +@main +struct EditIntentsExtension: AppIntentsExtension { +} diff --git a/EditIntents/HighlightIntent.swift b/EditIntents/HighlightIntent.swift new file mode 100644 index 0000000..25a0482 --- /dev/null +++ b/EditIntents/HighlightIntent.swift @@ -0,0 +1,71 @@ +import AppIntents + +import Neon +import SyntaxService +import Theme +import TreeSitterClient +import UniformTypeIdentifiers + +enum Language: String, Hashable, CaseIterable { + case swift = "Swift" + + var typeIdentifier: UTType { + switch self { + case .swift: + .swiftSource + } + } +} + +extension Language: AppEnum { + static let typeDisplayRepresentation: TypeDisplayRepresentation = "Language" + static let caseDisplayRepresentations: [Language: DisplayRepresentation] = [ + .swift: "Swift", + ] +} + +enum HighlightIntentError: Error { + case languageConfigurationUnavailable +} + +struct HighlightIntent: AppIntent { + nonisolated static let title: LocalizedStringResource = "Highlight Source Code" + static let description: IntentDescription = "Applies syntax highlighting to the input." + nonisolated static let openAppWhenRun = false + + @Parameter(title: "Source", description: "The source code to be highlighted", inputConnectionBehavior: .connectToPreviousIntentResult) + var source: String + + @Parameter(title: "Language") + var language: Language + + nonisolated static var parameterSummary: some ParameterSummary { + Summary("Highlight \(\.$language) source code.") + } + + @MainActor + func perform() async throws -> some IntentResult & ReturnsValue { + let theme = ThemeStore.currentTheme ?? Theme.fallback + let store = LanguageDataStore.global + guard let rootConfig = try await store.loadLanguageConfiguration(with: language.typeIdentifier) else { + throw HighlightIntentError.languageConfigurationUnavailable + } + + let context = Query.Context(controlState: .active, variant: .init(colorScheme: .dark, colorSchemeContrast: .standard)) + + let attrProvider: TokenAttributeProvider = { token in + let style = theme.highlightsQueryCaptureStyle(for: token.name, context: context) + + return [.foregroundColor: style.color] + } + + let highlightedSource = try await TreeSitterClient.highlight( + string: source, + attributeProvider: attrProvider, + rootLanguageConfig: rootConfig, + languageProvider: { store.languageConfiguration(with: $0, background: false) } + ) + + return .result(value: highlightedSource) + } +} diff --git a/EditIntents/Info.plist b/EditIntents/Info.plist new file mode 100644 index 0000000..8d15acb --- /dev/null +++ b/EditIntents/Info.plist @@ -0,0 +1,11 @@ + + + + + EXAppExtensionAttributes + + EXExtensionPointIdentifier + com.apple.appintents-extension + + + diff --git a/README.md b/README.md index 4cab73c..7f5e91a 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,11 @@ Features: - [editorconfig](https://editorconfig.org) - [extensions][chimekit] - file navigator -- QuickLook Preview extension -- syntax highlighting (driven by tree-sitter and LSP) -- structure highlighting +- Quick Look Preview extension - semantic symbol information +- Shortcuts extension (text highlighting) +- structure highlighting +- syntax highlighting (driven by tree-sitter and LSP) - textual/symbolic quick open - UI theming