Mon, 03 Oct 2011 19:16:34 +0200
Refined the autocompletion function even further.
--- a/AssistantEric/Assistant.py Mon Oct 03 13:12:36 2011 +0200 +++ b/AssistantEric/Assistant.py Mon Oct 03 19:16:34 2011 +0200 @@ -246,9 +246,6 @@ line, col = editor.getCursorPosition() self.__completingContext = context - apiCompletionsList = [] - docCompletionsList = [] - projectCompletionList = [] sep = "" if context: wc = re.sub("\w", "", editor.wordCharacters()) @@ -346,31 +343,58 @@ word = "" if word or importCompletion: - if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: - api = self.__apisManager.getAPIs(language) - apiCompletionsList = self.__getApiCompletions( - api, word, context, prefix, mod, editor) - - if self.__plugin.getPreferences("AutoCompletionSource") & AcsProject: - api = self.__apisManager.getAPIs(ApisNameProject) - projectCompletionList = self.__getApiCompletions( - api, word, context, prefix, mod, editor) - - if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument and \ - not importCompletion: - docCompletionsList = self.__getDocumentCompletions( - editor, word, context, sep, prefix, mod) - - completionsList = list( - set(apiCompletionsList) - .union(set(docCompletionsList)) - .union(set(projectCompletionList)) - ) - + completionsList = self.__getCompletions(word, context, prefix, language, + mod, editor, importCompletion, sep) + if len(completionsList) == 0 and prefix: + # searching with prefix didn't return anything, try without + completionsList = self.__getCompletions(word, context, "", language, + mod, editor, importCompletion, + sep) if len(completionsList) > 0: completionsList.sort() editor.showUserList(EditorAutoCompletionListID, completionsList) + def __getCompletions(self, word, context, prefix, language, module, editor, + importCompletion, sep): + """ + Private method to get the list of possible completions. + + @param word word (or wordpart) to complete (string) + @param context flag indicating to autocomplete a context (boolean) + @param prefix prefix of the word to be completed (string) + @param language programming language of the source (string) + @param module reference to the scanned module info (Module) + @param editor reference to the editor object (QScintilla.Editor.Editor) + @param importCompletion flag indicating an import completion (boolean) + @param sep separator string (string) + @return list of possible completions (list of strings) + """ + apiCompletionsList = [] + docCompletionsList = [] + projectCompletionList = [] + + if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: + api = self.__apisManager.getAPIs(language) + apiCompletionsList = self.__getApiCompletions( + api, word, context, prefix, module, editor) + + if self.__plugin.getPreferences("AutoCompletionSource") & AcsProject: + api = self.__apisManager.getAPIs(ApisNameProject) + projectCompletionList = self.__getApiCompletions( + api, word, context, prefix, module, editor) + + if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument and \ + not importCompletion: + docCompletionsList = self.__getDocumentCompletions( + editor, word, context, sep, prefix, module) + + completionsList = list( + set(apiCompletionsList) + .union(set(docCompletionsList)) + .union(set(projectCompletionList)) + ) + return completionsList + def __getApiCompletions(self, api, word, context, prefix, module, editor): """ Private method to determine a list of completions from an API object. @@ -380,7 +404,7 @@ @param context flag indicating to autocomplete a context (boolean) @param prefix prefix of the word to be completed (string) @param module reference to the scanned module info (Module) - @param editor reference to the editor object (QScintilla.Editor) + @param editor reference to the editor object (QScintilla.Editor.Editor) @return list of possible completions (list of strings) """ completionsList = [] @@ -468,7 +492,7 @@ """ Private method to determine autocompletion proposals from the document. - @param editor reference to the editor object (QScintilla.Editor) + @param editor reference to the editor object (QScintilla.Editor.Editor) @param word string to be completed (string) @param context flag indicating to autocomplete a context (boolean) @param sep separator string (string)
--- a/AssistantEric/Documentation/source/Plugin_Assistant_Eric.AssistantEric.Assistant.html Mon Oct 03 13:12:36 2011 +0200 +++ b/AssistantEric/Documentation/source/Plugin_Assistant_Eric.AssistantEric.Assistant.html Mon Oct 03 19:16:34 2011 +0200 @@ -80,6 +80,9 @@ <td><a href="#Assistant.__getCharacter">__getCharacter</a></td> <td>Private method to get the character to the left of the current position in the current line.</td> </tr><tr> +<td><a href="#Assistant.__getCompletions">__getCompletions</a></td> +<td>Private method to get the list of possible completions.</td> +</tr><tr> <td><a href="#Assistant.__getDocumentCalltips">__getDocumentCalltips</a></td> <td>Private method to determine calltips from the document.</td> </tr><tr> @@ -223,7 +226,7 @@ reference to the scanned module info (Module) </dd><dt><i>editor</i></dt> <dd> -reference to the editor object (QScintilla.Editor) +reference to the editor object (QScintilla.Editor.Editor) </dd> </dl><dl> <dt>Returns:</dt> @@ -250,6 +253,42 @@ requested character or "", if there are no more (string) and the next position (i.e. pos - 1) </dd> +</dl><a NAME="Assistant.__getCompletions" ID="Assistant.__getCompletions"></a> +<h4>Assistant.__getCompletions</h4> +<b>__getCompletions</b>(<i>word, context, prefix, language, module, editor, importCompletion, sep</i>) +<p> + Private method to get the list of possible completions. +</p><dl> +<dt><i>word</i></dt> +<dd> +word (or wordpart) to complete (string) +</dd><dt><i>context</i></dt> +<dd> +flag indicating to autocomplete a context (boolean) +</dd><dt><i>prefix</i></dt> +<dd> +prefix of the word to be completed (string) +</dd><dt><i>language</i></dt> +<dd> +programming language of the source (string) +</dd><dt><i>module</i></dt> +<dd> +reference to the scanned module info (Module) +</dd><dt><i>editor</i></dt> +<dd> +reference to the editor object (QScintilla.Editor.Editor) +</dd><dt><i>importCompletion</i></dt> +<dd> +flag indicating an import completion (boolean) +</dd><dt><i>sep</i></dt> +<dd> +separator string (string) +</dd> +</dl><dl> +<dt>Returns:</dt> +<dd> +list of possible completions (list of strings) +</dd> </dl><a NAME="Assistant.__getDocumentCalltips" ID="Assistant.__getDocumentCalltips"></a> <h4>Assistant.__getDocumentCalltips</h4> <b>__getDocumentCalltips</b>(<i>word, prefix, module, editor, doHierarchy=False</i>) @@ -285,7 +324,7 @@ </p><dl> <dt><i>editor</i></dt> <dd> -reference to the editor object (QScintilla.Editor) +reference to the editor object (QScintilla.Editor.Editor) </dd><dt><i>word</i></dt> <dd> string to be completed (string)