OCamlFormat config file auto-completion support in VSCode

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. :upside_down_face:

Cheers.

12 Likes

Here’s how it works.

3 Likes

Wow, this is great! Nice job!

If you decide to try this, you can look VSCode OCaml Platform source code to see how we wrote the OCaml extension in OCaml code. The basic idea is that it uses the Js_of_ocaml compiler 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.

1 Like

Thanks a lot! I’ll take a look at those Js_of_ocaml approach.

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.)

1 Like

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. I’d be glad to help you if you want (it also should be easier than writing your own extension in OCaml from scratch).

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!

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.

5 Likes

Well, I think lsp-server implementation is almost done! (I’m not going to lie, as a beginner, it was quit challenging. I found linol library 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, and it does auto-complete things as I expected.

6 Likes