-
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.
### Description Fixes a few bugs with #247 and converts it to use tree-sitter rather than a regex-based implementation. This should be faster on larger documents and makes it more robust to edge cases in tag regexes. This also handles newlines correctly, as the old PR caused the editor to no longer be able to delete newlines Also fixes a small bug in the `TreeSitterClient` that caused *every* query to be dispatched to main asynchronously. This was the cause for a few visual oddities like flashing colors when changing themes. This also improves highlighting while scrolling fast as most highlights are processed synchronously. - Removes extensions on `NewlineProcessingFilter` - Cleans up `TagFilter` - Moves all newline processing to the one filter - Use tree-sitter for tag completion, supporting the following languages: HTML, JSX, TSX - Adds a few methods to `TreeSitterClient` for synchronously querying the tree sitter tree. - Adds a new `TreeSitterClientExecutor` class that the client uses to execute operations safely asynchronously and synchronously. - This is extremely useful for testing, as it allows the tests to force all operations to happen synchronously. - Adds a check to `dispatchMain` to see if the thread is already the main thread (meaning no async dispatch) ### Related Issues * #244 * Discussion on discord [Here](https://discord.com/channels/951544472238444645/1242238782653075537) ### Checklist - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots https://github.com/CodeEditApp/CodeEditSourceEditor/assets/35942988/8fc559a4-15c9-4b4e-a3aa-57c86c57f7c9 https://github.com/CodeEditApp/CodeEditSourceEditor/assets/35942988/a209b40f-7aa3-4105-aa37-5608e8b4bcdb
- Loading branch information
1 parent
1740482
commit cf85789
Showing
22 changed files
with
893 additions
and
280 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
78 changes: 78 additions & 0 deletions
78
...SourceEditorExample.xcodeproj/xcshareddata/xcschemes/CodeEditSourceEditorExample.xcscheme
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,78 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1540" | ||
version = "1.7"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES" | ||
buildArchitectures = "Automatic"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6C1365292B8A7B94004A1D18" | ||
BuildableName = "CodeEditSourceEditorExample.app" | ||
BlueprintName = "CodeEditSourceEditorExample" | ||
ReferencedContainer = "container:CodeEditSourceEditorExample.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
shouldAutocreateTestPlan = "YES"> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6C1365292B8A7B94004A1D18" | ||
BuildableName = "CodeEditSourceEditorExample.app" | ||
BlueprintName = "CodeEditSourceEditorExample" | ||
ReferencedContainer = "container:CodeEditSourceEditorExample.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6C1365292B8A7B94004A1D18" | ||
BuildableName = "CodeEditSourceEditorExample.app" | ||
BlueprintName = "CodeEditSourceEditorExample" | ||
ReferencedContainer = "container:CodeEditSourceEditorExample.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
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
102 changes: 0 additions & 102 deletions
102
Sources/CodeEditSourceEditor/Extensions/NewlineProcessingFilter+TagHandling.swift
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
Sources/CodeEditSourceEditor/Extensions/Node+filterChildren.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,42 @@ | ||
// | ||
// Node+filterChildren.swift | ||
// CodeEditSourceEditor | ||
// | ||
// Created by Khan Winter on 5/29/24. | ||
// | ||
|
||
import SwiftTreeSitter | ||
|
||
extension Node { | ||
func firstChild(`where` isMatch: (Node) -> Bool) -> Node? { | ||
for idx in 0..<childCount { | ||
guard let node = child(at: idx) else { continue } | ||
if isMatch(node) { | ||
return node | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func mapChildren<T>(_ callback: (Node) -> T) -> [T] { | ||
var retVal: [T] = [] | ||
for idx in 0..<childCount { | ||
guard let node = child(at: idx) else { continue } | ||
retVal.append(callback(node)) | ||
} | ||
return retVal | ||
} | ||
|
||
func filterChildren(_ isIncluded: (Node) -> Bool) -> [Node] { | ||
var retVal: [Node] = [] | ||
for idx in 0..<childCount { | ||
guard let node = child(at: idx) else { continue } | ||
if isIncluded(node) { | ||
retVal.append(node) | ||
} | ||
} | ||
|
||
return retVal | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Sources/CodeEditSourceEditor/Extensions/String+/String+Groups.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,24 @@ | ||
// | ||
// NewlineProcessingFilter+TagHandling.swift | ||
// CodeEditSourceEditor | ||
// | ||
// Created by Roscoe Rubin-Rottenberg on 5/19/24. | ||
// | ||
|
||
import Foundation | ||
import TextStory | ||
import TextFormation | ||
|
||
// Helper extension to extract capture groups | ||
extension String { | ||
func groups(for regexPattern: String) -> [String]? { | ||
guard let regex = try? NSRegularExpression(pattern: regexPattern) else { return nil } | ||
let nsString = self as NSString | ||
let results = regex.matches(in: self, range: NSRange(location: 0, length: nsString.length)) | ||
return results.first.map { result in | ||
(1..<result.numberOfRanges).compactMap { | ||
result.range(at: $0).location != NSNotFound ? nsString.substring(with: result.range(at: $0)) : nil | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.