<s> import json , os , sublime <EOL> from . . import utils <EOL> def toggle_controller_view ( view , position ) : <EOL> file_info = get_file_info ( view . file_name ( ) ) <EOL> if not file_info : <EOL> return <EOL> dialect = utils . get_dialect ( view , position ) <EOL> file_type , root_path , containing_folder , relative_path = file_info <EOL> if file_type == "<STR_LIT>" : <EOL> function_name = get_controller_function ( view , position ) <EOL> if function_name : <EOL> view_path , view_exists = get_verified_path ( root_path + "<STR_LIT:/>" + containing_folder , relative_path + "<STR_LIT:/>" + function_name + get_file_extension ( "<STR_LIT>" , dialect ) ) <EOL> if not view_exists : <EOL> view_exists = sublime . ok_cancel_dialog ( containing_folder + "<STR_LIT:/>" + view_path + "<STR_LIT>" , "<STR_LIT>" ) <EOL> if view_exists : <EOL> view . window ( ) . open_file ( root_path + "<STR_LIT:/>" + containing_folder + "<STR_LIT:/>" + view_path , sublime . FORCE_GROUP ) <EOL> if file_type == "<STR_LIT>" : <EOL> controller_path , controller_exists = get_verified_path ( root_path + "<STR_LIT:/>" + containing_folder , relative_path + get_file_extension ( "<STR_LIT>" , dialect ) ) <EOL> if controller_exists : <EOL> file_path = root_path + "<STR_LIT:/>" + containing_folder + "<STR_LIT:/>" + controller_path <EOL> if file_path [ <NUM_LIT:1> ] == "<STR_LIT::>" : <EOL> file_path = "<STR_LIT:/>" + file_path [ <NUM_LIT:0> ] + file_path [ <NUM_LIT:2> : ] <EOL> symbol = view . file_name ( ) . replace ( "<STR_LIT:\\>" , "<STR_LIT:/>" ) . split ( "<STR_LIT:/>" ) [ - <NUM_LIT:1> ] . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] <EOL> row , col = <NUM_LIT:1> , <NUM_LIT:1> <EOL> index_locations = view . window ( ) . lookup_symbol_in_index ( symbol ) <EOL> for full_path , project_path , rowcol in index_locations : <EOL> if full_path == file_path : <EOL> row , col = rowcol <EOL> break <EOL> view . window ( ) . open_file ( file_path + "<STR_LIT::>" + str ( row ) + "<STR_LIT::>" + str ( col ) , sublime . ENCODED_POSITION | sublime . FORCE_GROUP ) <EOL> def get_folder_settings ( type ) : <EOL> folder_settings = sublime . load_settings ( "<STR_LIT>" ) <EOL> return folder_settings . get ( type ) <EOL> def get_file_info ( filename ) : <EOL> if not filename : <EOL> return None <EOL> filename_parts = filename . replace ( "<STR_LIT:\\>" , "<STR_LIT:/>" ) . split ( "<STR_LIT:/>" ) <EOL> if len ( filename_parts ) > <NUM_LIT:1> and filename_parts [ - <NUM_LIT:2> ] . lower ( ) in get_folder_settings ( "<STR_LIT>" ) : <EOL> root_path = "<STR_LIT:/>" . join ( filename_parts [ : - <NUM_LIT:2> ] ) <EOL> containing_folder = get_folder_name ( root_path , get_folder_settings ( "<STR_LIT>" ) ) <EOL> relative_path = filename_parts [ - <NUM_LIT:1> ] . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] . lower ( ) <EOL> return "<STR_LIT>" , root_path , containing_folder , relative_path <EOL> if len ( filename_parts ) > <NUM_LIT:2> and filename_parts [ - <NUM_LIT:3> ] . lower ( ) in get_folder_settings ( "<STR_LIT>" ) : <EOL> root_path = "<STR_LIT:/>" . join ( filename_parts [ : - <NUM_LIT:3> ] ) <EOL> containing_folder = get_folder_name ( root_path , get_folder_settings ( "<STR_LIT>" ) ) <EOL> relative_path = filename_parts [ - <NUM_LIT:2> ] . lower ( ) <EOL> return "<STR_LIT>" , root_path , containing_folder , relative_path <EOL> return None <EOL> def get_folder_name ( root_path , folders ) : <EOL> for folder_name in folders : <EOL> verified_path , path_exists = get_verified_path ( root_path , folder_name ) <EOL> if path_exists : <EOL> return verified_path <EOL> return "<STR_LIT>" <EOL> def get_file_extension ( type , dialect ) : <EOL> if dialect == "<STR_LIT>" : <EOL> return "<STR_LIT>" <EOL> if type == "<STR_LIT>" : <EOL> return "<STR_LIT>" <EOL> if type == "<STR_LIT>" : <EOL> return "<STR_LIT>" <EOL> return None <EOL> def get_controller_function ( view , position ) : <EOL> funct_body_scope = "<STR_LIT>" <EOL> funct_declaration_scope = "<STR_LIT>" <EOL> function_body_region = utils . get_scope_region_containing_point ( view , position , funct_body_scope ) <EOL> function_position = None <EOL> if function_body_region : <EOL> funct_regions = view . find_by_selector ( funct_declaration_scope ) <EOL> for funct_region in reversed ( funct_regions ) : <EOL> if funct_region . end ( ) <= function_body_region . begin ( ) : <EOL> function_position = funct_region . begin ( ) <EOL> break <EOL> elif view . match_selector ( position , "<STR_LIT>" ) : <EOL> if view . scope_name ( position ) . count ( "<STR_LIT>" ) == <NUM_LIT:1> : <EOL> function_position = position <EOL> if function_position : <EOL> return view . substr ( utils . get_function ( view , function_position ) [ <NUM_LIT:1> ] ) <EOL> return None <EOL> def get_verified_path ( root_path , rel_path ) : <EOL> normalized_root_path = root_path . replace ( "<STR_LIT:\\>" , "<STR_LIT:/>" ) <EOL> rel_path_elements = rel_path . replace ( "<STR_LIT:\\>" , "<STR_LIT:/>" ) . split ( "<STR_LIT:/>" ) <EOL> verified_path_elements = [ ] <EOL> for elem in rel_path_elements : <EOL> dir_map = { f . lower ( ) : f for f in os . listdir ( normalized_root_path + "<STR_LIT:/>" + "<STR_LIT:/>" . join ( verified_path_elements ) ) } <EOL> if elem . lower ( ) not in dir_map : <EOL> return rel_path , False <EOL> verified_path_elements . append ( dir_map [ elem . lower ( ) ] ) <EOL> return "<STR_LIT:/>" . join ( verified_path_elements ) , True </s>
