Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
353 changes: 343 additions & 10 deletions README.md

Large diffs are not rendered by default.

277 changes: 263 additions & 14 deletions docs/architecture/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,138 @@ RootTreeItem: "Code Notes (N)"
- `stripMarkdown(text)` - Remove markdown formatting from preview
- `truncateText(text, length)` - Truncate with ellipsis

### 10. Search Manager (`searchManager.ts`)

**Responsibility**: Manages search indexing and queries for notes

**Key Features**:

**Inverted Index**:
- Term β†’ Note IDs mapping for fast full-text search
- Stop word filtering (48 common words)
- Single-character token filtering
- Memory-efficient index structure (~0.2MB per 100 notes)

**Metadata Indexes**:
- Author index: Author β†’ Note IDs
- Date index: Note ID β†’ Note (for temporal queries)
- File index: File path β†’ Note IDs

**Search Capabilities**:
- Full-text search with tokenization
- Regex pattern matching with flags support
- Case-sensitive/insensitive modes
- Multiple filter combinations (AND logic)
- Relevance scoring with recency boost
- Max results limiting (configurable, default 100)

**Caching**:
- LRU-style cache (max 50 entries)
- 5-minute TTL per cache entry
- Cache key: stringified query
- Automatic invalidation on index updates

**Search History**:
- Last 20 searches persisted in global state
- Timestamp and query tracking
- History size configurable (5-100, default 20)

**Performance Optimizations**:
- Stop word filtering reduces index by ~30%
- Sub-100ms search times for typical workspaces
- Incremental index updates on note CRUD
- Detailed performance logging with metrics

**Public Methods**:
- `buildIndex(notes)` - Build complete search index
- `search(query, allNotes)` - Execute search with filters
- `searchFullText(text, caseSensitive)` - Text-only search
- `searchRegex(pattern, flags)` - Regex-based search
- `filterByAuthor(authors)` - Filter by one or more authors
- `filterByDateRange(start, end, field)` - Date range filtering
- `filterByFilePath(pattern)` - Glob pattern file filtering
- `updateIndex(note)` - Add/update note in index
- `removeFromIndex(noteId)` - Remove note from index
- `getIndexStats()` - Get indexing statistics
- `getAuthors()` - Get all unique authors
- `getSearchHistory()` - Retrieve search history
- `saveSearch(query)` - Save search to history
- `clearSearchHistory()` - Clear all search history

**Integration**:
- Initialized in `extension.ts` on activation
- Linked to NoteManager via `setSearchManager()`
- Background index building (1s delay) with progress notification
- Incremental updates on note create/update/delete

### 11. Search UI (`searchUI.ts`)

**Responsibility**: VSCode QuickPick interface for search interaction

**UI Components**:

**QuickPick Panel**:
- Title: "πŸ” Search Notes"
- Placeholder: "Type to search notes... (supports regex with /pattern/)"
- Live search with 200ms debouncing
- Keyboard navigation (↑↓ arrows, Enter to open)
- Multi-select support for batch operations

**Search Input**:
- Text search support
- Regex pattern detection (`/pattern/flags`)
- Case-sensitive toggle via filter
- Debounced input handling (prevents excessive queries)

**Filter UI**:
- Author filter: Multi-select QuickPick with all authors
- Date filter: Predefined ranges or custom dates
- Last 7 days, Last 30 days, Last 3 months, Last year
- Custom start/end date pickers
- Created vs. Modified date selection
- File filter: Glob pattern input
- Examples: `src/**/*.ts`, `*.js`, `**/*.{ts,tsx}`

**Search Results**:
- Format: `πŸ“ Line {line}: {preview}`
- Subtitle: `{file_path} ({author}) β€’ Score: {relevance}`
- Click to navigate to note location
- Relevance score displayed (0-100)
- Result count indicator in title

**Search History**:
- Recent searches button (clock icon)
- Shows last 20 searches with timestamps
- Click to re-execute previous search
- Timestamp format: "X minutes/hours/days ago"

**Active Filters Display**:
- Shows applied filters in subtitle area
- Format: "Author: john_doe | Date: Last 7 days | File: src/**"
- Clear filters button (βœ• icon)

**No Results State**:
- Empty state with helpful suggestions
- "No notes found. Try: Remove filters, Check spelling, Use different keywords"

**Public Methods**:
- `show()` - Display search panel
- `hide()` - Close search panel
- `dispose()` - Cleanup resources

**Event Handlers**:
- `onDidChangeValue` - Handle search input (debounced)
- `onDidAccept` - Navigate to selected note
- `onDidTriggerButton` - Handle filter buttons
- `onDidHide` - Cleanup on panel close

**Integration**:
- Command: `codeContextNotes.searchNotes`
- Keyboard shortcut: Ctrl/Cmd+Shift+F (when not in search view)
- Sidebar toolbar integration (search icon at navigation@2)
- Uses SearchManager for query execution
- Uses NoteManager for note retrieval

## Data Flow

### Creating a Note
Expand Down Expand Up @@ -442,6 +574,69 @@ RootTreeItem: "Code Notes (N)"
8. CodeLensProvider refreshes indicators
```

### Searching Notes

```
1. User opens search (Ctrl/Cmd+Shift+F or sidebar search icon)
↓
2. SearchUI displays QuickPick panel
↓
3. User types query (debounced 200ms)
↓
4. SearchUI detects regex pattern (/pattern/flags) if present
↓
5. SearchUI calls SearchManager.search(query)
↓
6. SearchManager:
- Checks cache for query (cache key: stringified query)
- If cache hit and TTL valid: return cached results
- If cache miss:
a. Parse query (text/regex, filters)
b. Search inverted index for matching terms
c. Apply metadata filters (author, date, file)
d. Intersect result sets (AND logic)
e. Calculate relevance scores (TF + recency boost)
f. Sort by relevance descending
g. Limit results (default 100, configurable)
h. Cache results with 5-minute TTL
↓
7. SearchUI formats results with preview and metadata
↓
8. User selects result and presses Enter
↓
9. SearchUI navigates to note location (file + line)
↓
10. SearchManager saves query to search history (last 20)
```

### Index Building and Updates

```
1. Extension activates (onStartupFinished)
↓
2. SearchManager initialized with VSCode context
↓
3. After 1 second delay (non-blocking):
- Show progress notification "Building search index..."
- NoteManager.getAllNotes() retrieves all notes
- SearchManager.buildIndex(notes) creates inverted index
- Progress notification updates: "Search index ready (N notes)"
↓
4. On note create/update/delete:
- NoteManager calls SearchManager.updateIndex(note)
- SearchManager incrementally updates indexes:
a. Remove old entries for note ID
b. Tokenize new content
c. Update inverted index (term β†’ note IDs)
d. Update metadata indexes (author, date, file)
e. Invalidate search cache (all entries)
↓
5. Index stays in memory (not persisted)
- Rebuilds on workspace reload
- Auto-updates on note changes
- Memory usage: ~0.2MB per 100 notes
```

## Performance Considerations

### Caching
Expand All @@ -459,6 +654,13 @@ RootTreeItem: "Code Notes (N)"
- VSCode handles CodeLens caching
- We trigger refresh only when needed

**Search Cache** (v0.3.0):
- LRU-style cache with max 50 entries
- 5-minute TTL per cache entry
- Cache key: stringified query (JSON)
- Invalidated on index updates
- Reduces search time from ~50ms to <1ms for repeated queries

### Debouncing

**Document Changes**:
Expand All @@ -470,6 +672,12 @@ RootTreeItem: "Code Notes (N)"
- Debounced to prevent flicker
- Only refreshes affected ranges

**Search Input** (v0.3.0):
- 200ms debounce on search input
- Prevents excessive search queries
- Configurable (50-1000ms)
- Batches rapid keystrokes

### Lazy Loading

**Notes**:
Expand Down Expand Up @@ -528,27 +736,53 @@ RootTreeItem: "Code Notes (N)"
**Scope**: VSCode API integration
- ContentHashTracker (19 tests)
- NoteManager (40+ tests)
- SearchManager (35 tests)
- Index building & management (7 tests)
- Full-text search (8 tests)
- Regex search (3 tests)
- Filter functions (8 tests)
- Search caching (4 tests)
- Search history (4 tests)
- Edge cases (3 tests)

**Approach**:
- Use VSCode test environment
- Test multi-file scenarios
- Test document change handling
- Mock VSCode context for search tests

### Coverage

- Target: >80% code coverage
- Current: 88% overall
- 100 total tests
- 76 total tests (41 existing + 35 search tests)

## Configuration

### Settings

```typescript
interface Configuration {
storageDirectory: string; // Default: ".code-notes"
authorName: string; // Default: "" (auto-detect)
showCodeLens: boolean; // Default: true
storageDirectory: string; // Default: ".code-notes"
authorName: string; // Default: "" (auto-detect)
showCodeLens: boolean; // Default: true

// Search settings (v0.3.0+)
search: {
fuzzyMatching: boolean; // Default: false
caseSensitive: boolean; // Default: false
maxResults: number; // Default: 100 (10-500)
debounceDelay: number; // Default: 200ms (50-1000)
saveHistory: boolean; // Default: true
historySize: number; // Default: 20 (5-100)
};

// Sidebar settings (v0.2.0+)
sidebar: {
previewLength: number; // Default: 50 (20-200)
autoExpand: boolean; // Default: false
sortBy: string; // Default: "file" (file/date/author)
};
}
```

Expand All @@ -565,6 +799,8 @@ interface Configuration {
- storageDirectory: Reload notes from new location
- authorName: Use for new notes
- showCodeLens: Refresh CodeLens provider
- search.*: Apply to next search operation
- sidebar.*: Refresh sidebar view
```

## Extension Manifest
Expand All @@ -575,10 +811,17 @@ interface Configuration {

### Contributions

- **Commands**: 19 commands for note operations
- **Commands**: 20 commands for note operations
- 19 core note commands (create, edit, delete, etc.)
- 1 search command (searchNotes)
- **Keybindings**: Keyboard shortcuts for common actions
- **Menus**: Context menus for comment threads
- **Configuration**: 3 settings
- Ctrl/Cmd+Shift+F for search (when not in search view)
- **Menus**: Context menus for comment threads and sidebar toolbar
- **Views**: Sidebar tree view for browsing notes
- **Configuration**: 12 settings
- 3 core settings (storage, author, CodeLens)
- 6 search settings (fuzzy, case-sensitive, max results, etc.)
- 3 sidebar settings (preview length, auto-expand, sort)

### Dependencies

Expand Down Expand Up @@ -629,18 +872,24 @@ interface Configuration {

## Future Enhancements

### Implemented Features

1. βœ… **Sidebar View** (v0.2.0): Browse all notes in workspace
2. βœ… **Search** (v0.3.0): Find notes by content or metadata with filters

### Planned Features

1. **Sidebar View**: Browse all notes in workspace
2. **Search**: Find notes by content or metadata
3. **Export**: Export notes to various formats
4. **Templates**: Create notes from templates
5. **Tags**: Categorize notes with tags
1. **Export**: Export notes to various formats
2. **Templates**: Create notes from templates
3. **Tags**: Categorize notes with tags
4. **Replace in Notes**: Bulk editing across multiple notes
5. **Natural Language Search**: "notes created last week by author X"
6. **Note References**: Link notes to each other

### Architecture Changes

1. **Database**: Consider SQLite for better query performance
2. **Indexing**: Full-text search index for notes
1. βœ… **Indexing** (v0.3.0): Inverted index for full-text search implemented
2. **Database**: Consider SQLite for enhanced query performance and persistence
3. **Sync**: Cloud sync for team collaboration
4. **Conflict Resolution**: Handle concurrent edits

Expand Down
Loading