From c86096a886701c96c6dd09fca36c0281bc140111 Mon Sep 17 00:00:00 2001 From: KCaverly Date: Tue, 25 Jul 2023 10:38:37 -0400 Subject: [PATCH] update semantic index tests for javascript --- .../src/semantic_index_tests.rs | 208 +++++++++++------- .../src/languages/javascript/embedding.scm | 96 ++++---- crates/zed/src/languages/tsx/embedding.scm | 118 +++++----- .../src/languages/typescript/embedding.scm | 126 +++++------ 4 files changed, 278 insertions(+), 270 deletions(-) diff --git a/crates/semantic_index/src/semantic_index_tests.rs b/crates/semantic_index/src/semantic_index_tests.rs index 432f6b5b53..9bd6efc954 100644 --- a/crates/semantic_index/src/semantic_index_tests.rs +++ b/crates/semantic_index/src/semantic_index_tests.rs @@ -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 { ( (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 { "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(), diff --git a/crates/zed/src/languages/javascript/embedding.scm b/crates/zed/src/languages/javascript/embedding.scm index a214040031..ab1a3b6b06 100644 --- a/crates/zed/src/languages/javascript/embedding.scm +++ b/crates/zed/src/languages/javascript/embedding.scm @@ -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 - ) +) diff --git a/crates/zed/src/languages/tsx/embedding.scm b/crates/zed/src/languages/tsx/embedding.scm index 4bb4fea254..ddcff66584 100644 --- a/crates/zed/src/languages/tsx/embedding.scm +++ b/crates/zed/src/languages/tsx/embedding.scm @@ -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) diff --git a/crates/zed/src/languages/typescript/embedding.scm b/crates/zed/src/languages/typescript/embedding.scm index 4bb4fea254..3170cb7c95 100644 --- a/crates/zed/src/languages/typescript/embedding.scm +++ b/crates/zed/src/languages/typescript/embedding.scm @@ -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) +)