# How to optimize code-completion of vshaxe?

**URL:** <https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664>\
**Category:** Haxe\
**Tags:** vscode\
**Created:** [April 7, 2019, 5:06am UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664 "2019-04-07T05:06:27Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![terurou](https://community.haxe.org/user_avatar/community.haxe.org/terurou/32/812_2.png) [@terurou](https://community.haxe.org/u/terurou)\
**Post date:** [April 7, 2019, 5:06am UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/1 "2019-04-07T05:06:28Z")

</div>

I’m developing a large haxe project using vscode/vshaxe. I’m troubled that code-completion is very slow in most cases.

I tried this settings:

```json
{
    "editor.quickSuggestions": {
        "other": false,
        "comments": false,
        "strings": false
    },
    "editor.parameterHints.enabled": false,
    "editor.hover.enabled": false,
    "editor.suggestOnTriggerCharacters": false,

    "haxe.buildCompletionCache": true,
    "haxe.enableDiagnostics": false,
    "haxe.enableSignatureHelpDocumentation": false,
    "haxe.diagnosticsPathFilter": "${workspaceRoot}/src|${haxelibPath}"
}

```

Is there any way to make “typing” faster?

 ![vshaxe](https://community.haxe.org/uploads/default/original/1X/e73d594fc6f0c784d26124264d34a407e1fd908a.png)

---

<div class="post-metadata">

**Author:** ![Gama11](https://community.haxe.org/user_avatar/community.haxe.org/gama11/32/7_2.png) [@Gama11](https://community.haxe.org/u/Gama11)\
**Post date:** [April 7, 2019, 8:28am UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/2 "2019-04-07T08:28:18Z")

</div>

Hm, that’s indeed quite bad… How big is that project?

vshaxe relies on the completion cache to skip as much typing / macros / etc as possible during Haxe completion requests. Clearly this isn’t working out in your case though.

I’m surprised the “typing” node isn’t expandable with how much time it takes. What about “macro” though? Perhaps one of the macros that runs invalidates a lot of types (and the results of the macro aren’t cached either, so it’s re-run each time)?

To debug invalidation, you can add this to your settings:

```haxe
"haxe.displayServer": {
	"arguments": ["-v"]
}

```

And then observe the reusing / skipping messages in the output channel.

Note that completion could still be slow if there’s only “reusing” messages (in case some modules aren’t cached to begin with, there won’t be a “skipping”).

With latest Haxe, you can also use the “Cache” view in the “Haxe Server” activity bar menu to observe what exactly has been cached, what dependencies the types have etc.

---

<div class="post-metadata">

**Author:** ![nadako](https://community.haxe.org/user_avatar/community.haxe.org/nadako/32/5_2.png) [@nadako](https://community.haxe.org/u/nadako)\
**Post date:** [April 7, 2019, 8:41am UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/3 "2019-04-07T08:41:17Z")

</div>

In my experience, one possible cause for the “typing” slowdown when using macros is redundant typing caused by “unfenced” `import`s and type references. If you’re not careful, you can easily get all your code and libs processed twice: once in normal compilation context and once in the macro context. In general all the macro code must reside in a separate module that only imports what’s needed for macros (usually just the `haxe.macro.` stuff), also don’t forget `import.hx` - you might need to add some `#if !macro` there.

That said, “completion” is supposed to be very lazy though, so I’m wondering how can it take 6 seconds… O\_o And even if my double-typing guess is correct, 3 seconds is still too much, so this needs more investigation.

---

<div class="post-metadata">

**Author:** ![terurou](https://community.haxe.org/user_avatar/community.haxe.org/terurou/32/812_2.png) [@terurou](https://community.haxe.org/u/terurou)\
**Post date:** [April 8, 2019, 2:55am UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/4 "2019-04-08T02:55:55Z")

</div>

Thanks your reply!  
Our project is using Haxe4.0.0-rc.2, OpenFL 8.9.0, Lime 7.3.0, Starling 2.5.1 and some tiny libs.

> In general all the macro code must reside in a separate module that only imports what’s needed for macros (usually just the haxe.macro. stuff), also don’t forget import.hx - you might need to add some #if !macro there.

Hm…, maybe this should have been done, but I’ll check again.

I got a log from starting the language server to running the first input completion.  
Please see it.

```plaintext
Haxe language server started
Listening on port 6000
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--display,{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"supportsResolve":true}}]
Completion Response =
{"jsonrpc":"2.0","id":0,"result":{"result":{"methods":["display/definition","server/contexts","server/invalidate","server/module","server/files","initialize","display/completion","typer/compiledTypes","display/references","server/modules","display/completionItem/resolve","display/typeDefinition","server/memory","display/hover","display/package","display/signatureHelp","server/readClassPaths","server/configure"],"haxeVersion":{"major":4,"minor":0,"patch":0,"pre":"rc.2","build":"77068e10c"},"protocolVersion":{"major":0,"minor":2,"patch":0}},"timestamp":1554687490.9749486}}
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.001s
Building Cache...
Compacted memory 0.002s 0.3MB
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":1,"method":"server/configure","params":{"noModuleChecks":true,"print":{"completion":false,"reusing":false}}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.000s
Processing Arguments [complete.hxml,--no-output]
Defines <...>
Using signature 919e086b300264bdd80df09c4d0867c1
Display position: ?: -1--1
...
Stats = 7397 files, 7028 classes, 11745 methods, 119 macros
Time spent : 10.950s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":2,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.001s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":3,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.000s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":4,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.001s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":5,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.000s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":6,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.000s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":7,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.002s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":8,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.001s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":9,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.000s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":10,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.001s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":11,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.000s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":12,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.001s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":13,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.000s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":14,"method":"server/invalidate","params":{"file":"/xxxx/yyyy/src/zzz.hx"}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.001s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":15,"method":"display/completion","params":{"file":"/xxxx/yyyy/src/zzz.hx","contents":"<...>","offset":61553,"wasAutoTriggered":false}}]
Defines <...>
Using signature 919e086b300264bdd80df09c4d0867c1
Display position: /xxxx/yyyy/src/zzz.hx: 61553-61553
 3, js: parsed /xxxx/yyyy/src/zzz.hx (not cached, is display file)
Stats = 63 files, 6573 classes, 758 methods, 26 macros
Time spent : 5.956s
Processing Arguments [--cwd,/xxxx/yyyy,complete.hxml,-D,display-details,--no-output,--times,-D,macro-times,--display,{"jsonrpc":"2.0","id":16,"method":"display/completionItem/resolve","params":{"index":0}}]
Stats = 0 files, 0 classes, 0 methods, 0 macros
Time spent : 0.004s

```

---

<div class="post-metadata">

**Author:** ![Gama11](https://community.haxe.org/user_avatar/community.haxe.org/gama11/32/7_2.png) [@Gama11](https://community.haxe.org/u/Gama11)\
**Post date:** [April 8, 2019, 10:25am UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/5 "2019-04-08T10:25:48Z")

</div>

> [@terurou](#):
>
> –cwd,/xxxx/yyyy,complete.hxml

This stands out to me. Are you using a custom HXML for code completion? It’s recommended to use the [official Lime extension](https://marketplace.visualstudio.com/items?itemName=openfl.lime-vscode-extension).

Considering there’s no “reusing” in your output at all, I wonder if anything has been cached at all.

> [@terurou](#):
>
> OpenFL 8.9.0, Lime 7.3.0, Starling 2.5.1 and some tiny libs

Oh, that actually doesn’t seem to bad dependency-wise. I guess “large project” is mostly referring to the project’s code itself?

In a Hello World Flixel project, completion only takes ~50 ms for me. Can you reproduce these issues in a pure Lime / OpenFL / Starling project? (if using the Lime extension doesn’t help)

---

<div class="post-metadata">

**Author:** ![terurou](https://community.haxe.org/user_avatar/community.haxe.org/terurou/32/812_2.png) [@terurou](https://community.haxe.org/u/terurou)\
**Post date:** [April 8, 2019, 2:50pm UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/6 "2019-04-08T14:50:19Z")

</div>

> [@Gama11](#):
>
> It’s recommended to use the [official Lime extension](https://marketplace.visualstudio.com/items?itemName=openfl.lime-vscode-extension).

Thanks for your recommendation!  
I installed lime extension and retried the completion. But this issue was not resolved…

```haxe
Stats = 1 files, 6567 classes, 757 methods, 26 macros
Time spent : 8.529s

```

> [@Gama11](#):
>
> Can you reproduce these issues in a pure Lime / OpenFL / Starling project?

This issue dose not reproduce in a pure OpenFL project.

I’m trying to create a project that reproduces this issue. If I succeed in reproducing, I will post here again.

---

<div class="post-metadata">

**Author:** ![terurou](https://community.haxe.org/user_avatar/community.haxe.org/terurou/32/812_2.png) [@terurou](https://community.haxe.org/u/terurou)\
**Post date:** [April 10, 2019, 12:53pm UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/7 "2019-04-10T12:53:22Z")

</div>

> [@terurou](#):
>
> I’m trying to create a project that reproduces this issue. If I succeed in reproducing, I will post here again.

I create a reproduction code similar to the our actual project.  
In this reproduction code, completion takes about 2 seconds.

Please check out this project.

> **[GitHub - terurou/haxe4-completion-issue](https://github.com/terurou/haxe4-completion-issue)**
>
> Contribute to terurou/haxe4-completion-issue development by creating an account on GitHub.

Open this in VS Code.  
Next, input “param.” and ctrl + space.

> <https://github.com/terurou/haxe4-completion-issue/blob/master/src/Logic.hx#L7>

---

<div class="post-metadata">

**Author:** ![nadako](https://community.haxe.org/user_avatar/community.haxe.org/nadako/32/5_2.png) [@nadako](https://community.haxe.org/u/nadako)\
**Post date:** [April 10, 2019, 1:13pm UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/8 "2019-04-10T13:13:17Z")

</div>

The completion is pretty fast here for me. The verbose output reports ~0.125s for a `display/completion` request.

---

<div class="post-metadata">

**Author:** ![nadako](https://community.haxe.org/user_avatar/community.haxe.org/nadako/32/5_2.png) [@nadako](https://community.haxe.org/u/nadako)\
**Post date:** [April 10, 2019, 1:16pm UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/9 "2019-04-10T13:16:15Z")

</div>

Actually, after opening (without modifying) one of these files I can reproduce the slowdown, seeing a ton of messages like `skipping generated.page199.Parameter49(generated.page199.Parameter26)` in the verbose log.

---

<div class="post-metadata">

**Author:** ![terurou](https://community.haxe.org/user_avatar/community.haxe.org/terurou/32/812_2.png) [@terurou](https://community.haxe.org/u/terurou)\
**Post date:** [April 10, 2019, 3:28pm UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/10 "2019-04-10T15:28:52Z")

</div>

> [@nadako](#):
>
> The verbose output reports ~0.125s

Oh, really? It seems that the way I conveyed it was not good.

1. Input “param.” and CTRL + SPACE.
2. Wait for displaying completion list.
3. Cancel completion.
4. Input BACKSPACE 1-time.
5. Input “.” and CTRL + SPACE.
6. Wait for displaying completion list. ← about 2sec

I repeated the steps 4-6 and tried the completion.

---

<div class="post-metadata">

**Author:** ![terurou](https://community.haxe.org/user_avatar/community.haxe.org/terurou/32/812_2.png) [@terurou](https://community.haxe.org/u/terurou)\
**Post date:** [April 11, 2019, 1:36am UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/11 "2019-04-11T01:36:08Z")

</div>

I retried this issue. This operation was incomplete.

Please input “this.” and CTRL + SPACE here.

> <https://github.com/terurou/haxe4-completion-issue/blob/master/src/generated/page0/Parameter0.hx#L19-L20>

If you do input completion once in `Parameter0` class, this issue will be reproduced again in `Logic`.

> [@terurou](#):
>
> - Input “param.” and CTRL + SPACE.
> - Wait for displaying completion list.
> - Cancel completion.
> - Input BACKSPACE 1-time.
> - Input “.” and CTRL + SPACE.
> - Wait for displaying completion list. \<- about 2sec

---

<div class="post-metadata">

**Author:** ![Gama11](https://community.haxe.org/user_avatar/community.haxe.org/gama11/32/7_2.png) [@Gama11](https://community.haxe.org/u/Gama11)\
**Post date:** [April 11, 2019, 12:03pm UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/12 "2019-04-11T12:03:34Z")

</div>

Thanks for the test project! I can definitely reproduce several issues here, starting with completion seemingly not auto-triggering… (seems an explicit Ctrl+Space is needed).

I’m not yet sure what’s causing the problem(s).

---

<div class="post-metadata">

**Author:** ![terurou](https://community.haxe.org/user_avatar/community.haxe.org/terurou/32/812_2.png) [@terurou](https://community.haxe.org/u/terurou)\
**Post date:** [April 11, 2019, 12:47pm UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/13 "2019-04-11T12:47:13Z")

</div>

> [@Gama11](#):
>
> seems an explicit Ctrl+Space is needed

In this project, auto-completion is disabled. If you want to enable it, please comment out this part.

> <https://github.com/terurou/haxe4-completion-issue/blob/master/.vscode/settings.json#L2-L9>

---

<div class="post-metadata">

**Author:** ![Gama11](https://community.haxe.org/user_avatar/community.haxe.org/gama11/32/7_2.png) [@Gama11](https://community.haxe.org/u/Gama11)\
**Post date:** [April 11, 2019, 12:58pm UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/14 "2019-04-11T12:58:12Z")

</div>

Oh, I hadn’t seen that. Well, that explains that part at least. 🙂

---

<div class="post-metadata">

**Author:** ![Gama11](https://community.haxe.org/user_avatar/community.haxe.org/gama11/32/7_2.png) [@Gama11](https://community.haxe.org/u/Gama11)\
**Post date:** [April 11, 2019, 5:30pm UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/15 "2019-04-11T17:30:54Z")

</div>

So, I think there’s at least two issues here, one regarding invalidation and one regarding having a ton of files in a project.

The test project has a shitton of “generated” files (11304 files are being parsed in total according to readClassPaths). Toplevel completion is of course not too happy about this, since it will show every single type and package.

Is this similar to your actual project? Are all these types macro-generated there, or actual source files? Do you care about these things showing up in toplevel completion?

I think one thing we should certainly do is enhance the `haxe.exclude` setting a bit - this already allows hiding specific packages from completion, but this happens client-side and is thus not too helpful performance wise, it’s mainly for less crowded completion results atm. We should send the list of filtered packages to Haxe so it doesn’t send these to the language server to begin with.

---

<div class="post-metadata">

**Author:** ![terurou](https://community.haxe.org/user_avatar/community.haxe.org/terurou/32/812_2.png) [@terurou](https://community.haxe.org/u/terurou)\
**Post date:** [April 13, 2019, 4:19am UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/16 "2019-04-13T04:19:34Z")

</div>

Thank you for your looing into this issue.

> [@Gama11](#):
>
> Are all these types macro-generated there, or actual source files?

Many actual source files exist. These are not macro-generated types.

> [@Gama11](#):
>
> Do you care about these things showing up in toplevel completion?

There is almost no problem with not showing up these types in top-level completion.

> [@Gama11](#):
>
> We should send the list of filtered packages to Haxe so it doesn’t send these to the language server to begin with.

It’s very good to me!

---

<div class="post-metadata">

**Author:** ![Gama11](https://community.haxe.org/user_avatar/community.haxe.org/gama11/32/7_2.png) [@Gama11](https://community.haxe.org/u/Gama11)\
**Post date:** [April 13, 2019, 8:04am UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/17 "2019-04-13T08:04:51Z")

</div>

FWIW, I implemented the change I mentioned, there’s screenshots showing the performance improvement [here](https://github.com/HaxeFoundation/haxe/pull/8156). This doesn’t help with your main issue regarding invalidation though, that still has to be looked into…

---

<div class="post-metadata">

**Author:** ![terurou](https://community.haxe.org/user_avatar/community.haxe.org/terurou/32/812_2.png) [@terurou](https://community.haxe.org/u/terurou)\
**Post date:** [April 14, 2019, 2:38am UTC](https://community.haxe.org/t/how-to-optimize-code-completion-of-vshaxe/1664/18 "2019-04-14T02:38:05Z")

</div>

Thanks, Gama11.  
I tried the dev-version haxe4 and vshaxe. There was no problem in the reproduced project, but it was not resolved in actual project…

I guess that this issue occurred because of compiler service compilations all dependency trees at the time of completion. I think that it can be solved if the Haxe compiler can cache the signatures of descendant nodes.
