316 if fn is None: |
316 if fn is None: |
317 fn = "" |
317 fn = "" |
318 mod = Module("", fn, imp.PY_SOURCE) |
318 mod = Module("", fn, imp.PY_SOURCE) |
319 mod.scan(src) |
319 mod.scan(src) |
320 |
320 |
321 if word: |
321 importCompletion = False |
|
322 if editor.isPy2File() or editor.isPy3File(): |
|
323 # check, if we are completing a from import statement |
|
324 maxLines = 10 |
|
325 text = editor.text(line).strip() |
|
326 while maxLines and line > 0 and not text.startswith("from"): |
|
327 line -= 1 |
|
328 textm1 = editor.text(line).strip() |
|
329 if not textm1.endswith("\\"): |
|
330 break |
|
331 text = textm1[:-1] + text |
|
332 maxLines -= 1 |
|
333 if text.startswith("from"): |
|
334 tokens = text.split() |
|
335 if len(tokens) >= 3 and tokens[2] == "import": |
|
336 importCompletion = True |
|
337 prefix = tokens[1] |
|
338 col = len(prefix) - 1 |
|
339 wsep = editor.getLexer().autoCompletionWordSeparators() |
|
340 while col >= 0 and prefix[col] not in wsep: |
|
341 col -= 1 |
|
342 if col >= 0: |
|
343 prefix = prefix[col + 1:] |
|
344 if word == tokens[2]: |
|
345 word = "" |
|
346 |
|
347 if word or importCompletion: |
322 if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: |
348 if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: |
323 api = self.__apisManager.getAPIs(language) |
349 api = self.__apisManager.getAPIs(language) |
324 apiCompletionsList = self.__getApiCompletions( |
350 apiCompletionsList = self.__getApiCompletions( |
325 api, word, context, prefix, mod, editor) |
351 api, word, context, prefix, mod, editor) |
326 |
352 |
327 if self.__plugin.getPreferences("AutoCompletionSource") & AcsProject: |
353 if self.__plugin.getPreferences("AutoCompletionSource") & AcsProject: |
328 api = self.__apisManager.getAPIs(ApisNameProject) |
354 api = self.__apisManager.getAPIs(ApisNameProject) |
329 projectCompletionList = self.__getApiCompletions( |
355 projectCompletionList = self.__getApiCompletions( |
330 api, word, context, prefix, mod, editor) |
356 api, word, context, prefix, mod, editor) |
331 |
357 |
332 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument: |
358 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument and \ |
|
359 not importCompletion: |
333 docCompletionsList = self.__getDocumentCompletions( |
360 docCompletionsList = self.__getDocumentCompletions( |
334 editor, word, context, sep, prefix, mod) |
361 editor, word, context, sep, prefix, mod) |
335 |
362 |
336 completionsList = list( |
363 completionsList = list( |
337 set(apiCompletionsList) |
364 set(apiCompletionsList) |
404 if completion["pictureId"]: |
431 if completion["pictureId"]: |
405 entry += "?{0}".format(completion["pictureId"]) |
432 entry += "?{0}".format(completion["pictureId"]) |
406 if entry not in completionsList: |
433 if entry not in completionsList: |
407 completionsList.append(entry) |
434 completionsList.append(entry) |
408 else: |
435 else: |
409 completions = api.getCompletions(start=word) |
436 if prefix: |
|
437 completions = api.getCompletions(start=word, context=prefix) |
|
438 else: |
|
439 completions = api.getCompletions(start=word) |
410 for completion in completions: |
440 for completion in completions: |
411 if not completion["context"]: |
441 if not completion["context"]: |
412 entry = completion["completion"] |
442 entry = completion["completion"] |
413 else: |
443 else: |
414 entry = "{0} ({1})".format( |
444 entry = "{0} ({1})".format( |