vscode-ocaml
vscode-ocaml copied to clipboard
Autoindent isn't working on VS Code 1.3.0 + plugin 0.4.0
I updated to the latest plugin version today and autoindent stopped working (automatic indentation of new line when pressing enter). This is on OSX 10.11, OCaml 4.02.3. It was working on an earlier version of the plugin - I think 0.1.0 or 0.2.0.
Thank you for your report. I've checked it works fine on my mac with latest version.
Did you check if "Format Code" command works with OCaml files? If it works, please check "editor.formatOnType" is set to true.
BTW: Current only *.ml and *.mli are supported. *.mll and *.mly are not supported.
"editor.formatOnType" was set to false in the default configuration, so it's a bit better now as it formats after I press enter at the end of the newly created line. However I still get:
let () =<press enter>
<-- Cursor ends up here
when I would expect/hope for:
let () =<press enter>
<-- Cursor ending up here
with the new line starting out at the proper indentation level.
This is all for a foo.ml, to be clear.
Also, thank you for the plugin - it's a very nice addition to the community!
Likely I add '\n' to trigger chars of auto format cause this. Should we only indent cursor line instead of whole document? So we can use "--indent-empty" option of ocp-indent to solve this problem.
I'd prefer to only indent the cursor line, ideally having the case I showed working without enabling "editor.formatOnType".
If "editor.formatOnType" on: we should format whole document or a range the text edit affects, like Typescript extension does.
If "editor.formatOnType" off: we should only indent the cursor line as you say. Looks like with current VS Code API it's not possible. It only support regex based indent rule now.
I found a way: combine two indent request (with and without "--indent-empty") result to achieve that.
Remark: Current implementation did not respect user's indent size setting. This should fix at the same time.
I've tried a lot. Seems formatOnType can't work well with '\n'.
If we use formatOnType to impl auto indent, it will encounter weird bugs, likes indentation is inserted after cursor not before cursor. I see TypeScript extension also has these bugs. So we'd better to wait for VS Code provide better API to allow us to impl auto indent.
For now. We must remove '\n' from formatOnType's trigger chars. And impl auto indent via regex based auto-indent rules.
Try new version 0.4.18!
In this version: Enter after "type ... =", "let ... =", "do", "begin", "struct", "sig", "with" will auto indent. Type last char of "done" and "end" will do format.
Thanks! I'll give it a try on Monday if not before then.
Just tested and I can confirm that the initial issue is fixed. Unfortunately outdenting seems to have suffered:
let () =
for i = 1 to 10 do
()
done
This is with "editor.formatOnType" disabled. It does work as expected with "editor.formatOnType" enabled.
Unfortunately outdenting seems to have suffered
Yes, due to this issue https://github.com/Microsoft/vscode/issues/2262, I didn't implement auto outdent through decreaseIndentPattern. I choose formatOnType right now until VS Code fix that issue.