344 prefix = prefix[col + 1:] |
341 prefix = prefix[col + 1:] |
345 if word == tokens[2]: |
342 if word == tokens[2]: |
346 word = "" |
343 word = "" |
347 |
344 |
348 if word or importCompletion: |
345 if word or importCompletion: |
349 if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: |
346 completionsList = self.__getCompletions(word, context, prefix, language, |
350 api = self.__apisManager.getAPIs(language) |
347 mod, editor, importCompletion, sep) |
351 apiCompletionsList = self.__getApiCompletions( |
348 if len(completionsList) == 0 and prefix: |
352 api, word, context, prefix, mod, editor) |
349 # searching with prefix didn't return anything, try without |
353 |
350 completionsList = self.__getCompletions(word, context, "", language, |
354 if self.__plugin.getPreferences("AutoCompletionSource") & AcsProject: |
351 mod, editor, importCompletion, |
355 api = self.__apisManager.getAPIs(ApisNameProject) |
352 sep) |
356 projectCompletionList = self.__getApiCompletions( |
|
357 api, word, context, prefix, mod, editor) |
|
358 |
|
359 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument and \ |
|
360 not importCompletion: |
|
361 docCompletionsList = self.__getDocumentCompletions( |
|
362 editor, word, context, sep, prefix, mod) |
|
363 |
|
364 completionsList = list( |
|
365 set(apiCompletionsList) |
|
366 .union(set(docCompletionsList)) |
|
367 .union(set(projectCompletionList)) |
|
368 ) |
|
369 |
|
370 if len(completionsList) > 0: |
353 if len(completionsList) > 0: |
371 completionsList.sort() |
354 completionsList.sort() |
372 editor.showUserList(EditorAutoCompletionListID, completionsList) |
355 editor.showUserList(EditorAutoCompletionListID, completionsList) |
373 |
356 |
|
357 def __getCompletions(self, word, context, prefix, language, module, editor, |
|
358 importCompletion, sep): |
|
359 """ |
|
360 Private method to get the list of possible completions. |
|
361 |
|
362 @param word word (or wordpart) to complete (string) |
|
363 @param context flag indicating to autocomplete a context (boolean) |
|
364 @param prefix prefix of the word to be completed (string) |
|
365 @param language programming language of the source (string) |
|
366 @param module reference to the scanned module info (Module) |
|
367 @param editor reference to the editor object (QScintilla.Editor.Editor) |
|
368 @param importCompletion flag indicating an import completion (boolean) |
|
369 @param sep separator string (string) |
|
370 @return list of possible completions (list of strings) |
|
371 """ |
|
372 apiCompletionsList = [] |
|
373 docCompletionsList = [] |
|
374 projectCompletionList = [] |
|
375 |
|
376 if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: |
|
377 api = self.__apisManager.getAPIs(language) |
|
378 apiCompletionsList = self.__getApiCompletions( |
|
379 api, word, context, prefix, module, editor) |
|
380 |
|
381 if self.__plugin.getPreferences("AutoCompletionSource") & AcsProject: |
|
382 api = self.__apisManager.getAPIs(ApisNameProject) |
|
383 projectCompletionList = self.__getApiCompletions( |
|
384 api, word, context, prefix, module, editor) |
|
385 |
|
386 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument and \ |
|
387 not importCompletion: |
|
388 docCompletionsList = self.__getDocumentCompletions( |
|
389 editor, word, context, sep, prefix, module) |
|
390 |
|
391 completionsList = list( |
|
392 set(apiCompletionsList) |
|
393 .union(set(docCompletionsList)) |
|
394 .union(set(projectCompletionList)) |
|
395 ) |
|
396 return completionsList |
|
397 |
374 def __getApiCompletions(self, api, word, context, prefix, module, editor): |
398 def __getApiCompletions(self, api, word, context, prefix, module, editor): |
375 """ |
399 """ |
376 Private method to determine a list of completions from an API object. |
400 Private method to determine a list of completions from an API object. |
377 |
401 |
378 @param api reference to the API object to be used (APIsManager.DbAPIs) |
402 @param api reference to the API object to be used (APIsManager.DbAPIs) |
379 @param word word (or wordpart) to complete (string) |
403 @param word word (or wordpart) to complete (string) |
380 @param context flag indicating to autocomplete a context (boolean) |
404 @param context flag indicating to autocomplete a context (boolean) |
381 @param prefix prefix of the word to be completed (string) |
405 @param prefix prefix of the word to be completed (string) |
382 @param module reference to the scanned module info (Module) |
406 @param module reference to the scanned module info (Module) |
383 @param editor reference to the editor object (QScintilla.Editor) |
407 @param editor reference to the editor object (QScintilla.Editor.Editor) |
384 @return list of possible completions (list of strings) |
408 @return list of possible completions (list of strings) |
385 """ |
409 """ |
386 completionsList = [] |
410 completionsList = [] |
387 if api is not None: |
411 if api is not None: |
388 if prefix and module and prefix == "self": |
412 if prefix and module and prefix == "self": |
466 def __getDocumentCompletions(self, editor, word, context, sep, prefix, module, |
490 def __getDocumentCompletions(self, editor, word, context, sep, prefix, module, |
467 doHierarchy=False): |
491 doHierarchy=False): |
468 """ |
492 """ |
469 Private method to determine autocompletion proposals from the document. |
493 Private method to determine autocompletion proposals from the document. |
470 |
494 |
471 @param editor reference to the editor object (QScintilla.Editor) |
495 @param editor reference to the editor object (QScintilla.Editor.Editor) |
472 @param word string to be completed (string) |
496 @param word string to be completed (string) |
473 @param context flag indicating to autocomplete a context (boolean) |
497 @param context flag indicating to autocomplete a context (boolean) |
474 @param sep separator string (string) |
498 @param sep separator string (string) |
475 @param prefix prefix of the word to be completed (string) |
499 @param prefix prefix of the word to be completed (string) |
476 @param module reference to the scanned module info (Module) |
500 @param module reference to the scanned module info (Module) |