Commits

abudden committed 614b021

Added extensive debug generation code.

  • Participants
  • Parent commits c319144

Comments (0)

Files changed (17)

autoload/TagHighlight/Debug.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    25/07/2011
+"   Date:    02/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 			\ ]
 
 function! TagHighlight#Debug#GetDebugLevel()
-	let debug_level = TagHighlight#Option#GetOption('DebugLevel')
+	try
+		let debug_level = TagHighlight#Option#GetOption('DebugLevel')
+	catch /Unrecognised option/
+		" Probably loading the option file, so no debug level available
+		" yet, so assume 'Information'
+		let debug_level = 'Information'
+	endtry
 	let debug_num = index(g:TagHighlight#Debug#DebugLevels, debug_level)
 	if debug_num != -1
 		return debug_num
 	return g:TagHighlight#Debug#DebugLevels[debug_level_num]
 endfunction
 
-function! TagHighlight#Debug#Print(str, level)
-	let level_index = index(g:TagHighlight#Debug#DebugLevels, a:level)
-	if level_index == -1
-		level_index = index(g:TagHighlight#Debug#DebugLevels, 'Critical')
+function! TagHighlight#Debug#DebugUpdateTypesFile(filename)
+	" Update the types file with debugging turned on
+	if a:filename ==? 'None'
+		" Force case to be correct
+		let debug_file = 'None'
+	else
+		let debug_file = a:filename
 	endif
-	if level_index <= TagHighlight#Debug#GetDebugLevel()
-		echomsg a:str
-	endif
+
+	let g:TagHighlightSettings['DebugFile'] = debug_file
+	let g:TagHighlightSettings['DebugLevel'] = 'Information'
+
+	call TagHighlight#Generation#UpdateTypesFile(1, 0)
+	let s:SavedTabNr = tabpagenr()
+	let s:SavedWinNr = winnr()
+	tabdo windo call TagHighlight#ReadTypes#ReadTypesAutoDetect()
+	exe 'tabn' s:SavedTabNr
+	exe s:SavedWinNr . "wincmd w"
 endfunction

autoload/TagHighlight/Find.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    25/07/2011
+"   Date:    02/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 "    ProjectConfigFileDirectory:str (NONE)
 
 function! TagHighlight#Find#LocateFile(which, suffix)
+	call TagHLDebug("Locating file " . a:which . " with suffix " . a:suffix, 'Information')
+
 	" a:which is 'TAGS', 'TYPES', 'CONFIG'
 	let default_priority = TagHighlight#Option#GetOption('DefaultDirModePriority')
 	let default_search_wildcards = TagHighlight#Option#GetOption('DefaultDirModeSearchWildcards')
 
+
 	let file = '<afile>'
 	if len(expand(file)) == 0
 		let file = '%'
 	for search_mode in search_priority
 		if search_mode == 'Explicit' && explicit_location != 'NONE'
 			" Use explicit location, overriding everything else
+			call TagHLDebug('Using explicit location', 'Information')
 			let result['Directory'] = explicit_location
 			let result['Filename'] = filename
 		elseif search_mode == 'UpFromCurrent'
 			let dir = fnamemodify('.',':p:h')
 			let result = s:ScanUp(dir, search_wildcards)
 			if has_key(result, 'Directory')
+				call TagHLDebug('Found location with UpFromCurrent', 'Information')
 				let result['Filename'] = filename
 			endif
 		elseif search_mode == 'UpFromFile'
 			let dir = fnamemodify(file,':p:h')
 			let result = s:ScanUp(dir, search_wildcards)
 			if has_key(result, 'Directory')
+				call TagHLDebug('Found location with UpFromFile', 'Information')
 				let result['Filename'] = filename
 			endif
 		elseif search_mode == 'CurrentDirectory'
+			call TagHLDebug('Using current directory', 'Information')
 			let result['Directory'] = fnamemodify(file,':p:h')
 			let result['Filename'] = filename
 		elseif search_mode == 'FileDirectory'
+			call TagHLDebug('Using file directory', 'Information')
 			let result['Directory'] = fnamemodify(file,':p:h')
 			let result['Filename'] = filename
 		endif
 		if has_key(result, 'Directory')
 			let result['FullPath'] = result['Directory'] . '/' . result['Filename']
 			let result['Found'] = 1
+			call TagHLDebug('Found file location', 'Information')
 			if filereadable(result['FullPath'])
+				call TagHLDebug('File exists', 'Information')
 				let result['Exists'] = 1
 			else
+				call TagHLDebug('File does not exist', 'Information')
 				let result['Exists'] = 0
 			endif
 			break
 	endfor
 
 	if ! has_key(result, 'Directory')
+		call TagHLDebug("Couldn't find path", 'Warning')
 		let result = {'Found': 0}
 	endif
 

autoload/TagHighlight/Generation.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    25/07/2011
+"   Date:    02/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 	" Call any PreUpdate hooks
 	let preupdate_hooks = TagHighlight#Option#GetOption('PreUpdateHooks')
 	for preupdate_hook in preupdate_hooks
+		call TagHLDebug("Calling pre-update hook " . preupdate_hook, "Information")
 		exe 'call' preupdate_hook . '()'
 	endfor
 	
 	let ctags_option = TagHighlight#Option#GetOption('CtagsExecutable')
 	if ctags_option == 'None'
 		" Option not set: search for 'ctags' in the path
+		call TagHLDebug("CtagsExecutable not set, searching for 'ctags' in path", "Information")
 		let RunOptions['CtagsExeFull'] = TagHighlight#RunPythonScript#FindExeInPath('ctags')
 	elseif ctags_option =~ '[\\/]'
 		" Option set and includes '/' or '\': must be explicit
 		" path to named executable: just pass to mktypes
+		call TagHLDebug("CtagsExecutable set with path delimiter, using as explicit path", "Information")
 		let RunOptions['CtagsExeFull'] = ctags_option
 	else
 		" Option set but doesn't include path separator: search
 		" in the path
+		call TagHLDebug("CtagsExecutable set without path delimiter, searching in path", "Information")
 		let RunOptions['CtagsExeFull'] = TagHighlight#RunPythonScript#FindExeInPath(ctags_option)
 	endif
 
 		" found, use that directory.  If not, but a types file was found,
 		" use that directory.  If not, but a tag file was found, use that
 		" directory.  If not, use the current directory.
+		call TagHLDebug("No source dir set", "Information")
 		if option_file_info['Found'] == 1
+			call TagHLDebug("Using project config file directory", "Information")
 			let RunOptions['SourceDir'] = option_file_info['Directory']
 		elseif types_file_info['Found'] == 1
+			call TagHLDebug("Using types file directory", "Information")
 			let RunOptions['SourceDir'] = types_file_info['Directory']
 		elseif tag_file_info['Found'] == 1
+			call TagHLDebug("Using tags file directory", "Information")
 			let RunOptions['SourceDir'] = tag_file_info['Directory']
 		else
+			call TagHLDebug("Using current directory", "Information")
 			let RunOptions['SourceDir'] = '.'
 		endif
 	endif
 	
+	call TagHLDebug("Running Generator with options: " . string(RunOptions), "Information")
 	call TagHighlight#RunPythonScript#RunGenerator(RunOptions)
 
 	let postupdate_hooks = TagHighlight#Option#GetOption('PostUpdateHooks')
 	for postupdate_hook in postupdate_hooks
+		call TagHLDebug("Calling post-update hook " . postupdate_hook, "Information")
 		exe 'call' postupdate_hook . '()'
 	endfor
 endfunction

autoload/TagHighlight/Libraries.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    25/07/2011
+"   Date:    02/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 		" Already loaded
 		return
 	endif
+	call TagHLDebug("Loading standard library information", "Information")
 
 	let g:TagHighlightPrivate['LibraryPath'] = g:TagHighlightPrivate['PluginPath'] . '/standard_libraries'
 	let g:TagHighlightPrivate['Libraries'] = {}
 
 	let required_keys = ["LibraryName","TypesFiles","CheckMode","TypesSuffixes"]
 	for library_config in library_config_files
+		call TagHLDebug("Loading information for " . library_config, "Information")
 		let skip = 0
 		let library_details = TagHighlight#LoadDataFile#LoadFile(library_config)
 		for key in required_keys
 			if ! has_key(library_details, key)
-				echomsg "Could not load library from " . library_config
+				call TagHLDebug("Could not load library from " . library_config, "Warning")
 				let skip = 1
 				break
 			endif
 			let library_details['MatchLines'] = 30
 		endif
 		
+		call TagHLDebug("Loaded library: " . string(library_details), "Information")
 		let g:TagHighlightPrivate['Libraries'][library_details['LibraryName']] = library_details
 	endfor
 endfunction
 
 function! TagHighlight#Libraries#FindUserLibraries()
 	" Open any explicitly configured libraries
+	call TagHLDebug("Searching for user libraries", "Information")
 	let user_library_dir = TagHighlight#Option#GetOption('UserLibraryDir')
 	let user_libraries = TagHighlight#Option#GetOption('UserLibraries')
 
+	call TagHLDebug("Library Dir: " . user_library_dir, "Information")
+	call TagHLDebug("Library List: " . string(user_libraries), "Information")
+
 	let libraries_to_load = []
 
 	for library in user_libraries
 		" If it looks like an absolute path, just load it
 		if (library[1] == ':' || library['0'] == '/') && filereadable(library)
+			call TagHLDebug("User library is absolute path: " . library, "Information")
 			let libraries_to_load +=
 						\ [{
 						\     'Name': 'User Library',
 						\ }]
 		" Otherwise, try appending to the library dir
 		elseif filereadable(user_library_dir . '/' . library)
+			call TagHLDebug("User library is relative path: " . library, "Information")
 			let library_path = user_library_dir . '/' . library
 			let libraries_to_load +=
 						\ [{
 						\     'Path': fnamemodify(library_path, '%:p'),
 						\ }]
 		else
-			echomsg "Cannot load user library " . library
+			TagHLDebug("Cannot load user library " . library, "Error")
 		endif
 	endfor
 	return libraries_to_load
 
 function! TagHighlight#Libraries#FindLibraryFiles(suffix)
 	" Should only actually read the libraries once
+	call TagHLDebug("Finding library files for current file with suffix " . a:suffix, "Information")
 	call TagHighlight#Libraries#LoadLibraries()
 
 	let libraries_to_load = []
 	let forced_standard_libraries = TagHighlight#Option#GetOption('ForcedStandardLibraries')
 
 	if TagHighlight#Option#GetOption('DisableStandardLibraries')
+		call TagHLDebug("Standard library loading disabled", "Information")
 		return []
 	endif
 
 	for library in values(g:TagHighlightPrivate['Libraries'])
+		call TagHLDebug("Checking " . library['LibraryName'], "Information")
 		let load = 0
 		if index(library['TypesSuffixes'], a:suffix) != -1
 			" Suffix is in the list of acceptable ones
 			if index(forced_standard_libraries, library['LibraryName']) != -1
-				"echomsg "Library(".library['LibraryName']."): Forced"
+				call TagHLDebug("Library(".library['LibraryName']."): Forced", "Information")
 				let load = 1
 			elseif library['CheckMode'] == 'Always'
-				"echomsg "Library(".library['LibraryName']."): Always"
+				call TagHLDebug("Library(".library['LibraryName']."): Always", "Information")
 				let load = 1
 			elseif library['CheckMode'] == 'MatchStart'
-				"echomsg "Library(".library['LibraryName']."): MatchStart"
+				call TagHLDebug("Library(".library['LibraryName']."): Checking MatchStart", "Information")
 				for matcher in library['MatchREs']
 					call cursor(1,1)
 					if search(matcher, 'nc',library['MatchLines'])
-						"echomsg "Match!"
+						call TagHLDebug("Library(".library['LibraryName']."): Match!", "Information")
 						let load = 1
 						break
 					endif
 				endfor
 			elseif library['CheckMode'] == 'MatchEnd'
-				"echomsg "Library(".library['LibraryName']."): MatchEnd"
+				call TagHLDebug("Library(".library['LibraryName']."): Checking MatchEnd", "Information")
 				for matcher in library['MatchREs']
 					call cursor(1000000,1000000)
 					if search(matcher, 'ncb', library['MatchLines'])
-						"echomsg "Match!"
+						call TagHLDebug("Library(".library['LibraryName']."): Match!", "Information")
 						let load = 1
 						break
 					endif
 				endfor
 			elseif library['CheckMode'] == 'Custom'
-				"echomsg "Library(".library['LibraryName']."): Custom (".library['CustomFunction'].")"
+				call TagHLDebug("Library(".library['LibraryName']."): Custom (".library['CustomFunction'].")", "Information")
 				" The hope is that this won't really ever be used, but
 				" call the function and check that it returns the right
 				" kind of thing (takes suffix as parameter)
 				exe 'let result = ' . library['CustomFunction'] . '(' . a:suffix . ')'
 				if result == 'Load'
+					call TagHLDebug("Custom result: Load", "Information")
 					let load = 1
 				elseif result == 'Skip'
+					call TagHLDebug("Custom result: Skip", "Information")
 					" Pass
 				else
-					echoerr "Misconfigured library: custom function has invalid return value"
+					call TagHLDebug("Misconfigured library: custom function has invalid return value", "Critical")
 				endif
 			endif
 		endif
 							\ }]
 			endfor
 		else
-			"echomsg "No match:" . library['LibraryName']
+			call TagHLDebug("No match:" . library['LibraryName'], "Information")
 		endif
 	endfor
 

autoload/TagHighlight/LoadDataFile.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    25/07/2011
+"   Date:    02/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 				" Clear the top key as this isn't a multi-line entry
 				let top_key = ''
 			else
-				echoerr "  Unhandled line: '" . entry . "'"
+				call TagHLDebug("  Unhandled line: '" . entry . "'", "Error")
 			endif
 		elseif entry[0] == "\t" && top_key != ''
 			" This is a continuation of a top level key
 				" The key is a dictionary, check for mismatch:
 				if has_key(result, top_key)
 					if type(result[top_key]) != type({})
-						echoerr "Type mismatch on line '".entry."': expected key:value"
+						call TagHLDebug("Type mismatch on line '".entry."': expected key:value", "Error")
 					endif
 				else
 					let result[top_key] = {}
 				" This is a list of strings, check for mismatch
 				if has_key(result, top_key)
 					if type(result[top_key]) != type([])
-						echoerr "Type mismatch on line '".entry."': didn't expect key:value"
+						call TagHLDebug("Type mismatch on line '".entry."': didn't expect key:value", "Error")
 					endif
 				else
 					let result[top_key] = []

autoload/TagHighlight/Option.vim

 endtry
 let g:loaded_TagHLOption = 1
 
-" TODO: Options should be customisable per project (following the same method
-" as looking for tags/types... look for options file).
-
 let s:log_defaults = 1
 let g:TagHighlightOptionDefaults = {}
 

autoload/TagHighlight/ReadTypes.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    25/07/2011
+"   Date:    02/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 
 function! TagHighlight#ReadTypes#ReadTypesAutoDetect()
 	let extension = expand('%:e')
-	" echomsg "Reading types for extension " . extension
+	call TagHLDebug("Reading types for extension " . extension, "Information")
 	for key in keys(g:TagHighlightPrivate['ExtensionLookup'])
 		let regex = '^'.key.'$'
 		if extension =~ regex
 		let file = '%'
 	endif
 
-	" echomsg "Reading types of suffix " . a:suffix . " for file " . file
+	call TagHLDebug("Reading types of suffix " . a:suffix . " for file " . file, "Information")
 
 	if TagHighlight#Option#GetOption('DisableTypeParsing') == 1
-		call TagHighlight#Debug#Print("Type file parsing disabled", 'Status')
+		call TagHLDebug("Type file parsing disabled", 'Status')
 		return
 	endif
 
 	if len(skiplist) > 0
 		let basename = expand(file . ':p:t')
 		if index(skiplist, basename) != -1
-			call TagHighlight#Debug#Print("Skipping file due to basename match", 'Status')
+			call TagHLDebug("Skipping file due to basename match", 'Status')
 			return
 		endif
 		if index(skiplist, fullname) != -1
-			call TagHighlight#Debug#Print("Skipping file due to fullname match", 'Status')
+			call TagHLDebug("Skipping file due to fullname match", 'Status')
 			return
 		endif
 	endif
 	" Call Pre Read hooks (if any)
 	let preread_hooks = TagHighlight#Option#GetOption('PreReadHooks')
 	for preread_hook in preread_hooks
+		call TagHLDebug("Calling pre-read hook " . preread_hook, 'Information')
 		exe 'call' preread_hook . '(fullname, a:suffix)'
 	endfor
 
-	call TagHighlight#Debug#Print("Searching for types file", 'Status')
+	call TagHLDebug("Searching for types file", 'Status')
 
 	" Clear any existing syntax entries
 	for group in g:TagHighlightPrivate['AllTypes']
 	
 	let type_files = TagHighlight#ReadTypes#FindTypeFiles(a:suffix)
 	for fname in type_files
+		call TagHLDebug("Loading type highlighter file " . fname, 'Information')
 		exe 'so' fname
 		let b:TagHighlightLoadedLibraries +=
 					\ [{
 	" Load user libraries
 	let user_library_files = TagHighlight#Libraries#FindUserLibraries()
 	for lib in user_library_files
+		call TagHLDebug("Loading user library type highlighter file " . lib['Path'], 'Information')
 		exe 'so' lib['Path']
 		let b:TagHighlightLoadedLibraries += [lib]
 	endfor
 	" Now load any libraries that are relevant
 	let library_files = TagHighlight#Libraries#FindLibraryFiles(a:suffix)
 	for lib in library_files
+		call TagHLDebug("Loading standard library type highlighter file " . lib['Path'], 'Information')
 		exe 'so' lib['Path']
 		let b:TagHighlightLoadedLibraries += [lib]
 	endfor
 	" Handle any special cases
 	if has_key(g:TagHighlightPrivate['SpecialSyntaxHandlers'], a:suffix)
 		for handler in g:TagHighlightPrivate['SpecialSyntaxHandlers'][a:suffix]
+			call TagHLDebug("Calling special handler " . handler, 'Information')
 			exe 'call' handler . '()'
 		endfor
 	endif
 	" Call Post Read Hooks (if any)
 	let postread_hooks = TagHighlight#Option#GetOption('PostReadHooks')
 	for postread_hook in postread_hooks
+		call TagHLDebug("Calling post-read hook " . postread_hook, 'Information')
 		exe 'call' postread_hook . '(fullname, a:suffix)'
 	endfor
 
 
 function! TagHighlight#ReadTypes#FindTypeFiles(suffix)
 	let results = []
-	" TODO: Currently only searches for a single types file; doesn't look
-	"       for library files
 	let search_result = TagHighlight#Find#LocateFile('TYPES', a:suffix)
 	if search_result['Found'] == 1 && search_result['Exists'] == 1
 		let results += [search_result['FullPath']]

autoload/TagHighlight/RunPythonScript.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    30/07/2011
+"   Date:    02/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 			let syscmd .= arg
 		endif
 	endfor
-	echomsg syscmd
+	call TagHLDebug(syscmd, "Information")
 	let result = system(syscmd)
 	echo result
 	return result
 	" changed.
 	call TagHighlight#RunPythonScript#FindPython()
 
-	echomsg "Using variant: " .s:python_variant
+	call TagHLDebug("Using variant: " .s:python_variant, "Information")
 
 	if index(["if_pyth","if_pyth3"], s:python_variant) != -1
 		let PY = s:python_cmd[0]
 		endfor
 		for check_opt in keys(a:options)
 			if index(handled_options, check_opt) == -1
-				echomsg "Unhandled run option: " . check_opt
+				call TagHLDebug("Unhandled run option: " . check_opt, "Information")
 			endif
 		endfor
 		exe PY 'RunWithOptions(options)'
 				elseif switch[:0] == "-"
 					let as_one = 0
 				else
-					echoerr "Invalid configuration for option " . option['VimOptionMap']
+					call TagHLDebug("Invalid configuration for option " . option['VimOptionMap'], "Error")
 				endif
 				" We can handle this one automatically
 				if option['Type'] == 'bool'
 					let s:python_variant = 'if_pyth3'
 					let s:python_cmd = ['py3']
 				catch
-					" TODO: Debug message
+					call TagHLDebug("Cannot use python3 interface", "Status")
 				endtry
 			elseif variant == 'if_pyth' && has('python')
 				" Check whether the python 2 interface works
 					let s:python_variant = 'if_pyth'
 					let s:python_cmd = ['py']
 				catch
-					" TODO: Debug message
+					call TagHLDebug("Cannot use python2 interface", "Status")
 				endtry
 			elseif variant == 'python'
 				" Try calling an external python
 	endfor
 
 	if s:python_variant != 'None'
-		" Consider checking that it's valid
-		if TagHighlight#Debug#GetDebugLevelName() == 'Information'
-			echomsg "Python variant is " . s:python_variant
-			echomsg "Python Command is " . join(s:python_cmd, " ")
-			echomsg "Python Path is " . s:python_path
-			call TagHighlight#Debug#Print("Python version reported as: " . s:python_version,
-						\ 'Information')
-		endif
+		call TagHLDebug("Python variant is " . s:python_variant, "Information")
+		call TagHLDebug("Python Command is " . join(s:python_cmd, " "), "Information")
+		call TagHLDebug("Python Path is " . s:python_path, "Information")
+		call TagHLDebug("Python version reported as: " . s:python_version,
+					\ 'Information')
 	else
 		throw "Tag highlighter: could not find python (2.6+) or the compiled version of the highlighter."
 	endif

autoload/TagHighlight/SpecialHandlers.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    28/07/2011
+"   Date:    02/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 let g:loaded_TagHLSpecialHandlers = 1
 
 function! TagHighlight#SpecialHandlers#CRainbowHandler()
+	call TagHLDebug("Language handler for rainbow.vim compatibility", "Information")
 	if exists("b:hlrainbow") && ! exists("g:nohlrainbow")
 		" Use a dictionary as a set (a unique item list)
 		let hl_dict = {}
 endfunction
 
 function! TagHighlight#SpecialHandlers#JavaTopHandler()
+	call TagHLDebug("Language handler for javaTop compatibility", "Information")
 	if has_key(g:TagHighlightPrivate['Kinds'], 'java')
 		exe 'syn cluster javaTop add=' . join(values(g:TagHighlightPrivate['Kinds']['java']), ',')
 	endif

doc/TagHighlight.txt

 ==============================================================================
 5. Troubleshooting                       *TagHighlight-troubleshooting*     {{{1
 
-	... TODO
+	A debugging log can be generated by running the command:
+>
+		:UpdateTypesFileDebug /path/to/debug_log.txt
+<
+	This will generate tags (recursively), create a types highlighter file and
+	try to read the relevant types highlighter files for all open files.  All
+	debugging information will be written to /path/to/debug_log.txt.
+
+	If you're having difficulties getting TagHighlight to work, please try
+	running the above command and send a brief description of the symptoms
+	along with a copy of the debug log to me at abudden _AT_ gmail _DOT_ com.
+	I'll do my best to help you get it working as quickly as I can.
 
 ==============================================================================
 6. Feature Wishlist                      *TagHighlight-wishlist*            {{{1
 ==============================================================================
 7. TagHighlight History                *TagHighlight-history*               {{{1
 
+2.0.10: 2nd August 2011    : Added extensive debug stuff.
+
 2.0.9: 30th July 2011      : Attempt to work around python bug 3905 (issue
                              with subprocess when called from GUI
                              application).

plugin/TagHighlight.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    25/07/2011
+"   Date:    02/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 endtry
 let g:loaded_TagHighlight = 1
 
-"let old_versions = globpath(&rtp, 'plugin/ctags_highlighting.vim')
-"if len(old_versions) > 0
-"	echoerr "Legacy ctags highlighter found.  This highlighter is"
-"				\ "intended to replace ctags_highlighter.  See the"
-"				\ "user documentation in doc/TagHighlight.txt for"
-"				\ "more information."
-"	finish
-"endif
+let old_versions = globpath(&rtp, 'plugin/ctags_highlighting.vim')
+if len(old_versions) > 0
+	echoerr "Legacy ctags highlighter found.  This highlighter is"
+				\ "intended to replace ctags_highlighter.  See the"
+				\ "user documentation in doc/TagHighlight.txt for"
+				\ "more information."
+	finish
+endif
 
 if ! exists('g:TagHighlightSettings')
 	let g:TagHighlightSettings = {}
 			\ silent exe 'tabn ' . s:SavedTabNr |
 			\ silent exe s:SavedWinNr . "wincmd w"
 
+command! -nargs=1 UpdateTypesFileDebug call TagHighlight#Debug#DebugUpdateTypesFile(<f-args>)
+
 function! s:LoadLanguages()
 	" This loads the language data files.
 	let language_files = split(glob(g:TagHighlightPrivate['PluginPath'] . '/data/languages/*.txt'), '\n')
 	let g:TagHighlightPrivate['AllTypes'] = sort(keys(tag_names_dict))
 endfunction
 
+function! TagHLDebug(str, level)
+	let level_index = index(g:TagHighlight#Debug#DebugLevels, a:level)
+	if level_index == -1
+		level_index = index(g:TagHighlight#Debug#DebugLevels, 'Critical')
+	endif
+	if level_index <= TagHighlight#Debug#GetDebugLevel()
+		try
+			let debug_file = TagHighlight#Option#GetOption('DebugFile')
+		catch /Unrecognised option/
+			" Probably haven't loaded the option definitions
+			" yet, so assume no debug log file
+			let debug_file = 'None'
+		endtry
+		if debug_file == 'None'
+			echomsg a:str
+		else
+			exe 'redir >>' debug_file
+			silent echo a:str
+			redir END
+		endif
+	endif
+endfunction
+
 call s:LoadLanguages()
 call s:LoadKinds()
 

plugin/TagHighlight/data/options.txt

 	Default:Error
 	Help:Debug level for printing (how much debug output to produce)
 
+debug_file:
+	CommandLineSwitches:--debug-file
+	VimOptionMap:DebugFile
+	Type:string
+	Default:None
+	Help:Debug log file into which messages should be stored
+
 source_root:
 	CommandLineSwitches:-d,--source-root
 	VimOptionMap:SourceDir
 	Default:False
 	Help:Parse the various options and then print the configuration and exit (for debugging)
 
-print_debug:
-	CommandLineSwitches:--print-debug
-	Type:bool
-	Default:False
-	Help:Print debug to console.
-
 # vim: ff=unix:noet

plugin/TagHighlight/module/config.py

 #!/usr/bin/env python
 # Tag Highlighter:
 #   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-#   Date:    25/07/2011
+#   Date:    02/08/2011
 # Copyright: Copyright (C) 2009-2011 A. S. Budden
 #            Permission is hereby granted to use and distribute this code,
 #            with or without modifications, provided that this copyright
 from optparse import Values
 from .utilities import TagHighlightOptionDict
 from .loaddata import LoadFile, LoadDataFile, SetLoadDataDirectory
+from .debug import SetDebugLogFile, SetDebugLogLevel, Debug
 
 config = TagHighlightOptionDict()
 
     global config
     for key in new_options:
         config[key] = new_options[key]
+    if 'debug_level' in config:
+        SetDebugLogLevel(config['debug_level'])
+    if 'debug_file' in config:
+        SetDebugLogFile(config['debug_file'])
 
 def LoadLanguages():
     global config
         config['language_list'] = full_language_list
     else:
         config['language_list'] = [i for i in full_language_list if i in config['languages']]
-    if config['print_debug']:
-        print("Languages:\n\t{0!r}\n\t{1!r}".format(full_language_list, config['language_list']))
+    Debug("Languages:\n\t{0!r}\n\t{1!r}".format(full_language_list, config['language_list']), "Information")
 
 SetDataDirectories()
 LoadVersionInfo()

plugin/TagHighlight/module/ctags_interface.py

 #!/usr/bin/env python
 # Tag Highlighter:
 #   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-#   Date:    25/07/2011
+#   Date:    02/08/2011
 # Copyright: Copyright (C) 2009-2011 A. S. Budden
 #            Permission is hereby granted to use and distribute this code,
 #            with or without modifications, provided that this copyright
 import glob
 from .utilities import DictDict
 from .languages import Languages
+from .debug import Debug
 
 field_processor = re.compile(
 r'''
 field_const = re.compile(r'\bconst\b')
 
 def GenerateTags(options):
-    print("Generating Tags")
+    Debug("Generating Tags", "Information")
 
     args = GetCommandArgs(options)
 
                         if short_kind not in languages.GetLanguageHandler(key)['SkipList']:
                             ctags_entries[key][kind].add(keyword)
                     except KeyError:
-                        print("Unrecognised kind '{kind}' for language {language}".format(kind=m.group('kind'), language=key))
+                        Debug("Unrecognised kind '{kind}' for language {language}".format(kind=m.group('kind'), language=key), "Error")
     p.close()
 
     return ctags_entries

plugin/TagHighlight/module/debug.py

+#!/usr/bin/env python
+# Tag Highlighter:
+#   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
+#   Date:    02/08/2011
+# Copyright: Copyright (C) 2009-2011 A. S. Budden
+#            Permission is hereby granted to use and distribute this code,
+#            with or without modifications, provided that this copyright
+#            notice is copied with it. Like anything else that's free,
+#            the TagHighlight plugin is provided *as is* and comes with no
+#            warranty of any kind, either expressed or implied. By using
+#            this plugin, you agree that in no event will the copyright
+#            holder be liable for any damages resulting from the use
+#            of this software.
+
+# ---------------------------------------------------------------------
+from __future__ import print_function
+
+import os
+
+debug_log_levels = ('Critical', 'Error', 'Warning', 'Status', 'Information', 'None')
+debug_log_file = None
+debug_log_level = 'None'
+
+def SetDebugLogFile(filename):
+    global debug_log_file
+    debug_log_file = filename
+
+def SetDebugLogLevel(level):
+    global debug_log_level
+    debug_log_level = level
+
+def Debug(msg, level):
+    if level not in debug_log_levels:
+        raise Exception("Invalid log level: " + level)
+    this_index = debug_log_levels.index(level)
+    current_index = debug_log_levels.index(debug_log_level)
+
+    if this_index > current_index:
+        return
+
+    if debug_log_file is None:
+        print(msg)
+    else:
+        fh = open(debug_log_file, 'a')
+        fh.write(msg)
+        fh.write("\n")
+        fh.close()

plugin/TagHighlight/module/generation.py

 #!/usr/bin/env python
 # Tag Highlighter:
 #   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-#   Date:    25/07/2011
+#   Date:    02/08/2011
 # Copyright: Copyright (C) 2009-2011 A. S. Budden
 #            Permission is hereby granted to use and distribute this code,
 #            with or without modifications, provided that this copyright
 import os
 import re
 from .utilities import GenerateValidKeywordRange, IsValidKeyword
+from .debug import Debug
 
 vim_synkeyword_arguments = [
         'contains',
     tag_types = list(tags.keys())
     tag_types.sort()
 
-    print("Writing types file\n")
+    Debug("Writing types file", "Information")
 
     language_handler = options['language_handler'].GetLanguageHandler(language)
 
     if options['check_keywords']:
         iskeyword = GenerateValidKeywordRange(language_handler['IsKeyword'])
-        if options['print_debug']:
-            print("Is Keyword is {0!r}".format(iskeyword))
+        Debug("Is Keyword is {0!r}".format(iskeyword), "Information")
 
     matchEntries = set()
     vimtypes_entries = []
                                 matchDone = True
                                 break
 
-                    if not matchDone and options['debug_level'] == 'Information':
-                        print("Skipping keyword '" + keyword + "'")
+                    if not matchDone:
+                        Debug("Skipping keyword '" + keyword + "'", "Information")
 
                     continue
 
     else:
         type_file_name = options['types_file_prefix'] + '_' + language_handler['Suffix'] + '.' + options['types_file_extension']
     filename = os.path.join(options['types_file_location'], type_file_name)
-    print("Filename is {0}\n".format(filename))
+    Debug("Filename is {0}\n".format(filename), "Information")
 
     try:
         # Have to open in binary mode as we want to write with Unix line endings
         # The resulting file will then work with any Vim (Windows, Linux, Cygwin etc)
         fh = open(filename, 'wb')
     except IOError:
-        sys.stderr.write("ERROR: Couldn't create {file}\n".format(file=outfile))
+        Debug("ERROR: Couldn't create {file}\n".format(file=outfile), "Error")
         sys.exit(1)
 
     try:
             try:
                 fh.write(line.encode('ascii'))
             except UnicodeDecodeError:
-                print("Error decoding line '{0!r}'".format(line))
+                Debug("Error decoding line '{0!r}'".format(line), "Error")
                 fh.write('echoerr "Types generation error"\n'.encode('ascii'))
             fh.write('\n'.encode('ascii'))
     except IOError:
-        sys.stderr.write("ERROR: Couldn't write {file} contents\n".format(file=outfile))
+        Debug("ERROR: Couldn't write {file} contents\n".format(file=outfile), "Error")
         sys.exit(1)
     finally:
         fh.close()

plugin/TagHighlight/module/languages.py

 
 from .config import config
 from .loaddata import LoadDataFile, LoadFile, GlobData
+from .debug import Debug
 
 class Languages():
     registry = {}