ruby-lsp 0.7.0 → 0.7.1

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