Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug buffer, fix a bug #70

Open
wants to merge 3 commits into
base: pathogen-bundle
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions autoload/coqtop.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@
Goal = namedtuple('Goal', ['id', 'hyp', 'ccl'])
Evar = namedtuple('Evar', ['info'])

class Emptylogger:
def log(self, message):
pass

logger = Emptylogger()

def set_debug(l):
global logger
logger = l

def info(message):
global logger
logger.log(message)

def parse_response(xml):
assert xml.tag == 'value'
if xml.get('val') == 'good':
Expand Down Expand Up @@ -159,12 +173,22 @@ def escape(cmd):
.replace("(", '(') \
.replace(")", ')')

# Extract <string> from a <message> element
def parse_message(elt):
for e in elt:
if e.tag == 'string':
return parse_value(e)
# message without string?
return ''

def get_answer():
fd = coqtop.stdout.fileno()
data = ''
info("RESPONSE:")
while True:
try:
data += os.read(fd, 0x4000)
info(data)
try:
elt = ET.fromstring('<coqtoproot>' + escape(data) + '</coqtoproot>')
shouldWait = True
Expand All @@ -176,9 +200,9 @@ def get_answer():
valueNode = c
if c.tag == 'message':
if messageNode is not None:
messageNode = messageNode + "\n\n" + parse_value(c[2])
messageNode = messageNode + "\n\n" + parse_message(c)
else:
messageNode = parse_value(c[2])
messageNode = parse_message(c)
if shouldWait:
continue
else:
Expand All @@ -201,6 +225,8 @@ def call(name, arg, encoding='utf-8'):
return response

def send_cmd(cmd):
info("SEND CMD:")
info(cmd)
coqtop.stdin.write(cmd)

def restart_coq(*args):
Expand Down
37 changes: 37 additions & 0 deletions autoload/coquille.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@
import vimbufsync
vimbufsync.check_version("0.1.0", who="coquille")

class Logger:
def __init__(self, buf):
self.vim_win = None
for win in vim.windows:
if win.buffer == buf:
self.vim_win = win
break
if self.vim_win:
self.vim_win.buffer[:] = None
self.vim_win.buffer[0] = "START DEBUGGING"
def log(self, message):
if self.vim_win is not None:
for l in message.split('\n'):
self.vim_win.buffer.append(l)
self.vim_win.cursor = (len(self.vim_win.buffer), 0)
ori_win = vim.current.window.number
cmd = "execute %d . 'winc w'\n\
execute %d . 'winc w'" % (self.vim_win.number, ori_win)
vim.command(cmd)

logger = Logger(None)

def set_debug(buf):
global logger
if buf:
logger = Logger(buf)
else:
logger = Logger(None)

#: See vimbufsync ( https://github.com/def-lkb/vimbufsync )
saved_sync = None

Expand Down Expand Up @@ -163,6 +192,8 @@ def coq_raw_query(*args):


def launch_coq(*args):
global logger
CT.set_debug(logger)
CT.restart_coq(*args)

def debug():
Expand Down Expand Up @@ -198,6 +229,12 @@ def show_goal():
print('ERROR: the Coq process died')
return

if isinstance(response, CT.Err):
text = response.err.text
for l in text.split('\n'):
buff.append(l)
return

if response.msg is not None:
info_msg = response.msg

Expand Down
21 changes: 18 additions & 3 deletions autoload/coquille.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ function! coquille#ShowPanels()
setlocal filetype=coq-infos
setlocal noswapfile
let s:info_buf = bufnr("%")
if exists("s:debug")
rightbelow new Debug
setlocal buftype=nofile
setlocal filetype=coq-debug
setlocal noswapfile
let s:debug_buf = bufnr("%")
endif
execute l:winnb . 'winc w'
endfunction

Expand Down Expand Up @@ -86,8 +93,14 @@ function! coquille#Launch(...)
if s:coq_running == 1
echo "Coq is already running"
else
let s:coq_running = 1
call coquille#ShowPanels()
if exists("s:debug_buf")
py coquille.set_debug(vim.buffers[int(vim.eval("s:debug_buf"))])
else
py coquille.set_debug(None)
endif

let s:coq_running = 1
" initialize the plugin (launch coqtop)
py coquille.launch_coq(*vim.eval("map(copy(a:000),'expand(v:val)')"))

Expand All @@ -100,8 +113,6 @@ function! coquille#Launch(...)

command! -buffer -nargs=* Coq call coquille#RawQuery(<f-args>)

call coquille#ShowPanels()

" Automatically sync the buffer when entering insert mode: this is usefull
" when we edit the portion of the buffer which has already been sent to coq,
" we can then rewind to the appropriate point.
Expand All @@ -113,6 +124,10 @@ function! coquille#Launch(...)
endif
endfunction

function! coquille#DebugOn()
let s:debug = 1
endfunction

function! coquille#Register()
hi default CheckedByCoq ctermbg=17 guibg=LightGreen
hi default SentToCoq ctermbg=60 guibg=LimeGreen
Expand Down