Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit c43fa8b

Browse files
committed
feat: use replace instead of custom function
1 parent d0b940e commit c43fa8b

File tree

2 files changed

+1
-38
lines changed

2 files changed

+1
-38
lines changed

languages/tree-sitter-stack-graphs-typescript/src/stack-graphs.tsg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ attribute node_symbol = node => symbol = (source-text node), source_n
541541
; module reference
542542
var mod_scope = mod_ref__ns
543543
; normalize path and remove the extension as we want to match 'foo', 'foo.js', 'foo.ts', etc.
544-
scan (path-remove-ext (path-normalize mod_path)) {
544+
scan (path-normalize (replace mod_path "\.(js|ts|jsx|tsx)$" "")) {
545545
"([^/]+)/?" {
546546
node mod_ref
547547
attr (mod_ref) push_symbol = $1

tree-sitter-stack-graphs/src/functions.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ pub mod path {
4343
path_fn(|p| normalize(p).map(|p| p.as_os_str().to_os_string())),
4444
);
4545
functions.add("path-split".into(), PathSplit);
46-
functions.add(
47-
"path-remove-ext".into(),
48-
path_fn(|p| remove_extension(p).map(|p| p.as_os_str().to_os_string())),
49-
);
5046
}
5147

5248
pub fn path_fn<F>(f: F) -> impl Function
@@ -163,37 +159,4 @@ pub mod path {
163159
}
164160
Some(ret)
165161
}
166-
167-
/// Removes the extension from a path.
168-
/// eg. `foo/bar.rs` -> `foo/bar`
169-
/// eg. `foo/bar` -> `foo/bar`
170-
/// eg. `foo/bar.rs.bak` -> `foo/bar.rs`
171-
pub fn remove_extension(path: &Path) -> Option<PathBuf> {
172-
path.extension()
173-
.map_or(Some(path.into()), |_| path.with_extension("").into())
174-
}
175-
176-
#[test]
177-
fn test_remove_extension() {
178-
assert_eq!(
179-
remove_extension(Path::new("foo/bar.rs")),
180-
Some(PathBuf::from("foo/bar"))
181-
);
182-
assert_eq!(
183-
remove_extension(Path::new("foo/bar")),
184-
Some(PathBuf::from("foo/bar"))
185-
);
186-
assert_eq!(
187-
remove_extension(Path::new("foo/bar.rs.bak")),
188-
Some(PathBuf::from("foo/bar.rs"))
189-
);
190-
assert_eq!(
191-
remove_extension(Path::new("foo")),
192-
Some(PathBuf::from("foo"))
193-
);
194-
assert_eq!(
195-
remove_extension(Path::new("foo.rs")),
196-
Some(PathBuf::from("foo"))
197-
);
198-
}
199162
}

0 commit comments

Comments
 (0)