395 self.__acCompletionsFinished = 0 |
395 self.__acCompletionsFinished = 0 |
396 self.__acCache = E5Cache( |
396 self.__acCache = E5Cache( |
397 size=Preferences.getEditor("AutoCompletionCacheSize")) |
397 size=Preferences.getEditor("AutoCompletionCacheSize")) |
398 self.__acCache.setMaximumCacheTime( |
398 self.__acCache.setMaximumCacheTime( |
399 Preferences.getEditor("AutoCompletionCacheTime")) |
399 Preferences.getEditor("AutoCompletionCacheTime")) |
|
400 self.__acCacheEnabled = Preferences.getEditor( |
|
401 "AutoCompletionCacheEnabled") |
400 self.__acTimer = QTimer(self) |
402 self.__acTimer = QTimer(self) |
401 self.__acTimer.setSingleShot(True) |
403 self.__acTimer.setSingleShot(True) |
402 self.__acTimer.setInterval( |
404 self.__acTimer.setInterval( |
403 Preferences.getEditor("AutoCompletionTimeout")) |
405 Preferences.getEditor("AutoCompletionTimeout")) |
404 self.__acTimer.timeout.connect(self.__autoComplete) |
406 self.__acTimer.timeout.connect(self.__autoComplete) |
609 elif line0.startswith("index: "): |
611 elif line0.startswith("index: "): |
610 bindName = "dummy.diff" |
612 bindName = "dummy.diff" |
611 elif line0.startswith("\\documentclass"): |
613 elif line0.startswith("\\documentclass"): |
612 bindName = "dummy.tex" |
614 bindName = "dummy.tex" |
613 |
615 |
614 # check filetype |
|
615 if not bindName and self.filetype: |
616 if not bindName and self.filetype: |
616 if self.filetype in ["Python", "Python2"]: |
617 # check filetype |
|
618 from . import Lexers |
|
619 supportedLanguages = Lexers.getSupportedLanguages() |
|
620 if self.filetype in supportedLanguages: |
|
621 bindName = supportedLanguages[self.filetype][1] |
|
622 elif self.filetype in ["Python", "Python2", "Python3"]: |
617 bindName = "dummy.py" |
623 bindName = "dummy.py" |
618 elif self.filetype == "Python3": |
624 |
619 bindName = "dummy.py" |
|
620 elif self.filetype == "Ruby": |
|
621 bindName = "dummy.rb" |
|
622 elif self.filetype == "D": |
|
623 bindName = "dummy.d" |
|
624 elif self.filetype == "Properties": |
|
625 bindName = "dummy.ini" |
|
626 elif self.filetype == "JavaScript": |
|
627 bindName = "dummy.js" |
|
628 |
|
629 # #! marker detection |
|
630 if not bindName and line0.startswith("#!"): |
625 if not bindName and line0.startswith("#!"): |
|
626 # #! marker detection |
631 if "python3" in line0: |
627 if "python3" in line0: |
632 bindName = "dummy.py" |
628 bindName = "dummy.py" |
633 self.filetype = "Python3" |
629 self.filetype = "Python3" |
634 elif "python2" in line0: |
630 elif "python2" in line0: |
635 bindName = "dummy.py" |
631 bindName = "dummy.py" |
3293 @param margin id of the clicked margin (integer) |
3289 @param margin id of the clicked margin (integer) |
3294 @param line line number of the click (integer) |
3290 @param line line number of the click (integer) |
3295 @param modifiers keyboard modifiers (Qt.KeyboardModifiers) |
3291 @param modifiers keyboard modifiers (Qt.KeyboardModifiers) |
3296 """ |
3292 """ |
3297 if margin == self.__bmMargin: |
3293 if margin == self.__bmMargin: |
3298 self.toggleBookmark(line + 1) |
3294 self.toggleBookmark(line + 1) |
3299 elif margin == self.__bpMargin: |
3295 elif margin == self.__bpMargin: |
3300 self.__toggleBreakpoint(line + 1) |
3296 self.__toggleBreakpoint(line + 1) |
3301 elif margin == self.__indicMargin: |
3297 elif margin == self.__indicMargin: |
3302 if self.markersAtLine(line) & (1 << self.syntaxerror): |
3298 if self.markersAtLine(line) & (1 << self.syntaxerror): |
3303 self.__showSyntaxError(line) |
3299 self.__showSyntaxError(line) |
3304 elif self.markersAtLine(line) & (1 << self.warning): |
3300 elif self.markersAtLine(line) & (1 << self.warning): |
3305 self.__showWarning(line) |
3301 self.__showWarning(line) |
4107 # set the auto-completion function |
4103 # set the auto-completion function |
4108 self.__acCache.setSize( |
4104 self.__acCache.setSize( |
4109 Preferences.getEditor("AutoCompletionCacheSize")) |
4105 Preferences.getEditor("AutoCompletionCacheSize")) |
4110 self.__acCache.setMaximumCacheTime( |
4106 self.__acCache.setMaximumCacheTime( |
4111 Preferences.getEditor("AutoCompletionCacheTime")) |
4107 Preferences.getEditor("AutoCompletionCacheTime")) |
|
4108 self.__acCacheEnabled = Preferences.getEditor( |
|
4109 "AutoCompletionCacheEnabled") |
4112 acTimeout = Preferences.getEditor("AutoCompletionTimeout") |
4110 acTimeout = Preferences.getEditor("AutoCompletionTimeout") |
4113 if acTimeout != self.__acTimer.interval: |
4111 if acTimeout != self.__acTimer.interval: |
4114 self.__acTimer.setInterval(acTimeout) |
4112 self.__acTimer.setInterval(acTimeout) |
4115 self.__setAutoCompletion() |
4113 self.__setAutoCompletion() |
4116 |
4114 |
4675 if self.isListActive(): |
4673 if self.isListActive(): |
4676 self.cancelList() |
4674 self.cancelList() |
4677 |
4675 |
4678 if self.__completionListHookFunctions or \ |
4676 if self.__completionListHookFunctions or \ |
4679 self.__completionListAsyncHookFunctions: |
4677 self.__completionListAsyncHookFunctions: |
|
4678 # Avoid delayed auto-completion after cursor repositioning |
|
4679 self.__acText = self.__getAcText() |
4680 if auto and Preferences.getEditor("AutoCompletionTimeout"): |
4680 if auto and Preferences.getEditor("AutoCompletionTimeout"): |
4681 self.__acTimer.stop() |
4681 self.__acTimer.stop() |
4682 self.__acContext = context |
4682 self.__acContext = context |
4683 self.__acTimer.start() |
4683 self.__acTimer.start() |
4684 else: |
4684 else: |
4686 elif not auto: |
4686 elif not auto: |
4687 self.autoCompleteQScintilla() |
4687 self.autoCompleteQScintilla() |
4688 elif self.autoCompletionSource() != QsciScintilla.AcsNone: |
4688 elif self.autoCompletionSource() != QsciScintilla.AcsNone: |
4689 self.autoCompleteQScintilla() |
4689 self.autoCompleteQScintilla() |
4690 |
4690 |
|
4691 def __getAcText(self): |
|
4692 """ |
|
4693 Private method to get the text from cursor position for autocompleting. |
|
4694 |
|
4695 @return text left of cursor position |
|
4696 @rtype str |
|
4697 """ |
|
4698 line, col = self.getCursorPosition() |
|
4699 text = self.text(line) |
|
4700 try: |
|
4701 if self.__isStartChar(text[col - 1]): |
|
4702 acText = self.getWordLeft(line, col - 1) + text[col - 1] |
|
4703 else: |
|
4704 acText = self.getWordLeft(line, col) |
|
4705 except IndexError: |
|
4706 acText = "" |
|
4707 |
|
4708 return acText |
|
4709 |
4691 def __autoComplete(self, auto=True, context=None): |
4710 def __autoComplete(self, auto=True, context=None): |
4692 """ |
4711 """ |
4693 Private method to start auto-completion via plug-ins. |
4712 Private method to start auto-completion via plug-ins. |
4694 |
4713 |
4695 @keyparam auto flag indicating a call from the __charAdded method |
4714 @keyparam auto flag indicating a call from the __charAdded method |
4696 (boolean) |
4715 (boolean) |
4697 @keyparam context flag indicating to complete a context |
4716 @keyparam context flag indicating to complete a context |
4698 @type bool or None |
4717 @type bool or None |
4699 """ |
4718 """ |
4700 line, col = self.getCursorPosition() |
|
4701 text = self.text(line) |
|
4702 try: |
|
4703 if self.__isStartChar(text[col - 1]): |
|
4704 self.__acText = self.getWordLeft(line, col - 1) + text[col - 1] |
|
4705 else: |
|
4706 self.__acText = self.getWordLeft(line, col) |
|
4707 except IndexError: |
|
4708 self.__acText = "" |
|
4709 |
|
4710 self.__acCompletions.clear() |
4719 self.__acCompletions.clear() |
4711 self.__acCompletionsFinished = 0 |
4720 self.__acCompletionsFinished = 0 |
4712 |
4721 |
4713 # Suppress empty completions |
4722 # Suppress empty completions |
4714 if auto and self.__acText == '': |
4723 if auto and self.__acText == '': |
4715 return |
4724 return |
4716 |
4725 |
4717 completions = self.__acCache.get(self.__acText) |
4726 if self.__acCacheEnabled: |
|
4727 completions = self.__acCache.get(self.__acText) |
|
4728 else: |
|
4729 completions = None |
4718 if completions is not None: |
4730 if completions is not None: |
4719 # show list with cached entries |
4731 # show list with cached entries |
4720 if self.isListActive(): |
4732 if self.isListActive(): |
4721 self.cancelList() |
4733 self.cancelList() |
4722 |
4734 |
4745 @param completions list of possible completions |
4757 @param completions list of possible completions |
4746 @type list of str or set of str |
4758 @type list of str or set of str |
4747 @param acText text to be completed |
4759 @param acText text to be completed |
4748 @type str |
4760 @type str |
4749 """ |
4761 """ |
|
4762 currentWord = self.__getAcText() or ' ' |
4750 # process the list only, if not already obsolete ... |
4763 # process the list only, if not already obsolete ... |
4751 if acText != self.__acText: |
4764 if acText != self.__acText or not self.__acText.endswith(currentWord): |
|
4765 # Suppress auto-completion done by QScintilla as fallback |
|
4766 self.__acWatchdog.stop() |
4752 return |
4767 return |
4753 |
4768 |
4754 self.__acCompletions.update(set(completions)) |
4769 self.__acCompletions.update(set(completions)) |
4755 |
4770 |
4756 self.__acCompletionsFinished += 1 |
4771 self.__acCompletionsFinished += 1 |
4773 |
4788 |
4774 if self.isListActive(): |
4789 if self.isListActive(): |
4775 self.cancelList() |
4790 self.cancelList() |
4776 |
4791 |
4777 if self.__acCompletions: |
4792 if self.__acCompletions: |
4778 self.__acCache.add(acText, set(self.__acCompletions)) |
4793 if self.__acCacheEnabled: |
|
4794 self.__acCache.add(acText, set(self.__acCompletions)) |
4779 self.__showCompletionsList(self.__acCompletions) |
4795 self.__showCompletionsList(self.__acCompletions) |
4780 |
4796 |
4781 def __showCompletionsList(self, completions): |
4797 def __showCompletionsList(self, completions): |
4782 """ |
4798 """ |
4783 Private method to show the completions list. |
4799 Private method to show the completions list. |