Skip to content

Commit

Permalink
Merge branch 'main' into md-private-class-method
Browse files Browse the repository at this point in the history
  • Loading branch information
kcdragon authored Nov 20, 2024
2 parents ff65115 + fc2d91c commit 649ff6d
Show file tree
Hide file tree
Showing 58 changed files with 1,038 additions and 450 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ruby-lsp (0.21.4)
ruby-lsp (0.22.1)
language_server-protocol (~> 3.17.0)
prism (>= 1.2, < 2.0)
rbs (>= 3, < 4)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.21.4
0.22.1
2 changes: 1 addition & 1 deletion exe/ruby-lsp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ rescue OptionParser::InvalidOption => e
exit(1)
end

# When we're running without bundler, then we need to make sure the custom bundle is fully configured and re-execute
# When we're running without bundler, then we need to make sure the composed bundle is fully configured and re-execute
# using `BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle exec ruby-lsp` so that we have access to the gems that are a part of
# the application's bundle
if ENV["BUNDLE_GEMFILE"].nil?
Expand Down
3 changes: 0 additions & 3 deletions exe/ruby-lsp-launcher
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ rescue StandardError => e
# If Bundler.setup fails, we need to restore the original $LOAD_PATH so that we can still require the Ruby LSP server
# in degraded mode
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
ensure
require "fileutils"
FileUtils.rm(bundle_env_path) if File.exist?(bundle_env_path)
end

error_path = File.join(".ruby-lsp", "install_error")
Expand Down
44 changes: 14 additions & 30 deletions jekyll/add-ons.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ module RubyLsp
"0.1.0"
end

def create_hover_listener(response_builder, node_context, index, dispatcher)
def create_hover_listener(response_builder, node_context, dispatcher)
# Use the listener factory methods to instantiate listeners with parameters sent by the LSP combined with any
# pre-computed information in the add-on. These factory methods are invoked on every request
Hover.new(client, response_builder, @config, dispatcher)
Hover.new(response_builder, @config, dispatcher)
end
end

Expand All @@ -222,10 +222,7 @@ module RubyLsp
# to this object, which will then build the Ruby LSP's response.
# Additionally, listeners are instantiated with a message_queue to push notifications (not used in this example).
# See "Sending notifications to the client" for more information.
def initialize(client, response_builder, config, dispatcher)
super(dispatcher)

@client = client
def initialize(response_builder, config, dispatcher)
@response_builder = response_builder
@config = config

Expand Down Expand Up @@ -274,15 +271,11 @@ This is how you could write an enhancement to teach the Ruby LSP to understand t
class MyIndexingEnhancement < RubyIndexer::Enhancement
# This on call node handler is invoked any time during indexing when we find a method call. It can be used to insert
# more entries into the index depending on the conditions
def on_call_node_enter(owner, node, file_path, code_units_cache)
return unless owner
def on_call_node_enter(node)
return unless @listener.current_owner

# Get the ancestors of the current class
ancestors = @index.linearized_ancestors_of(owner.name)

# Return early unless the method call is the one we want to handle and the class invoking the DSL inherits from
# our library's parent class
return unless node.name == :my_dsl_that_creates_methods && ancestors.include?("MyLibrary::ParentClass")
# Return early unless the method call is the one we want to handle
return unless node.name == :my_dsl_that_creates_methods

# Create a new entry to be inserted in the index. This entry will represent the declaration that is created via
# meta-programming. All entries are defined in the `entry.rb` file.
Expand All @@ -293,28 +286,19 @@ class MyIndexingEnhancement < RubyIndexer::Enhancement
# Create the array of signatures that this method will accept. Every signatures is composed of a list of
# parameters. The parameter classes represent each type of parameter
signatures = [
Entry::Signature.new([Entry::RequiredParameter.new(name: :a)])
RubyIndexer::Entry::Signature.new([RubyIndexer::Entry::RequiredParameter.new(name: :a)])
]

new_entry = Entry::Method.new(
"new_method", # The name of the method that gets created via meta-programming
file_path, # The file_path where the DSL call was found. This should always just be the file_path received
location, # The Prism node location where the DSL call was found
location, # The Prism node location for the DSL name location. May or not be the same
nil, # The documentation for this DSL call. This should always be `nil` to ensure lazy fetching of docs
@index.configuration.encoding, # The negotiated encoding. This should always be `indexing.configuration.encoding`
signatures, # All signatures for this method (every way it can be invoked)
Entry::Visibility::PUBLIC, # The method's visibility
owner, # The method's owner. This is almost always going to be the same owner received
@listener.add_method(
"new_method", # Name of the method
location, # Prism location for the node defining this method
signatures # Signatures available to invoke this method
)

# Push the new entry to the index
@index.add(new_entry)
end

# This method is invoked when the parser has finished processing the method call node.
# It can be used to perform cleanups like popping a stack...etc.
def on_call_node_leave(owner, node, file_path, code_units_cache); end
def on_call_node_leave(node); end
end
```
Expand All @@ -326,7 +310,7 @@ module RubyLsp
class Addon < ::RubyLsp::Addon
def activate(global_state, message_queue)
# Register the enhancement as part of the indexing process
@index.register_enhancement(MyIndexingEnhancement.new(@index))
global_state.index.register_enhancement(MyIndexingEnhancement.new(global_state.index))
end

def deactivate
Expand Down
1 change: 0 additions & 1 deletion jekyll/design-and-roadmap.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ Interested in contributing? Check out the issues tagged with [help-wanted] or [g
- [Add rename support]
- [Add show type hierarchy support]
- [Show index view on the VS Code extension allowing users to browse indexed gems]
- Remove custom bundle in favor of using bundler-compose
- [Add more refactoring code actions such as extract to method, extract to class/module, etc]
- [Explore speeding up indexing by caching the index for gems]
- Explore speeding up indexing by making Prism AST allocations lazy
Expand Down
13 changes: 13 additions & 0 deletions jekyll/editors.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ mason_lspconfig.setup_handlers {
}
```

{: .important }
> Using Mason to manage your installation of the Ruby LSP may cause errors
Mason installs the Ruby LSP in a folder shared among all your Rubies. Some of the
Ruby LSP dependencies are C extensions, and they rely on the Ruby ABI to look and
act a certain way when they were linked to Ruby. This causes issues when a shared
folder is used.

See [this issue][mason-abi] for further information.

### Additional setup (optional)

`rubyLsp/workspace/dependencies` is a custom method currently supported only in the VS Code plugin.
Expand Down Expand Up @@ -293,3 +303,6 @@ To use it with Ruby LSP, you can override particular configuration items in the
Kate will start an instance of the Ruby LSP server in the background for any Ruby project matching the `rootIndicationFileNames`.
If starting Ruby LSP succeeds, the entries in the LSP-Client menu are activated.
Otherwise the error output can be inspected in the Output window.


[mason-abi]: https://github.com/williamboman/mason.nvim/issues/1292
22 changes: 11 additions & 11 deletions jekyll/troubleshooting.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,8 @@ As an example, the activation script for `zsh` using `rbenv` as a version manage
```

After activating the Ruby version, we then proceed to boot the server gem (`ruby-lsp`). To avoid having users include
the `ruby-lsp` in their `Gemfile`, we currently create a custom bundle under the `.ruby-lsp` directory inside your
project. That directory contains another `Gemfile`, that includes the `ruby-lsp` gem in addition to your project's
dependencies. This approach allows us to automatically detect which formatter your project uses and which gems we need
to index for features such as go to definition.

{: .note }
We are working with the RubyGems/Bundler team to have this type of mechanism properly supported from within
Bundler itself, which is currently being experimented with in a plugin called `bundler-compose`. Once
> `bundler-compose`is production ready, the entire custom bundle created under the `.ruby-lsp` directory will go away
> and we'll rely on Bundler to compose the LOAD_PATH including the `ruby-lsp` gem.
the `ruby-lsp` in their `Gemfile`, we create a [composed
bundle](https://shopify.github.io/ruby-lsp/composed-bundle.html) under the `.ruby-lsp` directory inside your project.

## Common issues

Expand Down Expand Up @@ -88,7 +80,7 @@ More context about this issue on https://github.com/Shopify/vscode-ruby-lsp/issu

### Bundler issues

If the extension successfully activated the Ruby environment, it may still fail when trying to compose the custom bundle
If the extension successfully activated the Ruby environment, it may still fail when trying to compose the composed bundle
to run the server gem. This could be a regular Bundler issue, like not being able to satisfy dependencies due to a
conflicting version requirement, or it could be a configuration issue.

Expand Down Expand Up @@ -127,6 +119,14 @@ that prevents it from responding to new requests coming from the editor. If you
report [here](https://github.com/Shopify/ruby-lsp/issues/new?labels=bug&template=bug_template.yml) including the
steps that led to the server getting stuck.

### Missing Features

If you find that some features are working (such as formatting), but others aren't (such as go to definition),
and are working on a codebase that uses Sorbet, then this may indicate the
[Sorbet LSP isn't running](https://sorbet.org/docs/lsp#instructions-for-specific-language-clients).
To avoid duplicate/conflicting behavior, Ruby LSP disables some features when a Sorbet codebase is detected, with the
intention that Sorbet can provide better accuracy.

### Gem installation locations and permissions

To launch the Ruby LSP server, the `ruby-lsp` gem must be installed. And in order to automatically index your project's
Expand Down
Loading

0 comments on commit 649ff6d

Please sign in to comment.