Module: Vim::Netbeans
- Included in:
- Integration
- Defined in:
- lib/vim/netbeans.rb
Defined Under Namespace
Classes: Event, Message, Reply
Constant Summary
collapse
- SERVER_MUTEX =
Mutex.new
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#port ⇒ Object
Returns the value of attribute port.
86
87
88
|
# File 'lib/vim/netbeans.rb', line 86
def port
@port
end
|
#seqno ⇒ Object
Returns the value of attribute seqno.
107
108
109
|
# File 'lib/vim/netbeans.rb', line 107
def seqno
@seqno
end
|
Instance Method Details
#interpret_message(mess) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/vim/netbeans.rb', line 62
def interpret_message(mess)
if mess.index ':'
event = Event.new(mess)
case event.name
when 'fileOpened'
path = event.rest.first
if event.buffer == 0
send_command(new_buffer(path), 'putBufferNumber', path)
send_command(last_buffer, 'startDocumentListen')
else
@buffers[event.buffer] = path
send_command(event.buffer, 'startDocumentListen')
end
else
mess
end
event
else
reply = Reply.new(mess)
remember_reply reply
reply
end
end
|
#new_seqno ⇒ Object
108
109
110
111
112
113
114
|
# File 'lib/vim/netbeans.rb', line 108
def new_seqno
if @seqno
@seqno += 1
else
@seqno = 1
end
end
|
#remember_reply(reply) ⇒ Object
58
59
60
|
# File 'lib/vim/netbeans.rb', line 58
def remember_reply(reply)
replies[reply.seqno] = reply
end
|
#replies ⇒ Object
54
55
56
|
# File 'lib/vim/netbeans.rb', line 54
def replies
@replies ||= {}
end
|
#send_command(buf, name, *args) ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/vim/netbeans.rb', line 115
def send_command(buf,name,*args)
command = %Q~#{buf}:#{name}!#{new_seqno}~
unless args.empty?
command << ' ' + args.map do |arg|
case arg
when String
%Q~"#{arg.gsub('"','\\"')}"~
when Array arg.length == 2 ? arg.join('/') : arg.join('-')
when true
'T'
when false
'F'
else
arg
end
end.join(' ')
end
send_message command
end
|
#send_function(buf, name) ⇒ Object
137
138
139
140
141
142
143
144
145
|
# File 'lib/vim/netbeans.rb', line 137
def send_function(buf,name)
seq = new_seqno
send_message %Q~#{buf}:#{name}/#{seq}~
while not reply = replies[seq]
sleep 0.005
end
replies.delete(seq)
reply
end
|
#send_message(message) ⇒ Object
147
148
149
150
151
|
# File 'lib/vim/netbeans.rb', line 147
def send_message(message)
SERVER_MUTEX.synchronize do
vim.puts message
end
end
|
#server ⇒ Object
87
88
89
90
91
92
93
94
95
|
# File 'lib/vim/netbeans.rb', line 87
def server
if @server
@server
else
@server = TCPServer.open('localhost', 0)
@port = @server.addr[1]
@server
end
end
|
#vim ⇒ Object
97
98
99
100
101
102
103
104
105
|
# File 'lib/vim/netbeans.rb', line 97
def vim
begin
@vim_session ||= server.accept_nonblock
rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
IO.select([server])
retry
end
return @vim_session
end
|