-
Notifications
You must be signed in to change notification settings - Fork 0
/
YACAutoComplete.py
39 lines (35 loc) · 1.47 KB
/
YACAutoComplete.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Extends Sublime Text autocompletion to find matches in .ctags
# files. By default, Sublime only considers words from the current file.
# Current support: methods (f kind of ctags)
# TODOs:
# Check support for PHP's namespaces
# Check support for JS
import sublime_plugin
import sublime
from sublime import status_message
from yac.Class import *
from yac.CTags import *
from yac.Setting import *
from yac.Parser import *
class YACAutoComplete(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
results = []
try:
cTags = CTags(view)
except CTagsException as e:
status_message('YAC: CTags exception: ' + str(e))
return results
setting = Setting(view)
parser = Parser(view)
if not parser.isCurrentPositionAMethod() or not view.window().folders():
return results
if not setting.isSupportedSyntax():
status_message('YAC: auto complete not supported for language "' + setting.getSyntax() + '"')
return results
currentClass = cTags.getClassFromName(parser.getClassFromMethodInCurrentPosition())
results = cTags.getMethodsFromClass(currentClass, prefix)
if len(results):
results = [(result.getDefinitionLine().strip(), result.getDefinitionLine.strip().replace('$', '\$')) for result in results]
return (results, sublime.INHIBIT_EXPLICIT_COMPLETIONS)
else:
return results