Class: Yoda::Model::CompletionItem

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/yoda/model/completion_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description: nil, descriptions: [], range:, kind: nil, prefix: nil) ⇒ CompletionItem

Returns a new instance of CompletionItem.

Parameters:

  • descriptions (Array<Descriptions::Base>) (defaults to: [])
  • range (Parsing::Range)
  • kind (Symbol, nil) (defaults to: nil)
  • prefix (String, nil) (defaults to: nil)


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

#descriptionsArray<Descriptions::Base> (readonly)

Returns:



7
8
9
# File 'lib/yoda/model/completion_item.rb', line 7

def descriptions
  @descriptions
end

#kindSymbol (readonly)

Returns:

  • (Symbol)


13
14
15
# File 'lib/yoda/model/completion_item.rb', line 13

def kind
  @kind
end

#prefixString (readonly)

Returns:

  • (String)


16
17
18
# File 'lib/yoda/model/completion_item.rb', line 16

def prefix
  @prefix
end

#rangeParsing::Range (readonly)

Returns:



10
11
12
# File 'lib/yoda/model/completion_item.rb', line 10

def range
  @range
end

Instance Method Details

#available_kindsSymbol

Returns:

  • (Symbol)


45
46
47
# File 'lib/yoda/model/completion_item.rb', line 45

def available_kinds
  %i(method class module constant variable)
end

#edit_textString

Returns:

  • (String)


40
41
42
# File 'lib/yoda/model/completion_item.rb', line 40

def edit_text
  prefix + primary_description.sort_text
end

#language_server_kindSymbol

Returns:

  • (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 } }

Returns:

  • ({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

Parameters:

  • function_description (FunctionDescription)

Returns:

  • (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_descriptionObject



35
36
37
# File 'lib/yoda/model/completion_item.rb', line 35

def primary_description
  descriptions.first
end

#to_sObject



67
68
69
# File 'lib/yoda/model/completion_item.rb', line 67

def to_s
  title
end