Repository navigation
Async TreeSitterClient #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thecoolwinter
merged 10 commits into
CodeEditApp:main
from
thecoolwinter:feat/async-tree-sitter
Jun 3, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
51d95ad
Initial Implementation
thecoolwinter 4a3ed19
Fix deadlocks, remove debugs
thecoolwinter 1f72713
Use `PThreadLock`, Add Parallel Highlights
thecoolwinter 6392429
Correctly Destroy `pthread_mutex_t`
thecoolwinter 42e501a
Implement Basic Tests
thecoolwinter de8ea81
Rename `determineNextTask` to `determineNextJob`
thecoolwinter 9ef99bc
Remove Debug Comment
thecoolwinter 02c3162
Add Documentation
thecoolwinter 7705e91
Lint Error
thecoolwinter deb671f
Fix Formatting
thecoolwinter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Sources/CodeEditTextView/Extensions/HighlighterTextView+createReadBlock.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // | ||
| // HighlighterTextView+createReadBlock.swift | ||
| // | ||
| // | ||
| // Created by Khan Winter on 5/20/23. | ||
| // | ||
|
|
||
| import Foundation | ||
| import SwiftTreeSitter | ||
|
|
||
| extension HighlighterTextView { | ||
| func createReadBlock() -> Parser.ReadBlock { | ||
| return { byteOffset, _ in | ||
| let limit = self.documentRange.length | ||
| let location = byteOffset / 2 | ||
| let end = min(location + (1024), limit) | ||
| if location > end { | ||
| // Ignore and return nothing, tree-sitter's internal tree can be incorrect in some situations. | ||
| return nil | ||
| } | ||
| let range = NSRange(location..<end) | ||
| return self.stringForRange(range)?.data(using: String.nativeUTF16Encoding) | ||
| } | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
Sources/CodeEditTextView/Extensions/Parser+createTree.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // | ||
| // Parser+createTree.swift | ||
| // | ||
| // | ||
| // Created by Khan Winter on 5/20/23. | ||
| // | ||
|
|
||
| import Foundation | ||
| import SwiftTreeSitter | ||
|
|
||
| extension Parser { | ||
| /// Creates a tree-sitter tree. | ||
| /// - Parameters: | ||
| /// - parser: The parser object to use to parse text. | ||
| /// - readBlock: A callback for fetching blocks of text. | ||
| /// - Returns: A tree if it could be parsed. | ||
| internal func createTree(readBlock: @escaping Parser.ReadBlock) -> Tree? { | ||
| return parse(tree: nil, readBlock: readBlock) | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
Sources/CodeEditTextView/Extensions/STTextView+/STTextView+HighlighterTextView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // | ||
| // STTextView+HighlighterTextView.swift | ||
| // CodeEditTextView | ||
| // | ||
| // Created by Khan Winter on 6/2/23. | ||
| // | ||
|
|
||
| import Foundation | ||
| import STTextView | ||
|
|
||
| /// A default implementation for `STTextView` to be passed to `HighlightProviding` objects. | ||
| extension STTextView: HighlighterTextView { | ||
| public var documentRange: NSRange { | ||
| return NSRange( | ||
| location: 0, | ||
| length: textContentStorage?.textStorage?.length ?? 0 | ||
| ) | ||
| } | ||
|
|
||
| public func stringForRange(_ nsRange: NSRange) -> String? { | ||
| return textContentStorage?.textStorage?.mutableString.substring(with: nsRange) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.