ensime_bridge 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/ensime_bridge.rb +36 -27
- metadata +1 -1
    
        data/lib/ensime_bridge.rb
    CHANGED
    
    | @@ -32,8 +32,8 @@ class EnsimeBridge | |
| 32 32 | 
             
                    end
         | 
| 33 33 | 
             
                    @ensime = Ensime.new(path)
         | 
| 34 34 | 
             
                    @queue = Queue.new
         | 
| 35 | 
            -
                    @ | 
| 36 | 
            -
             | 
| 35 | 
            +
                    Dir.mkdir @cache if not File.exists?(@cache)
         | 
| 36 | 
            +
                    @logger = Logger.new(@cache+"bridge.log", 2, 100000)
         | 
| 37 37 | 
             
                end
         | 
| 38 38 | 
             
                def remote_stop
         | 
| 39 39 | 
             
                    if is_running?
         | 
| @@ -86,41 +86,37 @@ class EnsimeBridge | |
| 86 86 | 
             
                    @logger.info result.gsub("\n", "")
         | 
| 87 87 | 
             
                    return true
         | 
| 88 88 | 
             
                end
         | 
| 89 | 
            -
                def  | 
| 90 | 
            -
                    return if @no_ensime_config
         | 
| 91 | 
            -
                    @ensime.quiet = quiet
         | 
| 92 | 
            -
                    @ensime.run
         | 
| 93 | 
            -
                    if is_running?
         | 
| 94 | 
            -
                        @logger.info "bridge is already running"
         | 
| 95 | 
            -
                        return
         | 
| 96 | 
            -
                    end
         | 
| 97 | 
            -
                    wait_for_ensime
         | 
| 98 | 
            -
                    @logger.info "ensime is ready"
         | 
| 89 | 
            +
                def run_ensime_connection
         | 
| 99 90 | 
             
                    Thread.new do
         | 
| 100 91 | 
             
                        EventMachine.run do
         | 
| 101 92 | 
             
                            connect_to_ensime
         | 
| 102 93 | 
             
                        end
         | 
| 103 94 | 
             
                    end
         | 
| 95 | 
            +
                end
         | 
| 96 | 
            +
                def send_command command
         | 
| 97 | 
            +
                    while true
         | 
| 98 | 
            +
                        result = nil
         | 
| 99 | 
            +
                        @logger.info "command: #{command}"
         | 
| 100 | 
            +
                        if command.start_with? "{"
         | 
| 101 | 
            +
                            @logger.info "direct send #{command}"
         | 
| 102 | 
            +
                            @socket.send command
         | 
| 103 | 
            +
                        else
         | 
| 104 | 
            +
                            result = instance_eval command
         | 
| 105 | 
            +
                        end
         | 
| 106 | 
            +
                        if command == "unqueue"
         | 
| 107 | 
            +
                            break if not send_result result
         | 
| 108 | 
            +
                        else
         | 
| 109 | 
            +
                            break
         | 
| 110 | 
            +
                        end
         | 
| 111 | 
            +
                    end
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
                def run_forwarder
         | 
| 104 114 | 
             
                    server = TCPServer.new "localhost", 0
         | 
| 105 115 | 
             
                    File.write(@bridge_file, server.addr[1])
         | 
| 106 116 | 
             
                    while @client = server.accept
         | 
| 107 117 | 
             
                        begin
         | 
| 108 118 | 
             
                            command = @client.readline.chomp
         | 
| 109 | 
            -
                             | 
| 110 | 
            -
                                result = nil
         | 
| 111 | 
            -
                                @logger.info "command: #{command}"
         | 
| 112 | 
            -
                                if command.start_with? "{"
         | 
| 113 | 
            -
                                    @logger.info "direct send #{command}"
         | 
| 114 | 
            -
                                    @socket.send command
         | 
| 115 | 
            -
                                else
         | 
| 116 | 
            -
                                    result = instance_eval command
         | 
| 117 | 
            -
                                end
         | 
| 118 | 
            -
                                if command == "unqueue"
         | 
| 119 | 
            -
                                    break if not send_result result
         | 
| 120 | 
            -
                                else
         | 
| 121 | 
            -
                                    break
         | 
| 122 | 
            -
                                end
         | 
| 123 | 
            -
                            end
         | 
| 119 | 
            +
                            send_command command
         | 
| 124 120 | 
             
                            @client.close
         | 
| 125 121 | 
             
                        rescue => e
         | 
| 126 122 | 
             
                            @logger.error e
         | 
| @@ -128,5 +124,18 @@ class EnsimeBridge | |
| 128 124 | 
             
                        end
         | 
| 129 125 | 
             
                    end
         | 
| 130 126 | 
             
                end
         | 
| 127 | 
            +
                def run
         | 
| 128 | 
            +
                    return if @no_ensime_config
         | 
| 129 | 
            +
                    @ensime.quiet = quiet
         | 
| 130 | 
            +
                    @ensime.run
         | 
| 131 | 
            +
                    if is_running?
         | 
| 132 | 
            +
                        @logger.info "bridge is already running"
         | 
| 133 | 
            +
                        return
         | 
| 134 | 
            +
                    end
         | 
| 135 | 
            +
                    wait_for_ensime
         | 
| 136 | 
            +
                    @logger.info "ensime is ready"
         | 
| 137 | 
            +
                    run_ensime_connection
         | 
| 138 | 
            +
                    run_forwarder
         | 
| 139 | 
            +
                end
         | 
| 131 140 | 
             
            end
         | 
| 132 141 | 
             
            EnsimeBridge.new(ARGV.size == 0 ? ".ensime" : ARGV[0]).run if __FILE__ == $0
         |