ruby-lsp 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 812bcf5c0bc5512ad4382440118051b99d79e79d37a2e91e1fbe4341458dd94c
4
- data.tar.gz: 73a83f9e143bde544d72819e0c867182a0bc8b82ff2ef2dc98032aecdc28e825
3
+ metadata.gz: d58ee884d1824478d6c0823475b061ca15ac7b28046969a98b0e27643fb943a0
4
+ data.tar.gz: c90b7a8dbcd675625a28d23cc42d8821b6fe701ce66fb417f885a013c289cd61
5
5
  SHA512:
6
- metadata.gz: 03b1252a63bc78186983a8962b91f2e89efa679e2ee3b4978d655a83e9a6cbdeb6a8171647e416dd4ebf43ae82fc36e04b805444acbc2a7eade386166873026e
7
- data.tar.gz: 443e7b58bd600a27827043915897c1d848fe8f07c00d348677a9322dcff005bdb4427d2ceade5347f8256fbb6a68897f85215bdd563110d02b0a1887abb71224
6
+ metadata.gz: e39e30da28ef6118ab12fd1f4d82ca701f1f4f7e3a0f14c51df99b7adc118f81e018aee031e3f36b92423bd20771c82ed4275b3276a4fe6b03a13246acc53070
7
+ data.tar.gz: f2d5fa3658bc0bc89ab6fd714f26565b916ef25787e82affdcdd0ff68a3fc31b2a3ffc62fe31ca09c07052e5fe0667fe59bcbfc48d8a563cd893b9c247409dac
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.2
data/exe/ruby-lsp CHANGED
@@ -6,6 +6,7 @@
6
6
  # the application's bundle
7
7
  if ENV["BUNDLE_GEMFILE"].nil? && File.exist?("Gemfile.lock")
8
8
  require_relative "../lib/ruby_lsp/setup_bundler"
9
+ RubyLsp::SetupBundler.new(Dir.pwd).setup!
9
10
 
10
11
  # In some cases, like when the `ruby-lsp` is already a part of the bundle, we don't generate `.ruby-lsp/Gemfile`.
11
12
  # However, we still want to run the server with `bundle exec`. We need to make sure we're pointing to the right
@@ -1,86 +1,134 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
4
5
  require "bundler"
5
6
  require "fileutils"
6
- require "pathname"
7
7
 
8
8
  # This file is a script that will configure a custom bundle for the Ruby LSP. The custom bundle allows developers to use
9
9
  # the Ruby LSP without including the gem in their application's Gemfile while at the same time giving us access to the
10
10
  # exact locked versions of dependencies.
11
11
 
12
- # Do not setup a custom bundle if we're working on the Ruby LSP, since it's already included by default
13
- if Pathname.new(Dir.pwd).basename == "ruby-lsp"
14
- warn("Ruby LSP> Skipping custom bundle setup since we're working on the Ruby LSP itself")
15
- return
12
+ module RubyLsp
13
+ class SetupBundler
14
+ extend T::Sig
15
+
16
+ sig { params(project_path: String).void }
17
+ def initialize(project_path)
18
+ @project_path = project_path
19
+ @dependencies = T.let(load_dependencies, T::Hash[String, T.untyped])
20
+ end
21
+
22
+ sig { void }
23
+ def setup!
24
+ # Do not setup a custom bundle if we're working on the Ruby LSP, since it's already included by default
25
+ if File.basename(@project_path) == "ruby-lsp"
26
+ warn("Ruby LSP> Skipping custom bundle setup since we're working on the Ruby LSP itself")
27
+ run_bundle_install
28
+ return
29
+ end
30
+
31
+ # Do not setup a custom bundle if both `ruby-lsp` and `debug` are already in the Gemfile
32
+ if @dependencies["ruby-lsp"] && @dependencies["debug"]
33
+ warn("Ruby LSP> Skipping custom bundle setup since both `ruby-lsp` and `debug` are already in the Gemfile")
34
+ run_bundle_install
35
+ return
36
+ end
37
+
38
+ # Automatically create and ignore the .ruby-lsp folder for users
39
+ FileUtils.mkdir(".ruby-lsp") unless Dir.exist?(".ruby-lsp")
40
+ File.write(".ruby-lsp/.gitignore", "*") unless File.exist?(".ruby-lsp/.gitignore")
41
+
42
+ # Write the custom `.ruby-lsp/Gemfile` if it doesn't exist or if the content doesn't match
43
+ content = custom_gemfile_content
44
+
45
+ unless File.exist?(".ruby-lsp/Gemfile") && File.read(".ruby-lsp/Gemfile") == content
46
+ File.write(".ruby-lsp/Gemfile", content)
47
+ end
48
+
49
+ # If .ruby-lsp/Gemfile.lock already exists and the top level Gemfile.lock hasn't been modified since it was last
50
+ # updated, then we're ready to boot the server
51
+ if File.exist?(".ruby-lsp/Gemfile.lock") &&
52
+ File.stat(".ruby-lsp/Gemfile.lock").mtime > File.stat("Gemfile.lock").mtime
53
+ warn("Ruby LSP> Skipping custom bundle setup since .ruby-lsp/Gemfile.lock already exists and is up to date")
54
+ run_bundle_install(".ruby-lsp/Gemfile")
55
+ return
56
+ end
57
+
58
+ FileUtils.cp("Gemfile.lock", ".ruby-lsp/Gemfile.lock")
59
+ run_bundle_install(".ruby-lsp/Gemfile")
60
+ end
61
+
62
+ private
63
+
64
+ sig { returns(String) }
65
+ def custom_gemfile_content
66
+ parts = [
67
+ "# This custom gemfile is automatically generated by the Ruby LSP.",
68
+ "# It should be automatically git ignored, but in any case: do not commit it to your repository.",
69
+ "",
70
+ "eval_gemfile(File.expand_path(\"../Gemfile\", __dir__))",
71
+ ]
72
+
73
+ unless @dependencies["ruby-lsp"]
74
+ parts << 'gem "ruby-lsp", require: false, group: :development, source: "https://rubygems.org"'
75
+ end
76
+
77
+ unless @dependencies["debug"]
78
+ parts << 'gem "debug", require: false, group: :development, platforms: :mri, source: "https://rubygems.org"'
79
+ end
80
+
81
+ parts.join("\n")
82
+ end
83
+
84
+ sig { returns(T::Hash[String, T.untyped]) }
85
+ def load_dependencies
86
+ # We need to parse the Gemfile.lock manually here. If we try to do `bundler/setup` to use something more
87
+ # convenient, we may end up with issues when the globally installed `ruby-lsp` version mismatches the one included
88
+ # in the `Gemfile`
89
+ dependencies = Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock")).dependencies
90
+
91
+ # When working on a gem, the `ruby-lsp` might be listed as a dependency in the gemspec. We need to make sure we
92
+ # check those as well or else we may get version mismatch errors
93
+ gemspec_path = Dir.glob("*.gemspec").first
94
+ if gemspec_path
95
+ gemspec_dependencies = Bundler.load_gemspec(gemspec_path).dependencies.to_h { |dep| [dep.name, dep] }
96
+ dependencies.merge!(gemspec_dependencies)
97
+ end
98
+
99
+ dependencies
100
+ end
101
+
102
+ sig { params(bundle_gemfile: T.untyped).void }
103
+ def run_bundle_install(bundle_gemfile = nil)
104
+ # If the user has a custom bundle path configured, we need to ensure that we will use the absolute and not
105
+ # relative version of it when running `bundle install`. This is necessary to avoid installing the gems under the
106
+ # `.ruby-lsp` folder, which is not the user's intention. For example, if the path is configured as `vendor`, we
107
+ # want to install it in the top level `vendor` and not `.ruby-lsp/vendor`
108
+ path = Bundler.settings["path"]
109
+
110
+ command = +""
111
+ # Use the absolute `BUNDLE_PATH` to prevent accidentally creating unwanted folders under `.ruby-lsp`
112
+ command << "BUNDLE_PATH=#{File.expand_path(path, Dir.pwd)} " if path
113
+ command << "BUNDLE_GEMFILE=#{bundle_gemfile} " if bundle_gemfile
114
+
115
+ if @dependencies["ruby-lsp"] && @dependencies["debug"]
116
+ # Install gems using the custom bundle
117
+ command << "bundle install "
118
+ else
119
+ # If ruby-lsp or debug are not in the Gemfile, try to update them to the latest version
120
+ command << "bundle update "
121
+ command << "ruby-lsp " unless @dependencies["ruby-lsp"]
122
+ command << "debug " unless @dependencies["debug"]
123
+ end
124
+
125
+ # Redirect stdout to stderr to prevent going into an infinite loop. The extension might confuse stdout output with
126
+ # responses
127
+ command << "1>&2"
128
+
129
+ # Add bundle update
130
+ warn("Ruby LSP> Running bundle install for the custom bundle. This may take a while...")
131
+ system(command)
132
+ end
133
+ end
16
134
  end
17
-
18
- # We need to parse the Gemfile.lock manually here. If we try to do `bundler/setup` to use something more convenient, we
19
- # may end up with issues when the globally installed `ruby-lsp` version mismatches the one included in the `Gemfile`
20
- dependencies = Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock")).dependencies
21
-
22
- # When working on a gem, the `ruby-lsp` might be listed as a dependency in the gemspec. We need to make sure we check
23
- # those as well or else we may get version mismatch errors
24
- gemspec_path = Dir.glob("*.gemspec").first
25
- if gemspec_path
26
- gemspec_dependencies = Bundler.load_gemspec(gemspec_path).dependencies.to_h { |dep| [dep.name, dep] }
27
- dependencies.merge!(gemspec_dependencies)
28
- end
29
-
30
- # Do not setup a custom bundle if both `ruby-lsp` and `debug` are already in the Gemfile
31
- if dependencies["ruby-lsp"] && dependencies["debug"]
32
- warn("Ruby LSP> Skipping custom bundle setup since both `ruby-lsp` and `debug` are already in the Gemfile")
33
- return
34
- end
35
-
36
- # Automatically create and ignore the .ruby-lsp folder for users
37
- FileUtils.mkdir(".ruby-lsp") unless Dir.exist?(".ruby-lsp")
38
- File.write(".ruby-lsp/.gitignore", "*") unless File.exist?(".ruby-lsp/.gitignore")
39
-
40
- parts = [
41
- "# This custom gemfile is automatically generated by the Ruby LSP.",
42
- "# It should be automatically git ignored, but in any case: do not commit it to your repository.",
43
- "",
44
- "eval_gemfile(File.expand_path(\"../Gemfile\", __dir__))",
45
- ]
46
-
47
- unless dependencies["ruby-lsp"]
48
- parts << 'gem "ruby-lsp", require: false, group: :development, source: "https://rubygems.org"'
49
- end
50
-
51
- unless dependencies["debug"]
52
- parts << 'gem "debug", require: false, group: :development, platforms: :mri, source: "https://rubygems.org"'
53
- end
54
-
55
- gemfile_content = parts.join("\n")
56
-
57
- unless File.exist?(".ruby-lsp/Gemfile") && File.read(".ruby-lsp/Gemfile") == gemfile_content
58
- File.write(".ruby-lsp/Gemfile", gemfile_content)
59
- end
60
-
61
- # If .ruby-lsp/Gemfile.lock already exists and the top level Gemfile.lock hasn't been modified since it was last
62
- # updated, then we're ready to boot the server
63
- if File.exist?(".ruby-lsp/Gemfile.lock") && File.stat(".ruby-lsp/Gemfile.lock").mtime > File.stat("Gemfile.lock").mtime
64
- warn("Ruby LSP> Skipping custom bundle setup since .ruby-lsp/Gemfile.lock already exists and is up to date")
65
- return
66
- end
67
-
68
- FileUtils.cp("Gemfile.lock", ".ruby-lsp/Gemfile.lock")
69
-
70
- # If the user has a custom bundle path configured, we need to ensure that we will use the absolute and not relative
71
- # version of it when running bundle install. This is necessary to avoid installing the gems under the `.ruby-lsp`
72
- # folder, which is not the user's intention. For example, if path is configured as `vendor`, we want to install it in
73
- # the top level `vendor` and not `.ruby-lsp/vendor`
74
- path = Bundler.settings["path"]
75
-
76
- command = +""
77
- # Use the absolute `BUNDLE_PATH` to prevent accidentally creating unwanted folders under `.ruby-lsp`
78
- command << "BUNDLE_PATH=#{File.expand_path(path, Dir.pwd)} " if path
79
- # Install gems using the custom bundle
80
- command << "BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle install "
81
- # Redirect stdout to stderr to prevent going into an infinite loop. The extension might confuse stdout output with
82
- # responses
83
- command << "1>&2"
84
-
85
- warn("Ruby LSP> Running bundle install for the custom bundle. This may take a while...")
86
- system(command)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-14 00:00:00.000000000 Z
11
+ date: 2023-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: language_server-protocol