Skip to content

Commit cc19690

Browse files
authored
Merge pull request #884 from phanen/ws-sym-match
feat: smartcase match workspace/symbol query
2 parents 9f3f60b + 90f3309 commit cc19690

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

crates/emmylua_ls/src/handlers/workspace_symbol/build_workspace_symbols.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ use emmylua_code_analysis::{DbIndex, LuaCompilation, LuaSemanticDeclId, LuaType}
22
use lsp_types::{OneOf, SymbolKind, SymbolTag, WorkspaceSymbol, WorkspaceSymbolResponse};
33
use tokio_util::sync::CancellationToken;
44

5+
/// if query contains uppercase, do case-sensitive match; otherwise, ignore case
6+
fn match_symbol(text: &str, query: &str) -> bool {
7+
if query.chars().any(|c| c.is_uppercase()) {
8+
text.contains(query)
9+
} else {
10+
text.to_lowercase().contains(&query.to_lowercase())
11+
}
12+
}
13+
514
pub fn build_workspace_symbols(
615
compilation: &LuaCompilation,
716
query: String,
@@ -32,7 +41,7 @@ fn add_global_variable_symbols(
3241
return None;
3342
}
3443

35-
if decl.get_name().contains(query) {
44+
if match_symbol(decl.get_name(), query) {
3645
let typ = db
3746
.get_type_index()
3847
.get_type_cache(&decl_id.into())
@@ -78,7 +87,7 @@ fn add_type_symbols(
7887
return None;
7988
}
8089

81-
if typ.get_full_name().contains(query) {
90+
if match_symbol(typ.get_full_name(), query) {
8291
let property_owner_id = LuaSemanticDeclId::TypeDecl(typ.get_id());
8392
let location = typ.get_locations().first()?;
8493
let document = db.get_vfs().get_document(&location.file_id)?;

0 commit comments

Comments
 (0)