├── CONTRIBUTING.md ├── LICENSE.md ├── LuaComplete.py ├── LuaComplete.sublime-commands ├── LuaComplete.sublime-settings ├── Main.sublime-menu ├── Preferences.sublime-settings ├── README.md ├── messages.json └── messages └── post-install.txt /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | ## General Issues/Questions/Feature Suggestion 4 | If you just have an issue, question, or feature suggestion feel free to open a new issue on GitHub. I'll get to it when I can! 5 | 6 | ## Want to help out? 7 | Follow these guidelines: 8 | 9 | 1. Create an issue on GitHub so we can discuss it 10 | 1. Fork the repo 11 | 1. Make your changes in your fork 12 | 1. Create a pull request with a reference to the GitHub issue 13 | 1. Wait for feedback 14 | 1. Celebrate when it's merged! -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Shakil Thakur 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LuaComplete.py: -------------------------------------------------------------------------------- 1 | import sublime, sublime_plugin 2 | from subprocess import Popen, PIPE, call, STDOUT 3 | import sys, time 4 | 5 | state = {} 6 | 7 | def is_server_running(quick=False): 8 | 9 | # this is probably enough to see if everything is running 10 | if quick: 11 | if "server" in state: 12 | return True 13 | else: 14 | return False 15 | 16 | if "server" in state: 17 | if state["server"].poll() == None: 18 | return True 19 | else: 20 | return False 21 | else: 22 | return False 23 | 24 | def start_server(): 25 | global state 26 | # print("starting server") 27 | if not is_server_running(): 28 | # clean up any old instances that may be running... 29 | stop_server() 30 | state["server"] = Popen(state["server_command"], shell=True) 31 | 32 | # else: 33 | # print("LuaComplete: server already running") 34 | 35 | def stop_server(): 36 | # try to cleanly bring it down. 37 | shutdown = Popen(state["client_command"] + " -x", shell=True) 38 | shutdown.wait(.5) 39 | 40 | # if the command fails, and it's still running. terminate it. 41 | if shutdown.returncode != 0: 42 | if is_server_running(): 43 | state["server"].terminate() 44 | 45 | def create_completion(completion): 46 | (name, completion_type) = completion.split(":") 47 | completion_type = completion_type.strip() 48 | completion = name 49 | # add the '(' for functions! 50 | if completion_type.startswith("function"): 51 | completion = name + "(" 52 | 53 | # it's a Lua func and params have been found 54 | # if "|" in completion_type 55 | # doing this for the speed! 56 | if len(completion_type) >= 10: 57 | # split out the function params 58 | params = completion_type[11:].split() 59 | 60 | # set the completion type to just the start 61 | completion_type = completion_type[0:9] + "()" 62 | 63 | # figure this thing out 64 | completion = completion + ", ".join([ "${{{num}:{name}}}".format(num=num+1, name=val) for (num, val) in enumerate(params)]) 65 | completion = completion + ")" 66 | 67 | # for c funcs, we can't do completion 68 | else: 69 | completion = completion + "$1)" 70 | 71 | 72 | return "{0}\t{1}".format(name, completion_type), completion 73 | 74 | 75 | class LuaComplete(sublime_plugin.EventListener): 76 | def on_query_completions(self, view, prefix, locations): 77 | position = locations[0] 78 | scopes = view.scope_name(position).split() 79 | 80 | if ('source.lua' not in scopes or state["enabled"] == False): 81 | return None 82 | 83 | # load the server if it's not running. 84 | if not is_server_running(quick=True): 85 | start_server() 86 | 87 | # we can only autocomplete certain things 88 | current_char = view.substr(position-1) 89 | if current_char not in [":", ".", "[", "("]: 90 | return None 91 | 92 | # build the main command 93 | command = "{client} -i -c {pos}".format(client=state["client_command"], pos=str(position)) 94 | 95 | # append the filename if it exists 96 | file_name = view.file_name() 97 | if file_name is not None: 98 | command = command + " -f '{0}'".format(file_name) 99 | 100 | # get all the window vars 101 | package_folders = [] 102 | window_vars = view.window().extract_variables() 103 | if "folder" in window_vars: 104 | package_folders.append(window_vars["folder"]) 105 | 106 | if state["additional_includes"]: 107 | package_folders.append(state["additional_includes"]) 108 | 109 | # did we find a folder to add? 110 | if package_folders: 111 | command = command + " -r '{0}'".format(';'.join(package_folders)) 112 | 113 | 114 | # get the file contents 115 | file_contents = view.substr(sublime.Region(0, view.size())).encode('utf8') 116 | 117 | # send it to the client 118 | # print(command) 119 | client = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT) 120 | # print(file_contents) 121 | # print(position) 122 | 123 | # send communicate on stdin to the client 124 | output = client.communicate(file_contents)[0].decode('utf-8') 125 | # print("returncode", client.returncode) 126 | 127 | if client.returncode == 0: 128 | view.set_status("a", "") 129 | output = output.splitlines() 130 | output_type = output[0] 131 | # print(output_type) 132 | # main output is on lines 1 and below 133 | output = output[1:] 134 | # print(output) 135 | if output_type == "table": 136 | return [ create_completion(x) for x in output ] 137 | 138 | else: 139 | view.set_status("a", "The lua-complete client failed to return") 140 | # potentially retry the command or restart the server if his happens. 141 | 142 | def __exit__(self, type, value, traceback): 143 | stop_server() 144 | 145 | # start and stop are really only used for debug 146 | # class StartServerCommand(sublime_plugin.ApplicationCommand): 147 | # def run(self): 148 | # start_server() 149 | 150 | # class StopServerCommand(sublime_plugin.ApplicationCommand): 151 | # def run(self): 152 | # stop_server() 153 | 154 | class ClearCacheCommand(sublime_plugin.ApplicationCommand): 155 | def run(self): 156 | stop_server() 157 | start_server() 158 | 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 | 169 | def plugin_loaded(): 170 | global state 171 | state["settings"] = sublime.load_settings("LuaComplete.sublime-settings") 172 | 173 | # strip out the path/port 174 | path = state["settings"].get("path") 175 | if path is None: 176 | path = "lua-complete" 177 | port = state["settings"].get("port") 178 | if port is None: 179 | port = 24548 180 | 181 | # figure out if it's enabled 182 | enabled = state["settings"].get("enabled") 183 | if enabled is None: 184 | enabled = True 185 | 186 | # setup the command. 187 | state["server_command"] = "{path} server -p {port}".format(path=path, port=port) 188 | state["client_command"] = "{path} client -p {port}".format(path=path, port=port) 189 | state["enabled"] = enabled 190 | 191 | # get any additional include locations 192 | state["additional_includes"] = state["settings"].get("additional_includes") 193 | -------------------------------------------------------------------------------- /LuaComplete.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "LuaComplete: Clear Auto-complete Cache (Restart Server)", 4 | "command": "clear_cache" 5 | }, 6 | { 7 | "caption": "LuaComplete: Disable", 8 | "command": "disable" 9 | }, 10 | { 11 | "caption": "LuaComplete: Enable", 12 | "command": "enable" 13 | }, 14 | { 15 | "caption": "Preferences: LuaComplete Settings – Default", 16 | "command": "open_file", "args": 17 | { 18 | "file": "${packages}/LuaComplete/LuaComplete.sublime-settings" 19 | } 20 | }, 21 | { 22 | "caption": "Preferences: LuaComplete Settings – User", 23 | "command": "open_file", "args": 24 | { 25 | "file": "${packages}/User/LuaComplete.sublime-settings" 26 | } 27 | } 28 | ] 29 | -------------------------------------------------------------------------------- /LuaComplete.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | // Path to the directory containing lua-complete executables 3 | // if installed everywhere, just "lua-complete" should be fine 4 | "path": "lua-complete", 5 | 6 | // Port to use for the lua-complete client and server 7 | "port": 24548, 8 | 9 | // enable/disable toggle. it is enabled by default 10 | // set it to false to turn off LuaComplete 11 | // and restart Sublime Text for it to take affect 12 | // "enabled": true, 13 | // NOTE: it can also be enabled/disabled via the command palette 14 | // but will only stick until the next Sublime Text reboot 15 | 16 | // additional include location 17 | // by default lua-complete will search lua's regular 18 | // installed module paths (packages.path) 19 | // 20 | // The LuaComplete plugin will send the currently 21 | // open folder in the sublime text view for analysis 22 | // 23 | // Additional include locations can be specified in a 24 | // semi-colon delimited list below (be sure to comment out the line below) 25 | // "additional_includes": "/my/random/file/path;/another/path" 26 | } -------------------------------------------------------------------------------- /Main.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Preferences", 4 | "id": "preferences", 5 | "children": [ 6 | { 7 | "caption": "Package Settings", 8 | "mnemonic": "P", 9 | "id": "package-settings", 10 | "children": [ 11 | { 12 | "caption": "LuaComplete", 13 | "children": [ 14 | { 15 | "command": "open_file", 16 | "args": {"file": "${packages}/LuaComplete/LuaComplete.sublime-settings"}, 17 | "caption": "Settings – Default" 18 | }, 19 | { 20 | "command": "open_file", 21 | "args": {"file": "${packages}/User/LuaComplete.sublime-settings"}, 22 | "caption": "Settings – User" 23 | } 24 | ] 25 | } 26 | ] 27 | } 28 | ] 29 | } 30 | ] 31 | -------------------------------------------------------------------------------- /Preferences.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | "auto_complete_triggers": [ 3 | {"selector": "source.lua", "characters": "\\."}, 4 | {"selector": "source.lua", "characters": ":"} 5 | ] 6 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated: LuaComplete for Sublime Text 3 2 | LuaComplete is no longer being worked on. There are numerous other lua code completion tools out there (with actual language-server support!) 3 | 4 | Alternatives to take a look at: 5 | * https://github.com/sumneko/lua-language-server 6 | * https://github.com/EmmyLua/EmmyLua-LanguageServer 7 | 8 | 9 | # Original README below 10 | LuaComplete is an ST3 plugin that does auto-completing of Lua code. It uses the [lua-complete](https://github.com/FourierTransformer/lua-complete) engine for auto-completion and makes your Lua development a lot easier! 11 | ![Image of LuaComplete in Action](http://fouriertransformer.github.io/LuaComplete-Sublime/images/ftcsv-small.png) 12 | 13 | ## Installation 14 | 1. Install [lua-complete](https://github.com/FourierTransformer/lua-complete#setup) 15 | 16 | 2. Install the plugin. Currently, you can only install it manually: 17 | ``` 18 | cd /Users/[user]/Library/Application Support/Sublime Text 3/Packages/ 19 | git clone https://github.com/FourierTransformer/LuaComplete-Sublime LuaComplete 20 | ``` 21 | 22 | I'm working on a few more things before getting it in Package Control. 23 | 24 | 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. 25 | 26 | ## Settings 27 | 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: 28 | ``` 29 | { 30 | // Path to the directory containing lua-complete executables 31 | // if installed everywhere, just "lua-complete" should be fine 32 | "path": "lua-complete", 33 | 34 | // Port to use for the lua-complete client and server 35 | "port": 24548, 36 | 37 | // enable/disable toggle. it is enabled by default 38 | // set it to false to turn off LuaComplete 39 | // and restart Sublime Text for it to take effect 40 | // "enabled": true, 41 | // NOTE: it can also be enabled/disabled via the command palette 42 | // but will only stick until the next Sublime Text reboot 43 | 44 | // additional include location 45 | // by default lua-complete will search lua's regular 46 | // installed module paths (packages.path) 47 | // 48 | // The LuaComplete plugin will send the currently 49 | // open folder in the sublime text view for analysis 50 | // 51 | // Additional include locations can be specified in a 52 | // semi-colon delimited list below (be sure to comment out the line below) 53 | // "additional_includes": "/my/random/file/path;/another/path" 54 | } 55 | ``` 56 | 57 | ## Features and Shortcomings 58 | * It will only auto-complete things in tables - which includes most lua modules! 59 | * It can only determine function parameters for Lua functions (it currently doesn't know if a parameter is optional or not). 60 | * It should work with project-level files (by searching through the folder open in sublime text or folder the file resides in) 61 | * In the future, it should include function parameters for the built-in lua functions. However, it is not possible to determine function parameters for other C functions - without hard-coding them in. 62 | 63 | ## Comparison between Lua and C functions 64 | The LuaComplete plugin will show the difference between when it can fill in function parameters (for Lua functions) and when it can't (for C functions). Take a look at the example below: 65 | 66 | ### Lua Function 67 | The Lua function parameters get auto-completed and in the Sublime Text auto-complete hover - the function is described as `function ()`: 68 | 69 | ![Image of LuaComplete completing lua function parameters](http://fouriertransformer.github.io/LuaComplete-Sublime/images/dkjson.gif) 70 | 71 | ### C Function 72 | The C functions parameters don't get auto-completed and the function is described as `function`: 73 | ![Image of LuaComplete completing lua function parameters](http://fouriertransformer.github.io/LuaComplete-Sublime/images/cjson.gif) 74 | 75 | ## Troubleshooting 76 | If you see the error message "The lua-complete client failed to return" in the bottom right, try running the "LuaComplete: Clear Auto-complete Cache (Restart Server)" from the command palette. This will restart the server, and hopefully the client will be able to reconnect. 77 | 78 | ## Questions and Contributing 79 | Feel free to open a Github issue with any questions/issues/features that you have! Also, check out [CONTRIBUTING.md](CONTRIBUTING.md) if you want to help! 80 | 81 | ## Licenses 82 | LuaComplete is released under the [MIT License](LICENSE.md) 83 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/post-install.txt" 3 | } -------------------------------------------------------------------------------- /messages/post-install.txt: -------------------------------------------------------------------------------- 1 | Please ensure you have installed lua-complete (BETA) from luarocks for this plugin to work: 2 | 3 | luarocks install --server=http://luarocks.org/dev lua-complete 4 | 5 | Check out the GitHub Page for more info and to report any issues: 6 | https://github.com/FourierTransformer/LuaComplete-Sublime 7 | 8 | Thanks for installing LuaComplete! 9 | --------------------------------------------------------------------------------