diff --git a/CscopeSublime.sublime-settings b/CscopeSublime.sublime-settings index 85ef125..dd68170 100644 --- a/CscopeSublime.sublime-settings +++ b/CscopeSublime.sublime-settings @@ -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" ], diff --git a/cscope.py b/cscope.py index 10dceee..d1958e5 100644 --- a/cscope.py +++ b/cscope.py @@ -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)) @@ -283,7 +283,7 @@ 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 @@ -291,6 +291,7 @@ def __init__(self, view, platform, database, symbol, mode, executable): 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 @@ -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, @@ -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() @@ -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 @@ -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)