diff --git a/Edit.xcodeproj/project.pbxproj b/Edit.xcodeproj/project.pbxproj index 0fde976..595943d 100644 --- a/Edit.xcodeproj/project.pbxproj +++ b/Edit.xcodeproj/project.pbxproj @@ -1015,7 +1015,6 @@ 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 = ""; }; - C93A80492CC4052100B89FB4 /* Neon */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Neon; path = ../Neon; sourceTree = SOURCE_ROOT; }; 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 = ""; }; @@ -1864,7 +1863,6 @@ C9FE52902A7525D000CACA1A = { isa = PBXGroup; children = ( - C93A80492CC4052100B89FB4 /* Neon */, C9FE538E2A76674600CACA1A /* Configurations */, C9439A742C3EC13A0020DDF5 /* Dependencies */, C9FE529B2A7525D000CACA1A /* Edit */, @@ -5338,7 +5336,7 @@ repositoryURL = "https://github.com/ChimeHQ/Neon.git"; requirement = { kind = revision; - revision = 9101469ff9ae2258e88099327969c350a953407d; + revision = 32ef005f7fc9d8358739ef2e6702c2c73cec6ca9; }; }; C93F72252BF0F9290021ACF3 /* XCRemoteSwiftPackageReference "Sparkle" */ = { @@ -5394,7 +5392,7 @@ repositoryURL = "https://github.com/ChimeHQ/TextStory.git"; requirement = { kind = revision; - revision = 5cd0787b43f038051d42b39db3319cbf78c42861; + revision = e23226da4a29a606b532d3f4d7d04102cd7826c5; }; }; C98EA4162A90F17700B8815E /* XCRemoteSwiftPackageReference "ProcessEnv" */ = { @@ -5418,7 +5416,7 @@ repositoryURL = "https://github.com/ChimeHQ/Rearrange.git"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 1.6.0; + minimumVersion = 2.0.0; }; }; C9B8AA5B2B370A1800C79606 /* XCRemoteSwiftPackageReference "SwiftTreeSitter" */ = { diff --git a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index a19e234..a730b36 100644 --- a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "ff7de96f98e01194f786ca218f32286d1e04cc1961dd2ec8e8d690d02ed4a344", + "originHash" : "e20cc55708e58da63ecb4be4feef028e6a48818a25bdcd1f961cf924b58e7a18", "pins" : [ { "identity" : "asyncxpcconnection", @@ -122,6 +122,14 @@ "version" : "0.2.1" } }, + { + "identity" : "neon", + "kind" : "remoteSourceControl", + "location" : "https://github.com/ChimeHQ/Neon.git", + "state" : { + "revision" : "32ef005f7fc9d8358739ef2e6702c2c73cec6ca9" + } + }, { "identity" : "nsui", "kind" : "remoteSourceControl", @@ -161,8 +169,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/ChimeHQ/Rearrange", "state" : { - "revision" : "5ff7f3363f7a08f77e0d761e38e6add31c2136e1", - "version" : "1.8.1" + "revision" : "f1d74e1642956f0300756ad8d1d64e9034857bc3", + "version" : "2.0.0" } }, { @@ -213,7 +221,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/ChimeHQ/SwiftTreeSitter", "state" : { - "revision" : "f01316eaf3aae07e30478f8afa76192ab4a96420" + "revision" : "55f2c2fdaf859f86e4ea8513b9934badc7894019" } }, { @@ -221,7 +229,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/ChimeHQ/TextStory.git", "state" : { - "revision" : "5cd0787b43f038051d42b39db3319cbf78c42861" + "revision" : "e23226da4a29a606b532d3f4d7d04102cd7826c5" } }, { diff --git a/Edit/Modules/Highlighting/Highlighter.swift b/Edit/Modules/Highlighting/Highlighter.swift index 4d1b947..deab9c3 100644 --- a/Edit/Modules/Highlighting/Highlighter.swift +++ b/Edit/Modules/Highlighting/Highlighter.swift @@ -75,6 +75,7 @@ final class LowlightTokenProvider { } } +/// Manages syntax highlighting state. @MainActor public final class Highlighter { typealias Styler = ThreePhaseTextSystemStyler @@ -106,6 +107,7 @@ public final class Highlighter { return await tokenServiceWrapper.tokens(for: $0) } + // Don't forget about `TokenProvider.none` and `asyncOnlyNone` when debugging here. They are handy! self.styler = ThreePhaseTextSystemStyler( textSystem: interface, tokenProvider: syntaxService.tokenProvider, diff --git a/Edit/Modules/SyntaxService/SyntaxService.swift b/Edit/Modules/SyntaxService/SyntaxService.swift index 4781c62..3691402 100644 --- a/Edit/Modules/SyntaxService/SyntaxService.swift +++ b/Edit/Modules/SyntaxService/SyntaxService.swift @@ -26,7 +26,7 @@ extension TextTarget { } } - +/// Provides semantic information about text. @MainActor public final class SyntaxService { private enum State { @@ -71,6 +71,7 @@ public final class SyntaxService { let config = TreeSitterClient.Configuration( languageProvider: { [languageDataStore] in languageDataStore.languageConfiguration(with: $0) }, contentProvider: { [textSystem] in textSystem.storage.layerContent(for: $0) }, + contentSnapshopProvider: { [textSystem] in textSystem.storage.layerContentSnapshot(for: $0) }, lengthProvider: { [textSystem] in textSystem.storage.currentLength }, invalidationHandler: { [unowned self] in self.invalidationHandler(.set($0)) }, locationTransformer: { [textSystem] in textSystem.textMetrics.locationTransformer($0) } @@ -141,46 +142,6 @@ extension SyntaxService { return TreeSitterClient.ClientQueryParams(range: range, textProvider: textProvider, mode: .optional) } - private static let highlightsMap: [String: String] = [ - "keyword": "keyword", - "include": "keyword.include", - "keyword.return": "keyword.return", - "keyword.function": "keyword.function", - "keyword.operator": "keyword.operator.text", - "operator": "keyword.operator", - "conditional": "keyword.conditional", - "repeat": "keyword.loop", - "punctuation.special": "keyword.operator.text", - "punctuation.delimiter": "keyword.operator.text", - - "type": "type", - - "string": "literal.string", - "number": "literal.number", - "float": "literal.float", - "boolean": "literal.boolean", - "string.regex": "literal.regex", - "text.literal": "literal.string", - "string.escape": "literal.string.escape", - "text.uri": "literal.string.uri", - "string.uri": "literal.string.uri", - - "variable": "variable", - "variable.builtin": "variable.built-in", - - "method": "member.function", - "constructor": "member.constructor", - "property": "member.property", - - "parameter": "parameter", - "function": "function", - "function.call": "invocation.function", - "function.macro": "invocation.macro", - - "label": "label", - "text.reference": "label", - ] - public var tokenProvider: TokenProvider { TokenProvider( syncValue: { range in @@ -194,7 +155,7 @@ extension SyntaxService { return nil } - return TokenApplication(namedRanges: namedRanges, nameMap: [:], range: range) + return TokenApplication(namedRanges: namedRanges, range: range) } catch { self.logger.warning("Failed to get highlighting: \(error)") @@ -210,7 +171,7 @@ extension SyntaxService { let queryParams = try self.highlightsQueryParams(for: range) let namedRanges = try await client.highlightsProvider.async(queryParams) - return TokenApplication(namedRanges: namedRanges, nameMap: [:], range: range) + return TokenApplication(namedRanges: namedRanges, range: range) } catch { self.logger.warning("Failed to get highlighting: \(error)") diff --git a/Edit/Modules/SyntaxService/TextSystem+SwiftTreeSitterLayer.swift b/Edit/Modules/SyntaxService/TextSystem+SwiftTreeSitterLayer.swift index f09c374..6145f63 100644 --- a/Edit/Modules/SyntaxService/TextSystem+SwiftTreeSitterLayer.swift +++ b/Edit/Modules/SyntaxService/TextSystem+SwiftTreeSitterLayer.swift @@ -14,6 +14,16 @@ extension TextStorage { textProvider: fullString.predicateTextProvider ) } + + func layerContentSnapshot(for limit: Int) -> LanguageLayer.ContentSnapshot { + let fullString = string + let read = Parser.readFunction(for: fullString, limit: limit) + + return LanguageLayer.ContentSnapshot( + readHandler: read, + textProvider: fullString.predicateTextSnapshotProvider + ) + } } extension TextMetrics {