Class: CompleteCode

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

Direct Known Subclasses

RubyCompleteCode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_editor, _row, _col) ⇒ CompleteCode

Returns a new instance of CompleteCode.



374
375
376
377
378
379
380
381
382
# File 'ext/ae-editor/ae-editor.rb', line 374

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.



373
374
375
# File 'ext/ae-editor/ae-editor.rb', line 373

def filter
  @filter
end

Instance Method Details

#candidates(_show_error = false) ⇒ Object



459
460
461
# File 'ext/ae-editor/ae-editor.rb', line 459

def candidates(_show_error = false)
  process_source
end

#focus_word(focus_segment) ⇒ Object



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'ext/ae-editor/ae-editor.rb', line 384

def focus_word(focus_segment)
  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 !["\s","\t",";",",","(","[","{",">"].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)


451
452
453
454
455
456
457
# File 'ext/ae-editor/ae-editor.rb', line 451

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



400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'ext/ae-editor/ae-editor.rb', line 400

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



434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
# File 'ext/ae-editor/ae-editor.rb', line 434

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  ['"','(','[','{',"'",'=','>','<'].include?(can[0..0])
      can = can[1..-1].strip
    end
    @words << can if can != @filter && !@words.include?(can)
    m = _re.match(_txt)
  end
end