Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4637b8a
WIP: support for ocamlmerlin-lsp
andreypopp Jan 31, 2019
1072823
use merlin-lsp for all projects
Feb 24, 2019
aec1eac
remove ols-related code
Feb 28, 2019
a4c1821
add formatters
Feb 28, 2019
d52fee6
use temp files to better handle large files
Feb 28, 2019
57590da
fix formatting
Feb 28, 2019
690f2a4
revert unrelated change
Mar 10, 2019
c705687
tweak options format
Mar 10, 2019
32fe6d3
handle possible errors
Mar 10, 2019
798219e
remove debug
Mar 10, 2019
8bd13e5
remove unsupported settings
Mar 10, 2019
7000de8
prebuild merlin-lsp/merlin-reason and use them for reason projects
Mar 29, 2019
8f44e4e
use platform’s tmp dir
Mar 29, 2019
ce09262
fix lsp binaries
Mar 30, 2019
c6d6408
remove ocamlfind dependency
Mar 30, 2019
bf91e25
get rid of custom paths
Apr 5, 2019
280112c
add some checks
Apr 5, 2019
8e11395
use esy for formatters
Apr 5, 2019
9ae3159
fix code style
Apr 5, 2019
be95b57
add local opam switch support
Khady Apr 8, 2019
9e7085d
Merge pull request #1 from Khady/opam-switch-support
Apr 8, 2019
b06b7ec
add restart ls command
Apr 8, 2019
9c7682d
fix refmt’s temp file extension
Apr 8, 2019
6a75a9a
remove debug
Apr 8, 2019
7e1dc9d
add esy.json generation for bs projects
Apr 11, 2019
a6c0889
add resolutions for 4.02
Apr 11, 2019
d5845d8
ignore packaged extensions
Apr 22, 2019
6c78709
init merlin-lsp when it is installed
Apr 22, 2019
c95bbc2
"simplify" extension setup
Jul 20, 2019
c7c77e4
pass ocamlmerlin-reason path
Jul 21, 2019
520bdd4
describe 4.02 setup
Jul 21, 2019
2b66c0e
update readme
Jul 21, 2019
be6cac2
remove unused utils
Jul 21, 2019
c759a28
fix version
Jul 21, 2019
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk


*.vsix
202 changes: 76 additions & 126 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
**If you're on our default workflow, please try [this plugin](https://github.com/jaredly/reason-language-server) instead. Thanks!**

# vscode-reasonml

Reason support for Visual Studio Code
Expand All @@ -12,78 +10,97 @@ There is an `#editorsupport` channel on the Reason [discord server](https://disc

## Features

- highlighting
- [x] advanced syntax highlighting for reason
- [x] basic highlighting for merlin, ocamlbuild, and opam files

- editing
- [x] document formatting (enable on save with `editor.formatOnSave`)
- [x] completion and snippets
- [x] [rename symbol](https://code.visualstudio.com/docs/editor/editingevolved#_rename-symbol) (F2 or right click)
- [x] [case splitting](#case-splitting)

- navigation
- [x] [symbol outline for buffers](https://code.visualstudio.com/docs/editor/editingevolved#_goto-symbol) (⇧⌘O) (type `:` in list to sort items)
- [x] [symbol outline for project](https://code.visualstudio.com/docs/editor/editingevolved#_open-symbol-by-name) (⌘T) (supports regular expressions)
- [x] [jump-to-definition](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-definition) (⌃+click) and [code preview](https://code.visualstudio.com/docs/editor/editingevolved#_peek) (⌘+hover)
- [x] find references (⇧F12 or right click)

- static analysis
- [x] merlin integration with incremental edit synchronization
- [x] display types over definitions (disable with `editor.codeLens` setting)
- [x] display types and markdown-rendered docs on hover
- [x] [online linting and compiler diagnostics with suggested fixes](https://code.visualstudio.com/docs/editor/editingevolved#_errors-warnings)
- ⇧⌘M to toggle diagnostics panel
- F8 to loop through diagnostics for current file
- Click on lightbulb icon for suggested fixes
- [x] built-in support for showing BuckleScript's [bsb](https://bucklescript.github.io/bucklescript/Manual.html#_bucklescript_build_system_code_bsb_code) errors inline, as a companion to merlin's diagnosis.
* highlighting

## Getting Started
* [x] advanced syntax highlighting for reason
* [x] basic highlighting for merlin, ocamlbuild, and opam files

### Recommended Syntax Themes
* editing

Although syntax highlighting should display well in most themes we recommend and test with the following:
* [x] document formatting (enable on save with `editor.formatOnSave`)
* [x] completion and snippets
* [x] [rename symbol](https://code.visualstudio.com/docs/editor/editingevolved#_rename-symbol) (F2 or right click)

#### Default Themes
* navigation

- Dark+ (*recommended*; this theme is the most thoroughly tested)
* [x] [symbol outline for buffers](https://code.visualstudio.com/docs/editor/editingevolved#_goto-symbol) (⇧⌘O) (type `:` in list to sort items)
* [x] [symbol outline for project](https://code.visualstudio.com/docs/editor/editingevolved#_open-symbol-by-name) (⌘T) (supports regular expressions)
* [x] [jump-to-definition](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-definition) (⌃+click) and [code preview](https://code.visualstudio.com/docs/editor/editingevolved#_peek) (⌘+hover)
* [x] find references (⇧F12 or right click)

#### Other Themes
* static analysis
* [x] merlin integration with incremental edit synchronization
* [x] display types over definitions (disable with `editor.codeLens` setting)
* [x] display types and markdown-rendered docs on hover
* [x] [online linting and compiler diagnostics with suggested fixes](https://code.visualstudio.com/docs/editor/editingevolved#_errors-warnings)
* ⇧⌘M to toggle diagnostics panel
* F8 to loop through diagnostics for current file
* Click on lightbulb icon for suggested fixes
* [x] built-in support for showing BuckleScript's [bsb](https://bucklescript.github.io/bucklescript/Manual.html#_bucklescript_build_system_code_bsb_code) errors inline, as a companion to merlin's diagnosis.

- [Atom One Dark](https://marketplace.visualstudio.com/items?itemName=freebroccolo.theme-atom-one-dark)
- [Dracula](https://marketplace.visualstudio.com/items?itemName=dracula-theme.theme-dracula)
- [Flatland Monokai](https://marketplace.visualstudio.com/items?itemName=gerane.Theme-FlatlandMonokai)
- [Oceanic Next](https://marketplace.visualstudio.com/items?itemName=naumovs.theme-oceanicnext)
## Getting Started

### Configuration

Extension requires `ocamlmerlin-lsp` (and `ocamlmerlin-reason` if you are using Reason syntax) compatible with the project you are working with. Path to the binary can be specified with `reason.path.ocamlmerlin-lsp` key in your `.vscode/settings`:

### Configurations
#### Reason
```json
"reason.path.ocamlmerlin-dir": "_opam/bin/ocamlmerlin-lsp",
"reason.path.ocamlmerlin-reason": "_opam/bin/ocamlmerlin-reason"
```

#### esy

- [Reason](https://reasonml.github.io/docs/en/installation)
If you are using `esy`, you can use this configuration:

The Reason installation steps also installs Merlin for you, so you can skip the Merlin installation in the next section.
````json
"devDependencies": {
"@opam/merlin-lsp": "*",
"@opam/reason": "3.4.0", // if you are using reason
"ocaml": "4.06.x" // version of compiler in your project
},
"resolutions": {
"@opam/merlin-lsp": "ocaml/merlin:merlin-lsp.opam#f431006"
}

#### Merlin
Then run `esy exec-command which ocamlmerlin-lsp` and `esy exec-command which ocamlmerlin-reason` to get paths to binaries.

#### bs-platfrom <= 5

Bucklescript 5 and earlier using `OCaml 4.02.3` and you will have problems with compliling `merlin-lsp`. But it can be solved with a couple of well placed pins:

```json
// esy.json
"devDependencies": {
"@opam/merlin-lsp": "*",
"@opam/reason": "3.4.0",
"ocaml": "4.2.x"
},
"resolutions": {
"@opam/ppx_deriving": {
"source": "github:ocaml-ppx/ppx_deriving:opam#71e61a2",
"override": {
"build": ["ocaml pkg/build.ml native=true native-dynlink=true"]
}
},
"@opam/merlin-lsp": "github:Khady/merlin:merlin-lsp.opam#9325d1d"
}
```

**Configured for you already if you've installed Reason above & plan to use it for JS compilation. Skip this step.**
### Recommended Syntax Themes

This extension relies heavily on [merlin](https://github.com/the-lambda-church/merlin) so you will
need to have your project set up for that in order to enable completion and hover info. See the
Merlin [wiki](https://github.com/the-lambda-church/merlin/wiki/project-configuration) for details on
how to do that. Basically you need to have a `.merlin` file in your project root which lists the
source directories, libraries, and extensions used.
Although syntax highlighting should display well in most themes we recommend and test with the following:

#### Bsb
#### Default Themes

You can optionally start [bsb](https://bucklescript.github.io/bucklescript/Manual.html#_bucklescript_build_system_code_bsb_code) from the editor itself, and have the command-line errors appear inside the editor. Add the following to `Code > Preferences > Settings`:
* Dark+ (_recommended_; this theme is the most thoroughly tested)

```reason
"reason.diagnostics.tools": [
"merlin",
"bsb"
]
```
#### Other Themes

Merlin's diagnosis is best-effort and can sometimes be wrong; bsb's diagnosis is 100% correct. **bsb diagnosis also works on Windows**.
* [Atom One Dark](https://marketplace.visualstudio.com/items?itemName=freebroccolo.theme-atom-one-dark)
* [Dracula](https://marketplace.visualstudio.com/items?itemName=dracula-theme.theme-dracula)
* [Flatland Monokai](https://marketplace.visualstudio.com/items?itemName=gerane.Theme-FlatlandMonokai)
* [Oceanic Next](https://marketplace.visualstudio.com/items?itemName=naumovs.theme-oceanicnext)

### Installation

Expand All @@ -102,75 +119,8 @@ To enable formatting on save, add the following to `Code > Preferences > Setting
```

If you want to enable [codelens](https://code.visualstudio.com/blogs/2017/02/12/code-lens-roundup), add the following to `Code > Preferences > Settings`:
```
"reason.codelens.enabled": true
```

## Advanced Features

### Case splitting

For the examples below, `<cursor>` represents the position of the current VS Code editor cursor.

#### Introducing a `switch`

In order to introduce a `switch`, execute the following steps:

1. select an identifier or move the cursor anywhere within its word range (as below)
2. open the palette (⇧⌘P) and run `Reason: case split` (typing `case` should pull it up)

##### Before
```
let foo (arg: list 'a) => a<cursor>rg;
```

##### After
```
let foo (arg: list 'a) => switch arg {
| [] => failwith "<case>"
| [_, ..._] => failwith "<case>"
};
```

#### Nesting `switch` expressions

The `switch` introduction functionality works with nested `switch` expressions:

##### Before
```
let foo (arg: list 'a) => switch arg {
| [] => failwith "<case>"
| [_, ...xs] => x<cursor>s
};
```

##### After
```
let foo (arg: list 'a) => switch arg {
| [] => failwith "<case>"
| [_, ...xs] => switch xs {
| [] => failwith "<case>"
| [_, ..._] => failwith "<case>"
}
};
```

#### Splitting a pattern without introducing a `switch`

The case split feature can be used to split an existing pattern further:

##### Before
```
let foo (arg: list 'a) => switch arg {
| [] => failwith "<case>"
| [x, ...x<cursor>s] => failwith "<case>"
};
```

##### After
```
let foo (arg: list 'a) => switch arg {
| [] => failwith "<case>"
| [_] | [_, _, ..._] => failwith "<case>"
};
"reason.codelens.enabled": true
```
````
Loading