Skip to content

Commit

Permalink
Incorporated latest Neon
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Nov 26, 2024
1 parent 00334c4 commit d6654e2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 53 deletions.
8 changes: 3 additions & 5 deletions Edit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,6 @@
C92931422B80CC6700C64DDE /* EditKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = EditKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C92931722B822BFF00C64DDE /* EditKit.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = EditKit.xcconfig; sourceTree = "<group>"; };
C93791A32AD5E02C00665F50 /* Project-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Project-Debug.xcconfig"; sourceTree = "<group>"; };
C93A80492CC4052100B89FB4 /* Neon */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Neon; path = ../Neon; sourceTree = SOURCE_ROOT; };
C93F72482BF26BDC0021ACF3 /* EditIntents.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.extensionkit-extension"; includeInIndex = 0; path = EditIntents.appex; sourceTree = BUILT_PRODUCTS_DIR; };
C93F724A2BF26BDC0021ACF3 /* EditIntentsExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditIntentsExtension.swift; sourceTree = "<group>"; };
C93F724C2BF26BDC0021ACF3 /* HighlightIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighlightIntent.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1864,7 +1863,6 @@
C9FE52902A7525D000CACA1A = {
isa = PBXGroup;
children = (
C93A80492CC4052100B89FB4 /* Neon */,
C9FE538E2A76674600CACA1A /* Configurations */,
C9439A742C3EC13A0020DDF5 /* Dependencies */,
C9FE529B2A7525D000CACA1A /* Edit */,
Expand Down Expand Up @@ -5338,7 +5336,7 @@
repositoryURL = "https://github.com/ChimeHQ/Neon.git";
requirement = {
kind = revision;
revision = 9101469ff9ae2258e88099327969c350a953407d;
revision = 32ef005f7fc9d8358739ef2e6702c2c73cec6ca9;
};
};
C93F72252BF0F9290021ACF3 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
Expand Down Expand Up @@ -5394,7 +5392,7 @@
repositoryURL = "https://github.com/ChimeHQ/TextStory.git";
requirement = {
kind = revision;
revision = 5cd0787b43f038051d42b39db3319cbf78c42861;
revision = e23226da4a29a606b532d3f4d7d04102cd7826c5;
};
};
C98EA4162A90F17700B8815E /* XCRemoteSwiftPackageReference "ProcessEnv" */ = {
Expand All @@ -5418,7 +5416,7 @@
repositoryURL = "https://github.com/ChimeHQ/Rearrange.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.6.0;
minimumVersion = 2.0.0;
};
};
C9B8AA5B2B370A1800C79606 /* XCRemoteSwiftPackageReference "SwiftTreeSitter" */ = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "ff7de96f98e01194f786ca218f32286d1e04cc1961dd2ec8e8d690d02ed4a344",
"originHash" : "e20cc55708e58da63ecb4be4feef028e6a48818a25bdcd1f961cf924b58e7a18",
"pins" : [
{
"identity" : "asyncxpcconnection",
Expand Down Expand Up @@ -122,6 +122,14 @@
"version" : "0.2.1"
}
},
{
"identity" : "neon",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/Neon.git",
"state" : {
"revision" : "32ef005f7fc9d8358739ef2e6702c2c73cec6ca9"
}
},
{
"identity" : "nsui",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -161,8 +169,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/Rearrange",
"state" : {
"revision" : "5ff7f3363f7a08f77e0d761e38e6add31c2136e1",
"version" : "1.8.1"
"revision" : "f1d74e1642956f0300756ad8d1d64e9034857bc3",
"version" : "2.0.0"
}
},
{
Expand Down Expand Up @@ -213,15 +221,15 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/SwiftTreeSitter",
"state" : {
"revision" : "f01316eaf3aae07e30478f8afa76192ab4a96420"
"revision" : "55f2c2fdaf859f86e4ea8513b9934badc7894019"
}
},
{
"identity" : "textstory",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/TextStory.git",
"state" : {
"revision" : "5cd0787b43f038051d42b39db3319cbf78c42861"
"revision" : "e23226da4a29a606b532d3f4d7d04102cd7826c5"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions Edit/Modules/Highlighting/Highlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ final class LowlightTokenProvider {
}
}

/// Manages syntax highlighting state.
@MainActor
public final class Highlighter<Service: TokenService> {
typealias Styler = ThreePhaseTextSystemStyler<TextViewSystemNeonInterface>
Expand Down Expand Up @@ -106,6 +107,7 @@ public final class Highlighter<Service: TokenService> {
return await tokenServiceWrapper.tokens(for: $0)
}

// Don't forget about `TokenProvider.none` and `asyncOnlyNone` when debugging here. They are handy!
self.styler = ThreePhaseTextSystemStyler(
textSystem: interface,
tokenProvider: syntaxService.tokenProvider,
Expand Down
47 changes: 4 additions & 43 deletions Edit/Modules/SyntaxService/SyntaxService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension TextTarget {
}
}


/// Provides semantic information about text.
@MainActor
public final class SyntaxService {
private enum State {
Expand Down Expand Up @@ -71,6 +71,7 @@ public final class SyntaxService {
let config = TreeSitterClient.Configuration(
languageProvider: { [languageDataStore] in languageDataStore.languageConfiguration(with: $0) },
contentProvider: { [textSystem] in textSystem.storage.layerContent(for: $0) },
contentSnapshopProvider: { [textSystem] in textSystem.storage.layerContentSnapshot(for: $0) },
lengthProvider: { [textSystem] in textSystem.storage.currentLength },
invalidationHandler: { [unowned self] in self.invalidationHandler(.set($0)) },
locationTransformer: { [textSystem] in textSystem.textMetrics.locationTransformer($0) }
Expand Down Expand Up @@ -141,46 +142,6 @@ extension SyntaxService {
return TreeSitterClient.ClientQueryParams(range: range, textProvider: textProvider, mode: .optional)
}

private static let highlightsMap: [String: String] = [
"keyword": "keyword",
"include": "keyword.include",
"keyword.return": "keyword.return",
"keyword.function": "keyword.function",
"keyword.operator": "keyword.operator.text",
"operator": "keyword.operator",
"conditional": "keyword.conditional",
"repeat": "keyword.loop",
"punctuation.special": "keyword.operator.text",
"punctuation.delimiter": "keyword.operator.text",

"type": "type",

"string": "literal.string",
"number": "literal.number",
"float": "literal.float",
"boolean": "literal.boolean",
"string.regex": "literal.regex",
"text.literal": "literal.string",
"string.escape": "literal.string.escape",
"text.uri": "literal.string.uri",
"string.uri": "literal.string.uri",

"variable": "variable",
"variable.builtin": "variable.built-in",

"method": "member.function",
"constructor": "member.constructor",
"property": "member.property",

"parameter": "parameter",
"function": "function",
"function.call": "invocation.function",
"function.macro": "invocation.macro",

"label": "label",
"text.reference": "label",
]

public var tokenProvider: TokenProvider {
TokenProvider(
syncValue: { range in
Expand All @@ -194,7 +155,7 @@ extension SyntaxService {
return nil
}

return TokenApplication(namedRanges: namedRanges, nameMap: [:], range: range)
return TokenApplication(namedRanges: namedRanges, range: range)
} catch {
self.logger.warning("Failed to get highlighting: \(error)")

Expand All @@ -210,7 +171,7 @@ extension SyntaxService {
let queryParams = try self.highlightsQueryParams(for: range)
let namedRanges = try await client.highlightsProvider.async(queryParams)

return TokenApplication(namedRanges: namedRanges, nameMap: [:], range: range)
return TokenApplication(namedRanges: namedRanges, range: range)
} catch {
self.logger.warning("Failed to get highlighting: \(error)")

Expand Down
10 changes: 10 additions & 0 deletions Edit/Modules/SyntaxService/TextSystem+SwiftTreeSitterLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ extension TextStorage {
textProvider: fullString.predicateTextProvider
)
}

func layerContentSnapshot(for limit: Int) -> LanguageLayer.ContentSnapshot {
let fullString = string
let read = Parser.readFunction(for: fullString, limit: limit)

return LanguageLayer.ContentSnapshot(
readHandler: read,
textProvider: fullString.predicateTextSnapshotProvider
)
}
}

extension TextMetrics {
Expand Down

0 comments on commit d6654e2

Please sign in to comment.