Skip to content

Commit ed67646

Browse files
committed
Optimize the accuracy of the autocompletion function.
1 parent 718ff7c commit ed67646

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

erl_autocompletion.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,28 @@ def on_query_completions(self, view, prefix, locations):
4141
if not view.match_selector(locations[0], "source.erlang"):
4242
return []
4343

44-
pt = locations[0] - len(prefix) - 1
45-
ch = view.substr(sublime.Region(pt, pt + 1))
44+
point = locations[0] - len(prefix) - 1
45+
letter = view.substr(point)
4646

47-
if ch == ':':
48-
module_name = view.substr(view.word(pt))
47+
if letter == ':':
48+
module_name = view.substr(view.word(point))
4949
if module_name.strip() == ':':
5050
return
5151

5252
flag = sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS
53-
5453
if module_name in cache['libs'].libs:
5554
return (cache['libs'].libs[module_name], flag)
5655

5756
if module_name in cache['project'].libs:
5857
return (cache['project'].libs[module_name], flag)
58+
else:
59+
if letter == '-' and view.substr(view.line(point))[0] == '-':
60+
return GLOBAL_SET['-key']
61+
62+
if re.match('^[0-9a-z_]+$', prefix) and len(prefix) > 1:
63+
return []
64+
65+
return ([], sublime.INHIBIT_EXPLICIT_COMPLETIONS)
5966

6067
def on_text_command(self, view, command_name, args):
6168
if command_name == 'goto' and 'event' in args:

util/settings.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,26 @@ def get_erl_lib_dir():
3434
'take_define' : re.compile(r'\?\s*(\w+)'),
3535
'take_include' : re.compile(r'-include\("([^\)]*)"\)')
3636
},
37-
'package_name' : 'Erl-AutoCompletion'
37+
'package_name' : 'Erl-AutoCompletion',
38+
'-key' : [
39+
["-behaviour\tDirectives", "-behaviour(${1:behaviour})."],
40+
["-callback\tDirectives", "-callback ${1:function}(${2:Parameters}) -> ${3:ReturnType}."],
41+
["-compile\tDirectives", "-compile([${1:export_all}])."],
42+
["-define\tDirectives", "-define(${1:macro}${2: (${3:param})], ${4:body})."],
43+
["-else\tDirectives", "-else."],
44+
["-endif\tDirectives", "-endif."],
45+
["-export\tDirectives", "-export([${1:function}/${2:arity}])."],
46+
["-export_type\tDirectives", "-export_type([${1:type}/${2:arity}])."],
47+
["-ifdef\tDirectives", "-ifdef(${1:macro})."],
48+
["-ifndef\tDirectives", "-ifndef(${1:macro})."],
49+
["-import\tDirectives", "-import(${1:module}, [${2:function}/${3:arity}])."],
50+
["-include\tDirectives", "-include(\"${1:file.hrl}\")."],
51+
["-include_lib\tDirectives", "-include_lib(\"${1:app/file.hrl}\")."],
52+
["-module\tDirectives", "-module(${1:${TM_FILEPATH/^.*\\/(.*)\\.[a-z]+$/$1/g}})."],
53+
["-opaque\tDirectives", "-opaque ${1:type}() :: ${2:term()}."],
54+
["-record\tDirectives", "-record(${1:record, {${2:field}${3: = ${4:value}}}})."],
55+
["-spec\tDirectives", "-spec ${1:function}(${2:Parameters}) -> ${3:ReturnType}."],
56+
["-type\tDirectives", "-type ${1:type}() :: ${2:term()}."],
57+
["-undef\tDirectives", "-undef(${1:macro})."]
58+
]
3859
}

0 commit comments

Comments
 (0)