From 36d91bfd44170935461618316e1433a1246c44fc Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Mon, 15 Apr 2024 04:02:46 -0400 Subject: [PATCH 1/3] Add a lock around parse, to prevent concurrent access to the underlying parse tree. (#367) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add a lock around parse, as we can have both the OperationQueue-based parse and this parse happen at the same time * Fixes SwiftLint violation --------- Co-authored-by: Simon Støvring --- .../Internal/TreeSitter/TreeSitterInternalLanguageMode.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift b/Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift index aa2e44677..d089d7682 100644 --- a/Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift +++ b/Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift @@ -16,6 +16,7 @@ final class TreeSitterInternalLanguageMode: InternalLanguageMode { private let lineManager: LineManager private let rootLanguageLayer: TreeSitterLanguageLayer private let operationQueue = OperationQueue() + private let parseLock = NSLock() init(language: TreeSitterInternalLanguage, languageProvider: TreeSitterLanguageProvider?, stringView: StringView, lineManager: LineManager) { self.stringView = stringView @@ -37,7 +38,9 @@ final class TreeSitterInternalLanguageMode: InternalLanguageMode { } func parse(_ text: NSString) { - rootLanguageLayer.parse(text) + parseLock.withLock { + rootLanguageLayer.parse(text) + } } func parse(_ text: NSString, completion: @escaping ((Bool) -> Void)) { From 81e23a9a9e90d52b5b407f60d378731875aaea6b Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Mon, 13 May 2024 00:34:05 -0400 Subject: [PATCH 2/3] Allow TextLocation to be created (#372) --- Sources/Runestone/TextView/Navigation/TextLocation.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/Runestone/TextView/Navigation/TextLocation.swift b/Sources/Runestone/TextView/Navigation/TextLocation.swift index df587505c..f70a762a0 100644 --- a/Sources/Runestone/TextView/Navigation/TextLocation.swift +++ b/Sources/Runestone/TextView/Navigation/TextLocation.swift @@ -7,6 +7,12 @@ public struct TextLocation: Hashable, Equatable { /// Column in the line. public let column: Int + /// Initializes TextLocation from the given line and column + public init (lineNumber: Int, column: Int) { + self.lineNumber = lineNumber + self.column = column + } + init(_ linePosition: LinePosition) { self.lineNumber = linePosition.row self.column = linePosition.column From 1fad339aab99cf2136ce6bf8c32da3265b2e85e5 Mon Sep 17 00:00:00 2001 From: Eli Perkins Date: Mon, 10 Jun 2024 17:50:12 -0600 Subject: [PATCH 3/3] Fix build with Xcode 16 (#375) Prior to this, Xcode 16 was unable to infer the type of the variable (while Xcode 15 was), so the lookup to `reversed()` was ambiguous. This adds `String` as the inferred type, so that the call to `reversed()` is no longer ambiguous. --- Sources/Runestone/Library/UITextInput+Helpers.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Runestone/Library/UITextInput+Helpers.swift b/Sources/Runestone/Library/UITextInput+Helpers.swift index db115d56c..60b911840 100644 --- a/Sources/Runestone/Library/UITextInput+Helpers.swift +++ b/Sources/Runestone/Library/UITextInput+Helpers.swift @@ -6,7 +6,7 @@ import UIKit extension UITextInput where Self: NSObject { var sbs_textSelectionDisplayInteraction: UITextSelectionDisplayInteraction? { let interactionAssistantKey = "int" + "ssAnoitcare".reversed() + "istant" - let selectionViewManagerKey = "les_".reversed() + "ection" + "reganaMweiV".reversed() + let selectionViewManagerKey: String = "les_".reversed() + "ection" + "reganaMweiV".reversed() guard responds(to: Selector(interactionAssistantKey)) else { return nil }