# Bug - Lua autocomplete not working between if (...) then

**URL:** <https://forum.sublimetext.com/t/bug-lua-autocomplete-not-working-between-if-then/36635>\
**Category:** Technical Support\
**Created:** [May 7, 2018, 5:22pm UTC](https://forum.sublimetext.com/t/bug-lua-autocomplete-not-working-between-if-then/36635 "2018-05-07T17:22:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DigitalZilla](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/d/439d5e/32.png) [@DigitalZilla](https://forum.sublimetext.com/u/DigitalZilla)\
**Post date:** [May 7, 2018, 5:22pm UTC](https://forum.sublimetext.com/t/bug-lua-autocomplete-not-working-between-if-then/36635/1 "2018-05-07T17:22:59Z")

</div>

When writing Lua code, autocomplete stops working after _if_ once _then_ has been typed. This means that whenever I go back and add more code to an if-statement’s condition, I get no autocomplete unless I delete the _then_ and retype it afterward.

This happens regardless of the linter being active, and regardless of using parenthesis (parens are option in Lua).

 ![](https://forum.sublimetext.com/uploads/default/original/3X/1/b/1bd4e631e5bef1e7618744c1828b5ec1c98f0cad.png)

Thanks!

---

<div class="post-metadata">

**Author:** ![deathaxe](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/deathaxe/32/52468_2.png) [@deathaxe](https://forum.sublimetext.com/u/deathaxe)\
**Post date:** [May 7, 2018, 5:41pm UTC](https://forum.sublimetext.com/t/bug-lua-autocomplete-not-working-between-if-then/36635/2 "2018-05-07T17:41:42Z")

</div>

The default package provides a _Completion Rules.tmPreferences_ file which disables completions if a line contains `then`.

Maybe we should remove `then` from the list.

---

<div class="post-metadata">

**Author:** ![DigitalZilla](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/d/439d5e/32.png) [@DigitalZilla](https://forum.sublimetext.com/u/DigitalZilla)\
**Post date:** [May 8, 2018, 3:26pm UTC](https://forum.sublimetext.com/t/bug-lua-autocomplete-not-working-between-if-then/36635/3 "2018-05-08T15:26:30Z")

</div>

Hey Deathaxe,  
Thanks for the quick reply!

This definitely seems like something that should get removed. From my perspective, this definitely seems wrong. I can’t think of any case where I’d want that behavior and I’ve been using sublime for Lua for years. I’d be happy to give it a test if there’s a way I can make the change locally, and report back after a few days of use to make sure that doesn’t introduce a different problem.

Is this something I can change locally? I don’t see a Completion Rules anywhere inside \AppData\Roaming\Sublime Text 3…

---

<div class="post-metadata">

**Author:** ![OdatNurd](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/odatnurd/32/77607_2.png) [@OdatNurd](https://forum.sublimetext.com/u/OdatNurd)\
**Post date:** [May 8, 2018, 4:48pm UTC](https://forum.sublimetext.com/t/bug-lua-autocomplete-not-working-between-if-then/36635/4 "2018-05-08T16:48:29Z")

</div>

Something to note is that the `cancelCompletion` setting here stops the autocomplete panel from opening up automatically, but completions are still available; you can press Tab to insert the best completion or cycle between them, or you can can press Ctrl+Space (or Alt+/ on Linux) to open the panel manually):

![](https://forum.sublimetext.com/uploads/default/original/3X/2/b/2b52f07a1c976811a9623be40ac3c6db6142a486.gif)

That said, it’s possible to try the change out locally if you want to. The reason you don’t see the file that you’re looking for is that the packages that ship with Sublime are stored as packed packages in a location outside of the `Data` directory, since they’re common to all users on the machine that use Sublime.

The easiest way to effect the change is:

1. Install [PackageResourceViewer](https://packagecontrol.io/packages/PackageResourceViewer) if you don’t already have it installed
2. Open the command palette and enter `prvo` and select the `PackageResourceViewer: Open Resource` command
3. Select `Lua` (the package), then `Completion Rules.tmPreferences` (the file)

That will open the file and show you the following:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
    <key>scope</key>
    <string>source.lua</string>
    <key>settings</key>
    <dict>
        <key>cancelCompletion</key>
        <string>^.*\b(then|end|do|else)$</string>
    </dict>
</dict>
</plist>

```

You want to either erase the inner parts of the `settings` dict to remove that setting completely, or if you prefer you can modify the setting to some other regular expression (depending on your testing, etc). An example of the former is:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
    <key>scope</key>
    <string>source.lua</string>
    <key>settings</key>
    <dict>
        
    </dict>
</dict>
</plist>

```

Once you make the change, save the file. That will create an `override` that makes your edited version of the file be usef instead of the one that ships with Sublime. As soon as you save the file the changes will be reloaded, so it should start working for you right away.

What this is doing is creating a folder named `Lua` (named after the package) in your `Packages` folder, then storing your modified version of the file there.

This `override` will remain in effect as long as that file is there, including if you upgrade or reinstall Sublime. If an official fix is made, you’ll want to remove your modified version of the file so that it stops blocking the packed version. The [OverrideAudit](https://packagecontrol.io/packages/OverrideAudit) package will give you a warning if the underlying package is updated so that you can verify if you still need your change or not.

---

<div class="post-metadata">

**Author:** ![deathaxe](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/deathaxe/32/52468_2.png) [@deathaxe](https://forum.sublimetext.com/u/deathaxe)\
**Post date:** [May 9, 2018, 2:42pm UTC](https://forum.sublimetext.com/t/bug-lua-autocomplete-not-working-between-if-then/36635/5 "2018-05-09T14:42:09Z")

</div>

A fix for this issue was already merged to the default packages.

> <https://github.com/sublimehq/Packages/pull/1538>

---

<div class="post-metadata">

**Author:** ![DigitalZilla](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/d/439d5e/32.png) [@DigitalZilla](https://forum.sublimetext.com/u/DigitalZilla)\
**Post date:** [May 9, 2018, 3:15pm UTC](https://forum.sublimetext.com/t/bug-lua-autocomplete-not-working-between-if-then/36635/6 "2018-05-09T15:15:42Z")

</div>

Thanks for all the information OdatNurd. I never really understood how to interact with packages until you explained how to find them, and how overriding works. That all makes a ton of sense. I made the change locally and it working great.

Deathaxe. Thanks for committing the fix! I’ll be sure to remove my override as soon as it’s available.

Thanks again for the fantastic and quick support!
