Skip to content

Commit dc24a30

Browse files
committed
feat: add language enum
1 parent c7ff411 commit dc24a30

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

.github/workflows/CI.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- uses: actions/checkout@v4
3636
- uses: actions/setup-python@v5
3737
with:
38-
python-version: '3.10'
38+
python-version: '3.11'
3939
- name: Build wheels
4040
uses: PyO3/maturin-action@v1
4141
with:
@@ -62,7 +62,7 @@ jobs:
6262
- uses: actions/checkout@v4
6363
- uses: actions/setup-python@v5
6464
with:
65-
python-version: '3.10'
65+
python-version: '3.11'
6666
architecture: ${{ matrix.platform.target }}
6767
- name: Build wheels
6868
uses: PyO3/maturin-action@v1
@@ -89,7 +89,7 @@ jobs:
8989
- uses: actions/checkout@v4
9090
- uses: actions/setup-python@v5
9191
with:
92-
python-version: '3.10'
92+
python-version: '3.11'
9393
- name: Build wheels
9494
uses: PyO3/maturin-action@v1
9595
with:

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.PHONY: develop
2+
develop:
3+
maturin develop
4+
5+
6+
test: develop
7+
## TODO: Add actual tests with pytest
8+
python tests/test.py

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "maturin"
44

55
[project]
66
name = "stack-graphs-python-bindings"
7-
requires-python = ">=3.8"
7+
requires-python = ">=3.11"
88
classifiers = [
99
"Programming Language :: Rust",
1010
"Programming Language :: Python :: Implementation :: CPython",

src/classes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fmt::Display;
22

33
use pyo3::prelude::*;
4+
45
use tree_sitter_stack_graphs::cli::util::{SourcePosition, SourceSpan};
56

67
#[pyclass]

stack_graphs_python.pyi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
def index(paths: list[str], db_path: str) -> None: ...
1+
from enum import Enum
2+
3+
class Language(Enum):
4+
Python = 0
5+
JavaScript = 1
6+
TypeScript = 2
7+
Java = 3
28

39
class Position:
410
path: str
@@ -7,4 +13,5 @@ class Position:
713

814
def __init__(self, path: str, line: int, column: int) -> None: ...
915

16+
def index(paths: list[str], db_path: str, language: Language) -> None: ...
1017
def query_definition(reference: Position, db_path: str) -> list[Position]: ...

tests/test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from stack_graphs_python import index, query_definition, Position
2+
from stack_graphs_python import index, query_definition, Position, Language
33

44
# index ./js_sample directory
55

@@ -10,7 +10,7 @@
1010
print("Indexing directory: ", dir)
1111
print("Database path: ", db)
1212

13-
index([dir], db)
13+
index([dir], db, language=Language.Python)
1414

1515
source_reference: Position = Position(path=dir + "/index.js", line=2, column=12)
1616

@@ -25,3 +25,8 @@
2525
print("Line: ", result.line)
2626
print("Column: ", result.column)
2727
print("\n")
28+
29+
assert len(results) == 2
30+
assert results[0].path.endswith("index.js")
31+
assert results[0].line == 0
32+
assert results[0].column == 9

0 commit comments

Comments
 (0)