--- a/QScintilla/Editor.py Tue Oct 24 19:09:09 2017 +0200 +++ b/QScintilla/Editor.py Wed Oct 25 21:00:48 2017 +0200 @@ -388,6 +388,7 @@ self.__acContext = True self.__acText = "" self.__acCompletions = set() + self.__acCompletionsFinished = 0 self.__acCache = E5Cache( size=Preferences.getEditor("AutoCompletionCacheSize")) self.__acCache.setMaximumCacheTime( @@ -398,6 +399,12 @@ Preferences.getEditor("AutoCompletionTimeout")) self.__acTimer.timeout.connect(self.__autoComplete) + self.__acWatchdog = QTimer(self) + self.__acWatchdog.setSingleShot(True) + self.__acWatchdog.setInterval( + Preferences.getEditor("AutoCompletionWatchdogTime")) + self.__acWatchdog.timeout.connect(self.autoCompleteQScintilla) + self.__completionListHookFunctions = {} self.__completionListAsyncHookFunctions = {} self.__setAutoCompletion() @@ -4456,6 +4463,11 @@ """ Public method to perform an autocompletion using QScintilla methods. """ + self.__acText = ' ' # Prevent long running ACs to add results + self.__acWatchdog.stop() + if self.__acCompletions: + return + acs = Preferences.getEditor("AutoCompletionSource") if acs == QsciScintilla.AcsDocument: self.autoCompleteFromDocument() @@ -4673,6 +4685,7 @@ else: self.__acText = self.getWordLeft(line, col) self.__acCompletions.clear() + self.__acCompletionsFinished = 0 # Suppress empty completions if auto and self.__acText == '': @@ -4697,6 +4710,9 @@ completions = self.__completionListHookFunctions[key]( self, context) self.completionsListReady(completions, self.__acText) + + if Preferences.getEditor("AutoCompletionScintillaOnFail"): + self.__acWatchdog.start() # TODO: document this hook in chapter 6.2 of plug-in document def completionsListReady(self, completions, acText): @@ -4712,10 +4728,22 @@ if acText == self.__acText and bool(completions): # process the list only, if not already obsolete or completions # are not empty + self.__acCompletions.update(set(completions)) + + self.__acCompletionsFinished += 1 + # Got all results from auto completer? + if self.__acCompletionsFinished >= len( + self.__completionListAsyncHookFunctions): + self.__acWatchdog.stop() + + # Autocomplete with QScintilla if no results present + if (Preferences.getEditor("AutoCompletionScintillaOnFail") + and not self.__acCompletions): + self.autoCompleteQScintilla() + return if self.isListActive(): self.cancelList() - self.__acCompletions.update(set(completions)) if self.__acCompletions: self.__acCache.add(acText, set(self.__acCompletions)) self.__showCompletionsList(self.__acCompletions)