Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More functionnalities for repl #951

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ the settings under `File > Preferences > Settings`.
| `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.repl.jumpToNextExpression` | Allow the cursor to jump after expression evaluation to the next expression. | `true` |

If `ocaml.terminal.shell.*` or `ocaml.terminal.shellArgs.*` is `null`, the
configured VSCode shell and shell arguments will be used instead.
Expand Down Expand Up @@ -259,7 +260,12 @@ prefix `OCaml:`:
| `ocaml.current-dune-file` | Open Dune File (located in the same folder) | |
| `ocaml.switch-impl-intf` | Switch implementation/interface | `Alt+O` |
| `ocaml.open-repl` | Open REPL | |
| `ocaml.evaluate-selection` | Evaluate Selection | `Shift+Enter` |
| `ocaml.evaluate-expression` | Evaluate Expression in REPL | `Shift+Enter` |
| `ocaml.evaluate-file` | Evaluate Selection | `Shift+Alt+Enter` |

Note: `ocaml.evaluate-expression` was previously named
`ocaml.evaluate-selection`. You can also disabe the new cursor jumps after this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we preserve ocaml.evaluate-selection? I don't see anything wrong with having both commands.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new command evaluates the selection if there's one; otherwise, it evaluates a (module-level) let or module binding depending which comes first

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood. I just don't see why we should remove a command with a clear name and semantics and replace it with a command that has neither of those things. Seems like we're just irritating users who are used to the old command this way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, but then I would show a deprecation message saying to use the new command because

  1. The new command has almost the same semantics - select and evaluate (no selection resulted in evaluating the whole line but I'm not sure that's very useful and the new command does the same thing if it's a single-line let binding)
  2. There's then contention for the shortcut: keep the old and miss out on a better command or replace and still irritate

command execution with the `ocaml.repl.jumpToNextExpression` setting.

## Debugging the extension

Expand Down
23 changes: 19 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,14 @@
"title": "Open REPL"
},
{
"command": "ocaml.evaluate-selection",
"command": "ocaml.evaluate-expression",
"category": "OCaml",
"title": "Evaluate Selection"
"title": "Evaluate Expression in REPL"
},
{
"command": "ocaml.evaluate-file",
"category": "OCaml",
"title": "Evaluate File in REPL"
},
{
"command": "ocaml.open-ast-explorer-to-the-side",
Expand Down Expand Up @@ -300,10 +305,15 @@
"when": "editorLangId == ocaml.interface || editorLangId == reason"
},
{
"command": "ocaml.evaluate-selection",
"command": "ocaml.evaluate-expression",
"key": "Shift+Enter",
"when": "editorTextFocus && editorLangId == ocaml || editorTextFocus && editorLangId == ocaml.interface || editorTextFocus && editorLangId == reason || editorTextFocus && editorLangId == ocaml.ocamllex || editorTextFocus && editorLangId == ocaml.menhir"
},
{
"command": "ocaml.evaluate-file",
"key": "Shift+Alt+Enter",
"when": "editorTextFocus && editorLangId == ocaml || editorTextFocus && editorLangId == ocaml.interface || editorTextFocus && editorLangId == reason || editorTextFocus && editorLangId == ocaml.ocamllex || editorTextFocus && editorLangId == ocaml.menhir"
},
{
"command": "ocaml.next-hole",
"key": "Alt+Y",
Expand All @@ -328,7 +338,7 @@
"menus": {
"editor/context": [
{
"command": "ocaml.evaluate-selection",
"command": "ocaml.evaluate-expression",
"group": "OCaml",
"when": "editorTextFocus && editorLangId == ocaml || editorTextFocus && editorLangId == ocaml.interface || editorTextFocus && editorLangId == reason || editorTextFocus && editorLangId == ocaml.ocamllex || editorTextFocus && editorLangId == ocaml.menhir"
},
Expand Down Expand Up @@ -558,6 +568,11 @@
"type": "boolean",
"default": true,
"description": "Controls whether to use Utop for the REPL if it is installed in the current switch."
},
"ocaml.repl.jumpToNextExpression": {
"type": "boolean",
"default": true,
"description": "Cursor jumps to next expression after current expression is evaluated in REPL"
}
}
},
Expand Down
20 changes: 20 additions & 0 deletions src/custom_requests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,23 @@ let typedHoles =
Jsonoo.Encode.(object_ [ ("uri", string @@ Uri.toString uri ()) ]))
; decode_response = Jsonoo.Decode.list Range.t_of_json
}

module Wrapping_ast_node = struct
let meth = ocamllsp_prefixed "wrappingAstNode"

let encode_params uri position =
(* TODO: these params exist as a defined type in LSP *)
Jsonoo.Encode.(
object_
[ ("uri", string @@ Uri.toString uri ())
; ("position", Position.json_of_t position)
])

let decode_response json = Jsonoo.Decode.try_optional Range.t_of_json json

let send_request client ~doc:uri ~position =
let data = encode_params uri position in
let open Promise.Syntax in
let+ response = LanguageClient.sendRequest client ~meth ~data () in
decode_response response
end
10 changes: 10 additions & 0 deletions src/custom_requests.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ val switchImplIntf : (string, string array) custom_request
val inferIntf : (string, string) custom_request

val typedHoles : (Uri.t, Range.t list) custom_request

module Wrapping_ast_node : sig
(** [send_request client ~for_doc] will fetch ranges of holes in the file at
the URI [for_doc] *)
val send_request :
LanguageClient.t
-> doc:Uri.t
-> position:Position.t
-> Range.t option Promise.t
end
4 changes: 3 additions & 1 deletion src/extension_consts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module Commands = struct

let open_current_dune_file = ocaml_prefixed "current-dune-file"

let evaluate_selection = ocaml_prefixed "evaluate-selection"
let evaluate_expression = ocaml_prefixed "evaluate-expression"

let evaluate_file = ocaml_prefixed "evaluate-file"

let open_repl = ocaml_prefixed "open-repl"

Expand Down
7 changes: 7 additions & 0 deletions src/ocaml_lsp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ module Experimental_capabilities = struct
; handleSwitchImplIntf : bool
; handleInferIntf : bool
; handleTypedHoles : bool
; handleWrappingAstNode : bool
}

let default =
{ interfaceSpecificLangId = false
; handleSwitchImplIntf = false
; handleInferIntf = false
; handleTypedHoles = false
; handleWrappingAstNode = false
}

(** Creates [t] given a JSON of form [{ 'handleSwitchImplIntf' : true, .... }] *)
Expand All @@ -27,10 +29,12 @@ module Experimental_capabilities = struct
let handleSwitchImplIntf = has_capability "handleSwitchImplIntf" in
let handleInferIntf = has_capability "handleInferIntf" in
let handleTypedHoles = has_capability "handleTypedHoles" in
let handleWrappingAstNode = has_capability "handleWrappingAstNode" in
{ interfaceSpecificLangId
; handleSwitchImplIntf
; handleInferIntf
; handleTypedHoles
; handleWrappingAstNode
}
with Jsonoo.Decode_error err ->
show_message `Warn
Expand Down Expand Up @@ -162,3 +166,6 @@ let can_handle_switch_impl_intf t =
let can_handle_infer_intf t = t.experimental_capabilities.handleSwitchImplIntf

let can_handle_typed_holes t = t.experimental_capabilities.handleTypedHoles

let can_handle_wrapping_ast_node t =
t.experimental_capabilities.handleWrappingAstNode
2 changes: 2 additions & 0 deletions src/ocaml_lsp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ val can_handle_switch_impl_intf : t -> bool
val can_handle_infer_intf : t -> bool

val can_handle_typed_holes : t -> bool

val can_handle_wrapping_ast_node : t -> bool
Loading