Skip to content

Commit 28cf9d5

Browse files
authored
Merge pull request #19 from lukepistrol/chore/update-languages
[feat]: add `.jav` file extension to Java language definition
2 parents 1a2ac9b + b7c4022 commit 28cf9d5

File tree

5 files changed

+216
-107
lines changed

5 files changed

+216
-107
lines changed

CodeLanguages-Container/CodeLanguages-Container.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-119 KB
Binary file not shown.
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
//
2+
// CodeLanguage+Definitions.swift
3+
//
4+
//
5+
// Created by Lukas Pistrol on 15.01.23.
6+
//
7+
8+
import Foundation
9+
10+
public extension CodeLanguage {
11+
12+
/// An array of all language structures.
13+
static let allLanguages: [CodeLanguage] = [
14+
.bash,
15+
.c,
16+
.cpp,
17+
.cSharp,
18+
.css,
19+
.dockerfile,
20+
.elixir,
21+
.go,
22+
.goMod,
23+
.haskell,
24+
.html,
25+
.java,
26+
.javascript,
27+
.json,
28+
.jsx,
29+
.php,
30+
.python,
31+
.ruby,
32+
.rust,
33+
.swift,
34+
.yaml,
35+
.zig
36+
]
37+
38+
/// A language structure for `Bash`
39+
static let bash: CodeLanguage = .init(
40+
id: .bash,
41+
tsName: "bash",
42+
extensions: ["sh"]
43+
)
44+
45+
/// A language structure for `C`
46+
static let c: CodeLanguage = .init(
47+
id: .c,
48+
tsName: "c",
49+
extensions: ["c", "h", "o"]
50+
)
51+
52+
/// A language structure for `C++`
53+
static let cpp: CodeLanguage = .init(
54+
id: .cpp,
55+
tsName: "cpp",
56+
extensions: ["cpp", "h", "hpp", "cc"],
57+
parentURL: CodeLanguage.c.queryURL
58+
)
59+
60+
/// A language structure for `C#`
61+
static let cSharp: CodeLanguage = .init(
62+
id: .cSharp,
63+
tsName: "c-sharp",
64+
extensions: ["cs"]
65+
)
66+
67+
/// A language structure for `CSS`
68+
static let css: CodeLanguage = .init(
69+
id: .css,
70+
tsName: "css",
71+
extensions: ["css"]
72+
)
73+
74+
/// A language structure for `Dockerfile`
75+
static let dockerfile: CodeLanguage = .init(
76+
id: .dockerfile,
77+
tsName: "dockerfile",
78+
extensions: ["Dockerfile"]
79+
)
80+
81+
/// A language structure for `Elixir`
82+
static let elixir: CodeLanguage = .init(
83+
id: .elixir,
84+
tsName: "elixir",
85+
extensions: ["ex", "exs"]
86+
)
87+
88+
/// A language structure for `Go`
89+
static let go: CodeLanguage = .init(
90+
id: .go,
91+
tsName: "go",
92+
extensions: ["go"]
93+
)
94+
95+
/// A language structure for `GoMod`
96+
static let goMod: CodeLanguage = .init(
97+
id: .goMod,
98+
tsName: "go-mod",
99+
extensions: ["mod"]
100+
)
101+
102+
/// A language structure for `Haskell`
103+
static let haskell: CodeLanguage = .init(
104+
id: .haskell,
105+
tsName: "haskell",
106+
extensions: ["hs"]
107+
)
108+
109+
/// A language structure for `HTML`
110+
static let html: CodeLanguage = .init(
111+
id: .html,
112+
tsName: "html",
113+
extensions: ["html", "htm"]
114+
)
115+
116+
/// A language structure for `Java`
117+
static let java: CodeLanguage = .init(
118+
id: .java,
119+
tsName: "java",
120+
extensions: ["java", "jav"]
121+
)
122+
123+
/// A language structure for `JavaScript`
124+
static let javascript: CodeLanguage = .init(
125+
id: .javascript,
126+
tsName: "javascript",
127+
extensions: ["js"]
128+
)
129+
130+
/// A language structure for `JSON`
131+
static let json: CodeLanguage = .init(
132+
id: .json,
133+
tsName: "json",
134+
extensions: ["json"]
135+
)
136+
137+
/// A language structure for `JSX`
138+
static let jsx: CodeLanguage = .init(
139+
id: .jsx,
140+
tsName: "javascript",
141+
extensions: ["jsx"],
142+
highlights: ["highlights-jsx"]
143+
)
144+
145+
/// A language structure for `PHP`
146+
static let php: CodeLanguage = .init(
147+
id: .php,
148+
tsName: "php",
149+
extensions: ["php"]
150+
)
151+
152+
/// A language structure for `Python`
153+
static let python: CodeLanguage = .init(
154+
id: .python,
155+
tsName: "python",
156+
extensions: ["py"]
157+
)
158+
159+
/// A language structure for `Ruby`
160+
static let ruby: CodeLanguage = .init(
161+
id: .ruby,
162+
tsName: "ruby",
163+
extensions: ["rb"]
164+
)
165+
166+
/// A language structure for `Rust`
167+
static let rust: CodeLanguage = .init(
168+
id: .rust,
169+
tsName: "rust",
170+
extensions: ["rs"]
171+
)
172+
173+
/// A language structure for `Swift`
174+
static let swift: CodeLanguage = .init(
175+
id: .swift,
176+
tsName: "swift",
177+
extensions: ["swift"]
178+
)
179+
180+
/// A language structure for `YAML`
181+
static let yaml: CodeLanguage = .init(
182+
id: .yaml,
183+
tsName: "yaml",
184+
extensions: ["yml", "yaml"]
185+
)
186+
187+
/// A language structure for `Zig`
188+
static let zig: CodeLanguage = .init(
189+
id: .zig,
190+
tsName: "zig",
191+
extensions: ["zig"]
192+
)
193+
194+
/// The default language (plain text)
195+
static let `default`: CodeLanguage = .init(
196+
id: .plainText,
197+
tsName: "PlainText",
198+
extensions: ["txt"]
199+
)
200+
}

Sources/CodeEditLanguages/CodeLanguage.swift

Lines changed: 1 addition & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import CodeLanguages_Container
1212

1313
/// A structure holding metadata for code languages
1414
public struct CodeLanguage {
15-
private init(
15+
internal init(
1616
id: TreeSitterLanguage,
1717
tsName: String,
1818
extensions: Set<String>,
@@ -134,109 +134,4 @@ public extension CodeLanguage {
134134
return .default
135135
}
136136
}
137-
138-
/// An array of all language structures.
139-
static let allLanguages: [CodeLanguage] = [
140-
.bash,
141-
.c,
142-
.cpp,
143-
.cSharp,
144-
.css,
145-
.dockerfile,
146-
.elixir,
147-
.go,
148-
.goMod,
149-
.haskell,
150-
.html,
151-
.java,
152-
.javascript,
153-
.json,
154-
.jsx,
155-
.php,
156-
.python,
157-
.ruby,
158-
.rust,
159-
.swift,
160-
.yaml,
161-
.zig
162-
]
163-
164-
/// A language structure for `Bash`
165-
static let bash: CodeLanguage = .init(id: .bash, tsName: "bash", extensions: ["sh"])
166-
167-
/// A language structure for `C`
168-
static let c: CodeLanguage = .init(id: .c, tsName: "c", extensions: ["c", "h", "o"])
169-
170-
/// A language structure for `C++`
171-
static let cpp: CodeLanguage = .init(
172-
id: .cpp,
173-
tsName: "cpp",
174-
extensions: ["cpp", "h", "hpp", "cc"],
175-
parentURL: CodeLanguage.c.queryURL
176-
)
177-
178-
/// A language structure for `C#`
179-
static let cSharp: CodeLanguage = .init(id: .cSharp, tsName: "c-sharp", extensions: ["cs"])
180-
181-
/// A language structure for `CSS`
182-
static let css: CodeLanguage = .init(id: .css, tsName: "css", extensions: ["css"])
183-
184-
/// A language structure for `Dockerfile`
185-
static let dockerfile: CodeLanguage = .init(id: .dockerfile, tsName: "dockerfile", extensions: ["Dockerfile"])
186-
187-
/// A language structure for `Elixir`
188-
static let elixir: CodeLanguage = .init(id: .elixir, tsName: "elixir", extensions: ["ex", "exs"])
189-
190-
/// A language structure for `Go`
191-
static let go: CodeLanguage = .init(id: .go, tsName: "go", extensions: ["go"])
192-
193-
/// A language structure for `GoMod`
194-
static let goMod: CodeLanguage = .init(id: .goMod, tsName: "go-mod", extensions: ["mod"])
195-
196-
/// A language structure for `Haskell`
197-
static let haskell: CodeLanguage = .init(id: .haskell, tsName: "haskell", extensions: ["hs"])
198-
199-
/// A language structure for `HTML`
200-
static let html: CodeLanguage = .init(id: .html, tsName: "html", extensions: ["html", "htm"])
201-
202-
/// A language structure for `Java`
203-
static let java: CodeLanguage = .init(id: .java, tsName: "java", extensions: ["java"])
204-
205-
/// A language structure for `JavaScript`
206-
static let javascript: CodeLanguage = .init(id: .javascript, tsName: "javascript", extensions: ["js"])
207-
208-
/// A language structure for `JSON`
209-
static let json: CodeLanguage = .init(id: .json, tsName: "json", extensions: ["json"])
210-
211-
/// A language structure for `JSX`
212-
static let jsx: CodeLanguage = .init(
213-
id: .jsx,
214-
tsName: "javascript",
215-
extensions: ["jsx"],
216-
highlights: ["highlights-jsx"]
217-
)
218-
219-
/// A language structure for `PHP`
220-
static let php: CodeLanguage = .init(id: .php, tsName: "php", extensions: ["php"])
221-
222-
/// A language structure for `Python`
223-
static let python: CodeLanguage = .init(id: .python, tsName: "python", extensions: ["py"])
224-
225-
/// A language structure for `Ruby`
226-
static let ruby: CodeLanguage = .init(id: .ruby, tsName: "ruby", extensions: ["rb"])
227-
228-
/// A language structure for `Rust`
229-
static let rust: CodeLanguage = .init(id: .rust, tsName: "rust", extensions: ["rs"])
230-
231-
/// A language structure for `Swift`
232-
static let swift: CodeLanguage = .init(id: .swift, tsName: "swift", extensions: ["swift"])
233-
234-
/// A language structure for `YAML`
235-
static let yaml: CodeLanguage = .init(id: .yaml, tsName: "yaml", extensions: ["yml", "yaml"])
236-
237-
/// A language structure for `Zig`
238-
static let zig: CodeLanguage = .init(id: .zig, tsName: "zig", extensions: ["zig"])
239-
240-
/// The default language (plain text)
241-
static let `default`: CodeLanguage = .init(id: .plainText, tsName: "Plain Text", extensions: ["txt"])
242137
}

Tests/CodeEditLanguagesTests/CodeEditLanguagesTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ final class CodeEditLanguagesTests: XCTestCase {
8282
XCTAssertEqual(language.id, .cpp)
8383
}
8484

85+
func test_CodeLanguageCPP3() throws {
86+
let url = URL(fileURLWithPath: "~/path/to/file.hpp")
87+
let language = CodeLanguage.detectLanguageFrom(url: url)
88+
89+
XCTAssertEqual(language.id, .cpp)
90+
}
91+
8592
func test_FetchQueryCPP() throws {
8693
var language = CodeLanguage.cpp
8794
language.resourceURL = bundleURL
@@ -267,6 +274,13 @@ final class CodeEditLanguagesTests: XCTestCase {
267274
XCTAssertEqual(language.id, .java)
268275
}
269276

277+
func test_CodeLanguageJava2() throws {
278+
let url = URL(fileURLWithPath: "~/path/to/file.jav")
279+
let language = CodeLanguage.detectLanguageFrom(url: url)
280+
281+
XCTAssertEqual(language.id, .java)
282+
}
283+
270284
func test_FetchQueryJava() throws {
271285
var language = CodeLanguage.java
272286
language.resourceURL = bundleURL

0 commit comments

Comments
 (0)