Skip to content

Commit

Permalink
Update Lowlight for way better swift support
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed May 1, 2024
1 parent 1b8e8e9 commit 535b689
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Edit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4754,7 +4754,7 @@
repositoryURL = "https://github.com/ChimeHQ/Lowlight";
requirement = {
kind = revision;
revision = 51f98f2d252d1346d76a032f02a4a9b2add63084;
revision = 1687136e033f3f73494f228d83c80702933616a5;
};
};
C9CDEB582B51620E009E252A /* XCRemoteSwiftPackageReference "ColorToolbox" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/Lowlight",
"state" : {
"revision" : "51f98f2d252d1346d76a032f02a4a9b2add63084"
"revision" : "1687136e033f3f73494f228d83c80702933616a5"
}
},
{
Expand Down
14 changes: 9 additions & 5 deletions Edit/Modules/Highlighting/Highlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ final class LowlightTokenProvider {
let start = range.location
let neonTokens = output.tokens.map {
let shiftedRange = $0.range.shifted(by: start)!

return Neon.Token(name: $0.name, range: shiftedRange)
return Neon.Token(name: $0.element.treeSitterHighlightName, range: shiftedRange)
}

return .init(tokens: neonTokens)
Expand All @@ -56,15 +56,19 @@ final class LowlightTokenProvider {

private func language(for utType: UTType) -> Language? {
if utType.conforms(to: .goSource) {
return Language(keywords: ["import", "func", "const", "for", "var", "if", "return"], symbols: [])
return Language(patterns: [])
}

if utType.conforms(to: .swiftSource) {
return Language(keywords: ["import", "func", "let", "for", "var", "if", "return"], symbols: [])
return Language(
keywords: ["import", "for", "final", "class", "let", "func", "return", "private", "public", "guard", "actor"],
lineComment: "//"
)
}

if utType.conforms(to: .markdown) {
return Language(keywords: [], symbols: ["#"])
// return Language(keywords: [], symbols: ["#"])
return Language(patterns: [])
}

return nil
Expand Down

0 comments on commit 535b689

Please sign in to comment.