Class: RubyLsp::Extension
- Inherits:
-
Object
- Object
- RubyLsp::Extension
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/ruby_lsp/extension.rb
Overview
To register an extension, inherit from this class and implement both ‘name` and `activate`
# Example
“‘ruby module MyGem
class MyExtension < Extension
def activate
# Perform any relevant initialization
end
def name
"My extension name"
end
end
end “‘
Class Method Summary collapse
Instance Method Summary collapse
- #activate ⇒ Object
- #add_error(error) ⇒ Object
- #backtraces ⇒ Object
- #error? ⇒ Boolean
- #formatted_errors ⇒ Object
-
#initialize ⇒ Extension
constructor
A new instance of Extension.
- #name ⇒ Object
Constructor Details
permalink #initialize ⇒ Extension
Returns a new instance of Extension.
67 68 69 |
# File 'lib/ruby_lsp/extension.rb', line 67 def initialize @errors = T.let([], T::Array[StandardError]) end |
Class Method Details
permalink .extensions ⇒ Object
[View source]
39 40 41 |
# File 'lib/ruby_lsp/extension.rb', line 39 def extensions @extensions ||= T.let([], T.nilable(T::Array[Extension])) end |
permalink .inherited(child_class) ⇒ Object
[View source]
33 34 35 36 |
# File 'lib/ruby_lsp/extension.rb', line 33 def inherited(child_class) extensions << child_class.new super end |
permalink .load_extensions ⇒ Object
[View source]
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ruby_lsp/extension.rb', line 45 def load_extensions # Require all extensions entry points, which should be placed under # `some_gem/lib/ruby_lsp/your_gem_name/extension.rb` Gem.find_files("ruby_lsp/**/extension.rb").each do |extension| require File.(extension) rescue => e warn(e.) warn(e.backtrace.to_s) # rubocop:disable Lint/RedundantStringCoercion end # Activate each one of the discovered extensions. If any problems occur in the extensions, we don't want to # fail to boot the server extensions.each do |extension| extension.activate nil rescue => e extension.add_error(e) end end |
Instance Method Details
permalink #activate ⇒ Object
[View source]
98 |
# File 'lib/ruby_lsp/extension.rb', line 98 def activate; end |
permalink #add_error(error) ⇒ Object
[View source]
72 73 74 75 |
# File 'lib/ruby_lsp/extension.rb', line 72 def add_error(error) @errors << error self end |
permalink #backtraces ⇒ Object
[View source]
91 92 93 |
# File 'lib/ruby_lsp/extension.rb', line 91 def backtraces @errors.filter_map(&:backtrace).join("\n\n") end |
permalink #error? ⇒ Boolean
78 79 80 |
# File 'lib/ruby_lsp/extension.rb', line 78 def error? @errors.any? end |
permalink #formatted_errors ⇒ Object
[View source]
83 84 85 86 87 88 |
# File 'lib/ruby_lsp/extension.rb', line 83 def formatted_errors <<~ERRORS #{name}: #{@errors.map(&:).join("\n")} ERRORS end |
permalink #name ⇒ Object
[View source]
102 |
# File 'lib/ruby_lsp/extension.rb', line 102 def name; end |