Add missing language return in ts_query_new
Co-authored-by: Antonio <antonio@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev>
This commit is contained in:
parent
31c4044974
commit
3c66dd2d6c
2 changed files with 23 additions and 3 deletions
|
|
@ -1,7 +1,9 @@
|
|||
use crate::tests::helpers::{allocations, fixtures::WASM_DIR};
|
||||
use lazy_static::lazy_static;
|
||||
use std::fs;
|
||||
use tree_sitter::{wasmtime::Engine, Parser, WasmError, WasmErrorKind, WasmStore};
|
||||
use tree_sitter::{
|
||||
wasmtime::Engine, Parser, Query, QueryCursor, WasmError, WasmErrorKind, WasmStore,
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
static ref ENGINE: Engine = Engine::default();
|
||||
|
|
@ -29,9 +31,14 @@ fn test_load_wasm_language() {
|
|||
parser2
|
||||
.set_wasm_store(WasmStore::new(ENGINE.clone()).unwrap())
|
||||
.unwrap();
|
||||
let mut query_cursor = QueryCursor::new();
|
||||
|
||||
for mut parser in [parser, parser2] {
|
||||
for _ in 0..2 {
|
||||
let query_rust = Query::new(&language_rust, "(const_item) @foo").unwrap();
|
||||
let query_typescript =
|
||||
Query::new(&language_typescript, "(class_declaration) @foo").unwrap();
|
||||
|
||||
parser.set_language(&language_cpp).unwrap();
|
||||
let tree = parser.parse("A<B> c = d();", None).unwrap();
|
||||
assert_eq!(
|
||||
|
|
@ -40,11 +47,18 @@ fn test_load_wasm_language() {
|
|||
);
|
||||
|
||||
parser.set_language(&language_rust).unwrap();
|
||||
let tree = parser.parse("const A: B = c();", None).unwrap();
|
||||
let source = "const A: B = c();";
|
||||
let tree = parser.parse(source, None).unwrap();
|
||||
assert_eq!(
|
||||
tree.root_node().to_sexp(),
|
||||
"(source_file (const_item name: (identifier) type: (type_identifier) value: (call_expression function: (identifier) arguments: (arguments))))"
|
||||
);
|
||||
assert_eq!(
|
||||
query_cursor
|
||||
.matches(&query_rust, tree.root_node(), source.as_bytes())
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
|
||||
parser.set_language(&language_ruby).unwrap();
|
||||
let tree = parser.parse("class A; end", None).unwrap();
|
||||
|
|
@ -59,6 +73,12 @@ fn test_load_wasm_language() {
|
|||
tree.root_node().to_sexp(),
|
||||
"(program (class_declaration name: (type_identifier) body: (class_body)))"
|
||||
);
|
||||
assert_eq!(
|
||||
query_cursor
|
||||
.matches(&query_typescript, tree.root_node(), source.as_bytes())
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2698,7 +2698,7 @@ TSQuery *ts_query_new(
|
|||
.negated_fields = array_new(),
|
||||
.repeat_symbols_with_rootless_patterns = array_new(),
|
||||
.wildcard_root_pattern_count = 0,
|
||||
.language = language,
|
||||
.language = ts_language_copy(language),
|
||||
};
|
||||
|
||||
array_push(&self->negated_fields, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue