Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Afroozeh/add fields for navigation suffix #149

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,37 @@ on:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up tree-sitter
uses: tree-sitter/setup-action/cli@v1
- name: Generate parser
run: npm run generate
run: tree-sitter generate
- name: Verify that generated parser matches the repository
run: |
diff=`git diff HEAD -- src`
echo "$diff"
test -z "$diff"
- name: Output parser size
run: du -sh src/* | sort -h
- name: Run tests
run: npm test
run: tree-sitter test --show-fields
- name: Set up examples
run: |-
git clone https://github.com/square/okhttp.git examples/okhttp --single-branch --depth=1 --filter=blob:none
git clone https://github.com/ktorio/ktor.git examples/ktor --single-branch --depth=1 --filter=blob:none
git clone https://github.com/square/leakcanary.git examples/leakcanary --single-branch --depth=1 --filter=blob:none
git clone https://github.com/JetBrains/compose-multiplatform.git examples/compose-multiplatform --single-branch --depth=1 --filter=blob:none
git clone https://github.com/Kotlin/kotlinx.coroutines.git examples/kotlinx.coroutines --single-branch --depth=1 --filter=blob:none
- name: Parse examples
id: examples
continue-on-error: true
uses: tree-sitter/parse-action@v4
with:
files: examples/**/*.kt
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Build and test crate
Expand Down
34 changes: 26 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ license = "MIT"
readme = "bindings/rust/README.md"

build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"grammar.js",
"queries/*",
"src/*",
]
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]

[lib]
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = ">= 0.21, < 0.23"
tree-sitter-language = "0.1.0"

[dev-dependencies]
tree-sitter = "0.23.0"

[build-dependencies]
cc = "1.0"
4 changes: 2 additions & 2 deletions bindings/go/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package tree_sitter_kotlin_test
import (
"testing"

tree_sitter "github.com/smacker/go-tree-sitter"
"github.com/tree-sitter/tree-sitter-kotlin"
tree_sitter "github.com/tree-sitter/go-tree-sitter"
tree_sitter_kotlin "github.com/tree-sitter/tree-sitter-kotlin/bindings/go"
)

func TestCanLoadGrammar(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions bindings/go/go.mod

This file was deleted.

9 changes: 9 additions & 0 deletions bindings/node/binding_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="node" />

const assert = require("node:assert");
const { test } = require("node:test");

test("can load grammar", () => {
const parser = new (require("tree-sitter"))();
assert.doesNotThrow(() => parser.setLanguage(require(".")));
});
11 changes: 11 additions & 0 deletions bindings/python/tests/test_binding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from unittest import TestCase

import tree_sitter, tree_sitter_kotlin


class TestLanguage(TestCase):
def test_can_load_grammar(self):
try:
tree_sitter.Language(tree_sitter_kotlin.language())
except Exception:
self.fail("Error loading Kotlin grammar")
4 changes: 2 additions & 2 deletions bindings/python/tree_sitter_kotlin/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ typedef struct TSLanguage TSLanguage;

TSLanguage *tree_sitter_kotlin(void);

static PyObject* _binding_language(PyObject *self, PyObject *args) {
return PyLong_FromVoidPtr(tree_sitter_kotlin());
static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) {
return PyCapsule_New(tree_sitter_kotlin(), "tree_sitter.Language", NULL);
}

static PyMethodDef methods[] = {
Expand Down
39 changes: 20 additions & 19 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
//! This crate provides kotlin language support for the [tree-sitter][] parsing library.
//! This crate provides Kotlin language support for the [tree-sitter][] parsing library.
//!
//! Typically, you will use the [language][language func] function to add this language to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//!
//! ```
//! let code = "";
//! let code = r#"
//! "#;
//! let mut parser = tree_sitter::Parser::new();
//! parser.set_language(&tree_sitter_kotlin::language()).expect("Error loading kotlin grammar");
//! let language = tree_sitter_kotlin::LANGUAGE;
//! parser
//! .set_language(&language.into())
//! .expect("Error loading Kotlin parser");
//! let tree = parser.parse(code, None).unwrap();
//! assert!(!tree.root_node().has_error());
//! ```
//!
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
//! [language func]: fn.language.html
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
//! [tree-sitter]: https://tree-sitter.github.io/

use tree_sitter::Language;
use tree_sitter_language::LanguageFn;

extern "C" {
fn tree_sitter_kotlin() -> Language;
fn tree_sitter_kotlin() -> *const ();
}

/// Get the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language() -> Language {
unsafe { tree_sitter_kotlin() }
}
/// The tree-sitter [`LanguageFn`] for this grammar.
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_kotlin) };

/// The content of the [`node-types.json`][] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");

// Uncomment these to include any queries that this grammar contains
// NOTE: uncomment these to include any queries that this grammar contains:

pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
// pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");

#[cfg(test)]
mod tests {
#[test]
fn test_can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(&super::language())
.expect("Error loading kotlin language");
.set_language(&super::LANGUAGE.into())
.expect("Error loading Kotlin parser");
}
}
12 changes: 12 additions & 0 deletions bindings/swift/TreeSitterKotlinTests/TreeSitterKotlinTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import XCTest
import SwiftTreeSitter
import TreeSitterKotlin

final class TreeSitterKotlinTests: XCTestCase {
func testCanLoadGrammar() throws {
let parser = Parser()
let language = Language(language: tree_sitter_kotlin())
XCTAssertNoThrow(try parser.setLanguage(language),
"Error loading Kotlin grammar")
}
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/tree-sitter/tree-sitter-kotlin

go 1.23

require github.com/tree-sitter/go-tree-sitter v0.23
Loading