238 """ |
238 """ |
239 from QScintilla.Editor import EditorAutoCompletionListID |
239 from QScintilla.Editor import EditorAutoCompletionListID |
240 |
240 |
241 if editor.isListActive(): |
241 if editor.isListActive(): |
242 editor.cancelList() |
242 editor.cancelList() |
243 |
243 |
|
244 completionsList = self.getCompletionsList(editor, context) |
|
245 if len(completionsList) > 0: |
|
246 completionsList.sort() |
|
247 editor.showUserList(EditorAutoCompletionListID, |
|
248 completionsList) |
|
249 |
|
250 def getCompletionsList(self, editor, context): |
|
251 """ |
|
252 Public method to get a list of possible completions. |
|
253 |
|
254 @param editor reference to the editor object, that called this method |
|
255 (QScintilla.Editor) |
|
256 @param context flag indicating to autocomplete a context (boolean) |
|
257 @return list of possible completions (list of strings) |
|
258 """ |
244 language = editor.getLanguage() |
259 language = editor.getLanguage() |
245 if language == "": |
260 if language == "": |
246 return |
261 return [] |
247 |
262 |
248 line, col = editor.getCursorPosition() |
263 line, col = editor.getCursorPosition() |
249 self.__completingContext = context |
264 self.__completingContext = context |
250 sep = "" |
265 sep = "" |
251 if context: |
266 if context: |
351 if len(completionsList) == 0 and prefix: |
366 if len(completionsList) == 0 and prefix: |
352 # searching with prefix didn't return anything, try without |
367 # searching with prefix didn't return anything, try without |
353 completionsList = self.__getCompletions( |
368 completionsList = self.__getCompletions( |
354 word, context, "", language, mod, editor, importCompletion, |
369 word, context, "", language, mod, editor, importCompletion, |
355 sep) |
370 sep) |
356 if len(completionsList) > 0: |
371 return completionsList |
357 completionsList.sort() |
372 |
358 editor.showUserList(EditorAutoCompletionListID, |
373 return [] |
359 completionsList) |
|
360 |
374 |
361 def __getCompletions(self, word, context, prefix, language, module, editor, |
375 def __getCompletions(self, word, context, prefix, language, module, editor, |
362 importCompletion, sep): |
376 importCompletion, sep): |
363 """ |
377 """ |
364 Private method to get the list of possible completions. |
378 Private method to get the list of possible completions. |
756 |
770 |
757 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument: |
771 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument: |
758 documentCalltips = self.__getDocumentCalltips( |
772 documentCalltips = self.__getDocumentCalltips( |
759 word, prefix, mod, editor) |
773 word, prefix, mod, editor) |
760 |
774 |
761 return sorted( |
775 return list(sorted( |
762 set(apiCalltips) |
776 set(apiCalltips) |
763 .union(set(projectCalltips)) |
777 .union(set(projectCalltips)) |
764 .union(set(documentCalltips)) |
778 .union(set(documentCalltips)) |
765 ) |
779 )) |
766 |
780 |
767 def __getApiCalltips(self, api, word, commas, prefix, module, editor): |
781 def __getApiCalltips(self, api, word, commas, prefix, module, editor): |
768 """ |
782 """ |
769 Private method to determine calltips from APIs. |
783 Private method to determine calltips from APIs. |
770 |
784 |