Commits

abudden committed c891050

Cscope interface for maintaining cscope databases (fixes bitbucket #14).

This makes cscope buffer-local and thereby improves working on multiple
projects with different cscope databases.

Comments (0)

Files changed (8)

autoload/TagHighlight/BufferEntry.vim

 let g:loaded_TagHLBufferEntry = 1
 
 function! TagHighlight#BufferEntry#BufEnter(filename)
-
 	if ! exists('b:TagHighlightPrivate')
 		let b:TagHighlightPrivate = {}
 	endif
+
+	if TagHighlight#Option#GetOption('EnableCscope')
+		call TagHighlight#Cscope#BufEnter()
+	endif
+
 	let b:TagHighlightPrivate['BufEnterInitialised'] = 1
 endfunction
 
 function! TagHighlight#BufferEntry#BufLeave(filename)
-
 	if ! exists('b:TagHighlightPrivate')
 		let b:TagHighlightPrivate = {}
 	endif
+
+	if TagHighlight#Option#GetOption('EnableCscope')
+		call TagHighlight#Cscope#BufLeave()
+	endif
+
 	let b:TagHighlightPrivate['BufLeaveInitialised'] = 1
 endfunction

autoload/TagHighlight/Cscope.vim

+" Tag Highlighter:
+"   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
+" Copyright: Copyright (C) 2013 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.
+
+" ---------------------------------------------------------------------
+try
+	if &cp || v:version < 700 || (exists('g:loaded_TagHLCscope') && (g:plugin_development_mode != 1))
+		throw "Already loaded"
+	endif
+catch
+	finish
+endtry
+let g:loaded_TagHLCscope = 1
+
+function TagHighlight#Cscope#GetConnections()
+	if ! has("cscope")
+		return {}
+	endif
+	let result = {}
+
+	redir => connections
+	silent cs show
+	redir END
+
+	let lines = split(connections, '\n')
+	for entry in lines
+		let matches = matchlist(entry, '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(\k\+\).*')
+		if len(matches) >= 4
+			" Just store the path (likely to be inconclusive due to lack of
+			" explicit path in "cs show" output)
+			let result[matches[1]] = matches[3]
+		endif
+	endfor
+	return result
+endfunction
+
+function! TagHighlight#Cscope#RestoreConnections(connections)
+	if ! has("cscope")
+		return
+	endif
+	for index in keys(a:connections)
+		exe 'cs add' a:connections[index]
+	endfor
+endfunction
+
+let s:PausedConnections = {}
+function! TagHighlight#Cscope#PauseCscope()
+	if ! has("cscope")
+		return
+	endif
+	if ! TagHighlight#Option#GetOption('EnableCscope')
+		return
+	endif
+
+	let s:PausedConnections = TagHighlight#Cscope#GetConnections()
+
+	" Kill all cscope connections
+	cs kill -1
+endfunction
+
+function! TagHighlight#Cscope#ResumeCscope()
+	if ! has("cscope")
+		return
+	endif
+	if ! TagHighlight#Option#GetOption('EnableCscope')
+		return
+	endif
+
+	if has_key(b:TagHighlightPrivate, 'CscopeFileInfo') &&
+				\ b:TagHighlightPrivate['CscopeFileInfo']['Exists']
+		exe 'cs add' b:TagHighlightPrivate['CscopeFileInfo']['FullPath']
+	else
+		let b:TagHighlightPrivate['CscopeFileInfo'] = TagHighlight#Find#LocateFile('CSCOPE', '')
+		if b:TagHighlightPrivate['CscopeFileInfo']['Exists']
+			exe 'cs add' b:TagHighlightPrivate['CscopeFileInfo']['FullPath']
+		else
+			call TagHighlight#Cscope#RestoreConnections(s:PausedConnections)
+		endif
+	endif
+endfunction
+
+function! TagHighlight#Cscope#BufEnter()
+	if ! has("cscope")
+		return
+	endif
+	if ! TagHighlight#Option#GetOption('EnableCscope')
+		return
+	endif
+
+	let b:TagHighlightPrivate['StoredCscopeConnections'] =
+				\ TagHighlight#Cscope#GetConnections()
+	" Kill all connections
+	cs kill -1
+
+	if ! has_key(b:TagHighlightPrivate, 'CscopeFileInfo')
+		let b:TagHighlightPrivate['CscopeFileInfo'] = TagHighlight#Find#LocateFile('CSCOPE', '')
+	endif
+
+	if b:TagHighlightPrivate['CscopeFileInfo']['Exists']
+		exe 'cs add' b:TagHighlightPrivate['CscopeFileInfo']['FullPath']
+	endif
+endfunction
+function! TagHighlight#Cscope#BufLeave()
+	if ! has("cscope")
+		return
+	endif
+	if ! TagHighlight#Option#GetOption('EnableCscope')
+		return
+	endif
+
+	cs kill -1
+	if has_key(b:TagHighlightPrivate, 'StoredCscopeConnections')
+		if len(b:TagHighlightPrivate['StoredCscopeConnections']) > 0
+			call TagHighlight#Cscope#RestoreConnections(b:TagHighlightPrivate['StoredCscopeConnections'])
+		endif
+	endif
+endfunction
+
+function! TagHighlight#Cscope#FindCscopeExe()
+	" Find the cscope path
+	let cscope_option = TagHighlight#Option#GetOption('CscopeExecutable')
+	if cscope_option == 'None'
+		if len(&cscopeprg) > 0
+			let cscope_option = &cscopeprg
+		else
+			let cscope_option = 'cscope'
+		endif
+	endif
+
+	if cscope_option =~ '[\\/]'
+		" Option set and includes '/' or '\': must be explicit
+		" path to named executable: just pass to mktypes
+		call TagHLDebug("CscopeExecutable set with path delimiter, using as explicit path", "Information")
+		let b:TagHighlightSettings['CscopeExeFull'] = cscope_option
+	else
+		" Option set but doesn't include path separator: search
+		" in the path
+		call TagHLDebug("CscopeExecutable set without path delimiter, searching in path", "Information")
+		let b:TagHighlightSettings['CscopeExeFull'] = TagHighlight#RunPythonScript#FindExeInPath(cscope_option)
+	endif
+endfunction

autoload/TagHighlight/Find.vim

 "	TagFileDirModePriority:["Default"] or as above
 "	TypesFileDirModePriority:As tag file
 "	ConfigFileDirModePriority:As tag file
+"	CscopeFileDirModePriority:As tag file
 "	DefaultDirModeSearchWildcard:'' (look for tags file) or something specific (*.uvopt)?
 "	MaxDirSearchLevels: (integer)
 "
 "    TypesPrefix:str (types)
 "    ProjectConfigFileName:str (taghl_config.txt)
 "    ProjectConfigFileDirectory:str (NONE)
+"    CscopeFileName: str (cscope.out)
+"    CscopeFileDirectory: str (NONE)
 
 function! TagHighlight#Find#LocateFile(which, suffix)
 	call TagHLDebug("Locating file " . a:which . " with suffix " . a:suffix, 'Information')
 		let search_priority = TagHighlight#Option#GetOption('ProjectConfigFileDirModePriority')
 		let explicit_location = TagHighlight#Option#GetOption('ProjectConfigFileDirectory')
 		let search_wildcards = TagHighlight#Option#GetOption('ProjectConfigFileSearchWildcards')
+	elseif a:which == 'CSCOPE'
+		" Suffix is ignored here
+		let filename = TagHighlight#Option#GetOption('CscopeFileName')
+		let search_priority = TagHighlight#Option#GetOption('CscopeFileDirModePriority')
+		let explicit_location = TagHighlight#Option#GetOption('CscopeFileDirectory')
+		let search_wildcards = TagHighlight#Option#GetOption('CscopeFileSearchWildcards')
 	else
 		throw "Unrecognised file"
 	endif

autoload/TagHighlight/Generation.vim

 		call TagHLDebug("CtagsExecutable set without path delimiter, searching in path", "Information")
 		let b:TagHighlightSettings['CtagsExeFull'] = TagHighlight#RunPythonScript#FindExeInPath(ctags_option)
 	endif
+	
+	if TagHighlight#Option#GetOption('EnableCscope')
+		call TagHighlight#Cscope#FindCscopeExe()
+	endif
 
 	let tag_file_info = TagHighlight#Find#LocateFile('TAGS', '')
 	if tag_file_info['Found'] == 1
 			call TagHLDebug(" - " . var . ": UNSET", "Information")
 		endif
 	endfor
+
 	let RunOptions = TagHighlight#Option#CopyOptions()
+	if TagHighlight#Option#GetOption('EnableCscope')
+		call TagHighlight#Cscope#PauseCscope()
+		if TagHighlight#Option#GetOption('CscopeOnlyIfPresent')
+			if ! has_key(b:TagHighlightPrivate, 'CscopeFileInfo')
+				let b:TagHighlightPrivate['CscopeFileInfo'] = TagHighlight#Find#LocateFile('CSCOPE', '')
+			endif
+			if ! b:TagHighlightPrivate['CscopeFileInfo']['Exists']
+				let RunOptions['EnableCscope'] = 1
+			endif
+		endif
+	endif
+
 	call TagHighlight#RunPythonScript#RunGenerator(RunOptions)
 
+	if TagHighlight#Option#GetOption('EnableCscope')
+		call TagHighlight#Cscope#ResumeCscope()
+	endif
+
 	let postupdate_hooks = TagHighlight#Option#GetOption('PostUpdateHooks')
 	for postupdate_hook in postupdate_hooks
 		call TagHLDebug("Calling post-update hook " . postupdate_hook, "Information")

doc/TagHighlight.txt

 	2.4.4 Option Details                     |TagHighlight-option-details|
 	2.4.5 Options That I Use                 |TagHighlight-options-i-use|
 	2.5   Integration with Other Software    |TagHighlight-integration|
-	2.5.1 Tagbar Integration                 |TagHighlight-tagbar|
-	2.5.2 Git Integration                    |TagHighlight-git|
-	2.5.3 Bazaar Integration                 |TagHighlight-bazaar|
-	2.5.4 Mercurial Integration              |TagHighlight-mercurial|
-	2.5.5 Subversion Integration             |TagHighlight-subversion|
+	2.5.1 Cscope Integration                 |TagHighlight-cscope|
+	2.5.2 Tagbar Integration                 |TagHighlight-tagbar|
+	2.5.3 Git Integration                    |TagHighlight-git|
+	2.5.4 Bazaar Integration                 |TagHighlight-bazaar|
+	2.5.5 Mercurial Integration              |TagHighlight-mercurial|
+	2.5.6 Subversion Integration             |TagHighlight-subversion|
 	2.6   Installation                       |TagHighlight-install|
 	2.6.1 Requirements                       |TagHighlight-requirements|
 	2.6.2 Installation Guide                 |TagHighlight-install-guide|
 		CtagsExtraArguments              Link:|TagHL-CtagsExtraArguments|
 			Specify a list of extra arguments to pass to ctags.
 
+	Cscope Interface:
+
+		EnableCscope                     Link:|TagHL-EnableCscope|
+			Enable the cscope manager.
+		
+		CscopeExecutable                 Link:|TagHL-CscopeExecutable|
+			Specify the name of (or full path to) cscope.
+
+		CscopeOnlyIfPresent              Link:|TagHL-CscopeOnlyIfPresent|
+			Only generate a new cscope database if one exists already.
+
 	Locations of Files (normal):
 
 		DefaultDirModeSearchWildcards    Link:|TagHL-DirModeSearchWildcards|
 		TagFileSearchWildcards           Link:|TagHL-DirModeSearchWildcards|
 			What to search for when deciding which directory to use.
 
+	Location and name of cscope file:
+
+		CscopeFileDirModePriority        Link:|TagHL-CscopeFileDirModePriority|
+			Which directories to search for cscope database.
+
+		CscopeFileDirectory              Link:|TagHL-CscopeFileDirectory|
+			Explicit location for cscope database.
+
+		CscopeFileName                   Link:|TagHL-CscopeFileName|
+			File name for cscope database.
+
+		CscopeFileSearchWildcards        Link:|TagHL-DirModeSearchWildcards|
+			What to search for when deciding which directory to use.
+
 	Location and name of types file:
 
 		TypesFileDirModePriority         Link:|TagHL-TypesFileDirModePriority|
 		CtagsExeFull                     Link:|TagHL-CtagsExeFull|
 			Internal use only.
 
+		CscopeExeFull                    Link:|TagHL-CscopeExeFull|
+			Internal use only.
+
 		CtagsFileLocation                Link:|TagHL-CtagsFileLocation|
 			Internal use only.
 
 
 2.4.4 Option Details                     *TagHighlight-option-details*      {{{3
 
+	CscopeExecutable                     *TagHL-CscopeExecutable*
+		This option allows you to specify which cscope executable to run.  You
+		can either specify an absolute path (e.g. "/usr/bin/cscope") or the
+		name of an executable in the system path (e.g. "cscope").  By default
+		it will take the name from the 'cscopeprg' option.  It is probably
+		best to leave it this way as cscope probably won't work for you if
+		'cscopeprg' isn't set correctly.  Only relevant if
+		|TagHL-EnableCscope| is set; see |TagHighlight-cscope| for more
+		information.
+
+		Option Type: String
+		Default: Whatever 'cscopeprg' is set to or "cscope".
+
+	CscopeExeFull                        *TagHL-CscopeExeFull*
+		Used internally to tell the python part of the application where
+		cscope is.  Do not use this option as it will be automatically
+		overwritten.  Instead, see |TagHL-CscopeExecutable|.
+
+	CscopeFileDirectory                  *TagHL-CscopeFileDirectory*
+		This option is used to determine which directories to look in for a
+		cscope database or in which directory to place a cscope database when
+		it is generated.  See |TagHL-DefaultDirModePriority| for details.
+
+		Option Type: List
+		Default: ["Default"] (use DefaultDirModePriority value)
+
+	CscopeFileDirModePriority            *TagHL-CscopeFileDirModePriority*
+		If the dir mode priority for cscope databases (see the option
+		|TagHL-CscopeFileDirModePriority|) contains the mode "Explicit", the
+		directory specified in this option will be used unconditionally if the
+		option has been set.
+
+		Option Type: String
+		Default: None (no explicit directory)
+
+	CscopeFileName                       *TagHL-CscopeFileName*
+		By default, the file generated by cscope containing the database is
+		named "cscope.out".  If you wish to change this, adjust this option
+		appropriately.
+
+		Option Type: String
+		Default: "cscope"
+
+	CscopeOnlyIfPresent                  *TagHL-CscopeOnlyIfPresent*
+		If the cscope interface is enabled (see |TagHL-EnableCscope| and this
+		option is set to True or 1, a new cscope database will only be
+		generated if one exists already.  Otherwise, whenever tags and types
+		are generated, a cscope database will be generated as well.
+
+		Option Type: Boolean
+		Default: False
+
 	CtagsArguments                       *TagHL-CtagsArguments*
 		This option allows advanced users to specify an explicit list of
 		arguments to pass to ctags.  In most cases, you won't want to use
 		Option Type: List
 		Default: [] (empty list)
 
-	CtagsExeFull                         *TagHL-CtagsExeFull*
-		Used internally to tell the python part of the application where ctags
-		is.  Do not use this option as it will be automatically overwritten.
-		Instead, see |TagHL-CtagsExecutable|.
-
 	CtagsExecutable                      *TagHL-CtagsExecutable*
 		This option allows you to specify which exuberant ctags executable to
 		run.  You can either specify an absolute path (e.g. "/usr/bin/ctags")
 		Option Type: String
 		Default: "ctags"
 
+	CtagsExeFull                         *TagHL-CtagsExeFull*
+		Used internally to tell the python part of the application where ctags
+		is.  Do not use this option as it will be automatically overwritten.
+		Instead, see |TagHL-CtagsExecutable|.
+
 	CtagsExtraArguments                  *TagHL-CtagsExtraArguments*
 		This can be used to add a list of extra arguments for ctags to the
 		ones normally used by TagHighlight.  This should be used if you want
 		Option Type: Boolean
 		Default: False (always generate tags)
 
+	EnableCscope                         *TagHL-EnableCscope*
+		If this option is set to True or 1, the cscope manager is enabled.
+		For more information, see |TagHighlight-cscope|.  For additional control, see
+		also |TagHL-CscopeOnlyIfPresent|.
+
+		Option Type: Boolean
+		Default: False
+
 	ExtensionLanguageOverrides           *TagHL-ExtensionLanguageOverrides*
 		If there are any entries in this dictionary, they will be used to
 		force a particular file extension to be treated as representing a
 
 	TagFileName                          *TagHL-TagFileName*
 		By default, the file generated by ctags containing the tags
-		definitions are stored in a file named "tags".  If you wish to change
-		this, adjust this option appropriately.
+		definitions is named "tags".  If you wish to change this, adjust this
+		option appropriately.
 
 		Option Type: String
 		Default: "tags"
 
 2.5 Integration with Other Software      *TagHighlight-integration*         {{{2
 
-2.5.1 Tagbar Integration                 *TagHighlight-tagbar*              {{{3
+2.5.1 Cscope Integration                 *TagHighlight-cscope*              {{{3
+
+	|TagHighlight| comes with support for |cscope| as standard.  This is only
+	available if vim is compiled with support and is disabled by default.  To
+	turn it on, use the option |TagHL-EnableCscope|.  The support for cscope
+	is not designed to be buffer-specific in the way that many other settings
+	can be, so |TagHighlight| works round this by dynamically reconfiguring
+	the databases when switching between buffers.
+
+	Another common problem with cscope is that if you use
+>
+		cs add cscope.out
+<
+	and then try to regenerate the database because of changes made to your
+	code, cscope cannot write to cscope.out as the instance of cscope
+	connected to Vim has still got the existing file open.  If TagHighlight's
+	cscope support is enabled, when you generate a new types file with
+	|UpdateTypesFile|, the cscope connection will be closed, the cscope
+	database regenerated and the cscope connection re-opened, thereby making
+	the use of cscope transparent with tags and types highlighting updates.
+	To speed up the process, cscope and ctags are run in parallel in separate
+	threads.
+
+	In practice, the only options likely to be needed are |TagHL-EnableCscope|
+	and |TagHL-CscopeOnlyIfPresent|.  The latter option allows the cscope
+	interface to be turned on permanently and cscope databases will only be
+	generated automatically after the first one has been generated manually by
+	navigating to the project root and running "cscope -b".  This is mainly
+	useful if you work on C projects and on projects in other languages (for
+	which cscope probably isn't really useful so generating a database is
+	pointless).
+
+	In addition to the |TagHighlight| options, it is important to ensure that
+	Vim's 'cscopeprg' is set appropriately.
+
+2.5.2 Tagbar Integration                 *TagHighlight-tagbar*              {{{3
 
 	|TagHighlight| can be used to highlight the names of classes etc in the
 	tagbar window (thanks to Alexey Radkov for reporting this).  Tagbar uses
 <
 	This assumes that you are writing C code; customise as appropriate.
 
-2.5.2 Git Integration                    *TagHighlight-git*                 {{{3
+2.5.3 Git Integration                    *TagHighlight-git*                 {{{3
 
 	A similar method to that used with tagbar can be used to highlight git
 	commit messages.  Use something like this in your |taghl_config.txt|
 <
 	This assumes that you are writing python code; customise as required.
 
-2.5.3 Bazaar Integration                 *TagHighlight-bazaar*              {{{3
+2.5.4 Bazaar Integration                 *TagHighlight-bazaar*              {{{3
 
 	Unfortunately, there is no easy way to highlight tags in Bazaar projects
 	as the commit message is stored in a temporary directory rather than
 	within the project.  If anyone has a suggestion of how to work round this,
 	please let me know.
 
-2.5.4 Mercurial Integration              *TagHighlight-mercurial*           {{{3
+2.5.5 Mercurial Integration              *TagHighlight-mercurial*           {{{3
 
 	Unfortunately, there is no easy way to highlight tags in Mercurial projects
 	as the commit message is stored in a temporary directory rather than
 	within the project.  If anyone has a suggestion of how to work round this,
 	please let me know.
 
-2.5.5 Subversion Integration             *TagHighlight-subversion*          {{{3
+2.5.6 Subversion Integration             *TagHighlight-subversion*          {{{3
 
 	A similar method to that used with tagbar can be used to highlight
 	subversion commit messages (thanks to Alexey Radkov for reporting this).
 
 	New features:
 	
+	* Added cscope support - update cscope database at the same time as ctags
+	  one.  Also automatically manage cscope connections.
 	* Global configuration can now be set using a text file in the ~/.vim or
 	  vimfiles directory (|TagHLConfig.txt|).
 	* Added support for Javascript (thanks to Piotr Yordanov).

plugin/TagHighlight/data/options.txt

 	Default:Default
 	Help:Optional override for dir mode priority for project config files specifically
 
+cscope_dir_mode_priority:
+	VimOptionMap:CscopeFileDirModePriority
+	Type:list
+	Default:Default
+	Help:Optional override for dir mode priority for cscope files specifically
+
 tag_file_directory:
 	VimOptionMap:TagFileDirectory
 	Type:string
 default_dir_mode_search_wildcards:
 	VimOptionMap:DefaultDirModeSearchWildcards
 	Type:list
-	Default:OPT(TagFileName),OPT(ProjectConfigFileName)
+	Default:OPT(TagFileName),OPT(ProjectConfigFileName),OPT(CscopeFileName)
 	Help:When searching directories, wildcards to match against (if any matches, we'll use this directory)
 
 config_dir_mode_search_wildcards:
 	Default:Default
 	Help:When searching directories for project config files, wildcards to match against (if any matches, we'll use this directory)
 
+cscope_dir_mode_search_wildcards:
+	VimOptionMap:CscopeFileSearchWildcards
+	Type:list
+	Default:Default
+	Help:When searching directories for cscope files, wildcards to match against (if any matches, we'll use this directory)
+
 tag_dir_mode_search_wildcards:
 	VimOptionMap:TagFileSearchWildcards
 	Type:list
 	Default:None
 	Help:Name of the ctags executable, or full path to it
 
+cscope_executable:
+	VimOptionMap:CscopeExecutable
+	Type:string
+	Default:None
+	Help:Name of the cscope executable, or full path to it
+
 forced_python_variant:
 	VimOptionMap:ForcedPythonVariant
 	Type:string
 	Default:False
 	Help:When loading a highlight file, set the working directory for the buffer to the types file path.
 
+only_generate_cscope_db_if_present:
+	VimOptionMap:CscopeOnlyIfPresent
+	Type:bool
+	Default:False
+	Help:Only generate cscope database if one already exists
+
 ##########################
 # Python script options: #
 ##########################
 	Default:Error
 	Help:Debug level for printing (how much debug output to produce)
 
+enable_cscope:
+	CommandLineSwitches:--enable-cscope
+	VimOptionMap:EnableCscope
+	Type:bool
+	Default:False
+	Help:Enable cscope support in TagHighlight
+
+cscope_file_name:
+	CommandLineSwitches:--cscope-filename
+	VimOptionMap:CscopeFileName
+	Type:string
+	Default:cscope.out
+	Help:Filename for cscope database
+
+cscope_file_directory:
+	CommandLineSwitches:--cscope-file-directory
+	VimOptionMap:CscopeFileDirectory
+	Type:string
+	Default:None
+	Help:Explicitly specified location for cscope file (corresponding to Explicit search mode)
+
 debug_file:
 	CommandLineSwitches:--debug-file
 	VimOptionMap:DebugFile
 	Default:ctags
 	Help:CTAGS Executable Directory
 
+cscope_exe_full:
+	CommandLineSwitches:--cscope-exe-full-path
+	VimOptionMap:CscopeExeFull
+	Type:string
+	Default:cscope
+	Help:Cscope Executable Directory
+
 ctags_arguments:
 	CommandLineSwitches:--add-ctags-argument
 	VimOptionMap:CtagsArguments

plugin/TagHighlight/module/cscope_interface.py

+#!/usr/bin/env python
+# Tag Highlighter:
+#   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
+# Copyright: Copyright (C) 2013 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 subprocess
+import os
+import threading
+
+class CscopeThread(threading.Thread):
+    def __init__(self, root, command):
+        self.root = root
+        self.command = command
+        super(CscopeThread, self).__init__()
+
+    def run(self):
+        os.chdir(self.root)
+
+        #subprocess.call(" ".join(cscope_cmd), shell = (os.name != 'nt'))
+        # shell=True stops the command window popping up
+        # We don't use stdin, but have to define it in order
+        # to get round python bug 3905
+        # http://bugs.python.org/issue3905
+        process = subprocess.Popen(self.command,
+                stdin=subprocess.PIPE,
+                stderr=subprocess.PIPE,
+                stdout=subprocess.PIPE
+                )#, shell=True)
+        (sout, serr) = process.communicate()
+
+cscopeThread = None
+
+def StartCscopeDBGeneration(options):
+    global cscopeThread
+    root = options['source_root']
+
+    args = ['-b', '-f', options['cscope_file_name']]
+
+    if options['recurse']:
+        args.append('-R')
+
+    cscope_cmd = [options['cscope_exe_full']] + args
+
+    #Debug("cscope command is " + repr(cscope_cmd), "Information")
+
+    cscopeThread = CscopeThread(root, cscope_cmd)
+    cscopeThread.start()
+
+def CompleteCscopeDBGeneration():
+    global cscopeThread
+    if cscopeThread is not None:
+        cscopeThread.join()
+    cscopeThread = None

plugin/TagHighlight/module/worker.py

     from .ctags_interface import GenerateTags, ParseTags
     from .generation import CreateTypesFile
 
+    if config['enable_cscope']:
+        from .cscope_interface import StartCscopeDBGeneration, CompleteCscopeDBGeneration
+        StartCscopeDBGeneration(config)
+
     if not config['use_existing_tagfile']:
         Debug("Generating tag file", "Information")
         GenerateTags(config)
         if language in tag_db:
             CreateTypesFile(config, language, tag_db[language], file_tag_db[language])
 
+    if config['enable_cscope']:
+        CompleteCscopeDBGeneration()
+
     os.chdir(start_directory)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.