Skip to content

Commit

Permalink
Add a lock around parse, as we can have both the OperationQueue-based…
Browse files Browse the repository at this point in the history
… parse and this parse happen at the same time
  • Loading branch information
migueldeicaza committed Apr 5, 2024
1 parent 9a48654 commit dee8694
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ final class TreeSitterInternalLanguageMode: InternalLanguageMode {
private let lineManager: LineManager
private let rootLanguageLayer: TreeSitterLanguageLayer
private let operationQueue = OperationQueue()

private let parseLock = NSLock()

Check failure on line 20 in Sources/Runestone/TextView/SyntaxHighlighting/Internal/TreeSitter/TreeSitterInternalLanguageMode.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
init(language: TreeSitterInternalLanguage, languageProvider: TreeSitterLanguageProvider?, stringView: StringView, lineManager: LineManager) {
self.stringView = stringView
self.lineManager = lineManager
Expand All @@ -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)) {
Expand Down

0 comments on commit dee8694

Please sign in to comment.