# OCamlFormat config file auto-completion support in VSCode

**URL:** <https://discuss.ocaml.org/t/ocamlformat-config-file-auto-completion-support-in-vscode/8118>\
**Category:** Ecosystem\
**Tags:** vscode\
**Created:** [July 10, 2021, 3:30am UTC](https://discuss.ocaml.org/t/ocamlformat-config-file-auto-completion-support-in-vscode/8118 "2021-07-10T03:30:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tars0x9752](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/tars0x9752/32/3063_2.png) [@tars0x9752](https://discuss.ocaml.org/u/tars0x9752)\
**Post date:** [July 10, 2021, 3:30am UTC](https://discuss.ocaml.org/t/ocamlformat-config-file-auto-completion-support-in-vscode/8118/1 "2021-07-10T03:30:29Z")

</div>

Hi, I made a tiny vscode extension which provides auto-completion for `.ocamlformat` file. (I posted this on discord but let me post it here too.)

…BTW I’m **a complete beginner** so this is written in TS. If I become comfortable with OCaml and its ecosystems, I’d like to re-write this in OCaml. But as of now, I have no clue. 🙃

Cheers.

> **[tars0x9752/ocamlformat-auto-completion-vscode](https://github.com/tars0x9752/ocamlformat-auto-completion-vscode)**
>
> vscode auto completion support for ocamlformat config file - tars0x9752/ocamlformat-auto-completion-vscode

---

<div class="post-metadata">

**Author:** ![tars0x9752](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/tars0x9752/32/3063_2.png) [@tars0x9752](https://discuss.ocaml.org/u/tars0x9752)\
**Post date:** [July 10, 2021, 3:33am UTC](https://discuss.ocaml.org/t/ocamlformat-config-file-auto-completion-support-in-vscode/8118/2 "2021-07-10T03:33:02Z")

</div>

Here’s how it works.

[![](https://user-images.githubusercontent.com/46079709/124963946-666d0a80-e05b-11eb-9747-75002e458818.gif) ](https://user-images.githubusercontent.com/46079709/124963946-666d0a80-e05b-11eb-9747-75002e458818.gif)

---

<div class="post-metadata">

**Author:** ![mnxn](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mnxn/32/2445_2.png) [@mnxn](https://discuss.ocaml.org/u/mnxn)\
**Post date:** [July 10, 2021, 5:46am UTC](https://discuss.ocaml.org/t/ocamlformat-config-file-auto-completion-support-in-vscode/8118/3 "2021-07-10T05:46:23Z")

</div>

Wow, this is great! Nice job!

> [@tars0x9752](#):
>
> I’d like to re-write this in OCaml.

If you decide to try this, you can look [VSCode OCaml Platform source code](https://github.com/ocamllabs/vscode-ocaml-platform) to see how we wrote the OCaml extension in OCaml code. The basic idea is that it uses the [Js\_of\_ocaml compiler](https://github.com/ocsigen/js_of_ocaml) to compile OCaml code to Javascript with bindings to the VSCode API.

I glanced over your source code and it looks like it would translate very well to OCaml code. Feel free to reach out if you’d like help.

---

<div class="post-metadata">

**Author:** ![tars0x9752](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/tars0x9752/32/3063_2.png) [@tars0x9752](https://discuss.ocaml.org/u/tars0x9752)\
**Post date:** [July 10, 2021, 9:01am UTC](https://discuss.ocaml.org/t/ocamlformat-config-file-auto-completion-support-in-vscode/8118/4 "2021-07-10T09:01:33Z")

</div>

Thanks a lot! I’ll take a look at those Js\_of\_ocaml approach.

> [@mnxn](#):
>
> I glanced over your source code and it looks like it would translate very well to OCaml code. Feel free to reach out if you’d like help.

I’m glad to hear that. If I start doing translation and have trouble, I might contact you! Thanks!

(Currently, I don’t even understand OCaml’s module system properly yet, so I’ll start from there.)

---

<div class="post-metadata">

**Author:** ![Ulugbek](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ulugbek/32/1864_2.png) [@Ulugbek](https://discuss.ocaml.org/u/Ulugbek)\
**Post date:** [July 11, 2021, 2:49pm UTC](https://discuss.ocaml.org/t/ocamlformat-config-file-auto-completion-support-in-vscode/8118/5 "2021-07-11T14:49:28Z")

</div>

You can add support for ocamlformat file completions not only in vscode but all editors supporting Language Server Protocol by adding such support to [ocaml-lsp](https://github.com/ocaml/ocaml-lsp). I’d be glad to help you if you want (it also should be easier than writing your own extension in OCaml from scratch).

---

<div class="post-metadata">

**Author:** ![tars0x9752](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/tars0x9752/32/3063_2.png) [@tars0x9752](https://discuss.ocaml.org/u/tars0x9752)\
**Post date:** [July 12, 2021, 3:36pm UTC](https://discuss.ocaml.org/t/ocamlformat-config-file-auto-completion-support-in-vscode/8118/6 "2021-07-12T15:36:24Z")

</div>

That sounds great, indeed!

However, if I were actually to do that, I’d like to consider changing current project to a monorepo setup because I want to have both lsp-server implementation and vscode extension in a single same repository, which sounds rather complex to me tbh. In any case, I’m going to do some research first. And If I get stuck, I might ask for help. Thanks!

---

<div class="post-metadata">

**Author:** ![tars0x9752](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/tars0x9752/32/3063_2.png) [@tars0x9752](https://discuss.ocaml.org/u/tars0x9752)\
**Post date:** [July 15, 2021, 4:23pm UTC](https://discuss.ocaml.org/t/ocamlformat-config-file-auto-completion-support-in-vscode/8118/7 "2021-07-15T16:23:33Z")

</div>

Hi, Just a quick update to let you know the current progress.

I’ve created another repository for OCaml translation. And It took me a while to figure out how to use dune properly, but I think I’m about halfway through the core part. At least I’m making some progress.

That’s it. Cheers.

> **[tars0x9752/ocamlformat-auto-completion](https://github.com/tars0x9752/ocamlformat-auto-completion)**
>
> Contribute to tars0x9752/ocamlformat-auto-completion development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![tars0x9752](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/tars0x9752/32/3063_2.png) [@tars0x9752](https://discuss.ocaml.org/u/tars0x9752)\
**Post date:** [July 25, 2021, 4:10pm UTC](https://discuss.ocaml.org/t/ocamlformat-config-file-auto-completion-support-in-vscode/8118/8 "2021-07-25T16:10:40Z")

</div>

Well, I think [lsp-server implementation](https://github.com/tars0x9752/ocamlformat-auto-completion) is almost done! (I’m not going to lie, as a beginner, it was quit challenging. I found [linol library](https://github.com/c-cube/linol) and it helped me a lot. Big thanks to all the useful libraries.)

I’ve just tested the lsp-server with a simple [vscode lsp-client](https://github.com/tars0x9752/ocamlformat-auto-completion-vscode/tree/lsp-client), and it does auto-complete things as I expected.
