Skip to content

Commit 7eb72d8

Browse files
committed
Return suggestions only for the first word in a comment line
As apiDoc tags are first words in comment lines, it is useless to provide apiDoc auto completion suggestions in the middle of the line. So, now apiDoc suggestions are provided only for the first word in a comment line.
1 parent 798177c commit 7eb72d8

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

apiDocAutocompletion.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,25 @@
55

66
import sublime
77
import sublime_plugin
8+
import re
89

910
SETTINGS_FILENAME = 'apiDocAutocompletion.sublime-settings'
1011

12+
13+
def is_line_start(view, location):
14+
"""
15+
Determines whether the given location is situated on beginning of the comment line
16+
Returns:
17+
bool: True if the location is situated in the beginning of the comment line,
18+
False otherwise
19+
"""
20+
word_bounds = view.word(location)
21+
line_bounds = view.line(location)
22+
prefix_bounds = sublime.Region(line_bounds.begin(), word_bounds.begin())
23+
prefix = view.substr(prefix_bounds)
24+
return re.search('\w', prefix) == None
25+
26+
1127
class apiDocAutocompletion(sublime_plugin.EventListener):
1228
_suggestions = [
1329
("@api\tapiDoc", "@api {${1:method}} ${2:path} ${3:[title]}"),
@@ -91,6 +107,7 @@ def on_query_completions(self, view, prefix, locations):
91107
current_scope = view.scope_name(location)
92108

93109
if any(scope in current_scope for scope in target_scopes) == True:
94-
return apiDocAutocompletion._suggestions
95-
else:
96-
return None
110+
if is_line_start(view, location):
111+
return apiDocAutocompletion._suggestions
112+
113+
return None

0 commit comments

Comments
 (0)