def GetAutoCompList(self, command): """Returns the list of possible completions for a command string. If namespace is not specified the lookup is based on the locals namespace @param command: commadn lookup is done on @keyword namespace: namespace to do lookup in """ if command in [None, u'']: return list() buff = self.GetBuffer() cpos = buff.GetCurrentPos() # Check if we are in a php region or not if buff.GetStyleAt(cpos) not in HTML_AREA: return list() cline = buff.GetCurrentLine() tmp = buff.GetLine(cline).rstrip() # Check if we are completing an open tag if tmp.endswith('<'): if buff.GetLexer() == wx.stc.STC_LEX_XML: taglst = _FindXmlTags(buff.GetText()) else: taglst = TAGS return completer.CreateSymbols(taglst, completer.TYPE_ELEMENT) tmp = tmp.rstrip('>').rstrip() if len(tmp) and (tmp[-1] in '"\' \t' or tmp[-1].isalpha()): for line in range(cline, -1, -1): txt = buff.GetLine(line) if line == cline: txt = txt[:buff.GetColumn(cpos)] idx = txt.rfind('<') if idx != -1: parts = txt[idx:].lstrip('<').strip().split() if len(parts): tag = parts[0].rstrip('>') if len(tag) and \ tag not in ('img', 'br', '?php', '?xml', '?') and \ not tag[0] in ('!', '/'): rtag = u"</" + tag + u">" if tag in NLINE_TAGS: buff.BeginUndoAction() buff.AutoIndent() buff.BackTab() buff.EndUndoAction() if not parts[-1].endswith('>'): rtag = u">" + rtag return [ completer.Symbol(rtag, completer.TYPE_ELEMENT) ] break return list()
def _GetCompletionInfo(self, command, calltip=False): """Get Completion list or Calltip @return: list or string """ if command is None or (len(command) and command[0].isdigit()): if calltip: return u"" return list() try: cmpl = PyCompleter() # Put the files directory on the path so eval has a better # chance of getting the proper completions fname = self._buffer.GetFileName() if fname: fpath = os.path.dirname(fname) sys.path.insert(0, fpath) t1 = time.time() cmpl.evalsource(self._buffer.GetText(), self._buffer.GetCurrentLine()) dbg("[pycomp][info] Completion eval time: %f" % (time.time() - t1)) if fname: sys.path.pop(0) if calltip: return cmpl.get_completions(command + u'(', u'', calltip) else: # Get Auto-completion List complst = cmpl.get_completions(command) sigs = list() type = completer.TYPE_UNKNOWN for sig in complst: word = sig['word'].rstrip(u'(.') if sig['type'] == "function": type = completer.TYPE_FUNCTION elif sig['type'] == "method": type = completer.TYPE_METHOD elif sig['type'] == "class": type = completer.TYPE_CLASS elif sig['type'] == "attribute": type = completer.TYPE_ATTRIBUTE elif sig['type'] == "property": type = completer.TYPE_PROPERTY sigs.append(completer.Symbol(word, type)) sigs.sort(key=lambda x: x.Name.upper()) return sigs except BaseException, msg: self._log("[pycomp][err] _GetCompletionInfo: %s, %s" % \ (sys.exc_info()[0], sys.exc_info()[1])) if calltip: return u"" else: return list()
def _GetCompletionInfo(self, command, calltip=False): """Get Completion list or Calltip @return: list or string """ bf = self.GetBuffer() # A list of Symbol(keyword, TYPE_UNKNOWN) kwlst = map(lambda kw: completer.Symbol(kw, completer.TYPE_UNKNOWN), bf.GetKeywords()) if command in (None, u''): return kwlst fillups = self.GetAutoCompFillups() if command[0].isdigit() or (command[-1] in fillups): return list() currentPos = bf.GetCurrentPos() # Get the real word: segment using autocompFillup tmp = command for ch in fillups: tmp = command.strip(ch) ls = list(tmp) ls.reverse() idx = 0 for c in ls: if c in fillups: break idx += 1 ls2 = ls[:idx] ls2.reverse() command = u"".join(ls2) # Available completions so far wordsNear = [] maxWordLength = 0 nWords = 0 minPos = 0 maxPos = bf.GetLength() flags = stc.STC_FIND_WORDSTART if self.GetCaseSensitive(): flags |= stc.STC_FIND_MATCHCASE posFind = bf.FindText(minPos, maxPos, command, flags) while posFind >= 0 and posFind < maxPos: wordEnd = posFind + len(command) if posFind != currentPos: while -1 != Completer.wordCharacters.find( chr(bf.GetCharAt(wordEnd))): wordEnd += 1 wordLength = wordEnd - posFind if wordLength > len(command): word = bf.GetTextRange(posFind, wordEnd) sym = completer.Symbol(word, completer.TYPE_UNKNOWN) if not wordsNear.count(sym): wordsNear.append(sym) maxWordLength = max(maxWordLength, wordLength) nWords += 1 minPos = wordEnd posFind = bf.FindText(minPos, maxPos, command, flags) if len(wordsNear) > 0 and (maxWordLength > len(command)): return wordsNear return kwlst
def GetAutoCompList(self, command): """Returns the list of possible completions for a command string. @param command: command lookup is done on """ if command in [None, u'']: return list() buff = self.GetBuffer() cpos = buff.GetCurrentPos() # Check if we are in a php region or not if buff.GetStyleAt(cpos) not in HTML_AREA: return list() # Get current context cline = buff.GetCurrentLine() ccol = buff.GetColumn(cpos) tmp = buff.GetLine(cline).rstrip() if ccol < len(tmp): tmp = tmp[:ccol].rstrip() # Check if we are completing an open tag (i.e < was typed) if tmp.endswith('<'): if buff.GetLexer() == wx.stc.STC_LEX_XML: taglst = _FindXmlTags(buff.GetText()) else: taglst = TAGS return completer.CreateSymbols(taglst, completer.TYPE_ELEMENT) # Check for a self closing tag (i.e />) endchk = tmp.strip().replace(u" ", u"").replace(u"\t", u"") if endchk.endswith(u"/>"): return list() # Try to autocomplete a closing tag (if necessary) tmp = tmp.rstrip('>').rstrip() if len(tmp) and (tmp[-1] in '"\' \t' or tmp[-1].isalpha()): # Walk backwards from the current line for line in range(cline, -1, -1): txt = buff.GetLine(line) if line == cline: txt = txt[:buff.GetColumn(cpos)] idx = txt.rfind('<') if idx != -1: parts = txt[idx:].lstrip('<').strip().split() if len(parts): tag = parts[0].rstrip('>') if len(tag) and \ tag not in ('img', 'br', '?php', '?xml', '?') and \ not tag[0] in ('!', '/'): rtag = u"</" + tag + u">" if not parts[-1].endswith('>'): rtag = u">" + rtag return [ completer.Symbol(rtag, completer.TYPE_ELEMENT) ] break return list()
def _GetCompletionInfo(self, command, calltip=False): """Get Completion list or Calltip @return: list or string """ if command is None or (len(command) and command[0].isdigit()): if calltip: return u"" return list() try: cmpl = PyCompleter() # Put the files directory on the path so eval has a better # chance of getting the proper completions fname = self._buffer.GetFileName() if fname: fpath = os.path.dirname(fname) sys.path.insert(0, fpath) snapshot = list(sys.modules.keys()) t1 = time.time() cmpl.evalsource(self._buffer.GetText(), self._buffer.GetCurrentLine()) dbg("[pycomp][info] Completion eval time: %f" % (time.time() - t1)) if fname: sys.path.pop(0) # Dump any other modules that got brought in during eval # so that they get properly updated on next pass through. nsnapshot = sys.modules.keys() nimport = list(set(nsnapshot).difference(set(snapshot))) for k in nimport: del sys.modules[k] if calltip: return cmpl.get_completions(command + u'(', u'', calltip) else: # Get Auto-completion List complst = cmpl.get_completions(command) sigs = list() tmap = { "function": completer.TYPE_FUNCTION, "method": completer.TYPE_METHOD, "class": completer.TYPE_CLASS, "attribute": completer.TYPE_ATTRIBUTE, "property": completer.TYPE_PROPERTY } for sig in complst: word = sig['word'].rstrip(u'(.') tval = tmap.get(sig['type'], completer.TYPE_UNKNOWN) sigs.append(completer.Symbol(word, tval)) sigs.sort(key=lambda x: x.Name.upper()) return sigs except BaseException, msg: self._log("[pycomp][err] _GetCompletionInfo: %s, %s" % \ (sys.exc_info()[0], sys.exc_info()[1])) if calltip: return u"" else: return list()