Exemplo n.º 1
0
 def signature_response_handler(decoded_message):
     if decoded_message['result'].get('signatures', None):
         tip = '{}\n\n{}'.format(
             decoded_message['result']['signatures'][0]['label'],
             decoded_message['result']['signatures'][0]['documentation']
             [:1000])
         if tip.strip():
             editor.callTipShow(editor.getCurrentPos(), tip)
Exemplo n.º 2
0
 def hover_response_handler(self, decoded_message):
     log(decoded_message)
     if 'contents' in decoded_message['result']:
         tip = decoded_message['result']['contents']
         if tip and self.current_hover_position != -1:
             if isinstance(tip[0], dict) and 'value' in tip[0]:
                 editor.callTipShow(self.current_hover_position,
                                    tip[0]['value'])
             else:
                 editor.callTipShow(self.current_hover_position,
                                    tip[0][:500])
             self.current_hover_position = -1
Exemplo n.º 3
0
 def onAutocomplete(self, args):
     '''Check if auto complete data can be added and displayed:
     "." after objects: show auto completion list with properties and methods
     "[" after dict: show auto completion list with keys
     "(" after functions: insert template and display a call tip with the doc string.'''
     if args['ch'] == 46 and args['code'] == 2001:  # character "."
         iPos = editor.getCurrentPos()
         autoCompleteList = self.interp.autoCompleteObject(
             self.getUncompleteLine(iPos))
         if autoCompleteList is None: return
         if autoCompleteList:
             editor.autoCSetSeparator(ord('\t'))
             editor.autoCSetIgnoreCase(False)
             editor.autoCSetCaseInsensitiveBehaviour(False)
             editor.autoCSetOrder(2)
             editor.autoCSetDropRestOfWord(True)
             editor.autoCShow(0, autoCompleteList)
     elif args['ch'] == 40 and args['code'] == 2001:  # character "("
         iPos = editor.getCurrentPos()
         r = self.interp.autoCompleteFunction(self.getUncompleteLine(iPos))
         if r is None: return
         n, funcParam, callTip = r
         if callTip:
             editor.callTipShow(max(0, iPos - n), callTip)
             editor.callTipSetHlt(0, max(0, callTip.find('\n')))
             self.activeCalltip = 'doc'
         if funcParam and iPos == editor.getCurrentPos():
             editor.insertText(iPos, funcParam + ')')
             editor.setSelectionStart(iPos)
             editor.setSelectionStart(iPos + len(funcParam) + 1)
             editor.setCurrentPos(iPos)
     elif args['ch'] == 91 and args['code'] == 2001:  # character "["
         iPos = editor.getCurrentPos()
         autoCompleteList = self.interp.autoCompleteDict(
             self.getUncompleteLine(iPos))
         if autoCompleteList:
             editor.autoCSetSeparator(ord('\t'))
             editor.autoCSetIgnoreCase(False)
             editor.autoCSetCaseInsensitiveBehaviour(False)
             editor.autoCSetOrder(0)
             editor.autoCSetDropRestOfWord(True)
             editor.autoCShow(0, autoCompleteList)
Exemplo n.º 4
0
 def showCalltip(self, pos=None):
     iStart = editor.getSelectionStart()
     iEnd = editor.getSelectionEnd()
     if pos is None:
         pos = editor.getCurrentPos()
         CT_unselected = True
         CT_expression = True
     else:
         CT_unselected = self.popupForUnselectedVariable
         CT_expression = self.popupForSelectedExpression
     if iEnd != iStart and iStart <= pos <= iEnd:
         if CT_expression and iEnd - iStart > 1:
             expression = editor.getTextRange(iStart, iEnd)
             if expression == 'False':
                 self.activeCalltip = False
                 editor.callTipShow(iStart, 'set to True')
             elif expression == 'True':
                 self.activeCalltip = True
                 editor.callTipShow(iStart, 'set to False')
             elif not '\n' in expression:
                 ret = self.interp.getCallTip(None, expression)
                 if ret and (CT_unselected or ret[-1] != 'value error'):
                     element, nHighlight, calltip = ret
                     self.activeCalltip = 'doc'
                     editor.callTipShow(iStart, ''.join(calltip))
                     editor.callTipSetHlt(0, int(nHighlight))
         else:
             iLineStart = editor.positionFromLine(
                 editor.lineFromPosition(iStart))
             var = editor.getTextRange(iStart, iEnd)
             line = editor.getTextRange(iLineStart, iEnd)
             if var == '.':
                 autoCompleteList = self.interp.autoCompleteObject(
                     self.getUncompleteLine(iStart + 1))
                 if autoCompleteList:
                     editor.autoCSetSeparator(ord('\t'))
                     editor.autoCSetIgnoreCase(False)
                     editor.autoCSetCaseInsensitiveBehaviour(False)
                     editor.autoCSetOrder(0)
                     editor.autoCSetDropRestOfWord(True)
                     editor.autoCShow(0, autoCompleteList)
             else:
                 ret = self.interp.getCallTip(line, var)
                 if ret:
                     element, nHighlight, calltip = ret
                     if element == var == 'False':
                         self.activeCalltip = False
                         editor.callTipShow(iStart, 'set to True')
                     elif element == var == 'True':
                         self.activeCalltip = True
                         editor.callTipShow(iStart, 'set to False')
                     elif ret[-1] != 'value error':
                         self.activeCalltip = 'doc'
                         editor.callTipShow(iStart, ''.join(calltip))
                         editor.callTipSetHlt(0, int(nHighlight))
     elif CT_unselected and iStart == iEnd and pos >= 0:
         iLine = editor.lineFromPosition(pos)
         line = editor.getLine(iLine)
         iLineStart = editor.positionFromLine(iLine)
         posInLine = pos - iLineStart
         iWordEnd = 0
         for iWordStart in range(posInLine, -1, -1):
             s = line[iWordStart]
             if not ('a' <= s <= 'z' or 'A' <= s <= 'Z' or '0' <= s <= '9'
                     or s == '_'):
                 iWordStart += 1
                 break
         if iWordStart <= posInLine:
             for iWordEnd in range(posInLine + 1, len(line)):
                 s = line[iWordEnd]
                 if not ('a' <= s <= 'z' or 'A' <= s <= 'Z'
                         or '0' <= s <= '9' or s == '_'):
                     iWordEnd -= 1
                     break
         var = line[iWordStart:iWordEnd + 1]
         if var:
             var = line[iWordStart:iWordEnd + 1]
             ret = self.interp.getCallTip(line[0:iWordEnd + 1], var)
             pos = iLineStart + iWordStart
             if ret:
                 element, nHighlight, calltip = ret
                 if calltip != 'value error':
                     self.activeCalltip = 'doc'
                     editor.callTipShow(pos, ''.join(calltip))
                     editor.callTipSetHlt(0, int(nHighlight))
Exemplo n.º 5
0
 def onMouseDwell(self, args):
     '''Show a call tip window about the current content
     of a selected variable'''
     if self.bufferBusy or self.interp.kernelBusy.isSet(): return
     if editor.callTipActive(): return
     p = editor.positionFromPoint(args['x'], args['y'])
     iStart = editor.getSelectionStart()
     iEnd = editor.getSelectionEnd()
     if iEnd != iStart and iStart <= p <= iEnd:
         if self.popupForSelectedExpression and iEnd - iStart > 1:
             expression = editor.getTextRange(iStart, iEnd)
             if expression == 'False':
                 self.activeCalltip = False
                 editor.callTipShow(iStart, 'set to True')
             elif expression == 'True':
                 self.activeCalltip = True
                 editor.callTipShow(iStart, 'set to False')
             elif not '\n' in expression:
                 ret = self.interp.getCallTip(None, expression)
                 if ret:
                     element, nHighlight, calltip = ret
                     self.activeCalltip = 'doc'
                     editor.callTipShow(iStart, ''.join(calltip))
                     editor.callTipSetHlt(0, int(nHighlight))
         else:
             iLineStart = editor.positionFromLine(
                 editor.lineFromPosition(iStart))
             var = editor.getTextRange(iStart, iEnd)
             line = editor.getTextRange(iLineStart, iEnd)
             if var == '.':
                 autoCompleteList = self.interp.autoCompleteObject(
                     self.getUncompleteLine(iStart + 1))
                 if autoCompleteList:
                     editor.autoCSetSeparator(ord('\t'))
                     editor.autoCSetIgnoreCase(False)
                     editor.autoCSetCaseInsensitiveBehaviour(False)
                     editor.autoCSetOrder(0)
                     editor.autoCSetDropRestOfWord(True)
                     editor.autoCShow(0, autoCompleteList)
             else:
                 ret = self.interp.getCallTip(line, var)
                 if ret:
                     element, nHighlight, calltip = ret
                     if element == var == 'False':
                         self.activeCalltip = False
                         editor.callTipShow(iStart, 'set to True')
                     elif element == var == 'True':
                         self.activeCalltip = True
                         editor.callTipShow(iStart, 'set to False')
                     else:
                         self.activeCalltip = 'doc'
                         editor.callTipShow(iStart, ''.join(calltip))
                         editor.callTipSetHlt(0, int(nHighlight))
     elif self.popupForUnselectedVariable and iStart == iEnd and p >= 0:
         iLine = editor.lineFromPosition(p)
         line = editor.getLine(iLine)
         iLineStart = editor.positionFromLine(iLine)
         posInLine = p - iLineStart
         iWordEnd = 0
         for iWordStart in range(posInLine, -1, -1):
             s = line[iWordStart]
             if not ('a' <= s <= 'z' or 'A' <= s <= 'Z' or '0' <= s <= '9'
                     or s == '_'):
                 iWordStart += 1
                 break
         if iWordStart <= posInLine:
             for iWordEnd in range(posInLine + 1, len(line)):
                 s = line[iWordEnd]
                 if not ('a' <= s <= 'z' or 'A' <= s <= 'Z'
                         or '0' <= s <= '9' or s == '_'):
                     iWordEnd -= 1
                     break
         var = line[iWordStart:iWordEnd + 1]
         if var:
             var = line[iWordStart:iWordEnd + 1]
             ret = self.interp.getCallTip(line[0:iWordEnd + 1], var)
             pos = iLineStart + iWordStart
             if ret:
                 element, nHighlight, calltip = ret
                 self.activeCalltip = 'doc'
                 editor.callTipShow(pos, ''.join(calltip))
                 editor.callTipSetHlt(0, int(nHighlight))