Class: Yoda::Model::CompletionItem
- Inherits:
-
Object
- Object
- Yoda::Model::CompletionItem
- Extended by:
- Forwardable
- Defined in:
- lib/yoda/model/completion_item.rb
Instance Attribute Summary collapse
- #descriptions ⇒ Array<Descriptions::Base> readonly
- #kind ⇒ Symbol readonly
- #prefix ⇒ String readonly
- #range ⇒ Parsing::Range readonly
Instance Method Summary collapse
- #available_kinds ⇒ Symbol
- #edit_text ⇒ String
-
#initialize(description: nil, descriptions: [], range:, kind: nil, prefix: nil) ⇒ CompletionItem
constructor
A new instance of CompletionItem.
- #language_server_kind ⇒ Symbol
- #language_server_range ⇒ {Symbol => { Symbol => Integer } }
- #merge(completion_item) ⇒ FunctionDescription, MultipleFunctionDescription
- #primary_description ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(description: nil, descriptions: [], range:, kind: nil, prefix: nil) ⇒ CompletionItem
Returns a new instance of CompletionItem.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/yoda/model/completion_item.rb', line 24 def initialize(description: nil, descriptions: [], range:, kind: nil, prefix: nil) fail ArgumentError, description if description && !description.is_a?(Descriptions::Base) fail ArgumentError, descriptions unless descriptions.all? { |description| description.is_a?(Descriptions::Base) } fail ArgumentError, range unless range.is_a?(Parsing::Range) fail ArgumentError, kind if !kind.nil? && !available_kinds.include?(kind) @descriptions = ([description] + descriptions).compact @range = range @kind = kind @prefix = prefix || '' end |
Instance Attribute Details
#descriptions ⇒ Array<Descriptions::Base> (readonly)
7 8 9 |
# File 'lib/yoda/model/completion_item.rb', line 7 def descriptions @descriptions end |
#kind ⇒ Symbol (readonly)
13 14 15 |
# File 'lib/yoda/model/completion_item.rb', line 13 def kind @kind end |
#prefix ⇒ String (readonly)
16 17 18 |
# File 'lib/yoda/model/completion_item.rb', line 16 def prefix @prefix end |
#range ⇒ Parsing::Range (readonly)
10 11 12 |
# File 'lib/yoda/model/completion_item.rb', line 10 def range @range end |
Instance Method Details
#available_kinds ⇒ Symbol
45 46 47 |
# File 'lib/yoda/model/completion_item.rb', line 45 def available_kinds %i(method class module constant variable) end |
#edit_text ⇒ String
40 41 42 |
# File 'lib/yoda/model/completion_item.rb', line 40 def edit_text prefix + primary_description.sort_text end |
#language_server_kind ⇒ Symbol
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/yoda/model/completion_item.rb', line 50 def language_server_kind case kind when :constant LanguageServer::Protocol::Constant::CompletionItemKind::VALUE when :method LanguageServer::Protocol::Constant::CompletionItemKind::METHOD when :class LanguageServer::Protocol::Constant::CompletionItemKind::CLASS when :module LanguageServer::Protocol::Constant::CompletionItemKind::MODULE when :variable LanguageServer::Protocol::Constant::CompletionItemKind::VARIABLE else nil end end |
#language_server_range ⇒ {Symbol => { Symbol => Integer } }
72 73 74 |
# File 'lib/yoda/model/completion_item.rb', line 72 def language_server_range range.to_language_server_protocol_range end |
#merge(completion_item) ⇒ FunctionDescription, MultipleFunctionDescription
78 79 80 81 82 83 84 85 |
# File 'lib/yoda/model/completion_item.rb', line 78 def merge(completion_item) self.class.new( descriptions: descriptions + completion_item.descriptions, range: range, kind: kind, prefix: prefix, ) end |
#primary_description ⇒ Object
35 36 37 |
# File 'lib/yoda/model/completion_item.rb', line 35 def primary_description descriptions.first end |
#to_s ⇒ Object
67 68 69 |
# File 'lib/yoda/model/completion_item.rb', line 67 def to_s title end |