From dee8694c073b16122a55e722e7e815ccea7c3244 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Thu, 4 Apr 2024 22:34:49 -0400 Subject: [PATCH 1/2] Add a lock around parse, as we can have both the OperationQueue-based parse and this parse happen at the same time --- .../TreeSitter/TreeSitterInternalLanguageMode.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift b/Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift index aa2e44677..259395735 100644 --- a/Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift +++ b/Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift @@ -16,7 +16,8 @@ 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 self.lineManager = lineManager @@ -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 6d14dcf61af9935eb8eea9a707e8e48ffdd35993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Mon, 8 Apr 2024 15:01:42 +0200 Subject: [PATCH 2/2] Fixes SwiftLint violation --- .../Internal/TreeSitter/TreeSitterInternalLanguageMode.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift b/Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift index 259395735..d089d7682 100644 --- a/Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift +++ b/Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift @@ -17,7 +17,7 @@ final class TreeSitterInternalLanguageMode: InternalLanguageMode { private let rootLanguageLayer: TreeSitterLanguageLayer private let operationQueue = OperationQueue() private let parseLock = NSLock() - + init(language: TreeSitterInternalLanguage, languageProvider: TreeSitterLanguageProvider?, stringView: StringView, lineManager: LineManager) { self.stringView = stringView self.lineManager = lineManager