AssistantEric/Assistant.py

changeset 42
2489ae0286ef
parent 41
333735b1a460
child 43
263a7d088c75
diff -r 333735b1a460 -r 2489ae0286ef AssistantEric/Assistant.py
--- a/AssistantEric/Assistant.py	Sun Oct 02 14:37:06 2011 +0200
+++ b/AssistantEric/Assistant.py	Sun Oct 02 18:18:43 2011 +0200
@@ -318,7 +318,33 @@
                 mod = Module("", fn, imp.PY_SOURCE)
                 mod.scan(src)
         
-        if word:
+        importCompletion = False
+        if editor.isPy2File() or editor.isPy3File():
+            # check, if we are completing a from import statement
+            maxLines = 10
+            text = editor.text(line).strip()
+            while maxLines and line > 0 and not text.startswith("from"):
+                line -= 1
+                textm1 = editor.text(line).strip()
+                if not textm1.endswith("\\"):
+                    break
+                text = textm1[:-1] + text
+                maxLines -= 1
+            if text.startswith("from"):
+                tokens = text.split()
+                if len(tokens) >= 3 and tokens[2] == "import":
+                    importCompletion = True
+                    prefix = tokens[1]
+                    col = len(prefix) - 1
+                    wsep = editor.getLexer().autoCompletionWordSeparators()
+                    while col >= 0 and prefix[col] not in wsep:
+                        col -= 1
+                    if col >= 0:
+                        prefix = prefix[col + 1:]
+                    if word == tokens[2]:
+                        word = ""
+        
+        if word or importCompletion:
             if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs:
                 api = self.__apisManager.getAPIs(language)
                 apiCompletionsList = self.__getApiCompletions(
@@ -329,7 +355,8 @@
                 projectCompletionList = self.__getApiCompletions(
                     api, word, context, prefix, mod, editor)
             
-            if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument:
+            if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument and \
+               not importCompletion:
                 docCompletionsList = self.__getDocumentCompletions(
                     editor, word, context, sep, prefix, mod)
             
@@ -406,7 +433,10 @@
                     if entry not in completionsList:
                         completionsList.append(entry)
             else:
-                completions = api.getCompletions(start=word)
+                if prefix:
+                    completions = api.getCompletions(start=word, context=prefix)
+                else:
+                    completions = api.getCompletions(start=word)
                 for completion in completions:
                     if not completion["context"]:
                         entry = completion["completion"]

eric ide

mercurial