ruby-lsp 0.7.3 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dba33af47ce558162b73c39422465b451e4af9e835d9446ff90414de0f44fd66
4
- data.tar.gz: fb9b769fceb2563b2392b6395cb65a17511e5dee9614d8158fb28c5bd5628843
3
+ metadata.gz: 4825b35aef41194e36092d705d02735786950d140842c20d210ae79ece322a00
4
+ data.tar.gz: 980bb51fca93844ec0e2bcf2ce57779441fd90a243bf8dab1c30d6dec683e438
5
5
  SHA512:
6
- metadata.gz: 53b879df720b44940dc838245a174bebc08849d6673a9076b612df90a47036e69fdc367cc7e0dc3df934a762758e36cebea2d6c84e4b3e992023f2bf9056b14f
7
- data.tar.gz: 65856714024b1329d693cc49eb3e846af1b7737dfd4f914ddb2b677ddada993cca65f81ec9447605325380aee2564930ee2401efc87e57f9d11e92600533d9ca
6
+ metadata.gz: 5ce7d7401bf7a817a90b6cabeb3d2da7bcc7115d5cb2bf38d5866d4e30061eab615e1fc5366059e7c46630701e11345eb00ac8a09d171d17864ec7fae2ef5a58
7
+ data.tar.gz: cb90d3684d0ea67aa35b53ff694821ecac2b30d43a878a6b24ac6bed873c8ed1eb284fb94a01f4295abda13a612dc0c757e233e0e6a96b2ab70e08c1ce2ddaf1
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.3
1
+ 0.7.5
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
+ env = { "BUNDLE_GEMFILE" => bundle_gemfile }
29
+ env["BUNDLE_PATH"] = File.expand_path(path, Dir.pwd) if path
30
+ exit exec(env, "bundle exec ruby-lsp #{ARGV.join(" ")}")
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.dup
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
@@ -26,7 +26,7 @@ module RubyLsp
26
26
  params(node: T.any(SyntaxTree::ConstPathRef, SyntaxTree::ConstRef, SyntaxTree::TopConstRef)).returns(String)
27
27
  end
28
28
  def full_constant_name(node)
29
- name = +node.constant.value
29
+ name = node.constant.value.dup
30
30
  constant = T.let(node, SyntaxTree::Node)
31
31
 
32
32
  while constant.is_a?(SyntaxTree::ConstPathRef)
@@ -38,7 +38,10 @@ module RubyLsp
38
38
 
39
39
  sig { params(gem_pattern: Regexp).returns(T::Boolean) }
40
40
  def direct_dependency?(gem_pattern)
41
- Bundler.locked_gems.dependencies.keys.grep(gem_pattern).any?
41
+ Bundler.with_original_env { Bundler.default_gemfile } &&
42
+ Bundler.locked_gems.dependencies.keys.grep(gem_pattern).any?
43
+ rescue Bundler::GemfileNotFound
44
+ false
42
45
  end
43
46
  end
44
47
  end
@@ -120,16 +120,18 @@ module RubyLsp
120
120
  # want to install it in the top level `vendor` and not `.ruby-lsp/vendor`
121
121
  path = Bundler.settings["path"]
122
122
 
123
- command = +""
124
123
  # Use the absolute `BUNDLE_PATH` to prevent accidentally creating unwanted folders under `.ruby-lsp`
125
- command << "BUNDLE_PATH=#{File.expand_path(path, Dir.pwd)} " if path
126
- command << "BUNDLE_GEMFILE=#{bundle_gemfile} " if bundle_gemfile
124
+ env = {}
125
+ env["BUNDLE_GEMFILE"] = bundle_gemfile if bundle_gemfile
126
+ env["BUNDLE_PATH"] = File.expand_path(path, Dir.pwd) if path
127
127
 
128
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
129
  # produce undesired source control changes. If the custom bundle was just created and either `ruby-lsp` or `debug`
130
130
  # weren't a part of the Gemfile, then we need to run `bundle install` for the first time to generate the
131
131
  # Gemfile.lock with them included or else Bundler will complain that they're missing. We can only update if the
132
132
  # custom `.ruby-lsp/Gemfile.lock` already exists and includes both gems
133
+ command = +""
134
+
133
135
  if (@dependencies["ruby-lsp"] && @dependencies["debug"]) ||
134
136
  @custom_bundle_dependencies["ruby-lsp"].nil? || @custom_bundle_dependencies["debug"].nil?
135
137
  # Install gems using the custom bundle
@@ -147,7 +149,7 @@ module RubyLsp
147
149
 
148
150
  # Add bundle update
149
151
  warn("Ruby LSP> Running bundle install for the custom bundle. This may take a while...")
150
- system(command)
152
+ system(env, command)
151
153
  end
152
154
  end
153
155
  end
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.3
4
+ version: 0.7.5
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-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: language_server-protocol