Skip to content

Commit

Permalink
feat: add support for syntax highlighting for diff/patch files
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed May 16, 2024
1 parent 8e7ee7c commit f2fea85
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 5 deletions.
1 change: 1 addition & 0 deletions org.eclipse.tm4e.language_pack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ for the [Eclipse IDE](https://eclipseide.org).
| CSS | file-extensions="css" | [1.87.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/019f4d1419fbc8219a181fab7892ebccf7ee29a2/extensions/css) [[upstream]](https://github.com/microsoft/vscode-css/commit/c216f777497265700ff336f739328e5197e012cd)
| CUDA C++ | file-extensions="cu, cuh" | [1.87.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/019f4d1419fbc8219a181fab7892ebccf7ee29a2/extensions/cpp) [[upstream]](https://github.com/NVIDIA/cuda-cpp-grammar/commit/81e88eaec5170aa8585736c63627c73e3589998c)
| Dart | file-extensions="dart" | [1.87.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/019f4d1419fbc8219a181fab7892ebccf7ee29a2/extensions/dart) [[upstream]](https://github.com/dart-lang/dart-syntax-highlight/commit/0a6648177bdbb91a4e1a38c16e57ede0ccba4f18)
| Diff | file-extensions="diff, patch, rej" | [1.87.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/019f4d1419fbc8219a181fab7892ebccf7ee29a2/extensions/diff) [[upstream]](https://github.com/textmate/diff.tmbundle/commit/0593bb775eab1824af97ef2172fd38822abd97d7)
| Docker | file-extensions="containerfile, dockerfile"<br />file-names="Containerfile, Dockerfile"<br />file-patterns="Containerfile.\*, Dockerfile.\*" | [1.87.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/019f4d1419fbc8219a181fab7892ebccf7ee29a2/extensions/docker) [[upstream]](https://github.com/moby/moby/commit/abd39744c6f3ed854500e423f5fabf952165161f)
| F# | file-extensions="fs, fsi, fsscript, fsx" | [1.87.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/019f4d1419fbc8219a181fab7892ebccf7ee29a2/extensions/fsharp) [[upstream]](https://github.com/ionide/ionide-fsgrammar/commit/7d029a46f17637228b2ee85dd02e511c3e8039b3)
| Git Commit Message <img src="syntaxes/git-base/icon.png" width=16/> | file-names="COMMIT_EDITMSG, MERGE_MSG" | [1.87.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/019f4d1419fbc8219a181fab7892ebccf7ee29a2/extensions/git-base) [[upstream]](https://github.com/walles/git-commit-message-plus/commit/35a079dea5a91b087021b40c01a6bb4eb0337a87)
Expand Down
5 changes: 5 additions & 0 deletions org.eclipse.tm4e.language_pack/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ <h2>About This Content</h2>
<td>file-extensions="dart"</td>
<td><a href="https://github.com/microsoft/vscode/tree/019f4d1419fbc8219a181fab7892ebccf7ee29a2/extensions/dart">1.87.0@microsoft/vscode</a> <a href="https://github.com/dart-lang/dart-syntax-highlight/commit/0a6648177bdbb91a4e1a38c16e57ede0ccba4f18">[upstream]</a>
</tr>
<tr>
<td>Diff</td>
<td>file-extensions="diff, patch, rej"</td>
<td><a href="https://github.com/microsoft/vscode/tree/019f4d1419fbc8219a181fab7892ebccf7ee29a2/extensions/diff">1.87.0@microsoft/vscode</a> <a href="https://github.com/textmate/diff.tmbundle/commit/0593bb775eab1824af97ef2172fd38822abd97d7">[upstream]</a>
</tr>
<tr>
<td>Docker</td>
<td>file-extensions="containerfile, dockerfile"<br />file-names="Containerfile, Dockerfile"<br />file-patterns="Containerfile.*, Dockerfile.*"</td>
Expand Down
20 changes: 20 additions & 0 deletions org.eclipse.tm4e.language_pack/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,26 @@
<snippet name="Dart Example" path="syntaxes/dart/dart.example.dart" scopeName="source.dart" />
</extension>

<!-- ======================================== -->
<!-- diff/diff: Diff -->
<!-- ======================================== -->
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type id="org.eclipse.tm4e.language_pack.diff" name="Diff" base-type="org.eclipse.tm4e.language_pack.basetype" priority="low"
file-extensions="diff,patch,rej" />
</extension>
<extension point="org.eclipse.tm4e.registry.grammars">
<grammar scopeName="source.diff" path="syntaxes/diff/diff.tmLanguage.json" />
<scopeNameContentTypeBinding scopeName="source.diff" contentTypeId="org.eclipse.tm4e.language_pack.diff" />
</extension>

<extension point="org.eclipse.tm4e.languageconfiguration.languageConfigurations">
<languageConfiguration contentTypeId="org.eclipse.tm4e.language_pack.diff" path="syntaxes/diff/diff.language-configuration.json" />
</extension>

<extension point="org.eclipse.tm4e.ui.snippets">
<snippet name="Diff Example" path="syntaxes/diff/diff.example.diff" scopeName="source.diff" />
</extension>

<!-- ======================================== -->
<!-- docker/dockerfile: Docker -->
<!-- ======================================== -->
Expand Down
14 changes: 14 additions & 0 deletions org.eclipse.tm4e.language_pack/syntaxes/diff/diff.example.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- script1.py 2024-05-16 10:00:00.000000000 +0000
+++ script2.py 2024-05-16 10:00:00.000000000 +0000
@@ -1,6 +1,9 @@
# script1.py
def greet(name):
- print("Hello, " + name + "!")
+ print("Hi, " + name + "!")

def calculate_sum(a, b):
- return a + b
+ result = a + b
+ print("The sum of", a, "and", b, "is", result)
+ return result * 2
+
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"comments": {
"lineComment": "#",
"blockComment": [ "#", " " ]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
]
}
160 changes: 160 additions & 0 deletions org.eclipse.tm4e.language_pack/syntaxes/diff/diff.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"information_for_contributors": [
"This file has been converted from https://github.com/textmate/diff.tmbundle/blob/master/Syntaxes/Diff.plist",
"If you want to provide a fix or improvement, please create a pull request against the original repository.",
"Once accepted there, we are happy to receive an update request."
],
"version": "https://github.com/textmate/diff.tmbundle/commit/0593bb775eab1824af97ef2172fd38822abd97d7",
"name": "Diff",
"scopeName": "source.diff",
"patterns": [
{
"captures": {
"1": {
"name": "punctuation.definition.separator.diff"
}
},
"match": "^((\\*{15})|(={67})|(-{3}))$\\n?",
"name": "meta.separator.diff"
},
{
"match": "^\\d+(,\\d+)*(a|d|c)\\d+(,\\d+)*$\\n?",
"name": "meta.diff.range.normal"
},
{
"captures": {
"1": {
"name": "punctuation.definition.range.diff"
},
"2": {
"name": "meta.toc-list.line-number.diff"
},
"3": {
"name": "punctuation.definition.range.diff"
}
},
"match": "^(@@)\\s*(.+?)\\s*(@@)($\\n?)?",
"name": "meta.diff.range.unified"
},
{
"captures": {
"3": {
"name": "punctuation.definition.range.diff"
},
"4": {
"name": "punctuation.definition.range.diff"
},
"6": {
"name": "punctuation.definition.range.diff"
},
"7": {
"name": "punctuation.definition.range.diff"
}
},
"match": "^(((\\-{3}) .+ (\\-{4}))|((\\*{3}) .+ (\\*{4})))$\\n?",
"name": "meta.diff.range.context"
},
{
"match": "^diff --git a/.*$\\n?",
"name": "meta.diff.header.git"
},
{
"match": "^diff (-|\\S+\\s+\\S+).*$\\n?",
"name": "meta.diff.header.command"
},
{
"captures": {
"4": {
"name": "punctuation.definition.from-file.diff"
},
"6": {
"name": "punctuation.definition.from-file.diff"
},
"7": {
"name": "punctuation.definition.from-file.diff"
}
},
"match": "(^(((-{3}) .+)|((\\*{3}) .+))$\\n?|^(={4}) .+(?= - ))",
"name": "meta.diff.header.from-file"
},
{
"captures": {
"2": {
"name": "punctuation.definition.to-file.diff"
},
"3": {
"name": "punctuation.definition.to-file.diff"
},
"4": {
"name": "punctuation.definition.to-file.diff"
}
},
"match": "(^(\\+{3}) .+$\\n?| (-) .* (={4})$\\n?)",
"name": "meta.diff.header.to-file"
},
{
"captures": {
"3": {
"name": "punctuation.definition.inserted.diff"
},
"6": {
"name": "punctuation.definition.inserted.diff"
}
},
"match": "^(((>)( .*)?)|((\\+).*))$\\n?",
"name": "markup.inserted.diff"
},
{
"captures": {
"1": {
"name": "punctuation.definition.changed.diff"
}
},
"match": "^(!).*$\\n?",
"name": "markup.changed.diff"
},
{
"captures": {
"3": {
"name": "punctuation.definition.deleted.diff"
},
"6": {
"name": "punctuation.definition.deleted.diff"
}
},
"match": "^(((<)( .*)?)|((-).*))$\\n?",
"name": "markup.deleted.diff"
},
{
"begin": "^(#)",
"captures": {
"1": {
"name": "punctuation.definition.comment.diff"
}
},
"comment": "Git produces unified diffs with embedded comments\"",
"end": "\\n",
"name": "comment.line.number-sign.diff"
},
{
"match": "^index [0-9a-f]{7,40}\\.\\.[0-9a-f]{7,40}.*$\\n?",
"name": "meta.diff.index.git"
},
{
"captures": {
"1": {
"name": "punctuation.separator.key-value.diff"
},
"2": {
"name": "meta.toc-list.file-name.diff"
}
},
"match": "^Index(:) (.+)$\\n?",
"name": "meta.diff.index"
},
{
"match": "^Only in .*: .*$\\n?",
"name": "meta.diff.only-in"
}
]
}
3 changes: 0 additions & 3 deletions org.eclipse.tm4e.language_pack/updater/updater-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ sources:
bat:
label: Batch File

diff:
ignored: theme support required

git-base:
languages:
ignore:
Expand Down
13 changes: 11 additions & 2 deletions org.eclipse.tm4e.language_pack/updater/updater-state.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,17 @@ extensions:
github:
repo: microsoft/vscode
path: extensions/diff
ref: 1.84.0
commit: d037ac076cee195194f93ce6fe2bdfe2969cc82d
ref: 1.87.0
commit: 019f4d1419fbc8219a181fab7892ebccf7ee29a2
languages:
diff:
label: Diff
scope-name: source.diff
upstream-url: https://github.com/textmate/diff.tmbundle/commit/0593bb775eab1824af97ef2172fd38822abd97d7
file-extensions:
- .diff
- .patch
- .rej
docker:
github:
repo: microsoft/vscode
Expand Down

0 comments on commit f2fea85

Please sign in to comment.