<s> import sublime <EOL> import json <EOL> from os . path import dirname , realpath <EOL> from . . completions import CompletionList <EOL> from . . inline_documentation import Documentation <EOL> from . . import utils <EOL> COMPLETION_FILES = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> DOC_STYLES = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> completions = { } <EOL> cgi = { } <EOL> def get_tags ( view , prefix , position , info ) : <EOL> completion_list = completions [ info [ "<STR_LIT>" ] + "<STR_LIT>" ] <EOL> return CompletionList ( completion_list , <NUM_LIT:0> , False ) <EOL> def get_tag_attributes ( view , prefix , position , info ) : <EOL> if not info [ "<STR_LIT>" ] : <EOL> return None <EOL> if info [ "<STR_LIT>" ] : <EOL> info [ "<STR_LIT>" ] = ( "<STR_LIT::>" if info [ "<STR_LIT>" ] == "<STR_LIT>" else "<STR_LIT>" ) + info [ "<STR_LIT>" ] <EOL> if info [ "<STR_LIT>" ] : <EOL> if ( info [ "<STR_LIT>" ] in completions [ info [ "<STR_LIT>" ] + "<STR_LIT>" ] <EOL> and info [ "<STR_LIT>" ] in completions [ info [ "<STR_LIT>" ] + "<STR_LIT>" ] [ info [ "<STR_LIT>" ] ] ) : <EOL> completion_list = completions [ info [ "<STR_LIT>" ] + "<STR_LIT>" ] [ info [ "<STR_LIT>" ] ] [ info [ "<STR_LIT>" ] ] <EOL> return CompletionList ( completion_list , <NUM_LIT:0> , False ) <EOL> return None <EOL> prefix_start = position - len ( prefix ) <EOL> ch = view . substr ( prefix_start - <NUM_LIT:1> ) <EOL> if ch in [ "<STR_LIT:U+0020>" , "<STR_LIT:\t>" , "<STR_LIT:\n>" ] : <EOL> completion_list = completions [ info [ "<STR_LIT>" ] + "<STR_LIT>" ] . get ( info [ "<STR_LIT>" ] , None ) <EOL> return CompletionList ( completion_list , <NUM_LIT:0> , False ) <EOL> return None <EOL> def get_script_completions ( view , prefix , position , info ) : <EOL> completion_list = [ ] <EOL> completion_list . extend ( completions [ info [ "<STR_LIT>" ] + "<STR_LIT>" ] ) <EOL> completion_list . extend ( completions [ info [ "<STR_LIT>" ] + "<STR_LIT>" ] ) <EOL> return CompletionList ( completion_list , <NUM_LIT:0> , False ) <EOL> def get_dot_completions ( view , prefix , position , info ) : <EOL> if len ( info [ "<STR_LIT>" ] ) == <NUM_LIT:1> and info [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . name == "<STR_LIT>" : <EOL> return CompletionList ( completions [ "<STR_LIT>" ] , <NUM_LIT:1> , True ) <EOL> completion_list = completions [ info [ "<STR_LIT>" ] + "<STR_LIT>" ] <EOL> return CompletionList ( completion_list , <NUM_LIT:0> , False ) <EOL> def get_inline_documentation ( view , position ) : <EOL> if view . match_selector ( position , "<STR_LIT>" ) : <EOL> word = view . word ( position ) <EOL> dot_context = utils . get_dot_context ( view , word . begin ( ) - <NUM_LIT:1> ) <EOL> if len ( dot_context ) == <NUM_LIT:1> and dot_context [ <NUM_LIT:0> ] . name == "<STR_LIT>" : <EOL> key = "<STR_LIT>" + view . substr ( word ) . lower ( ) <EOL> if key in cgi : <EOL> doc = dict ( DOC_STYLES ) <EOL> doc . update ( cgi [ key ] ) <EOL> return Documentation ( doc , None , <NUM_LIT:1> ) <EOL> return None <EOL> def load_completions ( ) : <EOL> global completions , cgi <EOL> completions_data = { filename : load_json_data ( filename ) for filename in COMPLETION_FILES } <EOL> for dialect in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> completions [ dialect + "<STR_LIT>" ] = [ ] <EOL> completions [ dialect + "<STR_LIT>" ] = [ ] <EOL> completions [ dialect + "<STR_LIT>" ] = { } <EOL> completions [ dialect + "<STR_LIT>" ] = { } <EOL> for tag_name in sorted ( completions_data [ dialect + "<STR_LIT>" ] . keys ( ) ) : <EOL> if isinstance ( completions_data [ dialect + "<STR_LIT>" ] [ tag_name ] , list ) : <EOL> completions_data [ dialect + "<STR_LIT>" ] [ tag_name ] = { "<STR_LIT>" : completions_data [ dialect + "<STR_LIT>" ] [ tag_name ] , "<STR_LIT>" : { } } <EOL> tag_attributes = completions_data [ dialect + "<STR_LIT>" ] [ tag_name ] [ "<STR_LIT>" ] <EOL> completions [ dialect + "<STR_LIT>" ] . append ( make_tag_completion ( tag_name , dialect , tag_attributes [ <NUM_LIT:0> ] ) ) <EOL> completions [ dialect + "<STR_LIT>" ] . append ( make_tag_completion ( tag_name [ ( <NUM_LIT:1> if dialect == "<STR_LIT>" else <NUM_LIT:2> ) : ] , dialect , tag_attributes [ <NUM_LIT:0> ] ) ) <EOL> completions [ dialect + "<STR_LIT>" ] [ tag_name ] = [ ( a + '<STR_LIT>' , a + '<STR_LIT>' ) for a in tag_attributes [ <NUM_LIT:0> ] ] <EOL> completions [ dialect + "<STR_LIT>" ] [ tag_name ] . extend ( [ ( a + '<STR_LIT>' , a + '<STR_LIT>' ) for a in tag_attributes [ <NUM_LIT:1> ] ] ) <EOL> tag_attribute_values = completions_data [ dialect + "<STR_LIT>" ] [ tag_name ] [ "<STR_LIT>" ] <EOL> completions [ dialect + "<STR_LIT>" ] [ tag_name ] = { } <EOL> for attribute_name in sorted ( tag_attribute_values . keys ( ) ) : <EOL> completions [ dialect + "<STR_LIT>" ] [ tag_name ] [ attribute_name ] = [ ( v + '<STR_LIT:\t>' + attribute_name , v ) for v in tag_attribute_values [ attribute_name ] ] <EOL> completions [ dialect + "<STR_LIT>" ] = [ ( funct + '<STR_LIT>' + dialect + '<STR_LIT:)>' , funct + completions_data [ dialect + "<STR_LIT>" ] [ funct ] ) for funct in sorted ( completions_data [ dialect + "<STR_LIT>" ] . keys ( ) ) ] <EOL> mem_func_comp = [ ] <EOL> for member_function_type in sorted ( completions_data [ dialect + "<STR_LIT>" ] . keys ( ) ) : <EOL> for funct in sorted ( completions_data [ dialect + "<STR_LIT>" ] [ member_function_type ] . keys ( ) ) : <EOL> mem_func_comp . append ( ( funct + '<STR_LIT:\t>' + member_function_type + '<STR_LIT>' + dialect + '<STR_LIT:)>' , funct + completions_data [ dialect + "<STR_LIT>" ] [ member_function_type ] [ funct ] ) ) <EOL> completions [ dialect + "<STR_LIT>" ] = mem_func_comp <EOL> cgi = load_json_data ( "<STR_LIT>" ) <EOL> completions [ "<STR_LIT>" ] = [ ( scope_variable . split ( "<STR_LIT:.>" ) . pop ( ) . upper ( ) + "<STR_LIT>" , scope_variable . split ( "<STR_LIT:.>" ) . pop ( ) . upper ( ) ) for scope_variable in sorted ( cgi . keys ( ) ) ] <EOL> def load_json_data ( filename ) : <EOL> json_data = sublime . load_resource ( "<STR_LIT>" + utils . get_plugin_name ( ) + "<STR_LIT>" + filename + "<STR_LIT>" ) <EOL> return json . loads ( json_data ) <EOL> def make_tag_completion ( tag , type , required_attrs ) : <EOL> attrs = '<STR_LIT>' <EOL> for index , attr in enumerate ( required_attrs , <NUM_LIT:1> ) : <EOL> attrs += '<STR_LIT:U+0020>' + attr + '<STR_LIT>' + str ( index ) + '<STR_LIT:">' <EOL> return ( tag + '<STR_LIT>' + type + '<STR_LIT:)>' , tag + attrs ) </s>
