### Consuming DotRush API from another extension Source: https://context7.com/janeysprings/dotrush/llms.txt This example demonstrates how to import and use the DotRush API from within another VS Code extension. It shows how to get the DotRush extension, activate it, and subscribe to various project-related events. ```APIDOC ## Consuming DotRush API from another extension ### Description This example demonstrates how to import and use the DotRush API from within another VS Code extension. It shows how to get the DotRush extension, activate it, and subscribe to various project-related events such as project loading and active project changes. ### Language TypeScript ### Code Example ```typescript // Example: Consuming DotRush API from another extension import * as vscode from 'vscode'; interface Project { name: string; path: string; directory: string; frameworks: string[]; configurations: string[]; isTestProject: boolean; } interface DotRushExports { onProjectLoaded: { subscribe(callback: (project: Project) => void): void; }; onActiveProjectChanged: { subscribe(callback: (project: Project) => void): void; }; onActiveConfigurationChanged: { subscribe(callback: (configuration: string) => void): void; }; onActiveFrameworkChanged: { subscribe(callback: (framework: string) => void): void; }; } export async function activate(context: vscode.ExtensionContext) { // Get DotRush extension const dotrushExtension = vscode.extensions.getExtension('nromanov.dotrush'); if (dotrushExtension) { // Ensure extension is activated const api = await dotrushExtension.activate() as DotRushExports; // Subscribe to project events api.onProjectLoaded.subscribe((project) => { console.log(`Project loaded: ${project.name}`); console.log(`Frameworks: ${project.frameworks.join(', ')}`); console.log(`Is test project: ${project.isTestProject}`); }); api.onActiveProjectChanged.subscribe((project) => { console.log(`Active project changed to: ${project.name}`); // Update your extension's state based on active project }); api.onActiveConfigurationChanged.subscribe((config) => { console.log(`Build configuration: ${config}`); }); api.onActiveFrameworkChanged.subscribe((framework) => { console.log(`Target framework: ${framework}`); }); } } ``` ### Key Interfaces #### `Project` Interface Represents a C# project with the following properties: - **name** (string) - The name of the project. - **path** (string) - The full path to the project file. - **directory** (string) - The directory containing the project. - **frameworks** (string[]) - An array of target frameworks for the project. - **configurations** (string[]) - An array of available build configurations. - **isTestProject** (boolean) - Indicates if the project is a test project. #### `DotRushExports` Interface Defines the available exports from the DotRush extension API: - **onProjectLoaded** (`{ subscribe(callback: (project: Project) => void): void }`): An event that fires when a project is loaded. The callback receives a `Project` object. - **onActiveProjectChanged** (`{ subscribe(callback: (project: Project) => void): void }`): An event that fires when the active project changes. The callback receives the new active `Project` object. - **onActiveConfigurationChanged** (`{ subscribe(callback: (configuration: string) => void): void }`): An event that fires when the active build configuration changes. The callback receives the new configuration string. - **onActiveFrameworkChanged** (`{ subscribe(callback: (framework: string) => void): void }`): An event that fires when the active target framework changes. The callback receives the new framework string. ### Usage 1. Get the DotRush extension using `vscode.extensions.getExtension('nromanov.dotrush')`. 2. Activate the extension using `await dotrushExtension.activate()`. 3. Access the exported API and subscribe to the desired events using their `subscribe` methods. ``` -------------------------------- ### VS Code Command Palette and Keybindings Source: https://context7.com/janeysprings/dotrush/llms.txt Lists available DotRush commands for VS Code extensions or keybindings. Includes examples for workspace management, build operations, and debugging utilities. ```typescript const commands = { "dotrush.reloadWorkspace": "Reload the Roslyn workspace", "dotrush.pickProjectOrSolutionFiles": "Select project/solution files to load", "dotrush.setStartupProject": "Set active startup project (context menu)", "dotrush.selectActiveConfiguration": "Select build configuration and target framework", "dotrush.buildWorkspace": "Build the entire workspace", "dotrush.createNewProject": "Create new .NET project from template", "dotrush.build": "Build selected project/folder", "dotrush.restore": "Restore NuGet packages", "dotrush.clean": "Clean build output", "dotrush.pickProcess": "Show process picker for attach", "dotrush.activeTargetPath": "Get active project's output assembly path", "dotrush.activeTargetBinaryPath": "Get active project's executable path", "dotrush.attachTraceProfiler": "Start dotnet-trace profiling session", "dotrush.createHeapDump": "Create GC heap dump with dotnet-gcdump", "dotrush.activeProjectPath": "Returns active project file path", "dotrush.activeProjectDirectory": "Returns active project directory", "dotrush.activeConfiguration": "Returns active build configuration", "dotrush.activeTargetFramework": "Returns active target framework" }; ``` -------------------------------- ### Consume DotRush API in VS Code Extension (TypeScript) Source: https://context7.com/janeysprings/dotrush/llms.txt This example demonstrates how another VS Code extension can activate and consume the DotRush API. It subscribes to various project-related events such as project loading, active project changes, and active framework/configuration changes, logging relevant information to the console. Ensure DotRush is installed and activated for this code to function. ```typescript import * as vscode from 'vscode'; interface Project { name: string; path: string; directory: string; frameworks: string[]; configurations: string[]; isTestProject: boolean; } interface DotRushExports { onProjectLoaded: { subscribe(callback: (project: Project) => void): void; }; onActiveProjectChanged: { subscribe(callback: (project: Project) => void): void; }; onActiveConfigurationChanged: { subscribe(callback: (configuration: string) => void): void; }; onActiveFrameworkChanged: { subscribe(callback: (framework: string) => void): void; }; } export async function activate(context: vscode.ExtensionContext) { // Get DotRush extension const dotrushExtension = vscode.extensions.getExtension('nromanov.dotrush'); if (dotrushExtension) { // Ensure extension is activated const api = await dotrushExtension.activate() as DotRushExports; // Subscribe to project events api.onProjectLoaded.subscribe((project) => { console.log(`Project loaded: ${project.name}`); console.log(`Frameworks: ${project.frameworks.join(', ')}`); console.log(`Is test project: ${project.isTestProject}`); }); api.onActiveProjectChanged.subscribe((project) => { console.log(`Active project changed to: ${project.name}`); // Update your extension's state based on active project }); api.onActiveConfigurationChanged.subscribe((config) => { console.log(`Build configuration: ${config}`); }); api.onActiveFrameworkChanged.subscribe((framework) => { console.log(`Target framework: ${framework}`); }); } } ``` -------------------------------- ### Neovim LSP Configuration Source: https://context7.com/janeysprings/dotrush/llms.txt Configure the DotRush language server with Neovim for C# IntelliSense and diagnostics outside of VS Code. ```APIDOC ## Neovim LSP Configuration Use DotRush language server with Neovim for C# IntelliSense and diagnostics outside of VS Code. ### Installation and Setup 1. Install `nvim-lspconfig` plugin. 2. Register DotRush as a custom LSP server in your Neovim configuration (`init.lua` or `init.vim`). ### Configuration Example (`init.lua`) ```lua -- Neovim LSP configuration for DotRush -- Ensure nvim-lspconfig plugin is installed -- Plug 'neovim/nvim-lspconfig' -- Register DotRush as a custom LSP server require('lspconfig.configs').dotrush = { default_config = { -- Path to DotRush language server executable -- Download from: https://github.com/JaneySprings/DotRush/releases cmd = { '/usr/local/bin/dotrush' }, -- Linux/macOS example -- cmd = { 'C:\Tools\DotRush\DotRush.exe' }, -- Windows example filetypes = { 'cs', 'xaml' }, root_dir = function(fname) -- Use current working directory as workspace root return vim.fn.getcwd() end, -- Optional: custom initialization options init_options = { -- Configuration passed to language server } } } -- Enable the DotRush language server require('lspconfig').dotrush.setup({ -- Optional: custom handlers on_attach = function(client, bufnr) -- Enable completion triggered by vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- Keybindings for LSP functions local opts = { noremap=true, silent=true, buffer=bufnr } vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, opts) end }) ``` ``` -------------------------------- ### Sublime Text LSP Configuration Source: https://context7.com/janeysprings/dotrush/llms.txt Configure the DotRush language server with Sublime Text's LSP package for C# development. ```APIDOC ## Sublime Text LSP Configuration Configure DotRush language server with Sublime Text's LSP package for C# development. ### Configuration Steps 1. Open Sublime Text settings: `Preferences > Package Settings > LSP > Settings`. 2. Add the `dotrush` client configuration to your user settings. ### Settings Example (`Preferences.sublime-settings`) ```json { "clients": { "dotrush": { "enabled": true, "command": [ // Windows path example: "C:\\Tools\\DotRush\\DotRush.exe" // macOS/Linux path example: // "/usr/local/bin/dotrush" ], "selector": "source.cs", "initializationOptions": { // Optional server configuration } } }, // Recommended LSP settings for C# development "show_diagnostics_panel_on_save": 0, "diagnostics_highlight_style": "squiggly", "document_highlight_style": "stippled" } ``` ``` -------------------------------- ### Neovim LSP Configuration for DotRush Source: https://context7.com/janeysprings/dotrush/llms.txt Configures the DotRush language server within Neovim using the nvim-lspconfig plugin. Sets up the server command, filetypes, and keybindings for LSP features like definition and hover. ```lua require('lspconfig.configs').dotrush = { default_config = { cmd = { '/usr/local/bin/dotrush' }, filetypes = { 'cs', 'xaml' }, root_dir = function(fname) return vim.fn.getcwd() end } } require('lspconfig').dotrush.setup({ on_attach = function(client, bufnr) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { noremap=true, silent=true, buffer=bufnr }) end }) ``` -------------------------------- ### Configure .NET Core Debugging with launch.json Source: https://context7.com/janeysprings/dotrush/llms.txt Defines launch and attach configurations for debugging .NET Core applications within VS Code using DotRush. It supports launching new processes with pre-build tasks and attaching to existing processes by ID or path. ```json { "version": "0.2.0", "configurations": [ { "name": ".NET Core Debugger (launch)", "type": "coreclr", "request": "launch", "program": "${command:dotrush.activeTargetPath}", "preLaunchTask": "dotrush: Build", "cwd": "${workspaceFolder}", "console": "integratedTerminal", "args": ["--environment", "Development"], "env": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development" } }, { "name": ".NET Core Debugger (attach)", "type": "coreclr", "request": "attach", "processId": "${command:dotrush.pickProcess}" }, { "name": "Godot Debugger", "type": "coreclr", "request": "attach", "processPath": "C:\\Programs\\Godot\\Godot_v4.4.1-stable_mono_win64.exe", "preLaunchTask": "dotrush: Build" } ] } ``` -------------------------------- ### DotRush Project Configuration Source: https://github.com/janeysprings/dotrush/blob/main/src/AltEditors/Readme.md This configuration file allows users to specify project or solution files manually if the server fails to detect them automatically. It should be placed in the project root or next to the executable. ```json { "dotrush": { "roslyn": { "projectOrSolutionFiles": [ "/path/to/your/solution.sln" ] } } } ``` -------------------------------- ### Configure Unity Debugging with launch.json Source: https://context7.com/janeysprings/dotrush/llms.txt Sets up debugging configurations for Unity projects using the integrated Mono debugger within VS Code via DotRush. This includes attaching to the Unity Editor, standalone builds, Android devices, and advanced configurations with custom settings. ```json { "version": "0.2.0", "configurations": [ { "name": "Unity Debugger", "type": "unity", "request": "attach" }, { "name": "Unity Android Debugger", "type": "unity", "request": "attach", "transportArgs": { "type": "android" } }, { "name": "Unity Debugger (Advanced)", "type": "unity", "request": "attach", "cwd": "${workspaceFolder}", "env": { "UNITY_DEBUG": "1" }, "debuggerOptions": { "evaluationTimeout": 10000 }, "userAssemblies": [ "Assembly-CSharp.dll", "Assembly-CSharp-Editor.dll" ] } ] } ``` -------------------------------- ### Configure Test Run Settings Source: https://context7.com/janeysprings/dotrush/llms.txt An XML configuration file for test execution behavior. It allows setting CPU limits, timeouts, and parallelization options for NUnit and xUnit. ```xml 1 ./TestResults net8.0 60000 4 30000 true 0 ``` -------------------------------- ### Configure .NET Core Debugging in launch.json Source: https://github.com/janeysprings/dotrush/blob/main/README.md This configuration enables launching or attaching to .NET Core applications within VS Code using the DotRush environment. It utilizes the coreclr type to provide standard debugging capabilities. ```jsonc { "version": "0.2.0", "configurations": [ { "name": ".NET Core Debugger (launch)", "type": "coreclr", "request": "launch", "program": "${command:dotrush.activeTargetPath}", "preLaunchTask": "dotrush: Build" }, { "name": ".NET Core Debugger (attach)", "type": "coreclr", "request": "attach", "processId": "${command:dotrush.pickProcess}" } ] } ``` -------------------------------- ### Perform Performance Profiling with CLI Tools Source: https://context7.com/janeysprings/dotrush/llms.txt Commands to manually collect performance traces and heap dumps from a running .NET process. These are the underlying operations triggered by DotRush commands. ```bash dotnet run --project ./MyApp/MyApp.csproj & dotnet-trace ps dotnet-trace collect -p 12345 --format speedscope -o ./trace.speedscope.json dotnet-gcdump collect -p 12345 -o ./heap.gcdump dotnet-trace collect -p 12345 --providers Microsoft-DotNETCore-SampleProfiler --providers Microsoft-Windows-DotNETRuntime:0x1F000080018:5 ``` -------------------------------- ### Sublime Text LSP Configuration for DotRush Source: https://context7.com/janeysprings/dotrush/llms.txt Configures the DotRush language server in Sublime Text via the LSP package settings. Defines the server command path and selector for C# files. ```json { "clients": { "dotrush": { "enabled": true, "command": ["C:\\Tools\\DotRush\\DotRush.exe"], "selector": "source.cs" } } } ``` -------------------------------- ### Set Executable Permissions for Zed Source: https://github.com/janeysprings/dotrush/blob/main/src/AltEditors/Readme.md These terminal commands grant execution permissions to the DotRush language server binary on Unix-based systems to resolve 'failed to spawn command' errors in Zed. ```bash #MacOS chmod +x "/Users/You/Library/Application Support/Zed/extensions/work/dotrush/LanguageServer/dotrush" #Linux chmod +x "/home/You/.local/share/zed/extensions/work/dotrush/LanguageServer/dotrush" ``` -------------------------------- ### Configure Unity Debugging in launch.json Source: https://github.com/janeysprings/dotrush/blob/main/README.md This configuration allows the integrated Mono Debugger to attach to a running Unity project. It is specifically designed for Unity development workflows within VS Code. ```jsonc { "version": "0.2.0", "configurations": [ { "name": "Unity Debugger", "type": "unity", "request": "attach" } ] } ``` -------------------------------- ### Configure DotRush in Neovim Source: https://github.com/janeysprings/dotrush/blob/main/src/AltEditors/Readme.md This configuration registers the DotRush language server with nvim-lspconfig. It defines the executable path, supported file types, and root directory resolution. ```lua require('lspconfig.configs').dotrush = { default_config = { cmd = { '/Path/To/Executale/dotrush' }, filetypes = { 'cs', 'xaml' }, root_dir = function(fname) return vim.fn.getcwd() end }; } require('lspconfig').dotrush.setup({}) ``` -------------------------------- ### Configure DotRush Server via JSON Source: https://context7.com/janeysprings/dotrush/llms.txt Defines the structure for the dotrush.config.json file. This allows non-VS Code editors to specify project files, workspace properties, and diagnostic settings. ```json { "dotrush": { "roslyn": { "projectOrSolutionFiles": [ "/path/to/your/solution.sln", "/path/to/project/MyProject.csproj" ], "workspaceProperties": [ "Configuration=Debug", "Platform=AnyCPU" ], "skipUnrecognizedProjects": true, "loadMetadataForReferencedProjects": false, "restoreProjectsBeforeLoading": true, "compileProjectsAfterLoading": true, "showItemsFromUnimportedNamespaces": true, "targetTypedCompletionFilter": true, "triggerCompletionOnSpace": true, "compilerDiagnosticsScope": "Project", "analyzerDiagnosticsScope": "Document", "diagnosticsFormat": "NoHints", "dispatcherType": "MultiThread", "dotnetSdkDirectory": "/usr/share/dotnet/sdk/8.0.100", "analyzerAssemblies": [ "/path/to/StyleCop.Analyzers.dll" ] } } } ``` -------------------------------- ### Configure DotRush in Sublime Text Source: https://github.com/janeysprings/dotrush/blob/main/src/AltEditors/Readme.md This JSON snippet configures the LSP plugin in Sublime Text to recognize the DotRush language server. It requires the path to the executable and the file selector for C# files. ```json { "clients": { "dotrush": { "enabled": true, "command": ["Your\\Path\\To\\DotRush.exe"], "selector": "source.cs" } } } ``` -------------------------------- ### Configure DotRush Settings in VS Code Source: https://context7.com/janeysprings/dotrush/llms.txt This JSON configuration defines the behavior of the DotRush extension, including Roslyn workspace properties, debugger behavior, and MSBuild arguments. It allows users to specify project files, SDK paths, and diagnostic scopes. ```jsonc { "dotrush.roslyn.projectOrSolutionFiles": [ "src/MyApp.sln" ], "dotrush.roslyn.workspaceProperties": [ "Configuration=Debug", "Platform=AnyCPU" ], "dotrush.roslyn.showItemsFromUnimportedNamespaces": true, "dotrush.roslyn.targetTypedCompletionFilter": true, "dotrush.roslyn.triggerCompletionOnSpace": true, "dotrush.roslyn.skipUnrecognizedProjects": true, "dotrush.roslyn.loadMetadataForReferencedProjects": false, "dotrush.roslyn.restoreProjectsBeforeLoading": true, "dotrush.roslyn.compileProjectsAfterLoading": true, "dotrush.roslyn.compilerDiagnosticsScope": "Project", "dotrush.roslyn.analyzerDiagnosticsScope": "Document", "dotrush.roslyn.diagnosticsFormat": "NoHints", "dotrush.roslyn.dispatcherType": "MultiThread", "dotrush.roslyn.dotnetSdkDirectory": "C:\\Program Files\\dotnet\\sdk\\9.0.201", "dotrush.roslyn.analyzerAssemblies": [ "/path/to/custom/analyzer.dll" ], "dotrush.debugger.projectAssembliesOnly": true, "dotrush.debugger.stepOverPropertiesAndOperators": true, "dotrush.debugger.searchMicrosoftSymbolServer": false, "dotrush.debugger.automaticSourcelinkDownload": true, "dotrush.debugger.symbolSearchPaths": [ "/path/to/symbols" ], "dotrush.debugger.console": "integratedTerminal", "dotrush.debugger.launchBrowser": true, "dotrush.msbuild.noRestore": false, "dotrush.msbuild.noDependencies": false, "dotrush.msbuild.additionalBuildArguments": [ "-v:minimal", "-maxcpucount" ], "dotrush.testExplorer.preLaunchTask": "dotrush: Build", "dotrush.testExplorer.runSettingsPath": "./test.runsettings" } ``` -------------------------------- ### Implement NUnit Tests for Test Explorer Source: https://context7.com/janeysprings/dotrush/llms.txt Demonstrates a standard NUnit test class structure. These tests are automatically discovered by the VS Code Test Explorer when using DotRush. ```csharp using NUnit.Framework; namespace MyProject.Tests { [TestFixture] public class CalculatorTests { private Calculator _calculator; [SetUp] public void Setup() { _calculator = new Calculator(); } [Test] public void Add_TwoPositiveNumbers_ReturnsSum() { var result = _calculator.Add(2, 3); Assert.That(result, Is.EqualTo(5)); } [Test] [TestCase(10, 5, 5)] [TestCase(0, 0, 0)] [TestCase(-5, -3, -2)] public void Subtract_VariousNumbers_ReturnsCorrectDifference(int a, int b, int expected) { var result = _calculator.Subtract(a, b); Assert.That(result, Is.EqualTo(expected)); } [Test] [Ignore("Work in progress")] public void Divide_ByZero_ThrowsException() { Assert.Throws(() => _calculator.Divide(10, 0)); } } } ``` -------------------------------- ### Command Palette Commands Source: https://context7.com/janeysprings/dotrush/llms.txt DotRush exposes various commands through the VS Code command palette. These can be invoked programmatically or assigned to keyboard shortcuts. ```APIDOC ## Command Palette Commands DotRush exposes commands through the VS Code command palette. These commands can be invoked programmatically or bound to keyboard shortcuts. ### Workspace Management Commands - **dotrush.reloadWorkspace**: Reload the Roslyn workspace - **dotrush.pickProjectOrSolutionFiles**: Select project/solution files to load - **dotrush.setStartupProject**: Set active startup project (context menu) - **dotrush.selectActiveConfiguration**: Select build configuration and target framework - **dotrush.buildWorkspace**: Build the entire workspace - **dotrush.createNewProject**: Create new .NET project from template ### Build Operations (Context Menu) - **dotrush.build**: Build selected project/folder - **dotrush.restore**: Restore NuGet packages - **dotrush.clean**: Clean build output ### Debugging Commands - **dotrush.pickProcess**: Show process picker for attach - **dotrush.activeTargetPath**: Get active project's output assembly path - **dotrush.activeTargetBinaryPath**: Get active project's executable path ### Profiling Commands - **dotrush.attachTraceProfiler**: Start dotnet-trace profiling session - **dotrush.createHeapDump**: Create GC heap dump with dotnet-gcdump ### Status Bar Data (for use in launch.json) - **dotrush.activeProjectPath**: Returns active project file path - **dotrush.activeProjectDirectory**: Returns active project directory - **dotrush.activeConfiguration**: Returns active build configuration - **dotrush.activeTargetFramework**: Returns active target framework ### Example Keybindings ```json { "key": "ctrl+shift+b", "command": "dotrush.buildWorkspace" }, { "key": "f6", "command": "dotrush.selectActiveConfiguration" } ``` ``` -------------------------------- ### Define Custom DotRush Tasks Source: https://context7.com/janeysprings/dotrush/llms.txt This configuration defines custom build, restore, and clean tasks for DotRush in VS Code. It utilizes the dotrush.task type to interact with the active project and supports custom MSBuild arguments. ```jsonc { "version": "2.0.0", "tasks": [ { "label": "dotrush: Build", "type": "dotrush.task", "project": "${command:dotrush.activeProjectPath}", "problemMatcher": "$msCompile", "group": { "kind": "build", "isDefault": true } }, { "label": "Build Release", "type": "dotrush.task", "project": "${workspaceFolder}/src/MyApp/MyApp.csproj", "args": [ "-c:Release", "-p:PublishSingleFile=true" ], "problemMatcher": "$msCompile" }, { "label": "dotrush: Restore", "type": "dotrush.task", "project": "${command:dotrush.activeProjectPath}", "problemMatcher": [] }, { "label": "dotrush: Clean", "type": "dotrush.task", "project": "${command:dotrush.activeProjectPath}", "problemMatcher": [] } ] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.