ruby-lsp 0.7.2 → 0.7.4

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: d58ee884d1824478d6c0823475b061ca15ac7b28046969a98b0e27643fb943a0
4
- data.tar.gz: c90b7a8dbcd675625a28d23cc42d8821b6fe701ce66fb417f885a013c289cd61
3
+ metadata.gz: 5488592df860b1fd1439a1b2780a7d0da850fcb9b9164713fbf5ce07b6e67270
4
+ data.tar.gz: '055789cf32db04550a7bd4f602a4e3d69a96760698c567450eceffde5a7ef152'
5
5
  SHA512:
6
- metadata.gz: e39e30da28ef6118ab12fd1f4d82ca701f1f4f7e3a0f14c51df99b7adc118f81e018aee031e3f36b92423bd20771c82ed4275b3276a4fe6b03a13246acc53070
7
- data.tar.gz: f2d5fa3658bc0bc89ab6fd714f26565b916ef25787e82affdcdd0ff68a3fc31b2a3ffc62fe31ca09c07052e5fe0667fe59bcbfc48d8a563cd893b9c247409dac
6
+ metadata.gz: a3f710de0df843d8c45499b5f818433b9d25b56547d19b2a7cd3896b73ff29c6a6e2be35d091df7d9a7058d9d0d3994dc63898328efa689a198faf864ef61ffc
7
+ data.tar.gz: cc97f72b359d8125269d17cac6d0c8313ca7e2debcae54a81beb270f620b12b100ec89a2bf9c9a82990bb41411a9acf37f76909c09b561bf53eb7fcd74d407b6
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Build Status](https://github.com/Shopify/ruby-lsp/workflows/CI/badge.svg)](https://github.com/Shopify/ruby-lsp/actions/workflows/ci.yml)
2
2
  [![Ruby LSP extension](https://img.shields.io/badge/VS%20Code-Ruby%20LSP-success?logo=visual-studio-code)](https://marketplace.visualstudio.com/items?itemName=Shopify.ruby-lsp)
3
- [![Ruby DX Slack](https://img.shields.io/badge/Slack-Ruby%20DX-success?logo=slack)](https://join.slack.com/t/ruby-dx/shared_invite/zt-1s6f4y15t-v9jedZ9YUPQLM91TEJ4Gew)
3
+ [![Ruby DX Slack](https://img.shields.io/badge/Slack-Ruby%20DX-success?logo=slack)](https://join.slack.com/t/ruby-dx/shared_invite/zt-1zjp7lmgk-zL7bGvze8gj5hFaYS~r5vg)
4
4
 
5
5
  # Ruby LSP
6
6
 
@@ -9,7 +9,7 @@ for Ruby, used to improve rich features in editors. It is a part of a wider goal
9
9
  experience to Ruby developers using modern standards for cross-editor features, documentation and debugging.
10
10
 
11
11
  Want to discuss Ruby developer experience? Consider joining the public
12
- [Ruby DX Slack workspace](https://join.slack.com/t/ruby-dx/shared_invite/zt-1s6f4y15t-v9jedZ9YUPQLM91TEJ4Gew).
12
+ [Ruby DX Slack workspace](https://join.slack.com/t/ruby-dx/shared_invite/zt-1zjp7lmgk-zL7bGvze8gj5hFaYS~r5vg).
13
13
 
14
14
  ## Usage
15
15
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.7.4
data/exe/ruby-lsp CHANGED
@@ -1,6 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ # We should make sure that, if we're running on a bundler project, that it has a Gemfile.lock
5
+ if File.exist?("Gemfile") && !File.exist?("Gemfile.lock")
6
+ warn("Project contains a Gemfile, but no Gemfile.lock. Run `bundle install` to lock gems and restart the server")
7
+ exit(78)
8
+ end
9
+
4
10
  # When we're running without bundler, then we need to make sure the custom bundle is fully configured and re-execute
5
11
  # using `BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle exec ruby-lsp` so that we have access to the gems that are a part of
6
12
  # the application's bundle
@@ -12,7 +18,16 @@ if ENV["BUNDLE_GEMFILE"].nil? && File.exist?("Gemfile.lock")
12
18
  # However, we still want to run the server with `bundle exec`. We need to make sure we're pointing to the right
13
19
  # `Gemfile`
14
20
  bundle_gemfile = File.exist?(".ruby-lsp/Gemfile") ? ".ruby-lsp/Gemfile" : "Gemfile"
15
- exit exec("BUNDLE_GEMFILE=#{bundle_gemfile} bundle exec ruby-lsp #{ARGV.join(" ")}")
21
+
22
+ # In addition to BUNDLE_GEMFILE, we also need to make sure that BUNDLE_PATH is absolute and not relative. For example,
23
+ # if BUNDLE_PATH is `vendor/bundle`, we want the top level `vendor/bundle` and not `.ruby-lsp/vendor/bundle`.
24
+ # Expanding to get the absolute path ensures we're pointing to the correct folder, which is the same one we use in
25
+ # SetupBundler to install the gems
26
+ path = Bundler.settings["path"]
27
+
28
+ command = +"BUNDLE_GEMFILE=#{bundle_gemfile} bundle exec ruby-lsp #{ARGV.join(" ")}"
29
+ command.prepend("BUNDLE_PATH=#{File.expand_path(path, Dir.pwd)} ") if path
30
+ exit exec(command)
16
31
  end
17
32
 
18
33
  require "sorbet-runtime"
@@ -170,10 +170,15 @@ module RubyLsp
170
170
  when "textDocument/definition"
171
171
  definition(uri, request.dig(:params, :position))
172
172
  when "rubyLsp/textDocument/showSyntaxTree"
173
- { ast: Requests::ShowSyntaxTree.new(@store.get(uri)).run }
173
+ show_syntax_tree(uri, request.dig(:params, :range))
174
174
  end
175
175
  end
176
176
 
177
+ sig { params(uri: String, range: T.nilable(Document::RangeShape)).returns({ ast: String }) }
178
+ def show_syntax_tree(uri, range)
179
+ { ast: Requests::ShowSyntaxTree.new(@store.get(uri), range).run }
180
+ end
181
+
177
182
  sig { params(uri: String, position: Document::PositionShape).returns(T.nilable(Interface::Location)) }
178
183
  def definition(uri, position)
179
184
  document = @store.get(uri)
@@ -7,9 +7,6 @@ module RubyLsp
7
7
  module Requests
8
8
  # ![Code lens demo](../../code_lens.gif)
9
9
  #
10
- # This feature is currently experimental. Clients will need to pass `experimentalFeaturesEnabled`
11
- # in the initialization options to enable it.
12
- #
13
10
  # The
14
11
  # [code lens](https://microsoft.github.io/language-server-protocol/specification#textDocument_codeLens)
15
12
  # request informs the editor of runnable commands such as tests
@@ -7,7 +7,7 @@ module RubyLsp
7
7
  #
8
8
  # Show syntax tree is a custom [LSP
9
9
  # request](https://microsoft.github.io/language-server-protocol/specification#requestMessage) that displays the AST
10
- # for the current document in a new tab.
10
+ # for the current document or for the current selection in a new tab.
11
11
  #
12
12
  # # Example
13
13
  #
@@ -20,14 +20,57 @@ module RubyLsp
20
20
  class ShowSyntaxTree < BaseRequest
21
21
  extend T::Sig
22
22
 
23
+ sig { params(document: Document, range: T.nilable(Document::RangeShape)).void }
24
+ def initialize(document, range)
25
+ super(document)
26
+
27
+ @range = range
28
+ end
29
+
23
30
  sig { override.returns(String) }
24
31
  def run
25
32
  return "Document contains syntax error" if @document.syntax_error?
33
+ return ast_for_range if @range
26
34
 
27
35
  output_string = +""
28
36
  PP.pp(@document.tree, output_string)
29
37
  output_string
30
38
  end
39
+
40
+ private
41
+
42
+ sig { returns(String) }
43
+ def ast_for_range
44
+ range = T.must(@range)
45
+
46
+ scanner = @document.create_scanner
47
+ start_char = scanner.find_char_position(range[:start])
48
+ end_char = scanner.find_char_position(range[:end])
49
+
50
+ queue = T.cast(@document.tree, SyntaxTree::Program).statements.body
51
+ found_nodes = []
52
+
53
+ until queue.empty?
54
+ node = queue.shift
55
+ next unless node
56
+
57
+ loc = node.location
58
+
59
+ # If the node is fully covered by the selection, then we found one of the nodes to be displayed and don't want
60
+ # to continue descending into its children
61
+ if (start_char..end_char).cover?(loc.start_char..loc.end_char)
62
+ found_nodes << node
63
+ else
64
+ queue.unshift(*node.child_nodes)
65
+ end
66
+ end
67
+
68
+ found_nodes.map do |node|
69
+ output_string = +""
70
+ PP.pp(node, output_string)
71
+ output_string
72
+ end.join("\n")
73
+ end
31
74
  end
32
75
  end
33
76
  end
@@ -17,6 +17,14 @@ module RubyLsp
17
17
  def initialize(project_path)
18
18
  @project_path = project_path
19
19
  @dependencies = T.let(load_dependencies, T::Hash[String, T.untyped])
20
+ @custom_bundle_dependencies = T.let(
21
+ if File.exist?(".ruby-lsp/Gemfile.lock")
22
+ Bundler::LockfileParser.new(Bundler.read_file(".ruby-lsp/Gemfile.lock")).dependencies
23
+ else
24
+ {}
25
+ end,
26
+ T::Hash[String, T.untyped],
27
+ )
20
28
  end
21
29
 
22
30
  sig { void }
@@ -31,6 +39,11 @@ module RubyLsp
31
39
  # Do not setup a custom bundle if both `ruby-lsp` and `debug` are already in the Gemfile
32
40
  if @dependencies["ruby-lsp"] && @dependencies["debug"]
33
41
  warn("Ruby LSP> Skipping custom bundle setup since both `ruby-lsp` and `debug` are already in the Gemfile")
42
+
43
+ # If the user decided to add the `ruby-lsp` and `debug` to their Gemfile after having already run the Ruby LSP,
44
+ # then we need to remove the `.ruby-lsp` folder, otherwise we will run `bundle install` for the top level and
45
+ # try to execute the Ruby LSP using the custom bundle, which will fail since the gems are not installed there
46
+ FileUtils.rm_r(".ruby-lsp") if Dir.exist?(".ruby-lsp")
34
47
  run_bundle_install
35
48
  return
36
49
  end
@@ -112,7 +125,13 @@ module RubyLsp
112
125
  command << "BUNDLE_PATH=#{File.expand_path(path, Dir.pwd)} " if path
113
126
  command << "BUNDLE_GEMFILE=#{bundle_gemfile} " if bundle_gemfile
114
127
 
115
- if @dependencies["ruby-lsp"] && @dependencies["debug"]
128
+ # If both `ruby-lsp` and `debug` are already in the Gemfile, then we shouldn't try to upgrade them or else we'll
129
+ # produce undesired source control changes. If the custom bundle was just created and either `ruby-lsp` or `debug`
130
+ # weren't a part of the Gemfile, then we need to run `bundle install` for the first time to generate the
131
+ # Gemfile.lock with them included or else Bundler will complain that they're missing. We can only update if the
132
+ # custom `.ruby-lsp/Gemfile.lock` already exists and includes both gems
133
+ if (@dependencies["ruby-lsp"] && @dependencies["debug"]) ||
134
+ @custom_bundle_dependencies["ruby-lsp"].nil? || @custom_bundle_dependencies["debug"].nil?
116
135
  # Install gems using the custom bundle
117
136
  command << "bundle install "
118
137
  else
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.2
4
+ version: 0.7.4
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-18 00:00:00.000000000 Z
11
+ date: 2023-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: language_server-protocol