Skip to content

Commit b0d673e

Browse files
committed
WIP: Initial API design
1 parent 13264d3 commit b0d673e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+6846
-22
lines changed

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.4.5

.vscodeignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ vsc-extension-quickstart.md
1212
**/*.map
1313
**/*.ts
1414
**/.vscode-test.*
15+
16+
rubyEnvironmentsApi/**

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@ TODO: this extension is getting extracted from the Ruby LSP.
1313

1414
TODO
1515

16+
```
17+
{
18+
"extensionDependencies": [
19+
"shopify.ruby-environments"
20+
],
21+
"dependencies": {
22+
"@shopify/ruby-environments": "..."
23+
},
24+
}
25+
```
26+
1627
## API
1728

1829
TODO
30+
31+
```
32+
// Import the API
33+
import { RubyEnvironments } from '@shopify/ruby-environments';
34+
35+
// Load the RubyEnvironments API
36+
const rubyEnvApi: RubyEnvironmentsApi = await RubyEnvironmentsApi.getApi();
37+
38+
// Retrieve the resolved Ruby environment.
39+
const rubyEnv = await rubyEnvApi.getEnvironment(vscode.workspace.workspaceFolders[0]);
40+
```

activation.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Using .map.compact just so that it doesn't crash immediately on Ruby 2.6
2+
env = ENV.map do |k, v|
3+
utf_8_value = v.dup.force_encoding(Encoding::UTF_8)
4+
"#{k}RUBY_LSP_VS#{utf_8_value}" if utf_8_value.valid_encoding?
5+
end.compact
6+
env.unshift(RUBY_VERSION, Gem.path.join(","), !!defined?(RubyVM::YJIT))
7+
STDERR.print("RUBY_LSP_ACTIVATION_SEPARATOR#{env.join("RUBY_LSP_FS")}RUBY_LSP_ACTIVATION_SEPARATOR")

chruby_activation.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
# Typically, GEM_HOME points to $HOME/.gem/ruby/version_without_patch. For example, for Ruby 3.2.2, it would be
4+
# $HOME/.gem/ruby/3.2.0. However, chruby overrides GEM_HOME to use the patch part of the version, resulting in
5+
# $HOME/.gem/ruby/3.2.2. In our activation script, we check if a directory using the patch exists and then prefer
6+
# that over the default one.
7+
user_dir = Gem.user_dir
8+
paths = Gem.path
9+
default_dir = Gem.default_dir
10+
11+
if paths.length > 2
12+
paths.delete(default_dir)
13+
paths.delete(user_dir)
14+
first_path = paths[0]
15+
user_dir = first_path if first_path && Dir.exist?(first_path)
16+
end
17+
18+
newer_gem_home = File.join(File.dirname(user_dir), ARGV.first)
19+
gems = Dir.exist?(newer_gem_home) ? newer_gem_home : user_dir
20+
STDERR.print(
21+
[
22+
default_dir,
23+
gems,
24+
!!defined?(RubyVM::YJIT),
25+
RUBY_VERSION
26+
].join("RUBY_LSP_ACTIVATION_SEPARATOR")
27+
)

eslint.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ export default tseslint.config(
3232
"**/dist/",
3333
".vscode-test.mjs",
3434
"esbuild.js",
35+
"rubyEnvironmentsApi"
3536
],
3637
},
3738
{
3839
rules: {
40+
"@typescript-eslint/no-explicit-any": "off",
41+
"@typescript-eslint/no-unsafe-assignment": "off",
42+
"@typescript-eslint/no-unsafe-argument": "off",
43+
"@typescript-eslint/no-unsafe-member-access": "off",
44+
"@typescript-eslint/no-unsafe-return": "off",
3945
"@typescript-eslint/no-unused-vars": [
4046
"error",
4147
{

package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,25 @@
3636
"test": "vscode-test"
3737
},
3838
"devDependencies": {
39+
"@eslint/js": "^9.32.0",
3940
"@types/mocha": "^10.0.10",
4041
"@types/node": "20.x",
42+
"@types/sinon": "^17.0.4",
4143
"@types/vscode": "^1.102.0",
42-
"@eslint/js": "^9.32.0",
43-
"eslint": "^9.30.1",
44-
"typescript-eslint": "^8.38.0",
45-
"eslint-plugin-prettier": "^5.5.3",
46-
"prettier": "^3.6.2",
4744
"@vscode/test-cli": "^0.0.11",
4845
"@vscode/test-electron": "^2.5.2",
4946
"@vscode/vsce": "^3.6.0",
5047
"esbuild": "^0.25.3",
48+
"eslint": "^9.30.1",
49+
"eslint-plugin-prettier": "^5.5.3",
5150
"npm-run-all": "^4.1.5",
5251
"ovsx": "^0.10.5",
53-
"typescript": "^5.8.3"
52+
"prettier": "^3.6.2",
53+
"sinon": "^21.0.0",
54+
"typescript": "^5.8.3",
55+
"typescript-eslint": "^8.38.0"
56+
},
57+
"dependencies": {
58+
"glob": "^11.0.3"
5459
}
5560
}

rubyEnvironmentsApi/.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
src
3+
tsconfig.json

rubyEnvironmentsApi/LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022-present, Shopify Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

rubyEnvironmentsApi/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Ruby environments
2+
3+
This npm module provides a TypeScript API for interacting with Ruby environments VS Code extension.
4+
5+
## Extension Settings
6+
7+
```
8+
{
9+
"extensionDependencies": [
10+
"shopify.ruby-environments"
11+
],
12+
"dependencies": {
13+
"@shopify/ruby-environments": "..."
14+
},
15+
}
16+
```
17+
18+
## API
19+
20+
```
21+
// Import the API
22+
import { RubyEnvironments } from '@shopify/ruby-environments';
23+
24+
// Load the RubyEnvironments API
25+
const rubyEnvApi: RubyEnvironmentsApi = await RubyEnvironmentsApi.getApi();
26+
27+
// Retrieve the resolved Ruby environment.
28+
const rubyEnv = await rubyEnvApi.getEnvironment(vscode.workspace.workspaceFolders[0]);
29+
```

0 commit comments

Comments
 (0)