Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added syntax files for all windows

  • Loading branch information...
commit 083bba6449eeb448b3a86e638b5847b8eca64120 1 parent 3acdbcc
@joonty authored
View
2  plugin/debugger.vim
@@ -147,8 +147,6 @@ map <Leader>dt :python debugger_command('step_out')<cr>
nnoremap <Leader>e :python debugger_watch_input("eval")<cr>A
vnoremap <Leader>e :python debugger_visual_eval()<cr>A
-nnoremap <cr> :python vdebug.handle_watch_toggle()<cr>
-
map <F5> :python vdebug.run()<cr>
map <F6> :python vdebug.close()<cr>
View
103 plugin/python/dbgp.py
@@ -1,6 +1,7 @@
import xml.etree.ElementTree as ET
import socket
import log
+import base64
""" Response objects for the DBGP module."""
@@ -76,10 +77,20 @@ def get_stack(self):
class ContextGetResponse(Response):
"""Response object used by the context_get command."""
+ properties = []
def get_context(self):
+ for c in self.as_xml().getchildren():
+ self.__create_properties(ContextProperty(c))
+
return self.as_xml().getchildren()
+ def __create_properties(self,property):
+ self.properties.append(property)
+ for p in property.children:
+ self.__create_properties(p)
+
+
class BreakpointSetResponse(Response):
"""Response object returned by the breakpoint_set command."""
@@ -409,11 +420,99 @@ def send_msg(self, cmd):
"""
self.sock.send(cmd + '\0')
-class TimeoutError(Exception):
- pass
+class ContextProperty:
+
+ def __init__(self,node,parent = None,depth = 0):
+ self.parent = parent
+ self.__determine_type(node)
+ self.__determine_displayname(node)
+ self.encoding = node.get('encoding')
+ self.depth = depth
+ self.size = node.get('size')
+ self.value = ""
+ self.is_last_child = False
+
+ self.__determine_children(node)
+
+ if self.encoding == 'base64':
+ if node.text is None:
+ self.value = ""
+ else:
+ self.value = base64.decodestring(node.text)
+ elif not self.is_uninitialized() \
+ and not self.has_children:
+ self.value = node.text
+
+ if self.value is None:
+ self.value = ""
+
+ self.num_crs = self.value.count('\n')
+ if self.type == "string":
+ self.value = '`%s`' % self.value.replace('`','\\`')
+
+ self.__init_children(node)
+
+ def __determine_type(self,node):
+ type = node.get('classname')
+ if type is None:
+ type = node.get('type')
+ self.type = type
+
+ def __determine_displayname(self,node):
+ display_name = node.get('fullname')
+ if display_name == '::':
+ display_name = self.type
+ self.display_name = display_name
+
+ def __determine_children(self,node):
+ children = node.get('children')
+ self.num_declared_children = children
+ if children is None:
+ children = 0
+ else:
+ children = int(children)
+ self.has_children = True if children > 0 else False
+ self.children = []
+
+ def __init_children(self,node):
+ if self.has_children:
+ idx = 0
+ for c in node.getchildren():
+ idx += 1
+ p = ContextProperty(c,self,self.depth+1)
+ self.children.append(p)
+ if idx == self.num_declared_children:
+ p.mark_as_last_child()
+
+ def mark_as_last_child(self):
+ self.is_last_child = True
+
+ def is_uninitialized(self):
+ if self.type == 'uninitialized':
+ return True
+ else:
+ return False
+
+ def child_count(self):
+ return len(self.children)
+
+ def type_and_size(self):
+ size = None
+ if self.has_children:
+ size = self.num_declared_children
+ elif self.size is not None:
+ size = self.size
+
+ if size is None:
+ return self.type
+ else:
+ return "%s [%s]" %(self.type,size)
""" Errors/Exceptions """
+class TimeoutError(Exception):
+ pass
+
class DBGPError(Exception):
"""Raised when the debugger returns an error message."""
View
81 plugin/python/debugger.py
@@ -32,6 +32,16 @@ def handle_socket_end(self):
self.runner.ui.say("Connection to the debugger has been closed")
self.runner.ui.statuswin.set_status("stopped")
+ def handle_vim_error(self,e):
+ self.runner.ui.error("A Vim error occured: "+\
+ str(e)+\
+ "\n"+ traceback.format_exc())
+
+ def handle_general_exception(self):
+ self.runner.ui.error("An error occured: "+\
+ str(sys.exc_info()[0])+\
+ "\n"+ traceback.format_exc())
+
def run(self):
try:
self.runner.run()
@@ -40,33 +50,23 @@ def run(self):
except EOFError:
self.handle_socket_end()
except vim.error, e:
- self.runner.ui.error(str(e)+"\nTraceback: "+\
- traceback.format_exc())
+ self.handle_vim_error(e)
except:
- self.runner.ui.error("An error occured: "+\
- str(sys.exc_info()[0])+\
- "\nTraceback: "+\
- traceback.format_exc())
- #self.runner.close()
- raise
+ self.handle_general_exception()
- def handle_watch_toggle(self):
+ def handle_return_keypress(self):
try:
- self.runner.handle_watch_toggle()
+ return self.runner.handle_return_keypress()
except dbgp.TimeoutError:
self.handle_timeout()
except EOFError:
self.handle_socket_end()
except vim.error, e:
+ self.handle_vim_error(e)
self.runner.ui.error(str(e)+"\nTraceback: "+\
traceback.format_exc())
except:
- self.runner.ui.error("An error occured: "+\
- str(sys.exc_info()[0])+\
- "\nTraceback: "+\
- traceback.format_exc())
- #self.runner.close()
- raise
+ self.handle_general_exception()
def step_over(self):
try:
@@ -76,13 +76,9 @@ def step_over(self):
except EOFError:
self.handle_socket_end()
except vim.error, e:
- self.runner.ui.error(e)
+ self.handle_vim_error(e)
except:
- self.runner.ui.error("An error occured: "+\
- str(sys.exc_info()[0]))
- #self.runner.close()
- raise
-
+ self.handle_general_exception()
def set_breakpoint(self,args = None):
try:
@@ -94,12 +90,9 @@ def set_breakpoint(self,args = None):
except EOFError:
self.handle_socket_end()
except vim.error, e:
- self.runner.ui.error(e)
+ self.handle_vim_error(e)
except:
- self.runner.ui.error("An error occured: "+\
- str(sys.exc_info()[0]))
- #self.runner.close()
- raise
+ self.handle_general_exception()
def close(self):
self.runner.close()
@@ -168,8 +161,8 @@ def run(self):
if not self.is_alive():
self.open()
else:
- self.ui.sourcewin.remove_pointer()
self.ui.statuswin.set_status("running")
+ self.ui.sourcewin.remove_pointer()
self.api.run()
self.refresh()
@@ -177,6 +170,7 @@ def step_over(self):
if not self.is_alive():
self.open()
else:
+ self.ui.statuswin.set_status("running")
self.ui.sourcewin.remove_pointer()
self.api.step_over()
self.refresh()
@@ -192,17 +186,27 @@ def set_breakpoint(self,args):
return
self.breakpoints.add_breakpoint(bp)
- def handle_watch_toggle(self):
- """ Return the number of lines that a property block reaches to."""
- if self.ui.watchwin.name not in vim.current.buffer.name:
- return
- log.Log("Current buffer name: "+vim.current.buffer.name)
+ def handle_return_keypress(self):
+ """ Handle what happens when the user hits return."""
+ if not self.is_alive():
+ return True
lineno = vim.current.window.cursor[0]
- log.Log("Carriage return on line "+str(lineno))
- line = self.ui.watchwin.buffer[lineno-1]
- index = line.find("")
- if index > 0:
- self.handle_open(lineno,line,index)
+ if self.ui.watchwin.name in vim.current.buffer.name:
+ log.Log("Carriage return on line "+str(lineno))
+ line = self.ui.watchwin.buffer[lineno-1]
+ index = line.find("")
+ if index > 0:
+ self.handle_property_get(lineno,line,index)
+ if self.ui.stackwin.name in vim.current.buffer.name:
+ line = self.ui.stackwin.buffer[lineno-1]
+ filename_pos = line.find("\t\t")
+ file_and_line = line[filename_pos:]
+ line_pos = file_and_line.find(":")
+ file = file_and_line[:line_pos]
+ lineno = file_and_line[line_pos+1:]
+ self.ui.sourcewin.set_file(file)
+ self.ui.sourcewin.set_line(lineno)
+
def handle_open(self,lineno,line,pointer_index):
eq_index = line.find('=')
@@ -210,7 +214,6 @@ def handle_open(self,lineno,line,pointer_index):
context_res = self.api.property_get(name)
rend = ui.vimui.ContextGetResponseRenderer(context_res)
output = rend.render(pointer_index - 1)
- log.Log(output)
self.ui.watchwin.insert(output.rstrip(),lineno-1,True)
def listen(self,server,port,timeout):
View
140 plugin/python/ui/vimui.py
@@ -2,7 +2,6 @@
import ui.interface
import vim
import log
-import base64
class Ui(ui.interface.Ui):
"""Ui layer which manages the Vim windows.
@@ -21,7 +20,7 @@ def open(self):
self.watchwin = WatchWindow(self,'vertical belowright new')
self.watchwin.create()
- self.stackwin = StackWindow(self,'belowright 8new')
+ self.stackwin = StackWindow(self,'belowright 5new')
self.stackwin.create()
self.statuswin = StatusWindow(self,'belowright 5new')
@@ -71,7 +70,9 @@ def say(self,string):
log.Log(string,log.Logger.INFO)
def error(self,string):
- vim.command('echohl Error | echo "'+str(string)+'" | echohl None')
+ vim.command('echohl Error | echo "'+\
+ str(string).replace('"','\\"')+\
+ '" | echohl None')
log.Log(string,log.Logger.ERROR)
def close(self):
@@ -121,6 +122,10 @@ def set_file(self,file):
self.focus()
vim.command("silent edit " + file)
+ def set_line(self,lineno):
+ self.focus()
+ vim.command("normal %sgg" % str(lineno))
+
def clear_signs(self):
vim.command('sign unplace *')
@@ -244,17 +249,36 @@ def accept_renderer(self,renderer):
class LogWindow(Window):
name = "Log"
+
+ def on_create(self):
+ self.command('setlocal syntax=debugger_log')
+
def write(self, msg, return_focus = True):
Window.write(self, msg,return_focus=True)
class StackWindow(Window):
name = "Stack"
+
+ def on_create(self):
+ self.command('inoremap <buffer> <cr> <esc>'+\
+ ':python vdebug.handle_return_keypress()<cr>')
+ self.command('nnoremap <buffer> <cr> <esc>'+\
+ ':python vdebug.handle_return_keypress()<cr>')
+ self.command('setlocal syntax=debugger_stack')
+
def write(self, msg, return_focus = True):
Window.write(self, msg, after="normal gg")
class WatchWindow(Window):
name = "Watch"
+ def on_create(self):
+ self.command('inoremap <buffer> <cr> <esc>'+\
+ ':python vdebug.handle_return_keypress()<cr>')
+ self.command('nnoremap <buffer> <cr> <esc>'+\
+ ':python vdebug.handle_return_keypress()<cr>')
+ self.command('setlocal syntax=debugger_watch')
+
def write(self, msg, return_focus = True):
Window.write(self, msg, after="normal gg")
@@ -262,9 +286,10 @@ class StatusWindow(Window):
name = "Status"
def on_create(self):
- self.write("Status: \n\nPress <F5> to start "+\
+ self.write("Status: starting\n\nPress <F5> to start "+\
"debugging, <F6> to stop/close.\nType "+\
":help vim-debugger for more information.")
+ self.command('setlocal syntax=debugger_status')
def set_status(self,status):
self.insert("Status: "+str(status),0,True)
@@ -288,85 +313,6 @@ def render(self):
string += line + "\n"
return string
-class ContextProperty:
-
- def __init__(self,node,parent = None,depth = 0):
- self.parent = parent
- self.display_name = node.get('fullname')
- self.type = node.get('type')
- self.encoding = node.get('encoding')
- self.depth = depth
- self.size = node.get('size')
- self.value = ""
- self.is_last_child = False
-
- children = node.get('children')
- self.num_declared_children = children
- if children is None:
- children = 0
- else:
- children = int(children)
- self.has_children = True if children > 0 else False
- self.children = []
-
- if self.encoding == 'base64':
- if node.text is None:
- self.value = ""
- else:
- self.value = base64.decodestring(node.text)
- elif not self.is_uninitialized() \
- and not self.has_children:
- self.value = node.text
-
- if self.value is None:
- self.value = ""
-
- self.num_crs = self.value.count('\n')
- if self.type == "string":
- self.value = '"%s"' % self.value.replace('"','\\"')
-
- if self.has_children:
- idx = 0
- for c in node.getchildren():
- idx += 1
- p = ContextProperty(c,self,depth+1)
- self.children.append(p)
- if idx == self.num_declared_children:
- p.mark_as_last_child()
-
- def mark_as_last_child(self):
- self.is_last_child = True
-
- def is_uninitialized(self):
- if self.type == 'uninitialized':
- return True
- else:
- return False
-
- def marker(self):
- char = ""
- if self.has_children:
- if self.child_count() == 0:
- char = ""
- else:
- char = ""
- return char
-
- def child_count(self):
- return len(self.children)
-
- def type_and_size(self):
- size = None
- if self.has_children:
- size = self.num_declared_children
- elif self.size is not None:
- size = self.size
-
- if size is None:
- return self.type
- else:
- return "%s [%s]" %(self.type,size)
-
class ContextGetResponseRenderer(ResponseRenderer):
@@ -374,12 +320,9 @@ def __init__(self,response):
ResponseRenderer.__init__(self,response)
def render(self,indent = 0):
- context = self.response.get_context()
- string = ""
- properties = []
- for c in context:
- self.__create_properties(ContextProperty(c),properties)
-
+ res = ""
+ properties = self.response.get_context()
+
num_props = len(properties)
log.Log("Writing %i properties to the context window" % num_props,\
log.Logger.INFO )
@@ -391,14 +334,9 @@ def render(self,indent = 0):
except IndexError:
final = True
next_prop = None
- string += self.__render_property(prop,next_prop,final,indent)
-
- return string
+ res += self.__render_property(prop,next_prop,final,indent)
- def __create_properties(self,property,properties):
- properties.append(property)
- for p in property.children:
- self.__create_properties(p,properties)
+ return res
def __render_property(self,p,next_p,last = False,indent = 0):
line = "%(indent)s %(marker)s %(name)s = (%(type)s) %(value)s\n" \
@@ -424,3 +362,13 @@ def __render_property(self,p,next_p,last = False,indent = 0):
line += "".rjust((depth * 2) - 1 + indent) + " /" + "\n"
return line
+
+ def marker(self):
+ char = "¿"
+ if self.has_children:
+ if self.child_count() == 0:
+ char = "¿"
+ else:
+ char = "¿"
+ return char
+
View
20 syntax/debugger_log.vim
@@ -0,0 +1,20 @@
+" Vim syntax file
+" Language: Vim Debugger Watch
+" Maintainer: Jon Cairns
+" Latest Revision: 2 August 2012
+
+if exists("b:current_syntax")
+ finish
+endif
+
+syn match debuggerLogMarker '^-'
+syn match debuggerLogDebug '\zs\[Debug\]\ze'
+syn match debuggerLogInfo '\zs\[Info\]\ze'
+syn match debuggerLogError '\zs\[ERROR\]\ze'
+syn match debuggerLogDate '\s{.*}\s'
+
+hi def link debuggerLogMarker Type
+hi def link debuggerLogInfo Special
+hi def link debuggerLogDebug Comment
+hi def link debuggerLogError Error
+hi def link debuggerLogDate Comment
View
17 syntax/debugger_stack.vim
@@ -0,0 +1,17 @@
+" Vim syntax file
+" Language: Vim Debugger Watch
+" Maintainer: Jon Cairns
+" Latest Revision: 2 August 2012
+
+if exists("b:current_syntax")
+ finish
+endif
+
+syn match debuggerStackNumberGroup '^\[\d\+\]' contains=debuggerStackNumber
+syn match debuggerStackName '\s\zs\S\+\ze\s'
+syn region debuggerStackFile start=+\s\s.+ end=+$+ contains=debuggerStackLineNumber
+syn match debuggerStackLineNumber ':\zs\d\+\ze' contained
+
+hi def link debuggerStackNumberGroup Type
+hi def link debuggerStackFile String
+hi def link debuggerStackLineNumber Special
View
20 syntax/debugger_status.vim
@@ -0,0 +1,20 @@
+" Vim syntax file
+" Language: Vim Debugger Watch
+" Maintainer: Jon Cairns
+" Latest Revision: 2 August 2012
+
+if exists("b:current_syntax")
+ finish
+endif
+
+syn match debuggerStatusIdentifier '^Status:'
+syn match debuggerStatusBreak '\s\zsbreak\ze'
+syn match debuggerStatusStart '\s\zsrunning\ze'
+syn match debuggerStatusStop '\s\zs\(stopped\|stopping\)\ze'
+syn region debuggerStatusInfo start='Press' end='information.'
+
+hi def link debuggerStatusIdentifier Type
+hi def link debuggerStatusStop Special
+hi def link debuggerStatusBreak Error
+hi def link debuggerStatusStart Constant
+hi def link debuggerStatusInfo Comment
View
34 syntax/debugger_watch.vim
@@ -1,5 +1,5 @@
" Vim syntax file
-" Language: Vim Debugger Watch
+" Language: Vim Debugger debuggerWatch
" Maintainer: Jon Cairns
" Latest Revision: 2 August 2012
@@ -7,18 +7,24 @@ if exists("b:current_syntax")
finish
endif
-syn match watchMarker '^\s\+[^|\/]'
-syn match watchJoiner '^\s\+[|\/^]'
-syn match watchVarName '\s\zs.\+\ze\s='
-syn match watchTypeContainer '=\s\zs\(.*\)\ze\s' contains=watchType,watchSize
-syn match watchType '\w' contained
-syn match watchSize '\[\d\+\]' contained
-syn region watchString start='"' skip='\\"' end='"'
+syn match debuggerWatchMarker '^\s\+[^|\/]'
+syn match debuggerWatchJoiner '^\s\+[|\/^]'
+syn match debuggerWatchNumber '\d\+\.\=\d*'
+syn match debuggerWatchVarName '\s\zs.\+\ze\s=' contains=debuggerWatchStringKey
+syn match debuggerWatchStringKey '\'[^']\+\'' contained
+syn match debuggerWatchTypeContainer '=\s\zs(.*)\ze\s' contains=debuggerWatchType,debuggerWatchSize
+syn match debuggerWatchVarValue ')\zs.*$\ze'
+syn match debuggerWatchType '(\zs[^ )]\+)\ze' contained
+syn match debuggerWatchSize '\[\zs\d\+\ze\]' contained
+syn region debuggerWatchString start=+\s`+ skip=+\\`+ end=+`\s*$+
-hi def link watchMarker Special
-hi def link watchType Type
-hi def link watchString String
-hi def link watchVarName Identifier
-hi def link watchJoiner Structure
-hi def link watchSize Number
+hi def link debuggerWatchMarker Special
+hi def link debuggerWatchTypeContainer Type
+hi def link debuggerWatchType Type
+hi def link debuggerWatchString String
+hi def link debuggerWatchStringKey String
+hi def link debuggerWatchVarName Identifier
+hi def link debuggerWatchJoiner Structure
+hi def link debuggerWatchNumber Number
+hi def link debuggerWatchSize Number
Please sign in to comment.
Something went wrong with that request. Please try again.