1414logFileLevel = logging .WARN
1515logConsLevel = logging .WARN
1616
17+ nonBlankLinePattern = re .compile ("[\S]+" )
18+ validCompletionId = re .compile ("[a-zA-Z_$\.][\w$\.]*\Z" )
19+
1720def set_log_level (logger ):
1821 logger .logFile .setLevel (logFileLevel )
1922 logger .console .setLevel (logConsLevel )
@@ -511,6 +514,10 @@ def __init__(self):
511514 self .pendingCompletions = []
512515 self .completionsReady = False
513516 self .completionsLoc = None
517+ self .completionRequestSeq = None
518+ self .completionRequestPrefix = None
519+ self .completionRequestLoc = None
520+ self .completionRequestMember = False
514521 self .completionView = None
515522 self .mruFileList = []
516523 self .pendingTimeout = 0
@@ -957,24 +964,33 @@ def buildReplaceRegions(emptyRegionsA, emptyRegionsB):
957964
958965 # helper called back when completion info received from server
959966 def handleCompletionInfo (self , completionsResp ):
960- if completionsResp ["success" ]:
967+ self .pendingCompletions = []
968+ if (not cli .ST2 ()):
969+ view = active_view ()
970+ loc = view .sel ()[0 ].begin ()
971+ prefixLen = len (self .completionRequestPrefix )
972+ str = view .substr (sublime .Region (self .completionRequestLoc - prefixLen ,loc ))
973+ if (not str .startswith (self .completionRequestPrefix )):
974+ return
975+ if (str .find ("." ) > 0 ):
976+ if not self .completionRequestMember :
977+ print (str + " includes a dot but not req mem" )
978+ return
979+ if (len (str ) > 0 ) and (not validCompletionId .match (str )):
980+ return
981+ if completionsResp ["success" ] and ((completionsResp ["request_seq" ] == self .completionRequestSeq ) or cli .ST2 ()):
961982 completions = []
962983 rawCompletions = completionsResp ["body" ]
963-
964984 if rawCompletions :
965985 for rawCompletion in rawCompletions :
966986 name = rawCompletion ["name" ]
967987 completion = (name + "\t " + rawCompletion ["kind" ], name .replace ("$" , "\\ $" ))
968988 completions .append (completion )
969989 self .pendingCompletions = completions
970- else :
971- self .pendingCompletions = []
972990 if not cli .ST2 ():
973991 self .completionsReady = True
974992 active_view ().run_command ('hide_auto_complete' )
975993 self .run_auto_complete ()
976- else :
977- self .pendingCompletions = []
978994
979995 def run_auto_complete (self ):
980996 active_view ().run_command ("auto_complete" , {
@@ -989,27 +1005,27 @@ def run_auto_complete(self):
9891005 def on_query_completions (self , view , prefix , locations ):
9901006 info = self .getInfo (view )
9911007 if info :
992- print ("complete with: " + prefix )
1008+ # print("complete with: \"" + prefix + "\" ready: " + str(self.completionsReady) )
9931009 info .completionPrefixSel = decrLocsToRegions (locations , len (prefix ))
9941010 if not cli .ST2 ():
9951011 view .add_regions ("apresComp" , decrLocsToRegions (locations , 0 ), flags = sublime .HIDDEN )
9961012 if (not self .completionsReady ) or cli .ST2 ():
997- if info .lastCompletionLoc :
998- if ((len (prefix ) > 0 ) and ((len (prefix )- 1 )+ info .lastCompletionLoc == locations [0 ]) and (prefix .startswith (info .lastCompletionPrefix ))):
999- return (info .lastCompletions ,
1000- sublime .INHIBIT_WORD_COMPLETIONS | sublime .INHIBIT_EXPLICIT_COMPLETIONS )
1001-
10021013 location = getLocationFromPosition (view , locations [0 ])
10031014 checkUpdateView (view )
10041015 if cli .ST2 ():
10051016 cli .service .completions (view .file_name (), location , prefix , self .handleCompletionInfo )
10061017 else :
1018+ self .completionRequestLoc = locations [0 ]
1019+ self .completionRequestPrefix = prefix
1020+ self .completionRequestSeq = cli .service .seq
1021+ if (locations [0 ] > 0 ):
1022+ prevChar = view .substr (sublime .Region (locations [0 ]- 1 ,locations [0 ]- 1 ))
1023+ self .completionRequestMember = (prevChar == "." )
1024+ else :
1025+ self .completionRequestMember = False
10071026 cli .service .asyncCompletions (view .file_name (), location , prefix , self .handleCompletionInfo )
10081027 completions = self .pendingCompletions
10091028 info .lastCompletionLoc = locations [0 ]
1010- if self .completionsReady :
1011- info .lastCompletions = completions
1012- info .lastCompletionPrefix = prefix
10131029 self .pendingCompletions = []
10141030 self .completionsReady = False
10151031 return (completions , sublime .INHIBIT_WORD_COMPLETIONS | sublime .INHIBIT_EXPLICIT_COMPLETIONS )
@@ -1084,7 +1100,7 @@ def get_text_from_parts(displayParts):
10841100 result = ""
10851101 if displayParts :
10861102 for part in displayParts :
1087- result += part . text
1103+ result += part [ " text" ]
10881104 return result
10891105
10901106 for signature in response_dict ["body" ]["items" ]:
@@ -1099,7 +1115,7 @@ def get_text_from_parts(displayParts):
10991115 snippetText += ", "
11001116
11011117 paramText = ""
1102- paramText += get_text_from_parts (param . displayParts )
1118+ paramText += get_text_from_parts (param [ " displayParts" ] )
11031119 signatureText += paramText
11041120 snippetText += "${" + str (paramIdx ) + ":" + paramText + "}"
11051121 paramIdx += 1
@@ -1550,9 +1566,6 @@ def run(self, text):
15501566 formatRange (text , self .view , 0 , self .view .size ())
15511567
15521568
1553- nonBlankLinePattern = re .compile ("[\S]+" )
1554-
1555-
15561569# command to format the current line
15571570class TypescriptFormatLine (sublime_plugin .TextCommand ):
15581571 def run (self , text ):
0 commit comments