Smart Code Search
Find a pasted code snippet across your VS Code workspace, even when its indentation, line breaks or identifiers have changed. Searches run locally in two worker threads. The VSIX includes the engine and React sidebar and works offline.
Install and search
- In VS Code 1.146 or later, run Extensions: Install from VSIX… and select
smart-code-search-0.0.2.vsix.
- Open a workspace folder and select Smart Code Search in the Activity Bar. The default shortcut is ⌘⇧⌥F on macOS and Ctrl+Shift+Alt+F on Windows and Linux.
- Paste a snippet and press ⌘Enter or Ctrl+Enter, or click the magnifying glass. Enter inserts a newline. Use Aa to toggle case sensitivity.
- Click a filename to open it in the editor. Use its chevron to collapse or expand the matches. Click a match to select the original code. Show ranked list displays matches across files in score order. The title bar provides Clear, Refresh and Settings actions.
For example, searching for function getUser(){return user;} in Smart mode finds a reformatted copy at 100%. A structurally similar function such as function getEmployee(){return employee;} can also qualify at the default 75% threshold.
Modes and filters
- Smart combines literal, formatting-independent and fuzzy matches.
- Exact searches literal text, including whitespace, using the selected case setting.
- Ignore whitespace compares tokens across spaces, tabs and line breaks. Quoted text and word boundaries are preserved.
- Fuzzy includes normalized matches and scores candidate snippets by similarity.
Open Files to include / exclude to enter one glob per line. Bare filenames and patterns such as *.tsx match at any depth. Paths such as src/components/** are relative to each workspace root. The results summary counts all qualifying matches, even when the display limit is lower. Searches run on submission or Refresh.
Each workspace root uses its own .gitignore files, including nested rules, and its VS Code files.exclude and search.exclude settings. The scanner skips symlinks, binary and non-UTF-8 data, oversized files, and common generated directories (node_modules, .git, .next, dist, build, coverage, .venv, venv, __pycache__, and vendor). Open, modified workspace files use the editor buffer. Untitled buffers without a workspace file path are outside the search scope.
Configuration
Search for Smart Code Search in Settings. Defaults are Smart mode, case-sensitive matching, 75% minimum similarity, 500 displayed results, a 1,024 KiB file limit and enabled gitignore handling. The file limit and gitignore setting can vary by workspace folder. To assign the built-in global-search shortcut to this extension, open Keyboard Shortcuts and edit Smart Code Search: Open Search.
Matching and limits
The language-independent tokenizer recognizes Unicode word tokens, punctuation and common quoted strings, including backticks and triple quotes. It treats the entire quoted literal as one token. Language-specific constructs such as regex literals, heredocs and indentation-sensitive blocks can require Exact mode. The extension accepts queries up to 8,192 UTF-16 code units.
Normalized substring matching uses a prefix table. Fuzzy search locates candidate starts with shared tokens or partial words, then compares short windows using weighted token edit distance. Queries longer than 64 tokens use rolling token-pair overlap with partial credit for renamed identifiers. Fuzzy scores are heuristic and can miss heavily rewritten snippets. Exact and normalized matches score 100%. Overlapping candidates are deduplicated, with ties favoring literal matches.
Offsets are zero-based UTF-16 indices with exclusive ends. Displayed lines are one-based. Previews are cropped for readability. Navigation selects the entire match and checks a content fingerprint before using stored offsets. Refresh after a file changes.
Development
Run npm ci, then press F5 to build and launch an Extension Development Host.
npm run compile type-checks, lints and bundles the extension, worker and webview.
npm run test:unit tests ranking, normalization, offset mapping and fuzzy matching.
npm test runs the VS Code integration suite in a temporary multi-root workspace. Set VSCODE_EXECUTABLE to an installed desktop executable to use it offline. Otherwise the test runner downloads VS Code.
SCS_BENCHMARK=1 npm test additionally searches 1,024 generated source files and verifies global counts and result limits.
npm run vsix creates the locally installable package in the repository root.
Search logic lives in src/search, workspace scanning and caching in src/workspace, and the sidebar and message handling in src/view. Source files and queries stay on the machine. The extension reads workspace files, keeps a bounded in-memory text cache and writes no search index.