Skip to content
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
10 changes: 9 additions & 1 deletion CscopeSublime.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@
//
// Linux and OS X example: "executable": "/usr/bin/cscope"
// Windows example: "executable": "C:\\cscope\\cscope.exe"
//
// Can also be a list, for example: "executable": ["wsl", "cscope"]
"executable": "cscope",

// A location for the cscope database - this will be used in preference to any 'found' database
// A location for the cscope database - this will be used in preference
// to any 'found' database
//"database_location": "D:\\Program Files\\cscope\\cscope.out",

// An alternate DB path to use when invoking a search. This can used
// when the search functionality does not understand certain filesystems.
// Not yet implemented for build. For example, using cscope inside WSL:
//"search_db_alternate_path": "/mnt/d/Users/foo/src/cscope.out"

// An optional custom command used to build cscope's database.
// This must be in array format.
//"database_build_command": [ "cscope-indexer", "-r" ],
Expand Down
18 changes: 14 additions & 4 deletions cscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def rebuild(self):
# If the user provided a custom command to build their cscope database,
# use it, otherwise use a hopefully sane default
if not (cscope_arg_list and isinstance(cscope_arg_list, list)):
cscope_arg_list = [self.executable, '-Rbq']
cscope_arg_list = self.executable + ['-Rbq']

print('CscopeDatabase: Rebuilding database in directory: {}, using command: {}'
.format(self.root, cscope_arg_list))
Expand Down Expand Up @@ -283,14 +283,15 @@ def run(self):


class CscopeSublimeSearchWorker(threading.Thread):
def __init__(self, view, platform, database, symbol, mode, executable):
def __init__(self, view, platform, database, symbol, mode, executable, search_db_alternate_path):
super(CscopeSublimeSearchWorker, self).__init__()
self.view = view
self.platform = platform
self.database = database
self.symbol = symbol
self.mode = mode
self.executable = executable
self.search_db_alternate_path = search_db_alternate_path
self.output = ""

# switch statement for the different formatted output
Expand Down Expand Up @@ -356,7 +357,8 @@ def match_output_line(self, line, mode):
def run_cscope(self, mode, word):
newline = '\n'

cscope_arg_list = [self.executable, '-dL', '-f', self.database.location, '-' + str(mode) + word]
db = self.search_db_alternate_path or self.database.location
cscope_arg_list = self.executable + ['-dL', '-f', db, '-' + str(mode) + word]
popen_arg_list = {
"shell": False,
"stdout": subprocess.PIPE,
Expand Down Expand Up @@ -453,6 +455,7 @@ def __init__(self, view):
self.view = view
self.database = None
self.executable = None
self.exectuable_db_location = None
self.workers = []
settings = get_settings()

Expand Down Expand Up @@ -510,6 +513,12 @@ def display_results(self, symbol, output):
def run(self, edit, mode):
self.mode = mode
self.executable = get_setting("executable", "cscope")
self.search_db_alternate_path = get_setting("search_db_alternate_path", None)

# Support executables requiring addition options, such as
# ["wsl", "cscope"] on Windows.
if not isinstance(self.executable, list):
self.executable = [self.executable]

# Create a new database object every time we run. This way, if our user
# deleted cscope files or recreated them, we have a correct understanding
Expand Down Expand Up @@ -556,7 +565,8 @@ def on_search_confirmed(self, symbol):
database = self.database,
symbol = symbol,
mode = self.mode,
executable = self.executable
executable = self.executable,
search_db_alternate_path = self.search_db_alternate_path,
)
worker.start()
self.workers.append(worker)
Expand Down