55import functools
66import operator
77import os
8+ import platform
9+ import re
810import subprocess
911import threading
1012
@@ -31,7 +33,7 @@ class CsearchCommand(sublime_plugin.WindowCommand, _CsearchListener):
3133 def __init__ (self , * args , ** kwargs ):
3234 super (CsearchCommand , self ).__init__ (* args , ** kwargs )
3335 self ._is_running = False
34- self ._last_search = ''
36+ self ._last_search = 'file:* case:yes " '
3537
3638 def run (self , query = None ):
3739 """Runs the search command.
@@ -73,7 +75,8 @@ def _on_search(self, result):
7375 view = view , erase = True )
7476 view .set_status ('YetAnotherCodeSearch' , 'Searching...' )
7577 try :
76- s = settings .get_project_settings (self .window .project_data ())
78+ s = settings .get_project_settings (self .window .project_data (),
79+ self .window .project_file_name ())
7780 _CsearchThread (parser .parse_query (result ), self ,
7881 path_csearch = s .csearch_path ,
7982 index_filename = s .index_filename ).start ()
@@ -143,6 +146,23 @@ def on_finished(self, output, err=None):
143146 functools .partial (self ._finish , output , matches , err = err ))
144147
145148
149+ def fix_windows_output (output ):
150+ """Normalize file paths in csearch output on windows platform."""
151+
152+ result = []
153+ # replace ntpaths to posix
154+ r = re .compile (r"^([^:]*):([^:]*):([^:]*):(.*)$" )
155+ for line in output .splitlines ():
156+ m = r .match (line )
157+ if m :
158+ line = '/{0}{1}:{2}:{3}' .format (m .group (1 ),
159+ m .group (2 ).replace ('\\ ' , '/' ),
160+ m .group (3 ),
161+ m .group (4 ))
162+ result .append (line )
163+ return '\n ' .join (result )
164+
165+
146166class _CsearchThread (threading .Thread ):
147167 """Runs the csearch command in a thread."""
148168
@@ -182,7 +202,10 @@ def _do_search(self):
182202 error = subprocess .CalledProcessError (retcode , cmd )
183203 error .output = stderr
184204 raise error
185- return output .decode ('utf-8' )
205+ u8 = output .decode ('utf-8' )
206+ if platform .system () == 'Windows' :
207+ return fix_windows_output (u8 )
208+ return u8
186209
187210
188211class CodeSearchResultsGoToFileCommand (sublime_plugin .WindowCommand ):
@@ -217,3 +240,8 @@ def run(self):
217240 self .window .open_file ('{0}:{1}:{2}' .format (filename , linenum , col ),
218241 sublime .ENCODED_POSITION )
219242 # TODO(pope): Consider highlighting the match
243+
244+
245+ class DoubleClickCallback (sublime_plugin .WindowCommand ):
246+ def run (self ):
247+ self .window .run_command ("code_search_results_go_to_file" )
0 commit comments