External Type Tracking for C# - #65
Conversation
This change addresses a usability issue where types from external assemblies (DLLs, NuGet packages) were not tracked, leading to "symbol not found" errors when searching for commonly-used external types. **Changes:** 1. **Add ExternalType symbol kind** (`src/types/mod.rs`) - New `SymbolKind::ExternalType` variant for tracking external type references - Updated `FromStr` implementation and tests 2. **C# parser enhancements** (`src/parsing/csharp/parser.rs`) - Track locally-defined types (classes, interfaces, structs, enums, records) - Detect external type references in field declarations - Skip primitive and framework types (int, string, etc.) - Create ExternalType symbols for unresolved types 3. **MCP tool improvements** (`src/mcp/mod.rs`) - Add helpful note when ExternalType is found - Guide users to use `search_symbols` for finding usages 4. **Vector embedding support** (`src/vector/embedding.rs`) - Handle ExternalType in symbol text generation **Testing:** - Verified with C# codebase containing external assembly references - `MapperResult` from `Codere.SBGOnline.EventsMapper.Model` now correctly identified as ExternalType instead of "not found" **Impact:** - Improves user experience for C# developers (and future Java support) - Reduces confusion about missing symbols - Provides clear distinction between "not found" and "external type" **Future work:** - Extend to other compiled languages (Java, etc.) - Parse XML documentation for external types - Track namespace/assembly metadata Closes issue with external type references in C# projects.
|
Hi @sergitorres-codere , I checked the changes you proposed. Here’s what I think. We already have import tracking and external detection in place. Adding a new symbol kind for external types might not be the best solution. Instead, the retrieve_symbol function could check imports when no symbols are found. That would solve the confusing UX when an external symbol isn’t located. How about this simple adjustment. We enhance the find_symbol MCP tool to check imports when a symbol isn’t found: if symbols.is_empty() {
// Check if name exists in imports
let all_imports = indexer.get_all_imports();
let matching_imports: Vec<_> = all_imports
.iter()
.filter(|imp| {
imp.path.ends_with(&name) ||
imp.alias.as_ref() == Some(&name)
})
.collect();
if !matching_imports.is_empty() {
return format!(
"'{name}' is an external type (not defined in source code).
Found in imports:
{list_imports}
Use 'search_symbols query:\"{name}\"' to find usages."
);
}
}The benefit is that it uses the existing import storage.. no new symbol kind is needed, no index bloat, and it will work for all import types by leveraging the ImportOrigin determination. What do you think? I could go ahead and make those changes. |
|
hi @bartolli , makes sense, did not notice that... no worries i will take care of it, i am also about to create a new PR to support the rest of missing features in the C# parser so i can include this change on it i believe is better to close this PR and ignore it at this point |
When working with C# codebases, users frequently search for types that are defined in external assemblies (DLLs, NuGet packages) rather than in source code. Currently, Codanna returns "No symbols found" for these types, which is confusing because:
Example
Before this PR:
After this PR:
Solution
Add external type tracking specifically for C#, with a design that can be extended to other compiled languages (Java, etc.).
Key Features
Distinguish local vs. external types
Smart filtering
int,string,bool, etc.)String,Int32,Object, etc.)Clear communication
SymbolKind::ExternalTypemakes it explicitImplementation Details
1. New Symbol Kind (
src/types/mod.rs)2. C# Parser Changes (
src/parsing/csharp/parser.rs)Added tracking infrastructure:
Modified type processing methods:
process_class,process_interface,process_struct,process_enum,process_recordrecord_local_type()to track definitionsAdded external type detection:
process_field_declarationnow extracts type references3. MCP Tool Enhancement (
src/mcp/mod.rs)Testing
Test Case: External NuGet Package Type
Code:
Result:
Impact
search_symbols)Documentation Updates
docs/architecture/language-support.mdto document external type trackingdocs/user-guide/mcp-tools.mdwith ExternalType kind informationdocs/integrations/agent-guidance.mdwith guidance for AI agents on handling external types