You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You **must** have `rescript >=9.1` installed locally in your project, through the usual [npm installation](https://rescript-lang.org/docs/manual/latest/installation#integrate-into-existing-js-project). Older versions are not guaranteed to work.
-[Configuring the Code Analyzer](#configuring-the-code-analyzer)
28
+
-[Usage](#usage)
29
+
-[Caveats](#caveats)
30
+
-[🪄 Tips & Tricks](#-tips--tricks)
31
+
-[Hide generated files](#hide-generated-files)
32
+
-[⌨️ Use with Other Editors](#️-use-with-other-editors)
33
+
-[📰 Changelog](#-changelog)
34
+
-[👏 How to Contribute](#-how-to-contribute)
35
+
-[📄 License](#-license)
36
+
37
+
## 📝 Prerequisite
38
+
39
+
You **must** have [ReScript](https://www.npmjs.com/package/rescript) >= 9.1 installed locally in your project, through the usual [npm or yarn installation](https://rescript-lang.org/docs/manual/latest/installation#integrate-into-existing-js-project). Older versions are not guaranteed to work.
40
+
41
+
## 🌈 Supported Themes
12
42
13
43
Our highlighting works well with most popular VSCode themes, such as:
14
44
@@ -22,15 +52,10 @@ The only 2 themes we don't (and can't) support, due to their lack of coloring, a
22
52
23
53
- Dark (Visual Studio), Light (Visual Studio)
24
54
25
-
If your custom theme doesn't seem to highlight much (e.g. no colors for upper-case JSX tag, no distinction between module and variant), try one of the recommended themes to see if that's the problem. For more info, see [this post](https://github.com/rescript-lang/rescript-vscode/pull/8#issuecomment-764469070).
26
-
27
-
## Installation
55
+
> **Note**
56
+
> If your custom theme doesn't seem to highlight much (e.g. no colors for upper-case JSX tag, no distinction between module and variant), try one of the recommended themes to see if that's the problem. For more info, see [this post](https://github.com/rescript-lang/rescript-vscode/pull/8#issuecomment-764469070).
28
57
29
-
The plugin's on [VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=chenglou92.rescript-vscode). In VSCode, `cmd-shift-p` -> "Install Extensions", then find "rescript-vscode".
30
-
31
-
The plugin activates on `.res` and `.resi` files. If you've already got Reason-Language-Server installed, it's possible that the latter took precedence over this one. Make sure you're using this plugin ("ReScript syntax") rather than Reason-Language-Server ("BuckleScript syntax").
32
-
33
-
## Features
58
+
## 💡 Features
34
59
35
60
- Supports `.res`, `.resi` and `bsconfig.json`.
36
61
- Syntax highlighting.
@@ -49,79 +74,93 @@ The plugin activates on `.res` and `.resi` files. If you've already got Reason-L
49
74
-`try`, `for`, etc.
50
75
- Folding, and [custom folding](https://code.visualstudio.com/docs/editor/codebasics#_folding) through `//#region` and `//#endregion`.
51
76
52
-
### Commands
77
+
## 📥 Installation
78
+
79
+
Launch VS Code Quick Open (`Ctrl+P`), paste the following command, and press enter.
80
+
81
+
```
82
+
ext install chenglou92.rescript-vscode
83
+
```
84
+
85
+
The plugin activates on `.res` and `.resi` files. If you've already got Reason-Language-Server installed, it's possible that the latter took precedence over this one. Make sure you're using this plugin ("ReScript syntax") rather than Reason-Language-Server ("BuckleScript syntax").
| ReScript: Create an interface file for this implementation file | Creates an interface file (`.resi`) for the current `.res` file, automatically filling in all types and values in the current file. |
92
+
| ReScript: Open the compiled JS file for this implementation file | Opens the compiled JS file for the current ReScript file. |
93
+
| ReScript: Switch implementation/interface | Switches between the implementation and interface file. If you're in a `.res` file, the command will open the corresponding `.resi` file (if it exists), and if you're in a `.resi` file the command will open the corresponding `.res` file. This can also be triggered with the keybinding `Alt+O`. |
94
+
| ReScript: Start Code Analyzer | This will start code analysis in the ReScript project of the file you run the command from. |
53
95
54
-
#### `> ReScript: Create an interface file for this implementation file.`
96
+
##🔨 Settings
55
97
56
-
Creates an interface file (`.resi`) for the current `.res` file, automatically filling in all types and values in the current file.
98
+
You'll find all ReScript specific settings under the scope `rescript.settings`.
57
99
58
-
#### `> Open the compiled JS file for this implementation file.`
| Autostarting ReScript builds | If there's no ReScript build running already in the opened project, the extension will prompt you and ask if you want to start a build automatically. You can turn off this automatic prompt via the setting `rescript.settings.askToStartBuild`. |
103
+
| ReScript Binary Path | The extension will look for the existence of a `/node_modules/.bin/rescript` file and use its directory as the `binaryPath`. If it does not find it at the project root (which is where the nearest `bsconfig.json` resides), it goes up folders in the filesystem recursively until it either finds it (often the case in monorepos) or hits the top level. To override this lookup process, the path can be configured explicitly using the setting `rescript.settings.binaryPath`|
104
+
| Autostarting the Code Analyzer | The Code Analyzer needs to be started manually by default. However, you can configure the extension to start the Code Analyzer automatically via the setting `rescript.settings.autoRunCodeAnalysis`. |
59
105
60
-
Opens the compiled JS file for the current ReScript file.
// Whether you want the extension to prompt for autostarting a ReScript build if a project is opened with no build running
110
+
"rescript.settings.askToStartBuild":true,
63
111
64
-
Switches between the implementation and interface file. If you're in a `.res` file, the command will open the corresponding `.resi` file (if it exists), and if you're in a `.resi` file the command will open the corresponding `.res` file.
112
+
// Automatically start ReScript's code analysis.
113
+
"rescript.settings.autoRunCodeAnalysis":false,
65
114
66
-
> This can also be triggered with the keybinding `Alt+O`.
115
+
// Path to the directory where ReScript binaries are. You can use it if you haven't or don't want to use the installed ReScript from node_modules in your project.
116
+
"rescript.settings.binaryPath":null
117
+
```
67
118
68
-
###Code Analyzer
119
+
##🚀 Code Analyzer
69
120
70
121
The Code Analyzer is a mode in the extension that runs additional code analysis in your project. The analysis helps you find dead code at a granular level, find unhandled exceptions, and more.
71
122
72
123
> The Code Analyzer uses [reanalyze](https://github.com/rescript-association/reanalyze), which is embedded in the extension, so you don't need to install anything extra to run it.
73
124
74
-
####Configuring the Code Analyzer
125
+
### Configuring the Code Analyzer
75
126
76
127
You'll need to configure what code analysis you want to run, and what (if any) directories you want to ignore. Configuration is done via adding `reanalyze` in `bsconfig.json`. You'll get autocomplete for what configuration options are valid. You can also read [all about configuring `reanalyze` here](https://github.com/rescript-association/reanalyze#configuration-via-bsconfigjson).
77
128
78
-
##### Autostarting the Code Analyzer
129
+
###Usage
79
130
80
-
The Code Analyzer needs to be started manually by default. However, you can configure the extension to start the Code Analyzer automatically via the setting `rescript.settings.autoRunCodeAnalysis`.
81
-
82
-
#### Usage
83
-
84
-
Open the command palette and run `> ReScript: Start Code Analyzer`. This will start code analysis in the ReScript project of the file you run the command from.
131
+
Open the command palette and run `ReScript: Start Code Analyzer`. This will start code analysis in the ReScript project of the file you run the command from.
85
132
86
133
Dead code is highlighted in the editor, and code actions for suppressing dead code warnings are available in most cases.
87
134
88
135
When done, stop the code analysis mode by clicking the `Stop Code Analyzer` button in the editor status bar. This will clear all reported analysis warnings.
89
136
90
-
####Caveats
137
+
### Caveats
91
138
92
139
Currently does not work for full monorepo dead code analysis (although it should work for each monorepo package individually).
93
140
94
-
## Configuration
95
-
96
-
You'll find all ReScript specific settings under the scope `rescript.settings`. Open your VSCode settings and type `rescript.settings` to see them.
97
-
98
-
### Autostarting ReScript builds
99
-
100
-
If there's no ReScript build running already in the opened project, the extension will prompt you and ask if you want to start a build automatically. You can turn off this automatic prompt via the setting `rescript.settings.askToStartBuild`.
101
-
102
-
#### How does it find my ReScript binary?
103
-
104
-
The extension will look for the existence of a `/node_modules/.bin/rescript` file and use its directory as the `binaryPath`. If it does not find it at the project root (which is where the nearest `bsconfig.json` resides), it goes up folders in the filesystem recursively until it either finds it (often the case in monorepos) or hits the top level.
105
-
106
-
To override this lookup process, the path can be configured explicitly using the setting `rescript.settings.binaryPath`.
141
+
## 🪄 Tips & Tricks
107
142
108
143
### Hide generated files
109
144
110
145
You can configure VSCode to collapse the JavaScript files ReScript generates under its source ReScript file. This will "hide" the generated files in the VSCode file explorer, but still leaving them accessible by expanding the source ReScript file they belong to.
111
146
112
-
Open your VSCode settings and type`editor.filenesting`. Enable the feature and scroll down to patterns.
147
+
Open your VSCode settings and type:
113
148
114
-
The example has two patterns added:
115
-
116
-

This nests implementations under interfaces if they're present and nests all generated files under the main ReScript file. Adapt and tweak to your liking.
119
158
120
159
A screenshot of the result:
121
160
122
161

123
162
124
-
## Use with Other Editors
163
+
## ⌨️ Use with Other Editors
125
164
126
165
This repo also contains a language server that can power other editors. **However, the language server in this project is a pure implementation detail. We don't guarantee its stability for other editors' consumption** apart from Vim and Sublime Text.
127
166
@@ -130,3 +169,15 @@ Still, if you'd like to use this language-server with other editors:
130
169
- Get the release binaries from the Github Releases page.
131
170
- Unzip the `.vsix` and get the `server` folder. That's the only folder you need.
132
171
- The language server will be at `server/out/server.js`. Call it through node, and optionally pass `--stdio` if your editor doesn't support the default JSONRPC.
0 commit comments