<s> import sublime <EOL> from . . import model_index <EOL> from . . import utils <EOL> from . . completions import CompletionList <EOL> from . import cfc_utils <EOL> projects = { } <EOL> def build_project_map ( project_name ) : <EOL> global projects <EOL> data = { } <EOL> path_completions , constructor_completions = make_completions ( project_name ) <EOL> data [ "<STR_LIT>" ] = path_completions <EOL> data [ "<STR_LIT>" ] = constructor_completions <EOL> projects [ project_name ] = data <EOL> def make_completions ( project_name ) : <EOL> dot_paths = model_index . get_dot_paths ( project_name ) <EOL> path_map = map_paths ( dot_paths ) <EOL> path_completions = { } <EOL> constructor_completions = { } <EOL> for k in path_map : <EOL> path_completions [ k ] = [ ] <EOL> constructor_completions [ k ] = [ ] <EOL> for c in sorted ( path_map [ k ] , key = lambda i : i [ "<STR_LIT>" ] ) : <EOL> path_completions [ k ] . append ( make_completion ( c , k , dot_paths , project_name , False ) ) <EOL> constructor_completions [ k ] . append ( make_completion ( c , k , dot_paths , project_name , True ) ) <EOL> return path_completions , constructor_completions <EOL> def make_completion ( path_part_dict , key , dot_paths , project_name , constructor ) : <EOL> completion = path_part_dict [ "<STR_LIT>" ] <EOL> if path_part_dict [ "<STR_LIT>" ] and constructor : <EOL> full_key = key + ( "<STR_LIT:.>" if len ( key ) > <NUM_LIT:0> else "<STR_LIT>" ) + completion <EOL> constructor_completion = model_index . get_completions_by_file_path ( project_name , dot_paths [ full_key . lower ( ) ] [ "<STR_LIT>" ] ) [ "<STR_LIT>" ] <EOL> if constructor_completion : <EOL> completion = completion + constructor_completion . content [ <NUM_LIT:4> : ] <EOL> else : <EOL> completion = completion + "<STR_LIT>" <EOL> if not path_part_dict [ "<STR_LIT>" ] : <EOL> completion += "<STR_LIT:.>" <EOL> return path_part_dict [ "<STR_LIT>" ] + "<STR_LIT:\t>" + ( "<STR_LIT>" if path_part_dict [ "<STR_LIT>" ] else "<STR_LIT>" ) , completion <EOL> def map_paths ( dot_paths ) : <EOL> path_map = { } <EOL> for path_key in dot_paths : <EOL> path_parts = dot_paths [ path_key ] [ "<STR_LIT>" ] . split ( "<STR_LIT:.>" ) <EOL> for i in range ( len ( path_parts ) ) : <EOL> key = "<STR_LIT:.>" . join ( path_parts [ : i ] ) . lower ( ) <EOL> if key not in path_map : <EOL> path_map [ key ] = [ ] <EOL> is_cfc = i == len ( path_parts ) - <NUM_LIT:1> <EOL> path_part_dict = { "<STR_LIT>" : path_parts [ i ] , "<STR_LIT>" : is_cfc } <EOL> if path_part_dict not in path_map [ key ] : <EOL> path_map [ key ] . append ( path_part_dict ) <EOL> return path_map <EOL> def get_tag_attributes ( view , prefix , position , info ) : <EOL> if not info [ "<STR_LIT>" ] or info [ "<STR_LIT>" ] not in projects : <EOL> return None <EOL> if view . match_selector ( position - <NUM_LIT:1> , "<STR_LIT>" ) : <EOL> cfc_path = "<STR_LIT>" <EOL> folder_cfc_path = cfc_utils . get_folder_cfc_path ( view , info [ "<STR_LIT>" ] , cfc_path ) <EOL> completions = [ ] <EOL> completions . extend ( get_completions ( info [ "<STR_LIT>" ] , cfc_path , "<STR_LIT>" ) ) <EOL> completions . extend ( get_completions ( info [ "<STR_LIT>" ] , folder_cfc_path , "<STR_LIT>" ) ) <EOL> if len ( completions ) > <NUM_LIT:0> : <EOL> return CompletionList ( completions , <NUM_LIT:2> , True ) <EOL> if view . match_selector ( position - <NUM_LIT:1> , "<STR_LIT>" ) : <EOL> r = utils . get_scope_region_containing_point ( view , position - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> r = sublime . Region ( r . begin ( ) , position - len ( prefix ) ) <EOL> cfc_path = "<STR_LIT:.>" . join ( view . substr ( r ) . split ( "<STR_LIT:.>" ) [ : - <NUM_LIT:1> ] ) <EOL> folder_cfc_path = cfc_utils . get_folder_cfc_path ( view , info [ "<STR_LIT>" ] , cfc_path ) <EOL> completions = [ ] <EOL> completions . extend ( get_completions ( info [ "<STR_LIT>" ] , cfc_path , "<STR_LIT>" ) ) <EOL> completions . extend ( get_completions ( info [ "<STR_LIT>" ] , folder_cfc_path , "<STR_LIT>" ) ) <EOL> if len ( completions ) > <NUM_LIT:0> : <EOL> return CompletionList ( completions , <NUM_LIT:2> , True ) <EOL> def get_script_completions ( view , prefix , position , info ) : <EOL> if not info [ "<STR_LIT>" ] or info [ "<STR_LIT>" ] not in projects : <EOL> return None <EOL> if view . match_selector ( position , "<STR_LIT>" ) : <EOL> r = utils . get_scope_region_containing_point ( view , position , "<STR_LIT>" ) <EOL> r = sublime . Region ( r . begin ( ) , position + <NUM_LIT:1> ) <EOL> cfc_path = view . substr ( r ) <EOL> if cfc_path [ <NUM_LIT:0> ] not in [ "<STR_LIT>" , "<STR_LIT:'>" ] or cfc_path [ - <NUM_LIT:1> ] not in [ "<STR_LIT>" , "<STR_LIT:'>" ] : <EOL> return None <EOL> cfc_path = "<STR_LIT:.>" . join ( cfc_path [ <NUM_LIT:1> : - <NUM_LIT:1> ] . split ( "<STR_LIT:.>" ) [ : - <NUM_LIT:1> ] ) <EOL> folder_cfc_path = cfc_utils . get_folder_cfc_path ( view , info [ "<STR_LIT>" ] , cfc_path ) <EOL> completions = [ ] <EOL> completions . extend ( get_completions ( info [ "<STR_LIT>" ] , cfc_path , "<STR_LIT>" ) ) <EOL> completions . extend ( get_completions ( info [ "<STR_LIT>" ] , folder_cfc_path , "<STR_LIT>" ) ) <EOL> if len ( completions ) > <NUM_LIT:0> : <EOL> return CompletionList ( completions , <NUM_LIT:2> , True ) <EOL> if view . match_selector ( position - <NUM_LIT:1> , "<STR_LIT>" ) : <EOL> r = utils . get_scope_region_containing_point ( view , position - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> r = sublime . Region ( r . begin ( ) , position - len ( prefix ) ) <EOL> cfc_path = "<STR_LIT:.>" . join ( view . substr ( r ) [ <NUM_LIT:4> : ] . split ( "<STR_LIT:.>" ) [ : - <NUM_LIT:1> ] ) <EOL> folder_cfc_path = cfc_utils . get_folder_cfc_path ( view , info [ "<STR_LIT>" ] , cfc_path ) <EOL> completions = [ ] <EOL> completions . extend ( get_completions ( info [ "<STR_LIT>" ] , cfc_path , "<STR_LIT>" ) ) <EOL> completions . extend ( get_completions ( info [ "<STR_LIT>" ] , folder_cfc_path , "<STR_LIT>" ) ) <EOL> if len ( completions ) > <NUM_LIT:0> : <EOL> return CompletionList ( completions , <NUM_LIT:2> , True ) <EOL> return None <EOL> def get_dot_completions ( view , prefix , position , info ) : <EOL> if not info [ "<STR_LIT>" ] or len ( info [ "<STR_LIT>" ] ) == <NUM_LIT:0> : <EOL> return None <EOL> pt = position - len ( prefix ) <EOL> component_name = None <EOL> if info [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . name == "<STR_LIT>" and view . match_selector ( pt - <NUM_LIT:2> , "<STR_LIT>" ) : <EOL> component_name = cfc_utils . get_component_name ( view . substr ( info [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . args_region ) ) <EOL> elif view . match_selector ( pt - <NUM_LIT:2> , "<STR_LIT>" ) : <EOL> component_name = "<STR_LIT:.>" . join ( [ s . name for s in reversed ( info [ "<STR_LIT>" ] ) ] ) <EOL> if component_name : <EOL> comp = model_index . get_completions_by_dot_path ( info [ "<STR_LIT>" ] , component_name . lower ( ) ) <EOL> if not comp : <EOL> folder_cfc_path = cfc_utils . get_folder_cfc_path ( view , info [ "<STR_LIT>" ] , component_name ) <EOL> comp = model_index . get_completions_by_dot_path ( info [ "<STR_LIT>" ] , folder_cfc_path ) <EOL> if comp : <EOL> completions = [ ( completion . key + "<STR_LIT:\t>" + completion . file_path . split ( "<STR_LIT:/>" ) . pop ( ) , completion . content ) for completion in comp [ "<STR_LIT>" ] ] <EOL> return CompletionList ( completions , <NUM_LIT:1> , True ) <EOL> return None <EOL> def get_completions ( project_name , cfc_path , completion_type ) : <EOL> if cfc_path is not None and cfc_path . lower ( ) in projects [ project_name ] [ completion_type ] : <EOL> return projects [ project_name ] [ completion_type ] [ cfc_path . lower ( ) ] <EOL> return [ ] </s>
