<s> import sublime , sublime_plugin <EOL> from . . padawan import client <EOL> def sel_end ( sel ) : <EOL> return max ( sel . a , sel . b ) <EOL> def is_php_file ( view ) : <EOL> return view . score_selector ( sel_end ( view . sel ( ) [ <NUM_LIT:0> ] ) , "<STR_LIT>" ) > <NUM_LIT:0> <EOL> class PadawanCompleter ( sublime_plugin . EventListener ) : <EOL> def run_completion ( self , view ) : <EOL> view . run_command ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True <EOL> } ) <EOL> def on_modified_async ( self , view ) : <EOL> if not is_php_file ( view ) : <EOL> return <EOL> cursor = view . sel ( ) [ <NUM_LIT:0> ] . b <EOL> if cursor < <NUM_LIT:1> : <EOL> return <EOL> while cursor > <NUM_LIT:0> : <EOL> curChar = view . substr ( sublime . Region ( cursor - <NUM_LIT:1> , cursor ) ) <EOL> if curChar == '<STR_LIT:\\>' : <EOL> return self . run_completion ( view ) <EOL> if curChar == '<STR_LIT:$>' : <EOL> return self . run_completion ( view ) <EOL> if curChar == '<STR_LIT:(>' : <EOL> return self . run_completion ( view ) <EOL> if cursor > <NUM_LIT:1> : <EOL> curChar = view . substr ( sublime . Region ( cursor - <NUM_LIT:2> , cursor ) ) <EOL> if curChar == '<STR_LIT>' : <EOL> return self . run_completion ( view ) <EOL> if curChar == '<STR_LIT>' : <EOL> return self . run_completion ( view ) <EOL> if cursor > <NUM_LIT:3> : <EOL> curChar = view . substr ( sublime . Region ( cursor - <NUM_LIT:4> , cursor ) ) <EOL> if curChar == '<STR_LIT>' : <EOL> return self . run_completion ( view ) <EOL> if curChar == '<STR_LIT>' : <EOL> return self . run_completion ( view ) <EOL> if cursor > <NUM_LIT:9> : <EOL> curChar = view . substr ( sublime . Region ( cursor - <NUM_LIT:10> , cursor ) ) <EOL> if curChar == '<STR_LIT>' : <EOL> return self . run_completion ( view ) <EOL> cursor -= <NUM_LIT:1> <EOL> def on_query_completions ( self , view , prefix , locations ) : <EOL> if not is_php_file ( view ) : <EOL> return None <EOL> fname = view . file_name ( ) <EOL> if fname is None : <EOL> return None <EOL> column = <NUM_LIT:16> <EOL> line = <NUM_LIT> <EOL> line , column = view . rowcol ( locations [ <NUM_LIT:0> ] ) <EOL> contents = view . substr ( sublime . Region ( <NUM_LIT:0> , view . size ( ) ) ) <EOL> completions = client . GetCompletion ( <EOL> fname , <EOL> line + <NUM_LIT:1> , <EOL> column + <NUM_LIT:1> , <EOL> contents <EOL> ) [ "<STR_LIT>" ] <EOL> return ( <EOL> [ self . format_menu_item ( c ) for c in completions ] , <EOL> sublime . INHIBIT_WORD_COMPLETIONS <EOL> ) <EOL> def format_menu_item ( self , c ) : <EOL> return [ c [ "<STR_LIT>" ] if c [ "<STR_LIT>" ] else c [ "<STR_LIT:name>" ] , c [ "<STR_LIT:name>" ] ] </s>
