This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Max Heiber | |
I'm implementing IDE support for a language using Language Server Protocol. | |
I want to trigger a rename after extracting a variable into the current scope. That is, I've implemented steps 1 to 2 of the current flow and want to know how to implement 3 and 4 | |
1. When the user selects an expression a yellow lightbulb shows up. Example: `z = 3 + /*selection-start*/5000/*selection-end*/` | |
2. When the user selects "extract into variable" then a new variable called "placeholder" is created in the current scope and the original expression is assigned to it. Example: `placeholder = 5000; z = 3 + placeholder` | |
3. The first instance of `placeholder` is highlighted and the text box for renaming pops up. When the user types "the_new_name" and presses `Return` then the text is: `the_new_name = 5000; z = 3 + the_new_name` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
function fetch(uri) { | |
throw new Error("synchronous"); | |
} | |
function sync() { | |
return fetch('http://stuff'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module type Univ = sig | |
type t | |
val embed: unit -> ('a -> t) * (t -> 'a option) | |
end | |
module U1 = struct | |
type t = exn | |
let embed (type a) () = | |
let open struct | |
exception E of a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type (_, _) eq = Eq: ('a, 'a) eq | |
module M: sig | |
type t | |
type u | |
val tx: t | |
val ux: u | |
val eq_t_int: (t, int) eq | |
val eq_int_u: (int, u) eq | |
end = struct |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type zero = unit * unit | |
type 'a minus1 = 'snd constraint 'a = unit * 'snd | |
type 'a plus1 = unit * 'a | |
type _ lst = | |
| [] : zero lst | |
| ( :: ) : int * 'b lst -> ('b lst) plus1 lst | |
let cons n lst = n :: lst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* run like this: ocamlc unix.cma par.ml && ./a.out *) | |
open StdLabels | |
let par_iter (items: 'i list) ~(f: 'i -> unit): unit = | |
let orig_pid = Unix.getpid () in | |
let rec loop pids = function | |
| [] -> pids | |
| h :: t -> | |
match Unix.fork () with | |
| 0 -> f h; pids |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" usage: \b toggles the file browser, open to the directory containing the current file | |
nnoremap <leader>b :call ToggleNERDTree()<Cr> | |
function! ToggleNERDTree() | |
if !g:NERDTree.ExistsForTab() || !g:NERDTree.IsOpen() | |
if <SID>WindowFileExists() | |
:NERDTreeFind | |
else | |
let cwd = getcwd() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Compact_array = struct | |
type 'a t = { len: unit -> int | |
; get: int -> 'a | |
; set: int -> 'a -> unit | |
} | |
let of_string s = | |
{ len = (fun () -> String.length s) | |
; get = (fun i -> String.get s i) | |
; set = (fun i x -> String.set s i x) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* adapted from https://blog.janestreet.com/why-gadts-matter-for-performance/*) | |
module Compact_array : sig | |
type 'item t | |
val of_bytes : bytes -> char t | |
val of_array : 'item array -> 'item t | |
val length : 'item t -> int | |
val get : 'item t -> int -> 'item | |
end = struct | |
type 'a t = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct | |
type 'out t = < get : int -> 'out ; length : int > | |
let of_bytes v = | |
object | |
method length = bytes.length v | |
method get i = bytes.get v i | |
end | |
let of_array v = |