AssistantEric/Assistant.py

changeset 177
25cb41783971
parent 174
5c66380af8e3
child 180
89ff060ef0d9
equal deleted inserted replaced
176:cd43366c7394 177:25cb41783971
5 5
6 """ 6 """
7 Module implementing the eric assistant, an alternative autocompletion and 7 Module implementing the eric assistant, an alternative autocompletion and
8 calltips system. 8 calltips system.
9 """ 9 """
10
11 from __future__ import unicode_literals
12 10
13 import re 11 import re
14 import imp 12 import imp
15 13
16 from PyQt5.QtCore import QRegExp, QObject 14 from PyQt5.QtCore import QRegExp, QObject
116 editor.editorSaved.connect( 114 editor.editorSaved.connect(
117 self.__apisManager.getAPIs(ApisNameProject).editorSaved) 115 self.__apisManager.getAPIs(ApisNameProject).editorSaved)
118 self.__editors.append(editor) 116 self.__editors.append(editor)
119 117
120 # preload the api to give the manager a chance to prepare the database 118 # preload the api to give the manager a chance to prepare the database
121 try: 119 language = editor.getApiLanguage()
122 language = editor.getApiLanguage()
123 except AttributeError:
124 # backward compatibility < 16.12
125 language = editor.apiLanguage
126 if language: 120 if language:
127 projectType = self.__getProjectType(editor) 121 projectType = self.__getProjectType(editor)
128 self.__apisManager.getAPIs(language, projectType=projectType) 122 self.__apisManager.getAPIs(language, projectType=projectType)
129 123
130 def __editorClosed(self, editor): 124 def __editorClosed(self, editor):
156 @type Editor 150 @type Editor
157 @return project type 151 @return project type
158 @rtype str 152 @rtype str
159 """ 153 """
160 filename = editor.getFileName() 154 filename = editor.getFileName()
161 if ( 155 projectType = (
162 self.__project.isOpen() and 156 self.__project.getProjectType()
163 filename and 157 if (self.__project.isOpen() and
164 self.__project.isProjectFile(filename) 158 filename and
165 ): 159 self.__project.isProjectFile(filename)) else
166 projectType = self.__project.getProjectType() 160 ""
167 else: 161 )
168 projectType = ""
169 162
170 return projectType 163 return projectType
171 164
172 ################################# 165 #################################
173 ## auto-completion methods below 166 ## auto-completion methods below
215 @param editor reference to the editor object, that called this method 208 @param editor reference to the editor object, that called this method
216 (QScintilla.Editor) 209 (QScintilla.Editor)
217 @param context flag indicating to autocomplete a context (boolean) 210 @param context flag indicating to autocomplete a context (boolean)
218 @return list of possible completions (list of strings) 211 @return list of possible completions (list of strings)
219 """ 212 """
220 try: 213 language = editor.getApiLanguage()
221 language = editor.getApiLanguage()
222 except AttributeError:
223 # backward compatibility < 16.12
224 language = editor.apiLanguage
225
226 completeFromDocumentOnly = False 214 completeFromDocumentOnly = False
227 if language in ["", "Guessed"] or language.startswith("Pygments|"): 215 if language in ["", "Guessed"] or language.startswith("Pygments|"):
228 if ( 216 if (
229 self.__plugin.getPreferences("AutoCompletionSource") & 217 self.__plugin.getPreferences("AutoCompletionSource") &
230 AcsDocument 218 AcsDocument
282 else: 270 else:
283 self.__lastContext = None 271 self.__lastContext = None
284 272
285 prefix = "" 273 prefix = ""
286 mod = None 274 mod = None
287 if context: 275 beg = beg[:col + 1] if context else editor.text(line)[:col]
288 beg = beg[:col + 1]
289 else:
290 beg = editor.text(line)[:col]
291 col = len(beg) 276 col = len(beg)
292 if language: 277 wseps = (
293 wseps = editor.getLexer().autoCompletionWordSeparators() 278 editor.getLexer().autoCompletionWordSeparators()
294 else: 279 if language else
295 wseps = [] 280 []
281 )
296 if wseps: 282 if wseps:
297 wseps.append(" ") 283 wseps.append(" ")
298 if col > 0 and beg[col - 1] in wseps: 284 if col > 0 and beg[col - 1] in wseps:
299 col -= 1 285 col -= 1
300 else: 286 else:
716 @param pos position in the text for the calltip (integer) 702 @param pos position in the text for the calltip (integer)
717 @param commas minimum number of commas contained in the calltip 703 @param commas minimum number of commas contained in the calltip
718 (integer) 704 (integer)
719 @return list of possible calltips (list of strings) 705 @return list of possible calltips (list of strings)
720 """ 706 """
721 try: 707 language = editor.getApiLanguage()
722 language = editor.getApiLanguage()
723 except AttributeError:
724 # backward compatibility < 16.12
725 language = editor.apiLanguage
726
727 completeFromDocumentOnly = False 708 completeFromDocumentOnly = False
728 if language in ["", "Guessed"] or language.startswith("Pygments|"): 709 if language in ["", "Guessed"] or language.startswith("Pygments|"):
729 if ( 710 if (
730 self.__plugin.getPreferences("AutoCompletionSource") & 711 self.__plugin.getPreferences("AutoCompletionSource") &
731 AcsDocument 712 AcsDocument
746 727
747 prefix = "" 728 prefix = ""
748 mod = None 729 mod = None
749 beg = editor.text(line)[:col] 730 beg = editor.text(line)[:col]
750 col = len(beg) 731 col = len(beg)
751 if language: 732 wseps = (
752 wseps = editor.getLexer().autoCompletionWordSeparators() 733 editor.getLexer().autoCompletionWordSeparators()
753 else: 734 if language else
754 wseps = [] 735 []
736 )
755 if wseps: 737 if wseps:
756 if col > 0 and beg[col - 1] in wseps: 738 if col > 0 and beg[col - 1] in wseps:
757 col -= 1 739 col -= 1
758 else: 740 else:
759 while col > 0 and beg[col - 1] not in wseps + [" ", "\t"]: 741 while col > 0 and beg[col - 1] not in wseps + [" ", "\t"]:

eric ide

mercurial