Skip to content

Commit

Permalink
feat: bump stack-graphs forked version & update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nohehf committed May 27, 2024
1 parent 28739d9 commit 2959c58
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 40 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

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

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stack-graphs-python-bindings"
version = "0.0.11"
version = "0.0.12"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -10,13 +10,13 @@ crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.20.0"
stack-graphs = { git = "https://github.com/nohehf/stack-graphs.git", rev = "9551ad995c79277d950ac2e0d5d9a2d5e42631e2", features = [
stack-graphs = { git = "https://github.com/nohehf/stack-graphs.git", rev = "41c9515b4f25b70e1e39526cd4c30c41988337c1", features = [
"storage",
] }
tree-sitter-stack-graphs = { git = "https://github.com/nohehf/stack-graphs.git", rev = "9551ad995c79277d950ac2e0d5d9a2d5e42631e2", features = [
tree-sitter-stack-graphs = { git = "https://github.com/nohehf/stack-graphs.git", rev = "41c9515b4f25b70e1e39526cd4c30c41988337c1", features = [
"cli",
] }
tree-sitter-stack-graphs-java = { git = "https://github.com/nohehf/stack-graphs.git", rev = "9551ad995c79277d950ac2e0d5d9a2d5e42631e2" }
tree-sitter-stack-graphs-javascript = { git = "https://github.com/nohehf/stack-graphs.git", rev = "9551ad995c79277d950ac2e0d5d9a2d5e42631e2" }
tree-sitter-stack-graphs-python = { git = "https://github.com/nohehf/stack-graphs.git", rev = "9551ad995c79277d950ac2e0d5d9a2d5e42631e2" }
tree-sitter-stack-graphs-typescript = { git = "https://github.com/nohehf/stack-graphs.git", rev = "9551ad995c79277d950ac2e0d5d9a2d5e42631e2" }
tree-sitter-stack-graphs-java = { git = "https://github.com/nohehf/stack-graphs.git", rev = "41c9515b4f25b70e1e39526cd4c30c41988337c1" }
tree-sitter-stack-graphs-javascript = { git = "https://github.com/nohehf/stack-graphs.git", rev = "41c9515b4f25b70e1e39526cd4c30c41988337c1" }
tree-sitter-stack-graphs-python = { git = "https://github.com/nohehf/stack-graphs.git", rev = "41c9515b4f25b70e1e39526cd4c30c41988337c1" }
tree-sitter-stack-graphs-typescript = { git = "https://github.com/nohehf/stack-graphs.git", rev = "41c9515b4f25b70e1e39526cd4c30c41988337c1" }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const foo = "bar"
## Known stack-graphs / tree-sitter issues

- Python: module resolution / imports seems to be broken: <https://github.com/github/stack-graphs/issues/430>
- Typescript: module resolution doesn't work with file extensions (eg. `import { foo } from "./module"` is ok, but `import { foo } from "./module.ts"` is not). **An issue should be opened on the stack-graphs repo**. See: `tests/ts_ok_test.py`
- Typescript: module resolution doesn't work with file extensions (eg. `import { foo } from "./module"` is ok, but `import { foo } from "./module.ts"` is not). **PR opened, fixed on the fork**. See: `tests/ts_ok_test.py`
- Typescript: tree-sitter-typescript fails when passing a generic type to a decorator: <https://github.com/tree-sitter/tree-sitter-typescript/issues/283>

## Development
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
version = "0.0.11"
version = "0.0.12"
[tool.maturin]
features = ["pyo3/extension-module"]
29 changes: 6 additions & 23 deletions tests/ts_ok_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"""

# Stack graphs will fail on this: TODO(@nohehf): Open issue
code2 = """
;---index.ts---
import { foo } from "./module.js";
Expand All @@ -31,7 +30,6 @@
"""

# Stack graphs will fail on this: TODO(@nohehf): Open issue
code3 = """
;---index.ts---
import { foo } from "./module.ts";
Expand All @@ -40,30 +38,15 @@
^{query}
console.log(baz);
;---module.js---
;---module.ts---
export const foo: string = "42";
^{ref2}
"""


def test_ts_ok() -> None:
with string_to_virtual_files(code1) as (dir, positions):
db_path = os.path.join(dir, "db.sqlite")
dir = os.path.abspath(dir)
indexer = Indexer(db_path, [Language.TypeScript])
indexer.index_all([dir])
querier = Querier(db_path)
source_reference = positions["query"]
results = querier.definitions(source_reference)
assert len(results) == 2
expected = [positions["ref1"], positions["ref2"]]
for i, result in enumerate(results):
assert result == expected[i]


def test_ts_fails_should_be_ok() -> None:
for code in [code2, code3]:
for code in [code1, code2, code3]:
with string_to_virtual_files(code) as (dir, positions):
db_path = os.path.join(dir, "db.sqlite")
dir = os.path.abspath(dir)
Expand All @@ -72,7 +55,7 @@ def test_ts_fails_should_be_ok() -> None:
querier = Querier(db_path)
source_reference = positions["query"]
results = querier.definitions(source_reference)
assert (
len(results) == 1
) # It should be 2, and find the ref2, but the module resolution doesn't work with file extensions
assert results[0] == positions["ref1"]
assert len(results) == 2
expected = [positions["ref1"], positions["ref2"]]
for i, result in enumerate(results):
assert result == expected[i]

0 comments on commit 2959c58

Please sign in to comment.