<s> import sublime , sublime_plugin <EOL> import subprocess <EOL> import os <EOL> class gotestsCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit ) : <EOL> settings = sublime . load_settings ( "<STR_LIT>" ) <EOL> gopath = settings . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if os . environ . get ( "<STR_LIT>" ) == None : <EOL> if gopath != "<STR_LIT>" : <EOL> os . environ [ "<STR_LIT>" ] = gopath <EOL> os . environ [ "<STR_LIT>" ] += os . pathsep + os . path . join ( gopath , "<STR_LIT>" ) <EOL> else : <EOL> sublime . message_dialog ( "<STR_LIT>" ) <EOL> return False <EOL> fn = self . view . file_name ( ) <EOL> if fn and fn . endswith ( '<STR_LIT>' ) and not fn . endswith ( '<STR_LIT>' ) : <EOL> fs = [ ] <EOL> for s in self . view . sel ( ) : <EOL> line = self . function_line ( s . begin ( ) ) <EOL> i = line . begin ( ) <EOL> while i <= s . end ( ) : <EOL> f = self . function_name ( line ) <EOL> i = line . end ( ) + <NUM_LIT:1> <EOL> line = self . view . line ( i ) <EOL> if not f : <EOL> continue <EOL> fs . append ( f ) <EOL> try : <EOL> gotests = settings . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> cmd = [ gotests , '<STR_LIT>' , '<STR_LIT>' + "<STR_LIT:|>" . join ( fs ) + '<STR_LIT>' , fn ] <EOL> proc = subprocess . Popen ( cmd , stdout = subprocess . PIPE ) <EOL> print ( proc . stdout . read ( ) . decode ( "<STR_LIT:utf-8>" ) . replace ( '<STR_LIT:\r\n>' , '<STR_LIT:\n>' ) ) <EOL> except OSError as e : <EOL> sublime . message_dialog ( "<STR_LIT>" + str ( e ) + "<STR_LIT:.>" ) <EOL> return False <EOL> return True <EOL> return False <EOL> def function_line ( self , point ) : <EOL> line = self . view . line ( point ) <EOL> if self . is_end_bracket ( line ) : <EOL> return line <EOL> above = line <EOL> while not self . is_end_bracket ( above ) and not self . function_name ( above ) and above . begin ( ) > <NUM_LIT:0> : <EOL> above = self . view . line ( above . begin ( ) - <NUM_LIT:1> ) <EOL> return above <EOL> def is_end_bracket ( self , line ) : <EOL> return self . view . substr ( line . begin ( ) ) == '<STR_LIT:}>' <EOL> def function_name ( self , line ) : <EOL> if self . view . substr ( self . view . word ( line . begin ( ) ) ) != "<STR_LIT>" : <EOL> return None <EOL> i = line . begin ( ) <EOL> while i <= line . end ( ) : <EOL> word = self . view . word ( i ) <EOL> i = word . end ( ) + <NUM_LIT:1> <EOL> c = self . view . substr ( word . end ( ) ) <EOL> if c . find ( "<STR_LIT:(>" ) != - <NUM_LIT:1> : <EOL> func = self . view . substr ( word ) <EOL> r = self . view . word ( word . begin ( ) - <NUM_LIT:1> ) <EOL> if self . view . substr ( r ) . find ( "<STR_LIT:)>" ) != - <NUM_LIT:1> : <EOL> receiver = self . view . substr ( self . view . word ( r . begin ( ) - <NUM_LIT:1> ) ) <EOL> func = receiver + func <EOL> return func <EOL> return None </s>
