There are several questions here on indenting code in visual studio code (How do you format code in Visual Studio Code (VSCode)?), and on indenting OCaml code (How to indent existing OCaml code), but none of the answers work for indenting OCaml code in visual studio code.
I have installed the OCaml Platform visual studio code extension, vscode-ocaml-format (following https://dev.realworldocaml.org/install.html), ocaml-lsp-server (following https://ocaml.org/learn/tutorials/up_and_running.html) using opam, updated and upgraded everything, used eval $(opam env), but this still does not work. I'm a bit at a loss...
CodePudding user response:
It is very hard to answer such questions as we need more debugging input from your side. On the other hand, it is so hard to get it from vscode so it is better just to walk you through the whole process from the very beginning to see where things might go wrong. I would suggest you follow the process for ease of debugging. After you have everything working you can adapt it to your particular setup.
- Create a fresh new folder and put some OCaml file into it, let's name it
test.mland let's put into it the following code,
let test = [
"hello"
]
- Now create a fresh local opam switch, by issuing in the same folder as the
test.mlfile the following command, (note the dot at the end of the command, it is required, it will create a local switch for you)
opam switch create .
- Next install the required dependencies.
opam install ocamlformat ocamlformat-rpc ocaml-lsp-server
Create the
.ocamlformatfile in the same folder as thetest.mlfile. It will tell ocamlformat that you want to be ocamlformatted and you can use this file to setup your preferences.Make sure that you have installed ocamlplatform for vscode
Now we are ready for the test. Start vscode and open
test.ml. It will ask you to select the sandbox. Select the sandbox that corresponds to the folder where you puttest.ml(it should be marked aslocaland have the same name as the folder name, and there will be the full path to it, so it will be easy for you to find it). The code syntax should be highlighted and there should be no error messages from vscode. Finally, hitCtrl-Shift-Ito re-indent your file, it should transform your code to,
let test = [ "hello" ]
