update semantic index tests for javascript

This commit is contained in:
KCaverly 2023-07-25 10:38:37 -04:00
parent 81b05f2a08
commit c86096a886
4 changed files with 278 additions and 270 deletions

View file

@ -388,43 +388,103 @@ fn assert_documents_eq(
);
}
// #[gpui::test]
// async fn test_code_context_retrieval_javascript() {
// let language = js_lang();
// let mut retriever = CodeContextRetriever::new();
#[gpui::test]
async fn test_code_context_retrieval_javascript() {
let language = js_lang();
let mut retriever = CodeContextRetriever::new();
// let text = "
// /* globals importScripts, backend */
// function _authorize() {}
let text = "
/* globals importScripts, backend */
function _authorize() {}
// /**
// * Sometimes the frontend build is way faster than backend.
// */
// export async function authorizeBank() {
// _authorize(pushModal, upgradingAccountId, {});
// }
/**
* Sometimes the frontend build is way faster than backend.
*/
export async function authorizeBank() {
_authorize(pushModal, upgradingAccountId, {});
}
// export class SettingsPage {
// /* This is a test setting */
// constructor(page) {
// this.page = page;
// }
// }
export class SettingsPage {
/* This is a test setting */
constructor(page) {
this.page = page;
}
}
// /* This is a test comment */
// class TestClass {}
/* This is a test comment */
class TestClass {}
// /* Schema for editor_events in Clickhouse. */
// export interface ClickhouseEditorEvent {
// installation_id: string
// operation: string
// }
// "
// .unindent();
/* Schema for editor_events in Clickhouse. */
export interface ClickhouseEditorEvent {
installation_id: string
operation: string
}
"
.unindent();
// let parsed_files = retriever
// .parse_file(Path::new("foo.js"), &text, language)
// .unwrap();
let documents = retriever.parse_file(&text, language.clone()).unwrap();
assert_documents_eq(
&documents,
&[
(
"
/* globals importScripts, backend */
function _authorize() {}"
.unindent(),
37,
),
(
"
/**
* Sometimes the frontend build is way faster than backend.
*/
export async function authorizeBank() {
_authorize(pushModal, upgradingAccountId, {});
}"
.unindent(),
131,
),
(
"
export class SettingsPage {
/* This is a test setting */
constructor(page) {
this.page = page;
}
}"
.unindent(),
225,
),
(
"
/* This is a test setting */
constructor(page) {
this.page = page;
}"
.unindent(),
290,
),
(
"
/* This is a test comment */
class TestClass {}"
.unindent(),
374,
),
(
"
/* Schema for editor_events in Clickhouse. */
export interface ClickhouseEditorEvent {
installation_id: string
operation: string
}"
.unindent(),
440,
),
],
)
}
// let test_documents = &[
// Document {
@ -924,38 +984,60 @@ fn js_lang() -> Arc<Language> {
(
(comment)* @context
.
[
(export_statement
(function_declaration
"async"? @name
"function" @name
name: (_) @name)) @item
)
(
(comment)* @context
.
name: (_) @name))
(function_declaration
"async"? @name
"function" @name
name: (_) @name) @item
)
name: (_) @name)
] @item
)
(
(comment)* @context
.
[
(export_statement
(class_declaration
"class" @name
name: (_) @name)) @item
)
name: (_) @name))
(class_declaration
"class" @name
name: (_) @name)
] @item
)
(
(comment)* @context
.
(class_declaration
"class" @name
name: (_) @name) @item
)
[
(export_statement
(interface_declaration
"interface" @name
name: (_) @name))
(interface_declaration
"interface" @name
name: (_) @name)
] @item
)
(
(comment)* @context
.
[
(export_statement
(enum_declaration
"enum" @name
name: (_) @name))
(enum_declaration
"enum" @name
name: (_) @name)
] @item
)
(
(comment)* @context
@ -969,41 +1051,7 @@ fn js_lang() -> Arc<Language> {
"static"
]* @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
(interface_declaration
"interface" @name
name: (_) @name)) @item
)
(
(comment)* @context
.
(interface_declaration
"interface" @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
(enum_declaration
"enum" @name
name: (_) @name)) @item
)
(
(comment)* @context
.
(enum_declaration
"enum" @name
name: (_) @name) @item
)
)
"#
.unindent(),

View file

@ -1,38 +1,60 @@
(
(comment)* @context
.
(export_statement
[
(export_statement
(function_declaration
"async"? @name
"function" @name
name: (_) @name))
(function_declaration
"async"? @name
"function" @name
name: (_) @name)) @item
)
name: (_) @name)
] @item
)
(
(comment)* @context
.
(function_declaration
"async"? @name
"function" @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
[
(export_statement
(class_declaration
"class" @name
name: (_) @name))
(class_declaration
"class" @name
name: (_) @name)) @item
)
name: (_) @name)
] @item
)
(
(comment)* @context
.
(class_declaration
"class" @name
name: (_) @name) @item
)
[
(export_statement
(interface_declaration
"interface" @name
name: (_) @name))
(interface_declaration
"interface" @name
name: (_) @name)
] @item
)
(
(comment)* @context
.
[
(export_statement
(enum_declaration
"enum" @name
name: (_) @name))
(enum_declaration
"enum" @name
name: (_) @name)
] @item
)
(
(comment)* @context
@ -46,38 +68,4 @@
"static"
]* @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
(interface_declaration
"interface" @name
name: (_) @name)) @item
)
(
(comment)* @context
.
(interface_declaration
"interface" @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
(enum_declaration
"enum" @name
name: (_) @name)) @item
)
(
(comment)* @context
.
(enum_declaration
"enum" @name
name: (_) @name) @item
)
)

View file

@ -1,37 +1,73 @@
(
(comment)* @context
.
(export_statement
[
(export_statement
(function_declaration
"async"? @name
"function" @name
name: (_) @name))
(function_declaration
"async"? @name
"function" @name
name: (_) @name)) @item
name: (_) @name)
] @item
)
(
(comment)* @context
.
(function_declaration
"async"? @name
"function" @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
[
(export_statement
(class_declaration
"class" @name
name: (_) @name))
(class_declaration
"class" @name
name: (_) @name)) @item
name: (_) @name)
] @item
)
(
(comment)* @context
.
(class_declaration
"class" @name
name: (_) @name) @item
[
(export_statement
(interface_declaration
"interface" @name
name: (_) @name))
(interface_declaration
"interface" @name
name: (_) @name)
] @item
)
(
(comment)* @context
.
[
(export_statement
(enum_declaration
"enum" @name
name: (_) @name))
(enum_declaration
"enum" @name
name: (_) @name)
] @item
)
(
(comment)* @context
.
[
(export_statement
(type_alias_declaration
"type" @name
name: (_) @name))
(type_alias_declaration
"type" @name
name: (_) @name)
] @item
)
(
@ -47,53 +83,3 @@
]* @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
(interface_declaration
"interface" @name
name: (_) @name)) @item
)
(
(comment)* @context
.
(interface_declaration
"interface" @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
(enum_declaration
"enum" @name
name: (_) @name)) @item
)
(
(comment)* @context
.
(enum_declaration
"enum" @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
(type_alias_declaration
"type" @name
name: (_) @name)) @item
)
(
(comment)* @context
.
(type_alias_declaration
"type" @name
name: (_) @name) @item)

View file

@ -1,38 +1,74 @@
(
(comment)* @context
.
(export_statement
[
(export_statement
(function_declaration
"async"? @name
"function" @name
name: (_) @name))
(function_declaration
"async"? @name
"function" @name
name: (_) @name)) @item
)
name: (_) @name)
] @item
)
(
(comment)* @context
.
(function_declaration
"async"? @name
"function" @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
[
(export_statement
(class_declaration
"class" @name
name: (_) @name))
(class_declaration
"class" @name
name: (_) @name)) @item
)
name: (_) @name)
] @item
)
(
(comment)* @context
.
(class_declaration
"class" @name
name: (_) @name) @item
)
[
(export_statement
(interface_declaration
"interface" @name
name: (_) @name))
(interface_declaration
"interface" @name
name: (_) @name)
] @item
)
(
(comment)* @context
.
[
(export_statement
(enum_declaration
"enum" @name
name: (_) @name))
(enum_declaration
"enum" @name
name: (_) @name)
] @item
)
(
(comment)* @context
.
[
(export_statement
(type_alias_declaration
"type" @name
name: (_) @name))
(type_alias_declaration
"type" @name
name: (_) @name)
] @item
)
(
(comment)* @context
@ -46,54 +82,4 @@
"static"
]* @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
(interface_declaration
"interface" @name
name: (_) @name)) @item
)
(
(comment)* @context
.
(interface_declaration
"interface" @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
(enum_declaration
"enum" @name
name: (_) @name)) @item
)
(
(comment)* @context
.
(enum_declaration
"enum" @name
name: (_) @name) @item
)
(
(comment)* @context
.
(export_statement
(type_alias_declaration
"type" @name
name: (_) @name)) @item
)
(
(comment)* @context
.
(type_alias_declaration
"type" @name
name: (_) @name) @item)
)