ruby-lsp 0.7.3 → 0.7.4

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: 5488592df860b1fd1439a1b2780a7d0da850fcb9b9164713fbf5ce07b6e67270
4
+ data.tar.gz: '055789cf32db04550a7bd4f602a4e3d69a96760698c567450eceffde5a7ef152'
5
5
  SHA512:
6
- metadata.gz: 53b879df720b44940dc838245a174bebc08849d6673a9076b612df90a47036e69fdc367cc7e0dc3df934a762758e36cebea2d6c84e4b3e992023f2bf9056b14f
7
- data.tar.gz: 65856714024b1329d693cc49eb3e846af1b7737dfd4f914ddb2b677ddada993cca65f81ec9447605325380aee2564930ee2401efc87e57f9d11e92600533d9ca
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.3
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
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.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