372 if word == tokens[2]: |
407 if word == tokens[2]: |
373 word = "" |
408 word = "" |
374 |
409 |
375 if word or importCompletion: |
410 if word or importCompletion: |
376 completionsList = self.__getCompletions( |
411 completionsList = self.__getCompletions( |
377 word, context, prefix, language, mod, editor, |
412 word, context, prefix, language, projectType, mod, editor, |
378 importCompletion, sep) |
413 importCompletion, completeFromDocumentOnly, sep) |
379 if len(completionsList) == 0 and prefix: |
414 if len(completionsList) == 0 and prefix: |
380 # searching with prefix didn't return anything, try without |
415 # searching with prefix didn't return anything, try without |
381 completionsList = self.__getCompletions( |
416 completionsList = self.__getCompletions( |
382 word, context, "", language, mod, editor, importCompletion, |
417 word, context, "", language, projectType, mod, editor, |
383 sep) |
418 importCompletion, completeFromDocumentOnly, sep) |
384 return completionsList |
419 return completionsList |
385 |
420 |
386 return [] |
421 return [] |
387 |
422 |
388 def __getCompletions(self, word, context, prefix, language, module, editor, |
423 def __getCompletions(self, word, context, prefix, language, projectType, |
389 importCompletion, sep): |
424 module, editor, importCompletion, documentOnly, sep): |
390 """ |
425 """ |
391 Private method to get the list of possible completions. |
426 Private method to get the list of possible completions. |
392 |
427 |
393 @param word word (or wordpart) to complete (string) |
428 @param word word (or wordpart) to complete (string) |
394 @param context flag indicating to autocomplete a context (boolean) |
429 @param context flag indicating to autocomplete a context (boolean) |
395 @param prefix prefix of the word to be completed (string) |
430 @param prefix prefix of the word to be completed (string) |
396 @param language programming language of the source (string) |
431 @param language programming language of the source (string) |
|
432 @param projectType type of the project (string) |
397 @param module reference to the scanned module info (Module) |
433 @param module reference to the scanned module info (Module) |
398 @param editor reference to the editor object (QScintilla.Editor.Editor) |
434 @param editor reference to the editor object (QScintilla.Editor.Editor) |
399 @param importCompletion flag indicating an import completion (boolean) |
435 @param importCompletion flag indicating an import completion (boolean) |
|
436 @param documentOnly flag indicating to complete from the document only |
|
437 (boolean) |
400 @param sep separator string (string) |
438 @param sep separator string (string) |
401 @return list of possible completions (list of strings) |
439 @return list of possible completions (list of strings) |
402 """ |
440 """ |
403 apiCompletionsList = [] |
441 apiCompletionsList = [] |
404 docCompletionsList = [] |
442 docCompletionsList = [] |
405 projectCompletionList = [] |
443 projectCompletionList = [] |
406 |
444 |
407 if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: |
445 if not documentOnly: |
408 api = self.__apisManager.getAPIs(language) |
446 if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: |
409 apiCompletionsList = self.__getApiCompletions( |
447 api = self.__apisManager.getAPIs( |
410 api, word, context, prefix, module, editor) |
448 language, projectType=projectType) |
411 |
449 apiCompletionsList = self.__getApiCompletions( |
412 if self.__plugin.getPreferences("AutoCompletionSource") & AcsProject: |
450 api, word, context, prefix, module, editor) |
413 api = self.__apisManager.getAPIs(ApisNameProject) |
451 |
414 projectCompletionList = self.__getApiCompletions( |
452 if self.__plugin.getPreferences("AutoCompletionSource") & \ |
415 api, word, context, prefix, module, editor) |
453 AcsProject: |
|
454 api = self.__apisManager.getAPIs(ApisNameProject) |
|
455 projectCompletionList = self.__getApiCompletions( |
|
456 api, word, context, prefix, module, editor) |
416 |
457 |
417 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument \ |
458 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument \ |
418 and not importCompletion: |
459 and not importCompletion: |
419 docCompletionsList = self.__getDocumentCompletions( |
460 docCompletionsList = self.__getDocumentCompletions( |
420 editor, word, context, sep, prefix, module) |
461 editor, word, context, sep, prefix, module) |
736 @param pos position in the text for the calltip (integer) |
777 @param pos position in the text for the calltip (integer) |
737 @param commas minimum number of commas contained in the calltip |
778 @param commas minimum number of commas contained in the calltip |
738 (integer) |
779 (integer) |
739 @return list of possible calltips (list of strings) |
780 @return list of possible calltips (list of strings) |
740 """ |
781 """ |
741 language = editor.getLanguage() |
782 try: |
742 if language == "": |
783 language = editor.getApiLanguage() |
743 return |
784 except AttributeError: |
|
785 # backward compatibility |
|
786 language = editor.apiLanguage |
|
787 |
|
788 completeFromDocumentOnly = False |
|
789 if language in ["", "Guessed"] or language.startswith("Pygments|"): |
|
790 if self.__plugin.getPreferences("AutoCompletionSource") & \ |
|
791 AcsDocument: |
|
792 completeFromDocumentOnly = True |
|
793 else: |
|
794 return [] |
|
795 |
|
796 projectType = self.__getProjectType(editor) |
744 |
797 |
745 line, col = editor.lineIndexFromPosition(pos) |
798 line, col = editor.lineIndexFromPosition(pos) |
746 wc = re.sub("\w", "", editor.wordCharacters()) |
799 wc = re.sub("\w", "", editor.wordCharacters()) |
747 pat = re.compile("\w{0}".format(re.escape(wc))) |
800 pat = re.compile("\w{0}".format(re.escape(wc))) |
748 text = editor.text(line) |
801 text = editor.text(line) |
776 |
829 |
777 apiCalltips = [] |
830 apiCalltips = [] |
778 projectCalltips = [] |
831 projectCalltips = [] |
779 documentCalltips = [] |
832 documentCalltips = [] |
780 |
833 |
781 if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: |
834 if not completeFromDocumentOnly: |
782 api = self.__apisManager.getAPIs(language) |
835 if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: |
783 if api is not None: |
836 api = self.__apisManager.getAPIs( |
784 apiCalltips = self.__getApiCalltips( |
837 language, projectType=projectType) |
|
838 if api is not None: |
|
839 apiCalltips = self.__getApiCalltips( |
|
840 api, word, commas, prefix, mod, editor) |
|
841 |
|
842 if self.__plugin.getPreferences("AutoCompletionSource") & \ |
|
843 AcsProject: |
|
844 api = self.__apisManager.getAPIs(ApisNameProject) |
|
845 projectCalltips = self.__getApiCalltips( |
785 api, word, commas, prefix, mod, editor) |
846 api, word, commas, prefix, mod, editor) |
786 |
|
787 if self.__plugin.getPreferences("AutoCompletionSource") & AcsProject: |
|
788 api = self.__apisManager.getAPIs(ApisNameProject) |
|
789 projectCalltips = self.__getApiCalltips( |
|
790 api, word, commas, prefix, mod, editor) |
|
791 |
847 |
792 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument: |
848 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument: |
793 documentCalltips = self.__getDocumentCalltips( |
849 documentCalltips = self.__getDocumentCalltips( |
794 word, prefix, mod, editor) |
850 word, prefix, mod, editor) |
795 |
851 |