Class: CompleteCode

Inherits:
ArcadiaExt
  • Object
show all
Defined in:
ext/ae-complete-code/ae-complete-code.rb

Instance Method Summary collapse

Instance Method Details

#candidates(_file, _line, _col) ⇒ Object

def do_editor_event(_event)

case _event.signature 
		when EditorContract::COMPLETE_CODE
		  if _event.context.file     		
		    _event.context.candidates = candidates(_event.context.file, _event.context.line, _event.context.col)
		    _event.handled(self)
			 end
end

end



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'ext/ae-complete-code/ae-complete-code.rb', line 53

def candidates(_file, _line, _col)
begin
  _options = "--completion-class-info --line="+_line+" --column="+_col
  #_options = "--line="+_line+" --column="+_col
    _cmp_s = "|ruby "+@complete_command+" "+_options+" "+_file
    _ret = nil
    open(_cmp_s,"r") do
      |f|
      _ret = f.readlines.collect!{| line | line.chomp}
      #p _ret
    end
    if _ret.length == 0
      _cmp_s_d = _cmp_s+" 2>&1"
     _error = nil
     open(_cmp_s_d,"r") do
	       |f|
	       _error = f.readlines.collect!{| line | line.chomp}
   		 end
   		 if _error != nil && _error.length > 0
    			Arcadia.new_error_msg(self, "Syntax error in current source")
      end
    end
    _ret
		rescue Exception => e
			 Arcadia.new_error_msg(self, e.to_s)
  end
end

#full_command(_command = 'rct-complete') ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'ext/ae-complete-code/ae-complete-code.rb', line 23

def full_command(_command='rct-complete')
	_ret = nil
	RUBY_PLATFORM.include?('win32') ? _sep = ';':_sep=':'
	ENV['PATH'].split(_sep).each{|_path|
		_file = File.join(_path, _command)
		if FileTest.exist?(_file)
  			_ret = _file
		end
	}
	_ret
end

#on_after_build(_event) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'ext/ae-complete-code/ae-complete-code.rb', line 10

def on_after_build(_event) 
  @complete_command=full_command('rct-complete')
  @doc_command=full_command('rct-doc')
  @ri_command="ri -T -f plain"
  @finder_command="rct-meth-args -n"
  if @complete_command !=nil #system(@rct_complete+" "+__FILE__)
   		Arcadia.add_listener(self, CompleteCodeEvent)
   		#ArcadiaContractListener.new(self, EditorContract, :do_editor_event)
   else
  		 Arcadia.new_error_msg(self, "Warning: Extension ae-complete-code depend upon rct-complete(rcodetools) command (install it or update system path!)")
   end
end

#on_complete_code(_event) ⇒ Object



35
36
37
38
39
40
41
# File 'ext/ae-complete-code/ae-complete-code.rb', line 35

def on_complete_code(_event)
  if _event.file
    _event.add_result(self,'candidates'=>candidates(_event.file, _event.row, _event.col))
#	    _event.results << CompleteCodeEvent::CompleteCodeResult.new(self)
#	    _event.results[0].candidates = candidates(_event.file, _event.row, _event.col)
  end
end