Semantic pattern-based search and replace for C# codebases in VS Code
SharpCodeSearch is a VS Code extension that brings powerful semantic code search to C# development, similar to ReSharper's Structural Search feature. Instead of simple text search, it understands C# code structure and allows you to find patterns using placeholders.
- Pattern-Based Search: Use placeholders to match code patterns
- Semantic Understanding: Powered by Roslyn for accurate C# code analysis
- Placeholder System: Match expressions, identifiers, and more
- Constraint Support: Filter matches with regex and other constraints
- JSON/Text Output: Get results in your preferred format
- VS Code: Version 1.95.0 or higher
- .NET 10 SDK: Required for the backend
- Node.js 20+: For building the extension
# Clone the repository
git clone https://github.com/yourusername/SharpCodeSearch.git
cd SharpCodeSearch
# Build the backend
cd src/backend
dotnet build
# Build the extension
cd ../extension
npm install
npm run compile
# Run tests
cd ../tests
dotnet testThe backend can be used directly from the command line:
PowerShell (Windows):
# Search for a pattern in a C# file - use SINGLE quotes!
dotnet run --project src/backend -- --pattern 'Console.WriteLine($arg$)' --file YourFile.cs
# Get results in text format
dotnet run --project src/backend -- --pattern '$x$ + $y$' --file Calculator.cs --output textBash/Zsh (Linux/Mac):
# Single or double quotes work
dotnet run --project src/backend -- --pattern "Console.WriteLine($arg$)" --file YourFile.cs
⚠️ Important: In PowerShell, always use single quotes for patterns with placeholders. Double quotes cause PowerShell variable expansion and will break your patterns.
- Open a C# project in VS Code
- Press
Ctrl+Shift+P(orCmd+Shift+Pon Mac) - Type "Sharp Code Search: Search"
- Enter your search pattern
- View results in the search panel
SharpCodeSearch uses patterns with placeholders to match code:
- Simple text:
Console.WriteLine- Matches literal text - Placeholders:
$identifier$- Matches any expression/identifier - Combined:
$obj$.ToString()- Matches method calls on any object
| Placeholder | Matches | Example Pattern | Example Match |
|---|---|---|---|
$expr$ |
Any expression | if ($expr$) |
if (x > 5) |
$id$ |
Identifiers | $id$ = 10 |
count = 10 |
$var$ |
Variables | var $var$ = $expr$ |
var result = calc() |
$obj$ |
Objects | $obj$.Method() |
user.Save() |
$arg$ |
Arguments | Method($arg$) |
Method(value) |
Add constraints to filter matches:
$var:regex=name.*$ = $value$
This pattern matches variable assignments where the variable name starts with "name".
Supported constraints:
regex=<pattern>- Match placeholder value with regextype=<typename>- Match specific types (requires semantic model)count=<n>- Match specific number of items
// Find all Console.WriteLine calls
Console.WriteLine($arg$)
// Find binary operations
$left$ + $right$
// Find method calls with specific pattern
$obj$.ToString()
// Find variable declarations
var $name$ = $value$;
// Find if statements with conditions
if ($condition$) { $body$ }Pattern:
Console.WriteLine($message$)
Matches:
Console.WriteLine("Hello"); // ✓
Console.WriteLine(userName); // ✓
Console.WriteLine($"Value: {x}"); // ✓Pattern:
$x$ + $y$
Matches:
int sum = a + b; // ✓
result = 5 + 10; // ✓
var total = count + 1; // ✓Pattern:
$obj$.ToString()
Matches:
user.ToString(); // ✓
value.ToString(); // ✓
item.ToString(); // ✓Pattern:
$var:regex=temp.*$ = $value$
Matches:
var tempValue = 10; // ✓ (var name starts with "temp")
int temperature = 20; // ✓ (var name starts with "temp")
var result = 30; // ✗ (var name doesn't match)Search entire workspace:
# Find all Console.WriteLine calls in the workspace
dotnet run --project src/backend -- --pattern 'Console.WriteLine($arg$)' --workspace . --output text
# Find all method calls in test files only
dotnet run --project src/backend -- --pattern '$method$($args$)' --file-filter '*Tests.cs'
# Find patterns in specific folder
dotnet run --project src/backend -- --pattern '$type$ $field$;' --folder-filter 'Services'
# Control parallelism for large projects
dotnet run --project src/backend -- --pattern '$var$' --max-parallelism 4Progress reporting: When searching a workspace, SharpCodeSearch reports progress as JSON to stdout:
{"type":"progress","stage":"scanning","message":"Scanning workspace for projects..."}
{"type":"progress","stage":"loading","message":"Loading 2 project(s)..."}
{"type":"progress","stage":"searching","message":"Searching... 10/22 files","totalFiles":22,"processedFiles":10}
{"type":"progress","stage":"complete","message":"Search complete. Found 34 match(es)."}SharpCodeSearch --pattern <pattern> [options]
Options:
--pattern <pattern> Search pattern (required)
--file <file> Search in a single C# file
--workspace <path> Search entire workspace (default: current directory)
--project-filter <pattern> Filter projects (e.g., "*.Tests.csproj")
--file-filter <pattern> Filter files (e.g., "*Controller.cs")
--folder-filter <name> Filter by folder path (e.g., "Controllers")
--max-parallelism <n> Max parallel tasks (default: CPU count)
--output <format> Output format: json|text (default: json)
--help, -h Show help message
SharpCodeSearch/
├── src/
│ ├── backend/ # C# pattern matching engine
│ │ ├── Services/ # Pattern parser, matcher, validators
│ │ ├── Models/ # Pattern AST, placeholder types
│ │ ├── Roslyn/ # Roslyn integration
│ │ ├── Caching/ # Compilation caching
│ │ └── Program.cs # CLI entry point
│ ├── extension/ # VS Code extension
│ │ ├── src/ # Extension TypeScript code
│ │ │ ├── extension.ts # Extension entry point
│ │ │ ├── BackendService.ts
│ │ │ └── SearchCommand.ts
│ │ └── webview/ # Search UI
│ └── tests/ # Backend unit & integration tests
├── Docs/ # Documentation
│ ├── ROADMAP.md
│ ├── ARCHITECTURE.md
│ └── QUICK_START_AND_EXAMPLES.md
└── README.md # This file
cd src/tests
dotnet test
# With coverage
dotnet test /p:CollectCoverage=trueTest Coverage: 142 tests passing ✅
cd src/extension
npm test- Clone the repository
- Install prerequisites (.NET 10, Node.js 20+)
- Build both backend and extension (see Installation)
- Open in VS Code
- Press F5 to launch extension in debug mode
- Backend: Use the
.NET Core Launchconfiguration in VS Code - Extension: Use
ExtensionorExtension Testsconfiguration
.vscode/launch.json- Debug configurations.vscode/tasks.json- Build taskssrc/backend/SharpCodeSearch.csproj- Backend project filesrc/extension/package.json- Extension manifestsrc/extension/tsconfig.json- TypeScript configuration
For more detailed information, see:
- ROADMAP.md - Development roadmap and phases
- ARCHITECTURE.md - Technical architecture
- QUICK_START_AND_EXAMPLES.md - Detailed examples
- TESTING_PHASE_1.4.md - Testing documentation
Phase 1 Complete ✅ (January 2026)
- ✅ CLI prototype functional
- ✅ Extension scaffolding complete
- ✅ Pattern parser working
- ✅ Basic pattern matching implemented
- ✅ Webview UI operational
- ✅ Backend/extension communication working
- ✅ 142 unit & integration tests passing
- ✅ Test coverage >80%
Phase 2.1 Complete ✅ (February 4, 2026)
- ✅ Statement placeholder support (
$stmt$ ) - ✅ Argument placeholder support (
$args$ ) - ✅ Type placeholder support (
$type$ ) - ✅ Expression placeholder enhancements
- ✅ 186 unit tests passing
Phase 2.2 Complete ✅ (February 5, 2026)
- ✅ Workspace-level search across multiple projects
- ✅ Parallel processing with Parallel.ForEachAsync
- ✅ Progress reporting with JSON streaming
- ✅ Multi-project support
- ✅ Filtering by project, file, and folder
- ✅ 11 integration tests passing
- ✅ Simple compilation without MSBuildWorkspace
Total Test Coverage: 197 tests passing ✅
Next Steps: Phase 2.3
- Search & replace functionality
- Replace pattern syntax
- Preview and batch replacement
- Undo support
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Run all tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Roslyn - Microsoft's .NET Compiler Platform
- VS Code Extension API - For extension infrastructure
- ReSharper - Inspiration for structural search
- Issues: GitHub Issues
- Discussions: GitHub Discussions
| Component | Technology | Purpose |
|---|---|---|
| Backend | C# (.NET 10) | Pattern matching engine |
| Code Analysis | Roslyn | C# syntax/semantic analysis |
| Extension | TypeScript | VS Code extension |
| Frontend | HTML/CSS/JS | Search UI webview |
| Testing | xUnit, Mocha | Test frameworks |
| Build | .NET CLI, npm | Build tooling |
Made with ❤️ for C# developers