Skip to content

Commit

Permalink
Temp limit TreeSitter to 6000 lines of code max.
Browse files Browse the repository at this point in the history
* Hotfix to resolve issues with the syntax highlighter, which
  becomes unstable with very large files, need to dig into
  TreeSitter to find the culprit of this unstability before we
  can increase this threshold higher.
  • Loading branch information
furby-tm committed Aug 9, 2024
1 parent 6c2c886 commit 38bc9c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
24 changes: 19 additions & 5 deletions Sources/Kraken/IO/Universal/KIO.USD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ import UniformTypeIdentifiers

public extension Kraken.IO
{
/// temporary maximum number of characters (6000 lines * 90 wide)
/// for treesitter, since it becomes unstable with massive files
/// TODO: find the culprit in treesitter, and remove the maximum
/// threshold once fixed.
static let TREE_SITTER_MAX = 6000 * 90

@Observable
final class USD: ReferenceFileDocument
{
Expand Down Expand Up @@ -75,15 +81,17 @@ public extension Kraken.IO

var contents = ""
context.stage.exportToString(&contents, addSourceFileComment: false)
context.usda = contents
context.usda = String(contents.prefix(Kraken.IO.TREE_SITTER_MAX))
return
}
context.usda = string
context.usda = String(string.prefix(Kraken.IO.TREE_SITTER_MAX))
}

public func fileWrapper(snapshot _: Kraken.IO.USD.Context, configuration _: WriteConfiguration) throws -> FileWrapper
{
context.stage.exportToString(&context.usda, addSourceFileComment: false)
var contents = ""
context.stage.exportToString(&contents, addSourceFileComment: false)
context.usda = String(contents.prefix(Kraken.IO.TREE_SITTER_MAX))

return .init(regularFileWithContents: context.usda.data(using: .utf8)!)
}
Expand Down Expand Up @@ -122,7 +130,10 @@ public extension Kraken.IO.USD
stage = Usd.Stage.open(fileURL.path)

Kraken.IO.Stage.manager.save(&stage)
stage.exportToString(&usda, addSourceFileComment: false)

var contents = ""
stage.exportToString(&contents, addSourceFileComment: false)
usda = String(contents.prefix(Kraken.IO.TREE_SITTER_MAX))
}

public func open(fileURL: URL)
Expand All @@ -131,7 +142,10 @@ public extension Kraken.IO.USD
stage = Usd.Stage.open(fileURL.path)

Kraken.IO.Stage.manager.save(&stage)
stage.exportToString(&self.usda, addSourceFileComment: false)

var contents = ""
stage.exportToString(&contents, addSourceFileComment: false)
usda = String(contents.prefix(Kraken.IO.TREE_SITTER_MAX))
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions Sources/Kraken/UI/Editors/KUI.CodeEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ public extension Kraken.UI
Task
{
Kraken.IO.Stage.manager.reloadAndSave(stage: &C.context.stage)

var contents = ""
C.context.stage.exportToString(&contents, addSourceFileComment: false)

if C.context.usda != contents
{
C.context.usda = contents
}
}
}
.onAppear
Expand Down

0 comments on commit 38bc9c6

Please sign in to comment.