-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework Async
tree-sitter
Model, Fix Strong Ref Cycle (#225)
- Loading branch information
1 parent
f76b48a
commit b5a8ca9
Showing
24 changed files
with
582 additions
and
629 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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
20 changes: 0 additions & 20 deletions
20
Sources/CodeEditSourceEditor/Extensions/Parser+createTree.swift
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
Sources/CodeEditSourceEditor/Extensions/TextView+/TextView+Point.swift
This file contains 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,18 @@ | ||
// | ||
// TextView+Point.swift | ||
// CodeEditSourceEditor | ||
// | ||
// Created by Khan Winter on 1/18/24. | ||
// | ||
|
||
import Foundation | ||
import CodeEditTextView | ||
import SwiftTreeSitter | ||
|
||
extension TextView { | ||
func pointForLocation(_ location: Int) -> Point? { | ||
guard let linePosition = layoutManager.textLineForOffset(location) else { return nil } | ||
let column = location - linePosition.range.location | ||
return Point(row: linePosition.index, column: column) | ||
} | ||
} |
This file contains 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 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 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
36 changes: 36 additions & 0 deletions
36
Sources/CodeEditSourceEditor/Highlighting/Highlighter+NSTextStorageDelegate.swift
This file contains 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,36 @@ | ||
// | ||
// Highlighter+NSTextStorageDelegate.swift | ||
// CodeEditSourceEditor | ||
// | ||
// Created by Khan Winter on 1/18/24. | ||
// | ||
|
||
import AppKit | ||
|
||
extension Highlighter: NSTextStorageDelegate { | ||
/// Processes an edited range in the text. | ||
/// Will query tree-sitter for any updated indices and re-highlight only the ranges that need it. | ||
func textStorage( | ||
_ textStorage: NSTextStorage, | ||
didProcessEditing editedMask: NSTextStorageEditActions, | ||
range editedRange: NSRange, | ||
changeInLength delta: Int | ||
) { | ||
// This method is called whenever attributes are updated, so to avoid re-highlighting the entire document | ||
// each time an attribute is applied, we check to make sure this is in response to an edit. | ||
guard editedMask.contains(.editedCharacters) else { return } | ||
|
||
self.storageDidEdit(editedRange: editedRange, delta: delta) | ||
} | ||
|
||
func textStorage( | ||
_ textStorage: NSTextStorage, | ||
willProcessEditing editedMask: NSTextStorageEditActions, | ||
range editedRange: NSRange, | ||
changeInLength delta: Int | ||
) { | ||
guard editedMask.contains(.editedCharacters) else { return } | ||
|
||
self.storageWillEdit(editedRange: editedRange) | ||
} | ||
} |
Oops, something went wrong.