Repository navigation
feat(search): support qualified symbol matching in workspace.rankNames and workspace.symbolQuery #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(search): support qualified symbol matching in workspace.rankNames and workspace.symbolQuery #255
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |||||||||||||||||||||||||||||||
| //! order retain contiguous and word-boundary matching. Search Everywhere additionally | ||||||||||||||||||||||||||||||||
| //! allows ordered fragments and arbitrary letter gaps for its workspace names. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| use super::name_matching::match_ranked_name as match_name; | ||||||||||||||||||||||||||||||||
| use super::name_matching::{match_ranked_name as match_name, split_qualified_symbol}; | ||||||||||||||||||||||||||||||||
| use crate::contracts::SearchNameRange; | ||||||||||||||||||||||||||||||||
| use lithe_core_rules::file_names::FileNameKey; | ||||||||||||||||||||||||||||||||
| use lithe_protocol::{CoreError, ErrorCode}; | ||||||||||||||||||||||||||||||||
|
|
@@ -32,6 +32,9 @@ struct RankNamesRequest { | |||||||||||||||||||||||||||||||
| /// Keeps the best N hits of each tier; the host shows tiers as separate sections. | ||||||||||||||||||||||||||||||||
| #[serde(default)] | ||||||||||||||||||||||||||||||||
| limit_per_tier: Option<usize>, | ||||||||||||||||||||||||||||||||
| /// Enables qualified symbol splitting (`Class.member`, `Class#member`, `ns::member`). | ||||||||||||||||||||||||||||||||
| #[serde(default)] | ||||||||||||||||||||||||||||||||
| qualified_symbols: bool, | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| #[derive(Deserialize)] | ||||||||||||||||||||||||||||||||
|
|
@@ -41,6 +44,9 @@ struct RankCandidate { | |||||||||||||||||||||||||||||||
| /// Full path; identifies the candidate in the context lists and is a weaker match target. | ||||||||||||||||||||||||||||||||
| #[serde(default)] | ||||||||||||||||||||||||||||||||
| path: Option<String>, | ||||||||||||||||||||||||||||||||
| /// Enclosing symbol or type name (such as LSP `containerName`) for qualified queries. | ||||||||||||||||||||||||||||||||
| #[serde(default)] | ||||||||||||||||||||||||||||||||
| container: Option<String>, | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /// Open and recently visited paths that break ties between equally good name matches. | ||||||||||||||||||||||||||||||||
|
|
@@ -143,6 +149,10 @@ pub fn rank_names_command(payload: Value) -> Result<Value, CoreError> { | |||||||||||||||||||||||||||||||
| .path | ||||||||||||||||||||||||||||||||
| .as_ref() | ||||||||||||||||||||||||||||||||
| .is_some_and(|path| path.len() > MAX_TEXT_BYTES) | ||||||||||||||||||||||||||||||||
| || candidate | ||||||||||||||||||||||||||||||||
| .container | ||||||||||||||||||||||||||||||||
| .as_ref() | ||||||||||||||||||||||||||||||||
| .is_some_and(|container| container.len() > MAX_TEXT_BYTES) | ||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||
| return Err(CoreError::new( | ||||||||||||||||||||||||||||||||
| ErrorCode::InvalidRequest, | ||||||||||||||||||||||||||||||||
|
|
@@ -155,6 +165,11 @@ pub fn rank_names_command(payload: Value) -> Result<Value, CoreError> { | |||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| let context = ContextIndex::new(&request.context); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| let qualified = request | ||||||||||||||||||||||||||||||||
| .qualified_symbols | ||||||||||||||||||||||||||||||||
| .then(|| split_qualified_symbol(query)) | ||||||||||||||||||||||||||||||||
| .flatten(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| struct Hit { | ||||||||||||||||||||||||||||||||
| ranked: RankedName, | ||||||||||||||||||||||||||||||||
| recent_rank: usize, | ||||||||||||||||||||||||||||||||
|
|
@@ -164,6 +179,18 @@ pub fn rank_names_command(payload: Value) -> Result<Value, CoreError> { | |||||||||||||||||||||||||||||||
| for (index, candidate) in request.candidates.iter().enumerate() { | ||||||||||||||||||||||||||||||||
| let (degree, ranges) = if let Some(hit) = match_name(query, &candidate.name) { | ||||||||||||||||||||||||||||||||
| (hit.degree, hit.ranges) | ||||||||||||||||||||||||||||||||
| } else if let Some((qualifier, member)) = qualified { | ||||||||||||||||||||||||||||||||
| if let Some(hit) = match_qualified(qualifier, member, candidate) { | ||||||||||||||||||||||||||||||||
| hit | ||||||||||||||||||||||||||||||||
| } else if let Some(hit) = candidate | ||||||||||||||||||||||||||||||||
| .path | ||||||||||||||||||||||||||||||||
| .as_deref() | ||||||||||||||||||||||||||||||||
| .and_then(|path| match_name(query, path)) | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| ((hit.degree / PATH_DEGREE_DIVISOR).max(1), Vec::new()) | ||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } else if let Some(hit) = candidate | ||||||||||||||||||||||||||||||||
| .path | ||||||||||||||||||||||||||||||||
| .as_deref() | ||||||||||||||||||||||||||||||||
|
|
@@ -209,3 +236,66 @@ pub fn rank_names_command(payload: Value) -> Result<Value, CoreError> { | |||||||||||||||||||||||||||||||
| .collect(); | ||||||||||||||||||||||||||||||||
| Ok(serde_json::json!({ "matches": matches })) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /// Matches a `(qualifier, member)` query against a candidate's name, container, and path. | ||||||||||||||||||||||||||||||||
| fn match_qualified( | ||||||||||||||||||||||||||||||||
| qualifier: &str, | ||||||||||||||||||||||||||||||||
| member: &str, | ||||||||||||||||||||||||||||||||
| candidate: &RankCandidate, | ||||||||||||||||||||||||||||||||
| ) -> Option<(i32, Vec<SearchNameRange>)> { | ||||||||||||||||||||||||||||||||
| let member_hit = match_name(member, &candidate.name)?; | ||||||||||||||||||||||||||||||||
| let container_bonus = candidate | ||||||||||||||||||||||||||||||||
| .container | ||||||||||||||||||||||||||||||||
| .as_deref() | ||||||||||||||||||||||||||||||||
| .filter(|container| !container.is_empty()) | ||||||||||||||||||||||||||||||||
| .and_then(|container| match_container(qualifier, container, candidate.path.as_deref())); | ||||||||||||||||||||||||||||||||
| if let Some(bonus) = container_bonus { | ||||||||||||||||||||||||||||||||
| return Some((member_hit.degree + bonus, member_hit.ranges)); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| let path = candidate.path.as_deref()?; | ||||||||||||||||||||||||||||||||
| let normalized = qualifier.replace("::", "/").replace('.', "/"); | ||||||||||||||||||||||||||||||||
| let path_hit = match_name(&normalized, path).or_else(|| match_name(qualifier, path))?; | ||||||||||||||||||||||||||||||||
|
Comment on lines
+255
to
+257
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Missing qualified symbols on Windows
Learn moreThe rankNames contract accepts full candidate paths and lets them supply a symbol's qualifier. The text matcher only compares characters case-insensitively; it does not equate the two slash characters (match_fragments). With an LSP container that only identifies the class, the package check needs to match the package prefix against the path. Both that check and the full qualifier fallback compare a forward-slash pattern against the original path. Example: Query Recommended fix: Use Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||||||||||||||||
| Some(( | ||||||||||||||||||||||||||||||||
| member_hit.degree + (path_hit.degree / (PATH_DEGREE_DIVISOR * 2)).max(1), | ||||||||||||||||||||||||||||||||
| member_hit.ranges, | ||||||||||||||||||||||||||||||||
| )) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| fn match_container(qualifier: &str, container: &str, path: Option<&str>) -> Option<i32> { | ||||||||||||||||||||||||||||||||
| if let Some(hit) = match_name(qualifier, container) { | ||||||||||||||||||||||||||||||||
| return Some((hit.degree / PATH_DEGREE_DIVISOR).max(1)); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| let (prefix, tail) = split_qualified_symbol(qualifier)?; | ||||||||||||||||||||||||||||||||
| let tail_hit = match_name(tail, container)?; | ||||||||||||||||||||||||||||||||
| if let Some(path) = path { | ||||||||||||||||||||||||||||||||
| let normalized_prefix = prefix.replace("::", "/").replace('.', "/"); | ||||||||||||||||||||||||||||||||
| if match_name(&normalized_prefix, path).is_none() { | ||||||||||||||||||||||||||||||||
| return None; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| Some((tail_hit.degree / (PATH_DEGREE_DIVISOR * 2)).max(1)) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+268
to
+276
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Unverified packages in symbol results When a candidate lacks a path, Learn moreThe rankNames contract allows candidates without a path, but a qualified search still needs evidence for the whole qualifier. When a container does not match the whole qualifier, the fallback can combine the class from the container with the package from the path. Without a path, it currently returns the class-only match even though nothing establishes the package. Example: Search for Recommended fix: Require a matching path prefix for this fallback. Leave the full-container match available without a path.
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| #[derive(Deserialize)] | ||||||||||||||||||||||||||||||||
| #[serde(rename_all = "camelCase", deny_unknown_fields)] | ||||||||||||||||||||||||||||||||
| struct SymbolQueryRequest { | ||||||||||||||||||||||||||||||||
| query: String, | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /// Splits a symbol search query into its optional qualifier and member name (`workspace.symbolQuery`). | ||||||||||||||||||||||||||||||||
| pub fn symbol_query_command(payload: Value) -> Result<Value, CoreError> { | ||||||||||||||||||||||||||||||||
| let request: SymbolQueryRequest = serde_json::from_value(payload).map_err(|error| { | ||||||||||||||||||||||||||||||||
| CoreError::new(ErrorCode::InvalidRequest, "Invalid symbol query request") | ||||||||||||||||||||||||||||||||
| .with_details(error.to_string()) | ||||||||||||||||||||||||||||||||
| })?; | ||||||||||||||||||||||||||||||||
| let trimmed = request.query.trim(); | ||||||||||||||||||||||||||||||||
| let (qualifier, member) = match split_qualified_symbol(trimmed) { | ||||||||||||||||||||||||||||||||
| Some((qualifier, member)) => (Some(qualifier.to_string()), member.to_string()), | ||||||||||||||||||||||||||||||||
| None => (None, trimmed.to_string()), | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
| Ok(serde_json::json!({ | ||||||||||||||||||||||||||||||||
| "query": trimmed, | ||||||||||||||||||||||||||||||||
| "qualifier": qualifier, | ||||||||||||||||||||||||||||||||
| "member": member, | ||||||||||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 File paths admit unrelated symbols
For qualified queries,
rank_names_commandreturns symbols whose paths match the full query even when their names fail the member match. Unrelated symbols from those files appear in the results.Learn more
The rankNames contract allows hosts to supply symbol or navigator lists. For a qualified query, the path can establish the qualifier but not the member. match_qualified rejects candidates whose symbol name fails the member match, but the caller then lets the path satisfy the whole query.
Example: A navigator list includes
loadDefaultsfromsrc/config.read.ts. Searching forConfig.readreturnsloadDefaultseven thoughreaddoes not match its name.Recommended fix: Drop this path-only fallback for recognized qualified queries. Keep the direct name match for candidates whose names already include their qualifier and the existing path-only fallback for unqualified queries.
Was this helpful? React with 👍 or 👎 to provide feedback.