@@ -7,12 +7,86 @@ need to activate the Ruby environment in order to launch Ruby executables, such
77
88## Features
99
10- TODO: this extension is getting extracted from the Ruby LSP.
10+ - ** Automatic Ruby detection** : Discovers the Ruby interpreter installed on your machine
11+ - ** Version manager integrations** : Supports popular version managers including:
12+ - [ chruby] ( https://github.com/postmodern/chruby )
13+ - [ rbenv] ( https://github.com/rbenv/rbenv )
14+ - [ rvm] ( https://rvm.io/ )
15+ - [ asdf] ( https://asdf-vm.com/ ) (with ruby plugin)
16+ - [ mise] ( https://mise.jdx.dev/ )
17+ - ** Environment activation** : Composes the correct environment variables (` PATH ` , ` GEM_HOME ` , ` GEM_PATH ` , etc.) to match your shell configuration
18+ - ** JIT detection** : Identifies available JIT compilers (YJIT, ZJIT) for the activated Ruby version
19+ - ** Shell support** : Works with various shells including bash, zsh, fish, and PowerShell
20+ - ** Extension API** : Provides a programmatic API for other extensions to access the activated Ruby environment
1121
1222## Extension Settings
1323
1424TODO
1525
1626## API
1727
18- TODO
28+ This extension exposes an API that other extensions can use to access the activated Ruby environment.
29+
30+ ### Getting the API
31+
32+ ``` typescript
33+ const rubyEnvExtension = vscode .extensions .getExtension (" Shopify.ruby-environments" );
34+
35+ if (rubyEnvExtension ) {
36+ const api = rubyEnvExtension .exports ;
37+ // Use the API...
38+ }
39+ ```
40+
41+ ### Activating the Ruby Environment
42+
43+ Request the extension to activate Ruby for a specific workspace:
44+
45+ ``` typescript
46+ api .activate (vscode .workspace .workspaceFolders ?.[0 ]);
47+ ```
48+
49+ ### Getting the Current Ruby Definition
50+
51+ Retrieve the currently activated Ruby environment:
52+
53+ ``` typescript
54+ const ruby = api .getRuby ();
55+
56+ if (ruby === null ) {
57+ console .log (" Ruby environment not yet activated" );
58+ } else if (ruby .error ) {
59+ console .log (" Ruby activation failed" );
60+ } else {
61+ console .log (` Ruby version: ${ruby .rubyVersion } ` );
62+ console .log (` Available JITs: ${ruby .availableJITs .join (" , " )} ` );
63+ console .log (` GEM_PATH: ${ruby .gemPath .join (" :" )} ` );
64+ }
65+ ```
66+
67+ ### Subscribing to Ruby Environment Changes
68+
69+ Listen for changes to the Ruby environment (e.g., when the user switches Ruby versions):
70+
71+ ``` typescript
72+ const disposable = api .onDidRubyChange ((event ) => {
73+ console .log (` Ruby changed in workspace: ${event .workspace ?.name } ` );
74+
75+ if (! event .ruby .error ) {
76+ console .log (` New Ruby version: ${event .ruby .rubyVersion } ` );
77+ }
78+ });
79+
80+ // Add to your extension's subscriptions for automatic cleanup
81+ context .subscriptions .push (disposable );
82+ ```
83+
84+ ### Extension Dependency
85+
86+ To ensure your extension loads after Ruby Environments, add it as a dependency in your ` package.json ` :
87+
88+ ``` json
89+ {
90+ "extensionDependencies" : [" Shopify.ruby-environments" ]
91+ }
92+ ```
0 commit comments