lib/ruby_lsp/requests/support/common.rb in ruby-lsp-0.12.3 vs lib/ruby_lsp/requests/support/common.rb in ruby-lsp-0.12.4
- old
+ new
@@ -7,11 +7,14 @@
module Common
# WARNING: Methods in this class may be used by Ruby LSP addons such as
# https://github.com/Shopify/ruby-lsp-rails, or addons by created by developers outside of Shopify, so be
# cautious of changing anything.
extend T::Sig
+ extend T::Helpers
+ requires_ancestor { Kernel }
+
sig { params(node: Prism::Node).returns(Interface::Range) }
def range_from_node(node)
loc = node.location
Interface::Range.new(
@@ -64,15 +67,32 @@
),
data: data,
)
end
- sig { params(title: String, entries: T::Array[RubyIndexer::Entry]).returns(Interface::MarkupContent) }
+ sig { params(file_path: String).returns(T.nilable(T::Boolean)) }
+ def defined_in_gem?(file_path)
+ DependencyDetector.instance.typechecker && BUNDLE_PATH && !file_path.start_with?(T.must(BUNDLE_PATH)) &&
+ !file_path.start_with?(RbConfig::CONFIG["rubylibdir"])
+ end
+
+ sig { params(node: Prism::CallNode).returns(T::Boolean) }
+ def self_receiver?(node)
+ receiver = node.receiver
+ receiver.nil? || receiver.is_a?(Prism::SelfNode)
+ end
+
+ sig do
+ params(
+ title: String,
+ entries: T.any(T::Array[RubyIndexer::Entry], RubyIndexer::Entry),
+ ).returns(Interface::MarkupContent)
+ end
def markdown_from_index_entries(title, entries)
markdown_title = "```ruby\n#{title}\n```"
definitions = []
content = +""
- entries.each do |entry|
+ Array(entries).each do |entry|
loc = entry.location
# We always handle locations as zero based. However, for file links in Markdown we need them to be one
# based, which is why instead of the usual subtraction of 1 to line numbers, we are actually adding 1 to
# columns. The format for VS Code file URIs is