From ad9197e2ec0a052328e57d91d269cb23c1b8a956 Mon Sep 17 00:00:00 2001 From: dabico Date: Fri, 1 Dec 2023 16:07:16 +0100 Subject: [PATCH 1/3] Added language submodule: gitattributes --- .gitmodules | 3 +++ tree-sitter-gitattributes | 1 + 2 files changed, 4 insertions(+) create mode 160000 tree-sitter-gitattributes diff --git a/.gitmodules b/.gitmodules index 20a208c1..8e4b7960 100644 --- a/.gitmodules +++ b/.gitmodules @@ -49,6 +49,9 @@ [submodule "tree-sitter-fortran"] path = tree-sitter-fortran url = https://github.com/stadelmanma/tree-sitter-fortran.git +[submodule "tree-sitter-gitattributes"] + path = tree-sitter-gitattributes + url = https://github.com/ObserverOfTime/tree-sitter-gitattributes.git [submodule "tree-sitter-go"] path = tree-sitter-go url = https://github.com/tree-sitter/tree-sitter-go.git diff --git a/tree-sitter-gitattributes b/tree-sitter-gitattributes new file mode 160000 index 00000000..19d554d3 --- /dev/null +++ b/tree-sitter-gitattributes @@ -0,0 +1 @@ +Subproject commit 19d554d39e4a8491f7a77abcdb75bfbc1c19d0b5 From 0f68365d5144207547b1d0082629b92aa36deaed Mon Sep 17 00:00:00 2001 From: dabico Date: Fri, 1 Dec 2023 16:08:48 +0100 Subject: [PATCH 2/3] Adding `GITATTRIBUTES` enum value to `Language` --- lib/ch_usi_si_seart_treesitter.h | 3 +++ lib/ch_usi_si_seart_treesitter_Language.cc | 9 +++++++++ lib/ch_usi_si_seart_treesitter_Language.h | 8 ++++++++ .../java/ch/usi/si/seart/treesitter/Language.java | 13 +++++++++++++ 4 files changed, 33 insertions(+) diff --git a/lib/ch_usi_si_seart_treesitter.h b/lib/ch_usi_si_seart_treesitter.h index 5b702a10..d7f91a36 100644 --- a/lib/ch_usi_si_seart_treesitter.h +++ b/lib/ch_usi_si_seart_treesitter.h @@ -299,6 +299,9 @@ TSLanguage* tree_sitter_erlang(); #ifdef TS_LANGUAGE_FORTRAN TSLanguage* tree_sitter_fortran(); #endif +#ifdef TS_LANGUAGE_GITATTRIBUTES +TSLanguage* tree_sitter_gitattributes(); +#endif #ifdef TS_LANGUAGE_GO TSLanguage* tree_sitter_go(); #endif diff --git a/lib/ch_usi_si_seart_treesitter_Language.cc b/lib/ch_usi_si_seart_treesitter_Language.cc index 7230844f..2516d815 100644 --- a/lib/ch_usi_si_seart_treesitter_Language.cc +++ b/lib/ch_usi_si_seart_treesitter_Language.cc @@ -148,6 +148,15 @@ JNIEXPORT jlong JNICALL Java_ch_usi_si_seart_treesitter_Language_fortran( #endif } +JNIEXPORT jlong JNICALL Java_ch_usi_si_seart_treesitter_Language_gitattributes( + JNIEnv* env, jclass self) { +#ifdef TS_LANGUAGE_GITATTRIBUTES + return (jlong)tree_sitter_gitattributes(); +#else + return (jlong)ch_usi_si_seart_treesitter_Language_INVALID; +#endif +} + JNIEXPORT jlong JNICALL Java_ch_usi_si_seart_treesitter_Language_go( JNIEnv* env, jclass self) { #ifdef TS_LANGUAGE_GO diff --git a/lib/ch_usi_si_seart_treesitter_Language.h b/lib/ch_usi_si_seart_treesitter_Language.h index c0ee8bb2..f8afab01 100644 --- a/lib/ch_usi_si_seart_treesitter_Language.h +++ b/lib/ch_usi_si_seart_treesitter_Language.h @@ -137,6 +137,14 @@ JNIEXPORT jlong JNICALL Java_ch_usi_si_seart_treesitter_Language_erlang JNIEXPORT jlong JNICALL Java_ch_usi_si_seart_treesitter_Language_fortran (JNIEnv *, jclass); +/* + * Class: ch_usi_si_seart_treesitter_Language + * Method: gitattributes + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_ch_usi_si_seart_treesitter_Language_gitattributes + (JNIEnv *, jclass); + /* * Class: ch_usi_si_seart_treesitter_Language * Method: go diff --git a/src/main/java/ch/usi/si/seart/treesitter/Language.java b/src/main/java/ch/usi/si/seart/treesitter/Language.java index c28fc955..4ea1c294 100644 --- a/src/main/java/ch/usi/si/seart/treesitter/Language.java +++ b/src/main/java/ch/usi/si/seart/treesitter/Language.java @@ -157,6 +157,13 @@ public enum Language { */ FORTRAN(fortran(), "f", "F90", "f77", "f90", "f95"), + /** + * Configurations used for associating attributes with file and path patterns in a repository. + * + * @see tree-sitter-gitattributes + */ + GITATTRIBUTES(gitattributes(), "gitattributes"), + /** * Go programming language. * @@ -390,6 +397,7 @@ public enum Language { private static native long embeddedTemplate(); private static native long erlang(); private static native long fortran(); + private static native long gitattributes(); private static native long go(); private static native long graphQl(); private static native long haskell(); @@ -535,6 +543,11 @@ public String toString() { case TSX: case YAML: return name(); + /* + * Lowercase + */ + case GITATTRIBUTES: + return name().toLowerCase(); /* * Capital Case */ From 2fd0bd2564a49d53dbef14e977d47efd1f5a16cf Mon Sep 17 00:00:00 2001 From: dabico Date: Fri, 1 Dec 2023 16:08:59 +0100 Subject: [PATCH 3/3] Adding additional test case for `Language#associatedWith` --- src/test/java/ch/usi/si/seart/treesitter/LanguageTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/ch/usi/si/seart/treesitter/LanguageTest.java b/src/test/java/ch/usi/si/seart/treesitter/LanguageTest.java index 7b0f0b6c..8eb719fd 100644 --- a/src/test/java/ch/usi/si/seart/treesitter/LanguageTest.java +++ b/src/test/java/ch/usi/si/seart/treesitter/LanguageTest.java @@ -60,6 +60,7 @@ public Stream provideArguments(ExtensionContext extensionCo return Stream.of( Arguments.of("requirements.txt", List.of()), Arguments.of(".py", List.of(Language.PYTHON)), + Arguments.of(".gitattributes", List.of(Language.GITATTRIBUTES)), Arguments.of("__init__.py", List.of(Language.PYTHON)), Arguments.of("Main.java", List.of(Language.JAVA)), Arguments.of("example.h", List.of(