You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document provides an overview of the project's architecture, focusing on its design principles and key components.
4
+
5
+
## Architecture Overview
6
+
7
+
The extension is designed following SOLID principles to ensure it is maintainable, scalable, and testable.
8
+
9
+
### Key Principles
10
+
11
+
***Single Responsibility Principle (SRP):** Each class has a single, well-defined responsibility. This is exemplified by the service layer, where responsibilities are highly granular. For instance, `VisualStudioCodeInstanceProvider` is solely responsible for discovering Visual Studio Code installations. `VisualStudioCodeWorkspaceProvider` orchestrates workspace discovery, which is further delegated to specialized reader classes like `VscdbWorkspaceReader` and `StorageJsonWorkspaceReader`, each handling a specific data source.
12
+
***Dependency Inversion Principle (DIP):** High-level modules do not depend on low-level modules; both depend on abstractions. This is achieved through the use of interfaces like `IVisualStudioCodeService`. The `WorkspaceLauncherForVSCodeCommandsProvider` and `VisualStudioCodePage` depend on the `IVisualStudioCodeService` interface, not the concrete `VisualStudioCodeService` implementation. This decoupling allows for easier testing and maintenance.
13
+
14
+
## Project Structure
15
+
16
+
The project is organized into the following key directories within the `VisualStudioCode` project:
17
+
18
+
-**`/`**:
19
+
-[`WorkspaceLauncherForVSCode.cs`](./WorkspaceLauncherForVSCode.cs) - The main extension implementation.
20
+
-**`/Classes`**: Contains core data models and helper classes.
-`VisualStudioCodeInstance.cs`, `VisualStudioCodeWorkspace.cs` - Core data models.
23
+
-**`/Commands`**: Contains command implementations that are executed by the user.
24
+
-`OpenVisualStudioCodeCommand.cs` - The primary command for launching a selected workspace.
25
+
-`CopyPathCommand.cs` - Copies the workspace path to the clipboard.
26
+
-`RemoveWorkspaceCommand.cs` - Removes a workspace from the recently opened list.
27
+
-**`/Interfaces`**: Defines the contracts for services.
28
+
-`IVisualStudioCodeService.cs` - The contract for the main Visual Studio Code service.
29
+
-**`/Pages`**: Contains UI components.
30
+
-[`VisualStudioCodePage.cs`](./Pages/VisualStudioCodePage.cs) - A dynamic list page that displays discovered workspaces.
31
+
-**`/Services`**: Contains the primary service implementations.
32
+
-[`WorkspaceLauncherForVSCodeCommandsProvider.cs`](./Services/WorkspaceLauncherForVSCodeCommandsProvider.cs) - The entry point for providing commands to the Command Palette.
33
+
-[`VisualStudioCodeService.cs`](./Services/VisualStudioCodeService.cs) - Acts as a facade, orchestrating calls to more specialized provider classes.
34
+
-[`VisualStudioCodeInstanceProvider.cs`](./Services/VisualStudioCodeInstanceProvider.cs) - Discovers all installed instances of Visual Studio Code.
35
+
-[`VisualStudioCodeWorkspaceProvider.cs`](./Services/VisualStudioCodeWorkspaceProvider.cs) - Orchestrates the process of finding recent workspaces.
-**`/Models`**: C# models that map to the JSON structures of Visual Studio Code's workspace storage.
38
+
-**`/Readers`**: Specialized classes for reading and parsing workspace data.
39
+
-[`VscdbWorkspaceReader.cs`](./Workspaces/Readers/VscdbWorkspaceReader.cs) - Reads workspace data from the `state.vscdb` SQLite database.
40
+
-[`StorageJsonWorkspaceReader.cs`](./Workspaces/Readers/StorageJsonWorkspaceReader.cs) - Reads workspace data from the `storage.json` file.
41
+
42
+
## Core Components
43
+
44
+
### Services and Providers
45
+
46
+
***`IVisualStudioCodeService` / `VisualStudioCodeService`**: This service acts as the primary entry point for interacting with local Visual Studio Code data. It delegates the complex tasks of instance and workspace discovery to specialized provider classes.
47
+
***`VisualStudioCodeInstanceProvider`**: A static provider class responsible for discovering all installed instances of Visual Studio Code (Stable, Insiders, User, System) by scanning known locations and the system's PATH environment variable.
48
+
***`VisualStudioCodeWorkspaceProvider`**: This static provider orchestrates the process of finding recently opened workspaces. It doesn't perform the reading itself but delegates the task to specialized reader classes.
49
+
50
+
### Workspace Readers and Performance
51
+
52
+
To ensure high performance and low memory usage, the extension uses the `System.Text.Json` source generator for deserializing workspace data. This avoids runtime reflection and minimizes allocations.
53
+
54
+
***`VscdbWorkspaceReader` & `StorageJsonWorkspaceReader`**: These static reader classes are responsible for retrieving workspace information from Visual Studio Code's two primary data sources: the `state.vscdb` SQLite database and the `storage.json` file. Each reader is optimized to read its specific source and deserialize the data efficiently using source-generated models.
55
+
56
+
### Settings
57
+
58
+
***`SettingsManager`**: Manages all user-configurable settings for the extension. It loads settings from a JSON file and provides them to the rest of the application. It raises an event when settings are changed, allowing other components to react accordingly.
59
+
60
+
### UI and Commands
61
+
62
+
***`WorkspaceLauncherForVSCodeCommandsProvider`**: The main entry point for providing commands to the Command Palette. It initializes the required services (`SettingsManager`, `VisualStudioCodeService`) and creates the top-level command items. It also listens for settings changes to reload Visual Studio Code instances when necessary.
63
+
***`VisualStudioCodePage`**: A dynamic list page that displays the discovered Visual Studio Code workspaces. It receives the `IVisualStudioCodeService` to fetch workspace data asynchronously and handles user interactions like searching and scrolling.
64
+
***`OpenVisualStudioCodeCommand`**: The primary command responsible for launching a selected Visual Studio Code workspace.
65
+
66
+
#### Secondary Commands
67
+
Beyond the primary action of opening a workspace, the extension provides secondary commands for managing the workspace list:
68
+
69
+
***`CopyPathCommand`**: This command allows the user to copy the full file path of a workspace or folder directly to the clipboard, providing a quick way to access the location of the project.
70
+
***`RemoveWorkspaceCommand`**: This command provides the functionality to remove a workspace or folder entry from the Visual Studio Code's list of recently opened items. It first presents a confirmation dialog to prevent accidental removals. The command directly modifies the `state.vscdb` or `storage.json` files where VS Code stores this information.
71
+
72
+
This architecture ensures a clean separation of concerns, making the codebase easier to understand, extend, and debug.
-**Workspace Management**: Retrieve and display a list of available workspaces, including their paths and types (e.g., Local, WSL, Remote).
12
20
-**Command Execution**: Open workspaces in Visual Studio Code using a dedicated command.
13
21
-**Multi-Installation Support**: Works for multiple installations of Visual Studio Code, including Insider and system installations.
22
+
-**Secondary Actions**: Access additional commands for each workspace entry:
23
+
-**Copy Path**: Copies the full file path of the workspace or folder to the clipboard.
24
+
-**Remove from List**: Removes the workspace entry from Visual Studio Code's list of recently opened projects. A confirmation is required to prevent accidental removal.
25
+
-**Open in Explorer**: Opens the workspace or folder location in the default file explorer.
26
+
-**Refresh Workspaces**: Manually reloads the list of workspaces to reflect any recent changes.
14
27
15
28
## Installation
16
29
@@ -19,21 +32,21 @@ This project provides a command palette extension for opening Visual Studio Code
@@ -43,40 +56,20 @@ This project provides a command palette extension for opening Visual Studio Code
43
56
44
57
## Settings
45
58
46
-
-**Preferred Edition**: Determines which edition (Default or Insider) is used when a folder or workspace has been opened in both editions of VS Code.
47
-
- Options:
48
-
-**Default**: Uses the standard VS Code edition
49
-
-**Insider**: Uses the VS Code Insider edition
59
+
-**Preferred Edition**: Determines which edition (Default or Insider) is used when a folder or workspace has been opened in both editions of Visual Studio Code.
60
+
-**Search By**: Choose what to search by (Path, Title, or Both).
50
61
-**Use Strict Search**: Enables or disables strict search for workspaces.
51
-
-**Strict Search**: Matches items where the search text appears as a contiguous substring in the item's title or subtitle. For example, searching for "abc" will match "abc" or "abc123" but not "a1b2c3".
52
-
-**Show Details Panel**: Toggles the visibility of the details panel in the UI.
53
-
-**Tags**: Configures the tags displayed for each workspace.
54
-
- Options:
55
-
-**None** (-): No tags are displayed.
56
-
-**Type**: Displays the workspace type (e.g., Local, WSL, Remote).
57
-
-**Target**: Displays the target instance name (e.g., VS Code, VS Code Insider).
58
-
-**Type & Target**: Displays both the workspace type and the target instance name.
59
-
-**Command Result Action**: Determines what should happen after opening a VS Code workspace.
60
-
- Options:
61
-
-**Dismiss**: Closes the Command Palette after opening the workspace
62
-
-**Go Back**: Returns to the previous Command Palette view
63
-
-**Keep Open**: Keeps the Command Palette open after opening the workspace
-**UI Pages**: [`VSCodePage.cs`](VsCode/Pages/VSCodePage.cs) - Main interface page
62
+
-**Page Size**: Sets the number of items to load and display at one time.
63
+
-**Show Details Panel**: Toggles the visibility of the details panel.
64
+
-**Tags**: Configures the tags displayed for each workspace (Type, Target, or both).
65
+
-**Enable Visual Studio Code Installations**: Toggles which installations of Visual Studio Code to search for workspaces.
66
+
-**Command Result Action**: Determines what should happen after opening a Visual Studio Code workspace.
67
+
68
+
## How It Works
69
+
70
+
This extension scans for installations of Visual Studio Code on your system, including stable, Insiders, and system-wide installations. It then reads the workspace history from Visual Studio Code's internal storage files (`state.vscdb` and `storage.json`) to populate the list of recent workspaces.
71
+
72
+
For more detailed technical information about the project's architecture and components, please see the [Project Guide](./GUIDE.md).
0 commit comments