Skip to content

Commit

Permalink
Make construct chaining configurable (#1673)
Browse files Browse the repository at this point in the history
* make construct configurable

* add changelog

* lint

* update ocamlformat

* make true by default

* make construct configurable

* add changelog

* lint

* make true by default

* Update markdownDescription

Co-authored-by: Ulysse <5031221+voodoos@users.noreply.github.com>

* review suggestions

---------

Co-authored-by: Sora Morimoto <sora@morimoto.io>
Co-authored-by: Ulysse <5031221+voodoos@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 6, 2024
1 parent a9ae86a commit 6a7b951
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Unreleased

- Add `ocaml.commands.construct.recursiveCalls` setting to configure construct chaining. (#1673)

## 1.23.0

- Add `ocaml.jump` to jump to a specific target. (#1654)
Expand Down
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,22 @@ to `ocamllsp`.
This extension provides options in VSCode's configuration settings. You can find
the settings under `File > Preferences > Settings`.

| Name | Description | Default |
| ---------------------------------- | ------------------------------------------------------------------------------------------------------- | ------- |
| `ocaml.sandbox` | Determines where to find the sandbox for a given project | `null` |
| `ocaml.dune.autoDetect` | Controls whether dune tasks should be automatically detected. | `true` |
| `ocaml.trace.server` | Controls the logging output of the language server. Valid settings are `off`, `messages`, or `verbose`. | `off` |
| `ocaml.useOcamlEnv` | Controls whether to use ocaml-env (if available) for opam commands from OCaml for Windows. | `true` |
| `ocaml.terminal.shell.linux` | The path of the shell that the sandbox terminal uses on Linux | `null` |
| `ocaml.terminal.shell.osx` | The path of the shell that the sandbox terminal uses on macOS | `null` |
| `ocaml.terminal.shell.windows` | The path of the shell that the sandbox terminal uses on Windows | `null` |
| `ocaml.terminal.shellArgs.linux` | The command line arguments that the sandbox terminal uses on Linux | `null` |
| `ocaml.terminal.shellArgs.osx` | The command line arguments that the sandbox terminal uses on macOS | `null` |
| `ocaml.terminal.shellArgs.windows` | The command line arguments that the sandbox terminal uses on Window | `null` |
| `ocaml.repl.path` | The path of the REPL that the extension uses | `null` |
| `ocaml.repl.args` | The REPL arguments that the extension uses | `null` |
| `ocaml.repl.useUtop` | Controls whether to use Utop for the REPL if it is installed in the current switch. | `true` |
| Name | Description | Default |
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------- |
| `ocaml.sandbox` | Determines where to find the sandbox for a given project | `null` |
| `ocaml.dune.autoDetect` | Controls whether dune tasks should be automatically detected. | `true` |
| `ocaml.trace.server` | Controls the logging output of the language server. Valid settings are `off`, `messages`, or `verbose`. | `off` |
| `ocaml.useOcamlEnv` | Controls whether to use ocaml-env (if available) for opam commands from OCaml for Windows. | `true` |
| `ocaml.terminal.shell.linux` | The path of the shell that the sandbox terminal uses on Linux | `null` |
| `ocaml.terminal.shell.osx` | The path of the shell that the sandbox terminal uses on macOS | `null` |
| `ocaml.terminal.shell.windows` | The path of the shell that the sandbox terminal uses on Windows | `null` |
| `ocaml.terminal.shellArgs.linux` | The command line arguments that the sandbox terminal uses on Linux | `null` |
| `ocaml.terminal.shellArgs.osx` | The command line arguments that the sandbox terminal uses on macOS | `null` |
| `ocaml.terminal.shellArgs.windows` | The command line arguments that the sandbox terminal uses on Window | `null` |
| `ocaml.repl.path` | The path of the REPL that the extension uses | `null` |
| `ocaml.repl.args` | The REPL arguments that the extension uses | `null` |
| `ocaml.repl.useUtop` | Controls whether to use Utop for the REPL if it is installed in the current switch. | `true` |
| `ocaml.commands.construct.recursiveCalls` | When enabled, the construct command will execute again on the next hole after a value has been chosen. | `true` |

If `ocaml.terminal.shell.*` or `ocaml.terminal.shellArgs.*` is `null`, the
configured VSCode shell and shell arguments will be used instead.
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@
"default": false,
"markdownDescription": "Enable/Disable syntax documentation"
},
"ocaml.commands.construct.recursiveCalls": {
"type": "boolean",
"default": true,
"markdownDescription": "When enabled, the construct command will execute again on the next hole after a value has been chosen."
},
"ocaml.dune.autoDetect": {
"type": "boolean",
"default": true,
Expand Down
31 changes: 17 additions & 14 deletions src/extension_commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -609,20 +609,23 @@ module Construct = struct
match selected_result with
| Some (value, range) -> (
let* value_inserted = insert_to_document text_editor range value in
match value_inserted with
| true -> (
let* new_range =
Holes_commands.closest_hole
(Range.start range)
text_editor
client
`Next
in
match new_range with
| Some range ->
process_construct (Range.end_ range) text_editor client instance
| None -> Promise.return ())
| false -> Promise.return ())
match Settings.(get server_constructRecursiveCalls_setting) with
| Some true | None -> (
match value_inserted with
| true -> (
let* new_range =
Holes_commands.closest_hole
(Range.start range)
text_editor
client
`Next
in
match new_range with
| Some range ->
process_construct (Range.end_ range) text_editor client instance
| None -> Promise.return ())
| false -> Promise.return ())
| Some false -> Promise.return ())
| None -> Promise.return ()

let _construct =
Expand Down
7 changes: 7 additions & 0 deletions src/settings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,10 @@ let server_syntaxDocumentation_setting =
~key:"ocaml.server.syntaxDocumentation"
~of_json:Jsonoo.Decode.bool
~to_json:Jsonoo.Encode.bool

let server_constructRecursiveCalls_setting =
create_setting
~scope:ConfigurationTarget.Workspace
~key:"ocaml.commands.construct.recursiveCalls"
~of_json:Jsonoo.Decode.bool
~to_json:Jsonoo.Encode.bool
2 changes: 2 additions & 0 deletions src/settings.mli
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ val server_extendedHover_setting : bool setting
val server_duneDiagnostics_setting : bool setting

val server_syntaxDocumentation_setting : bool setting

val server_constructRecursiveCalls_setting : bool setting

0 comments on commit 6a7b951

Please sign in to comment.