Class: CompleteCode

Inherits:
Object
  • Object
show all
Defined in:
ext/ae-editor/ae-editor.rb

Direct Known Subclasses

RubyCompleteCode

Constant Summary collapse

LEFT_CHARS =
['"','(','[','{',"'",'=','>','<',"\\","/",":","+","-"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_editor, _row, _col) ⇒ CompleteCode

Returns a new instance of CompleteCode.


494
495
496
497
498
499
500
501
502
# File 'ext/ae-editor/ae-editor.rb', line 494

def initialize(_editor, _row, _col)
  @editor = _editor
  @source = _editor.text_value
  @row = _row.to_i
  @col = _col.to_i
  @filter=''
  @words = Array.new
  @is_dot = nil
end

Instance Attribute Details

#filterObject (readonly)

Returns the value of attribute filter


493
494
495
# File 'ext/ae-editor/ae-editor.rb', line 493

def filter
  @filter
end

Instance Method Details

#candidates(_show_error = false) ⇒ Object


582
583
584
# File 'ext/ae-editor/ae-editor.rb', line 582

def candidates(_show_error = false)
  process_source
end

#focus_word(focus_segment) ⇒ Object


504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'ext/ae-editor/ae-editor.rb', line 504

def focus_word(focus_segment)
  focus_segment_parts = focus_segment.split
  focus_segment = focus_segment_parts[-1] if focus_segment_parts && focus_segment_parts.length > 1  
  focus_world = ''
  char = focus_segment[-1..-1]
  while [")","]","}"].include?(char) 
    char=focus_segment[-2..-2]
    focus_segment = focus_segment[0..-2]
  end
  j = focus_segment.length - 1
  
  while !LEFT_CHARS.include?(char) && j >= 0
    focus_world = "#{char}#{focus_world}"
    j=j-1
    char = focus_segment[j..j]
  end
  focus_world
end

#is_dot?Boolean

Returns:

  • (Boolean)

574
575
576
577
578
579
580
# File 'ext/ae-editor/ae-editor.rb', line 574

def is_dot?
  if @is_dot == nil
    fline = @editor.text.get('insert linestart', 'insert')
    @is_dot = fline != nil && fline.length > 0 && fline[-1..-1] == '.'
  end
  @is_dot
end

#process_sourceObject


523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'ext/ae-editor/ae-editor.rb', line 523

def process_source
  @source_array = @source.split("\n")
  @focus_line = @source_array[@row-1]
  @focus_line = @focus_line[0..@col] if @focus_line
  @focus_line = '' if @focus_line.nil?
  @focus_world = ''
  if @focus_line && @focus_line.strip.length > 0
    if @focus_line[@col-1..@col-1] == '.'
      #@is_dot=true
      focus_segment = @focus_line[0..@col-2]
    elsif @focus_line.include?('.')
      #@is_dot=true
      focus_segment_array = @focus_line.split('.')
      focus_segment = ''
      focus_segment_array[0..-2].each{|seg|
        if focus_segment.strip.length > 0
          focus_segment = focus_segment+'.'
        end
        focus_segment = focus_segment+seg
      }
      @filter = focus_word(focus_segment_array[-1].strip)
    else
      focus_segment = ''
      @filter = focus_word(@focus_line[0..@col-1].strip)
    end
    @focus_world = focus_word(focus_segment)
  end
  
  if @filter.strip.length > 0 && !is_dot?
    refresh_words
  end
  @words.sort
end

#refresh_wordsObject


557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
# File 'ext/ae-editor/ae-editor.rb', line 557

def refresh_words
  @words.clear
  _re = /[\s\t\n"'(\[\{=><\\\/\:\+\-]#{@filter}[a-zA-Z0-9\-_]*/
  m = _re.match(@source)
  while m && (_txt=m.post_match)
    can = m[0].strip
    if can.include?(' ')
      can = can.split[1].strip
    end
    if  LEFT_CHARS.include?(can[0..0])
      can = can[1..-1].strip
    end
    @words << can if can != @filter && !@words.include?(can)
    m = _re.match(_txt)
  end
end