From 31227c2dd98a72fdc7f7621697f456c2c66214eb Mon Sep 17 00:00:00 2001 From: Thiago Holanda Date: Fri, 22 Nov 2024 21:02:15 +0100 Subject: [PATCH] Add support to JSON (#25) --- Configurations/NonSwiftWorkaround.xcconfig | 1 + Dependencies/Package.swift | 2 ++ .../Sources/TreeSitterParsers/TreeSitterParsers.swift | 1 + .../Modules/SyntaxService/LanguageProfile+Profiles.swift | 9 +++++++++ Edit/Modules/SyntaxService/RootLanguage.swift | 6 ++++++ EditIntents/HighlightIntent.swift | 1 + QuickLookPreview/Info.plist | 1 + 7 files changed, 21 insertions(+) diff --git a/Configurations/NonSwiftWorkaround.xcconfig b/Configurations/NonSwiftWorkaround.xcconfig index 174b228..467476c 100644 --- a/Configurations/NonSwiftWorkaround.xcconfig +++ b/Configurations/NonSwiftWorkaround.xcconfig @@ -17,6 +17,7 @@ OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DI OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterGosum.modulemap OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterGoWork.modulemap OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterHTML.modulemap +OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterJSON.modulemap OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterMarkdown.modulemap OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterMarkdownInline.modulemap OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterOCaml.modulemap diff --git a/Dependencies/Package.swift b/Dependencies/Package.swift index dfe1caf..958c6fa 100644 --- a/Dependencies/Package.swift +++ b/Dependencies/Package.swift @@ -22,6 +22,7 @@ let package = Package( .package(url: "https://github.com/camdencheek/tree-sitter-go-mod", branch: "main"), .package(url: "https://github.com/tree-sitter-grammars/tree-sitter-go-sum", branch: "master"), .package(url: "https://github.com/mattmassicotte/tree-sitter-go-work", branch: "feature/spm"), + .package(url: "https://github.com/tree-sitter/tree-sitter-json", branch: "master"), .package(url: "https://github.com/tree-sitter-grammars/tree-sitter-markdown", branch: "split_parser"), .package(url: "https://github.com/tree-sitter/tree-sitter-ocaml", branch: "master"), .package(url: "https://github.com/tree-sitter/tree-sitter-python", branch: "master"), @@ -43,6 +44,7 @@ let package = Package( .product(name: "TreeSitterGosum", package: "tree-sitter-go-sum"), .product(name: "TreeSitterGoWork", package: "tree-sitter-go-work"), .product(name: "TreeSitterHTML", package: "tree-sitter-html"), + .product(name: "TreeSitterJSON", package: "tree-sitter-json"), .product(name: "TreeSitterMarkdown", package: "tree-sitter-markdown"), .product(name: "TreeSitterOCaml", package: "tree-sitter-ocaml"), .product(name: "TreeSitterPython", package: "tree-sitter-python"), diff --git a/Dependencies/Sources/TreeSitterParsers/TreeSitterParsers.swift b/Dependencies/Sources/TreeSitterParsers/TreeSitterParsers.swift index 2db3b54..da171f5 100644 --- a/Dependencies/Sources/TreeSitterParsers/TreeSitterParsers.swift +++ b/Dependencies/Sources/TreeSitterParsers/TreeSitterParsers.swift @@ -8,6 +8,7 @@ @_exported import TreeSitterGosum @_exported import TreeSitterGoWork @_exported import TreeSitterHTML +@_exported import TreeSitterJSON @_exported import TreeSitterMarkdown @_exported import TreeSitterMarkdownInline @_exported import TreeSitterOCaml diff --git a/Edit/Modules/SyntaxService/LanguageProfile+Profiles.swift b/Edit/Modules/SyntaxService/LanguageProfile+Profiles.swift index 7317ca5..228a000 100644 --- a/Edit/Modules/SyntaxService/LanguageProfile+Profiles.swift +++ b/Edit/Modules/SyntaxService/LanguageProfile+Profiles.swift @@ -40,6 +40,10 @@ extension LanguageProfile { return LanguageProfile.htmlProfile } + if utType.conforms(to: .json) { + return LanguageProfile.jsonProfile + } + if utType.conforms(to: .markdown) { return LanguageProfile.markdownProfile } @@ -127,6 +131,11 @@ extension LanguageProfile { language: Language(tree_sitter_html()) ) + static let jsonProfile = LanguageProfile( + RootLanguage.json, + language: Language(tree_sitter_json()) + ) + static let markdownProfile = LanguageProfile( RootLanguage.markdown, language: Language(tree_sitter_markdown()) diff --git a/Edit/Modules/SyntaxService/RootLanguage.swift b/Edit/Modules/SyntaxService/RootLanguage.swift index 4c7cf68..3ce8ba6 100644 --- a/Edit/Modules/SyntaxService/RootLanguage.swift +++ b/Edit/Modules/SyntaxService/RootLanguage.swift @@ -17,6 +17,7 @@ public enum RootLanguage: Hashable, CaseIterable, Sendable { case goSum case goWork case html + case json case markdown case ocaml case ocamlInterface @@ -37,6 +38,7 @@ public enum RootLanguage: Hashable, CaseIterable, Sendable { case .goSum: .goSumFile case .goWork: .goWorkFile case .html: .html + case .json: .json case .markdown: .markdown case .ocaml: .ocamlSource case .ocamlInterface: .ocamlInterface @@ -75,6 +77,8 @@ extension RootLanguage: RawRepresentable { self = .goWork case "html": self = .html + case "json": + self = .json case "markdown": self = .markdown case "ocaml": @@ -116,6 +120,8 @@ extension RootLanguage: RawRepresentable { "Go Work" case .html: "HTML" + case .json: + "JSON" case .markdown: "Markdown" case .ocaml: diff --git a/EditIntents/HighlightIntent.swift b/EditIntents/HighlightIntent.swift index 28218e8..61f0575 100644 --- a/EditIntents/HighlightIntent.swift +++ b/EditIntents/HighlightIntent.swift @@ -20,6 +20,7 @@ extension RootLanguage: AppEnum { .goSum: "Go Sum", .goWork: "Go Work", .html: "HTML", + .json: "JSON", .markdown: "Markdown", .ocaml: "OCaml", .ocamlInterface: "OCaml Interface", diff --git a/QuickLookPreview/Info.plist b/QuickLookPreview/Info.plist index be7fe34..d6dfedf 100644 --- a/QuickLookPreview/Info.plist +++ b/QuickLookPreview/Info.plist @@ -22,6 +22,7 @@ dev.go.go-work dev.go.go-sum public.html + public.json org.ocaml.ocaml org.ocaml.ocaml-interface public.python-script