Skip to content

Commit

Permalink
feat: avante repo map rust crate (yetone#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone authored Sep 25, 2024
1 parent 5461342 commit 0d90c04
Show file tree
Hide file tree
Showing 23 changed files with 1,399 additions and 737 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ jobs:
uses: lunarmodules/luacheck@v1
with:
args: ./lua/
rust-tests:
name: Run Rust tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: clippy, rustfmt
- name: Run rust tests
run: cargo test --features luajit
rust:
name: Check Rust style
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
fi
cp target/release/libavante_templates.$EXT results/avante_templates.$EXT
cp target/release/libavante_tokenizers.$EXT results/avante_tokenizers.$EXT
cp target/release/libavante_repo_map.$EXT results/avante_repo_map.$EXT
cd results
tar zcvf avante_lib-${{ matrix.os }}-${{ matrix.feature }}.tar.gz *.${EXT}
Expand All @@ -85,6 +86,7 @@ jobs:
Copy-Item -Path "target\release\avante_templates.dll" -Destination "results\avante_templates.dll"
Copy-Item -Path "target\release\avante_tokenizers.dll" -Destination "results\avante_tokenizers.dll"
Copy-Item -Path "target\release\avante_repo_map.dll" -Destination "results\avante_repo_map.dll"
Set-Location -Path results
Expand Down
133 changes: 131 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ version = "0.1.0"
[workspace.dependencies]
avante-tokenizers = { path = "crates/avante-tokenizers" }
avante-templates = { path = "crates/avante-templates" }
avante-repo-map = { path = "crates/avante-repo-map" }
minijinja = { version = "2.2.0", features = [
"loader",
"json",
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ all: luajit
define make_definitions
ifeq ($(BUILD_FROM_SOURCE),true)
ifeq ($(TARGET_LIBRARY), all)
$1: $(BUILD_DIR)/libAvanteTokenizers-$1.$(EXT) $(BUILD_DIR)/libAvanteTemplates-$1.$(EXT)
$1: $(BUILD_DIR)/libAvanteTokenizers-$1.$(EXT) $(BUILD_DIR)/libAvanteTemplates-$1.$(EXT) $(BUILD_DIR)/libAvanteRepoMap-$1.$(EXT)
else ifeq ($(TARGET_LIBRARY), tokenizers)
$1: $(BUILD_DIR)/libAvanteTokenizers-$1.$(EXT)
else ifeq ($(TARGET_LIBRARY), templates)
$1: $(BUILD_DIR)/libAvanteTemplates-$1.$(EXT)
else ifeq ($(TARGET_LIBRARY), repo-map)
$1: $(BUILD_DIR)/libAvanteRepoMap-$1.$(EXT)
else
$$(error TARGET_LIBRARY must be one of all, tokenizers, templates)
$$(error TARGET_LIBRARY must be one of all, tokenizers, templates, repo-map)
endif
else
$1:
Expand All @@ -41,16 +43,18 @@ $(foreach lua_version,$(LUA_VERSIONS),$(eval $(call make_definitions,$(lua_versi
define build_package
$1-$2:
cargo build --release --features=$1 -p avante-$2
cp target/release/libavante_$2.$(EXT) $(BUILD_DIR)/avante_$2.$(EXT)
cp target/release/libavante_$(shell echo $2 | tr - _).$(EXT) $(BUILD_DIR)/avante_$(shell echo $2 | tr - _).$(EXT)
endef

define build_targets
$(BUILD_DIR)/libAvanteTokenizers-$1.$(EXT): $(BUILD_DIR) $1-tokenizers
$(BUILD_DIR)/libAvanteTemplates-$1.$(EXT): $(BUILD_DIR) $1-templates
$(BUILD_DIR)/libAvanteRepoMap-$1.$(EXT): $(BUILD_DIR) $1-repo-map
endef

$(foreach lua_version,$(LUA_VERSIONS),$(eval $(call build_package,$(lua_version),tokenizers)))
$(foreach lua_version,$(LUA_VERSIONS),$(eval $(call build_package,$(lua_version),templates)))
$(foreach lua_version,$(LUA_VERSIONS),$(eval $(call build_package,$(lua_version),repo-map)))
$(foreach lua_version,$(LUA_VERSIONS),$(eval $(call build_targets,$(lua_version))))

$(BUILD_DIR):
Expand Down
38 changes: 38 additions & 0 deletions crates/avante-repo-map/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[lib]
crate-type = ["cdylib"]

[package]
name = "avante-repo-map"
edition.workspace = true
rust-version.workspace = true
license.workspace = true
version.workspace = true

[build-dependencies]
cc="*"

[dependencies]
mlua = { workspace = true }
minijinja = { workspace = true }
serde = { workspace = true, features = ["derive"] }
tree-sitter = "0.23"
tree-sitter-language = "0.1"
tree-sitter-rust = "0.23"
tree-sitter-python = "0.23"
tree-sitter-javascript = "0.23"
tree-sitter-typescript = "0.23"
tree-sitter-go = "0.23"
tree-sitter-c = "0.23"
tree-sitter-cpp = "0.23"
tree-sitter-lua = "0.2"
tree-sitter-ruby = "0.23"

[lints]
workspace = true

[features]
lua51 = ["mlua/lua51"]
lua52 = ["mlua/lua52"]
lua53 = ["mlua/lua53"]
lua54 = ["mlua/lua54"]
luajit = ["mlua/luajit"]
11 changes: 11 additions & 0 deletions crates/avante-repo-map/queries/tree-sitter-c-defs.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;; Capture extern functions, variables, public classes, and methods
(function_definition
(storage_class_specifier) @extern
) @function
(class_specifier
(public) @class
(function_definition) @method
) @class
(declaration
(storage_class_specifier) @extern
) @variable
11 changes: 11 additions & 0 deletions crates/avante-repo-map/queries/tree-sitter-cpp-defs.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;; Capture extern functions, variables, public classes, and methods
(function_definition
(storage_class_specifier) @extern
) @function
(class_specifier
(public) @class
(function_definition) @method
) @class
(declaration
(storage_class_specifier) @extern
) @variable
18 changes: 18 additions & 0 deletions crates/avante-repo-map/queries/tree-sitter-go-defs.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
;; Capture top-level functions and struct definitions
(var_declaration
(var_spec) @variable
)
(const_declaration
(const_spec) @variable
)
(function_declaration) @function
(type_declaration
(type_spec (struct_type)) @class
)
(type_declaration
(type_spec
(struct_type
(field_declaration_list
(field_declaration) @class_variable)))
)
(method_declaration) @method
23 changes: 23 additions & 0 deletions crates/avante-repo-map/queries/tree-sitter-javascript-defs.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
;; Capture exported functions, arrow functions, variables, classes, and method definitions
(export_statement
declaration: (lexical_declaration
(variable_declarator) @variable
)
)
(export_statement
declaration: (function_declaration) @function
)
(export_statement
declaration: (class_declaration
body: (class_body
(field_definition) @class_variable
)
)
)
(export_statement
declaration: (class_declaration
body: (class_body
(method_definition) @method
)
)
)
3 changes: 3 additions & 0 deletions crates/avante-repo-map/queries/tree-sitter-lua-defs.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
;; Capture function and method definitions
(variable_list) @variable
(function_declaration) @function
25 changes: 25 additions & 0 deletions crates/avante-repo-map/queries/tree-sitter-python-defs.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
;; Capture top-level functions, class, and method definitions
(module
(expression_statement
(assignment) @assignment
)
)
(module
(function_definition) @function
)
(module
(class_definition
body: (block
(expression_statement
(assignment) @class_assignment
)
)
)
)
(module
(class_definition
body: (block
(function_definition) @method
)
)
)
16 changes: 16 additions & 0 deletions crates/avante-repo-map/queries/tree-sitter-ruby-defs.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;; Capture top-level methods, class definitions, and methods within classes
(program
(class
(body_statement
(call) @class_call
(assignment) @class_assignment
(method) @method
)
) @class
)
(program
(method) @function
)
(program
(assignment) @assignment
)
Loading

0 comments on commit 0d90c04

Please sign in to comment.