Skip to content

Commit f56b84d

Browse files
added ability to disable if wanted
1 parent eafb143 commit f56b84d

4 files changed

+41
-5
lines changed

LuaComplete.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def is_server_running(quick=False):
2222
return False
2323

2424
def start_server():
25+
global state
2526
# print("starting server")
2627
if not is_server_running():
2728
# clean up any old instances that may be running...
@@ -73,11 +74,10 @@ def create_completion(completion):
7374

7475
class LuaComplete(sublime_plugin.EventListener):
7576
def on_query_completions(self, view, prefix, locations):
76-
global state
77-
7877
position = locations[0]
7978
scopes = view.scope_name(position).split()
80-
if ('source.lua' not in scopes):
79+
80+
if ('source.lua' not in scopes or state["enabled"] == False):
8181
return None
8282

8383
# load the server if it's not running.
@@ -115,7 +115,7 @@ def on_query_completions(self, view, prefix, locations):
115115
file_contents = view.substr(sublime.Region(0, view.size())).encode('utf8')
116116

117117
# send it to the client
118-
print(command)
118+
# print(command)
119119
client = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
120120
# print(file_contents)
121121
# print(position)
@@ -156,6 +156,16 @@ def run(self):
156156
stop_server()
157157
start_server()
158158

159+
class DisableCommand(sublime_plugin.ApplicationCommand):
160+
def run(self):
161+
global state
162+
state["enabled"] = False
163+
164+
class EnableCommand(sublime_plugin.ApplicationCommand):
165+
def run(self):
166+
global state
167+
state["enabled"] = True
168+
159169
def plugin_loaded():
160170
global state
161171
state["settings"] = sublime.load_settings("LuaComplete.sublime-settings")
@@ -168,9 +178,15 @@ def plugin_loaded():
168178
if port is None:
169179
port = 24548
170180

181+
# figure out if it's enabled
182+
enabled = state["settings"].get("enabled")
183+
if enabled is None:
184+
enabled = True
185+
171186
# setup the command.
172187
state["server_command"] = "{path} server -p {port}".format(path=path, port=port)
173188
state["client_command"] = "{path} client -p {port}".format(path=path, port=port)
189+
state["enabled"] = enabled
174190

175191
# get any additional include locations
176192
state["additional_includes"] = state["settings"].get("additional_includes")

LuaComplete.sublime-commands

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
"caption": "LuaComplete: Clear Auto-complete Cache (Restart Server)",
44
"command": "clear_cache"
55
},
6+
{
7+
"caption": "LuaComplete: Disable",
8+
"command": "disable"
9+
},
10+
{
11+
"caption": "LuaComplete: Enable",
12+
"command": "enable"
13+
},
614
{
715
"caption": "Preferences: LuaComplete Settings – Default",
816
"command": "open_file", "args":

LuaComplete.sublime-settings

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
// Port to use for the lua-complete client and server
77
"port": 24548,
88

9+
// enable/disable toggle. it is enabled by default
10+
// you would set it to false to turn off LuaComplete
11+
// "enabled": false,
12+
// NOTE: it can also be toggled via the command palette
13+
// but will only apply until Sublime Text reboots
14+
915
// additional include location
1016
// by default lua-complete will search lua's regular
1117
// installed module paths (packages.path)

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LuaComplete is an ST3 plugin that does auto-completing of Lua code. It uses the
1616
3. That's about it! LuaComplete will start up the server and send code automatically via the client. There are a few settings that can be tweaked, as referenced below.
1717
1818
## Settings
19-
The default settings should work out of the box, but they can be modified via the Preferences menu or from the Command Palette (`Ctrl+Shift+P` and type LuaComplete). Make any changes in the User settings. Here are the default settings:
19+
The default settings should work out of the box, but they can be modified via the Preferences menu or from the Command Palette (`Ctrl+Shift+P` and type LuaComplete). Make any changes in the User settings. You will likely need to restart Sublime Text after changing settings. Here are the default settings:
2020
```
2121
{
2222
// Path to the directory containing lua-complete executables
@@ -26,6 +26,12 @@ The default settings should work out of the box, but they can be modified via th
2626
// Port to use for the lua-complete client and server
2727
"port": 24548,
2828

29+
// enable/disable toggle. it is enabled by default
30+
// you would set it to false to turn off LuaComplete
31+
// "enabled": false,
32+
// NOTE: it can also be toggled via the command palette
33+
// but will only apply until Sublime Text reboots
34+
2935
// additional include location
3036
// by default lua-complete will search lua's regular
3137
// installed module paths (packages.path)

0 commit comments

Comments
 (0)