Module: RText::ContextBuilder

Extended by:
Tokenizer
Defined in:
lib/rtext/context_builder.rb

Overview

The ContextBuilder builds context information for a set of context lines and the cursor position in the current line. The context consists of

  • the context element, i.e. the element surrounding the current cursor position, the element is a new stand-alone element with all parent elements set up to the root, all attributes and non-containment references before the cursor position will be set, values right or below of the current cursor position will be ommitted, the value directly left of the cursor with no space in between will also be ommitted, (it is assumed that the value is currently being completed) references are not being resolved

  • the current feature or nil if it can not be determined if the cursor is inside or directly behind a role label, this label will be ignored (it is assumed that the lable is currently being completed)

  • the completion prefix, this is the word directly left of the cursor

  • flag if cursor is in an array (i.e. within square brackets)

  • flag if the cursor is in the content block of the context element (i.e. within curly braces)

Defined Under Namespace

Classes: Context, ContextInternal, PositionContext

Class Method Summary collapse

Methods included from Tokenizer

tokenize

Class Method Details

.build_context(language, context_lines, position_in_line) ⇒ Object

Builds the context information based on a set of content_lines. Content lines are the RText lines containing the nested command headers in the original order. The cursor is assumed to be in the last context line at column position_in_line



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rtext/context_builder.rb', line 38

def build_context(language, context_lines, position_in_line)
  context_info = fix_context(language, context_lines, position_in_line)
  return nil unless context_info
  element = instantiate_context_element(language, context_info)
  if element
    after_label = false
    if context_info.role
      if context_info.role.is_a?(Integer)
        feature = language.unlabled_arguments(element.class.ecore)[context_info.role] 
      else
        feature = element.class.ecore.eAllStructuralFeatures.find{|f| f.name == context_info.role}
        after_label = true
      end
    else
      feature = nil
    end
    context_info.position.after_label = after_label
    Context.new(element, feature, context_info.prefix, context_info.problem, context_info.position,
                get_line_indent(context_lines.last), get_indent(context_lines))
  else
    context_info.position.after_label = false
    Context.new(nil, nil, context_info.prefix, context_info.problem, context_info.position,
                get_line_indent(context_lines.last), get_indent(context_lines))
  end
end