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

vim-rescript v3: Remove server and vim commands #72

Merged
merged 16 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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
12 changes: 2 additions & 10 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@ jobs:
with:
neovim: true
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'
- run: npm install
- name: Test with neovim
run: |
nvim --version
vim --version
make test
- name: Neovim Version
run: nvim --version
- name: Test syntax
run: make test-syntax
22 changes: 0 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,4 @@
.merlin
.DS_Store

.bsb.lock
lib/bs
node_modules
test/**/*.js
doc/tags

server/**/*.d.ts
server/**/*.js.map
server/node_modules/.bin

# We don't need that file
server/analysis_binaries/README.md

# We need to vendor node_modules and all the executables
!server/**/node_modules/
!server/analysis_binaries/darwin/rescript-editor-analysis.exe
!server/analysis_binaries/linux/rescript-editor-analysis.exe
!server/analysis_binaries/win32/rescript-editor-analysis.exe

examples/**/node_modules
examples/**/lib
examples/**/src/*.js
examples/**/.merlin
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

## master

**Breaking Changes:**

- Remove vendored ReScript LS and remove native Vim Commands (e.g. `:RescriptBuild`, etc)
- The ReScript Language Server will now be shipped as a dedicated npm package [rescript-language-server](https://github.com/rescript-lang/rescript-vscode/tree/master/server#rescript-language-server)
aspeddro marked this conversation as resolved.
Show resolved Hide resolved
- Migrate to the official language server as described in our README instructions

**Improvements:**

- Improve syntax highlighting for escaped backticks in interpolated strings ([#55](https://github.com/rescript-lang/vim-rescript/pull/55))
- Improve syntax highlighting for escaped backticks in interpolated strings ([#55](https://github.com/rescript-lang/vim-rescript/pull/55))
- Highlight improvements ([#69](https://github.com/rescript-lang/vim-rescript/pull/69))

## 2.1.0
Expand Down
73 changes: 1 addition & 72 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
## Development

- Clone the repo
- `npm install` dependencies
- `make test` to run the tests
- `make test-syntax`, require Neovim >= 0.9.0
- `make test-syntax` to run the syntax tests, require Neovim >= 0.9.0

**Working within VIM**

Expand All @@ -19,9 +17,6 @@ Plug ~/Projects/vim-rescript
- Run `:PlugInstall` (you'll not see the plugin in the interactive vim-plug list, because it is a local project)
- You can open and edit functionality in any plugin file. After any changes, just run `:so %` in the same buffer to source the current file, then proceed to do your manual tests

**Integration Specs:**
For all the informal specs about editor integration & the ReScript platform, check out the [CONTRIBUTING](https://github.com/rescript-lang/rescript-vscode/blob/master/CONTRIBUTING.md) file of the rescript-vscode reference implementation.

### Syntax Tests

Syntax tests require Neovim >= 0.9.0
Expand All @@ -35,69 +30,3 @@ Syntax tests require Neovim >= 0.9.0
//^
```
- Run `make test-syntax`

### Use custom rescript-editor-support.exe

> Note: Don't do this as a ReScript user. This is only intended for extension development purposes only.
> We won't consider bug reports that are caused by custom editor-support setups.

We are currently using a forked version of RLS to be able to do type-hinting (without using an LSP client actually). To build the binary, do the following:

```bash
cd ~/Projects

git clone https://github.com/rescript-lang/rescript-editor-support.git

# You will need esy to build the project
esy
```

After a successful build, you will find a binary at path `_esy/default/build/install/default/bin/Bin`. To make things easier, we will symlink it:

```bash
cd ~/Projects/rescript-editor-support
ln -s _esy/default/build/install/default/bin/Bin bin.exe
```

Now open your `vimrc` file and add following line:

```vim
let g:rescript_editor_support_exe = "~/Projects/reason-language-server/bin.exe"
```

#### Testing the local setup

That's it! Now you should be able to use `RescriptTypeHint` / omnicompletion on a `.res` file:

- Within a ReScript project, create a new `myfile.res`
- Add `let a = ""`
- Move your cursor above the empty string `""`
- Type `:RescriptTypeHint`. A preview window will open to show the type information



## Vendoring a new rescript-vscode version

We are currently vendoring rescript-vscode to provide all the binaries + LSP for our coc-vim setup.

First, `curl` the tagged zip bundle from the `rescript-vscode` GH releases:

```
curl -L https://github.com/rescript-lang/rescript-vscode/releases/download/1.1.1/rescript-vscode-1.1.1.vsix -o rescript-vscode-1.1.1.zip
```

Unzip it and replace the `rescript-vscode` directory. Like this:

```
unzip rescript-vscode-1.1.1.zip -d rescript-vscode-1.1.1
rm -rf server

mv rescript-vscode-1.1.1/extension/server server
```

Lastly:

- Check in the changes and push to a working branch
- Do a last sanity check, update your `PlugInstall` to point to the newly created branch. Run `PlugUpdate` and check if the LSP / vim setup works as expected
- Run `:RescriptInfo` and check if the output reflects all the changes
- To wrap up, merge the branch, update CHANGELOG, push a new tag
10 changes: 0 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
.PHONY: test test-ci

MYVIM ?= nvim --headless

INMAKE := 1
export INMAKE

test:
@$(MYVIM) -u ./test/test_all.vim

test-syntax:
nvim -l test/test-syntax.lua
git diff --name-only --exit-code -- 'test/syntax/expected/*.res.txt'
124 changes: 39 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,22 @@
# vim-rescript

**This is the official vim plugin for ReScript.**
Vim runtime files for ReScript.

> If you are experiencing any troubles, open an issue or visit our [Forum](https://forum.rescript-lang.org) and ask for guidance.

## Features

**Supported Workflows:**
- Plain VIM (without any third party plugins)
- LSP + [coc-vim](https://github.com/neoclide/coc.nvim)

**Basics:**
- Syntax highlighting for ReSript files
- Filetype detection for `.res`, `.resi`
- Basic automatic indentation
- Includes LSP for coc-vim usage
- Proper tooling detection for monorepo like setups (yarn workspaces)

**Provided by vim-rescript commands:**
- Formatting `.res` files w/ syntax error diagnostics in VIM quickfix
- Convert existing `.re` /`.rei` files to `.res` /`.resi`
- Type hint for current cursor position
- Jump to definition for current cursor position
- Building the current projec w/ build diagnostics in VIM quickfix
- Autocompletion w/ Vim's omnicomplete

**Monorepo support:**

The vim-rescript plugin automatically updates its project environment on each file open separately.
- Tested for yarn workspaces (see [./examples/monorepo-yarn-workspaces])
- **Note for non-LSP usage:** Always make sure to switch to a `.res` file **within the project you want to compile** before running `:RescriptBuild` etc.

See `:h rescript` for the detailed [helpfile](./doc/rescript.txt).

## Requirements

The plugin works with projects based on `bs-platform@8.3` or later

## Installation

`vim-rescript` can be installed either manually or by using your favourite plugin manager.

```viml
```vim
" vim-plug
Plug 'rescript-lang/vim-rescript'

Expand All @@ -50,89 +25,68 @@ Plugin 'rescript-lang/vim-rescript'

" NeoBundle
NeoBundle 'rescript-lang/vim-rescript'
```

" Packer
use 'rescript-lang/vim-rescript'
```lua
-- Lazy.nvim
{ 'rescript-lang/vim-rescript' }
aspeddro marked this conversation as resolved.
Show resolved Hide resolved
```

You can also pin your installation to specific tags (check our releases [here](https://github.com/rescript-lang/vim-rescript/releases)):

```
With Plug:

```vim
Plug 'rescript-lang/vim-rescript', {'tag': 'v2.1.0'}
```

## Using vim-rescript with COC

(`:h rescript-coc`)

Our plugin comes with all the necessary tools (LSP + editor-support binaries for Windows, Mac, Linux) to set up coc-vim.
After the installation, open your coc config (`:CocConfig`) and add the following configuration:
With [Lazy.nvim](https://github.com/folke/lazy.nvim):

```json
"languageserver": {
"rescript": {
"enable": true,
"module": "~/.config/nvim/plugged/vim-rescript/server/out/server.js",
"args": ["--node-ipc"],
"filetypes": ["rescript"],
"rootPatterns": ["bsconfig.json"]
}
}
```lua
{ 'rescript-lang/vim-rescript', tag = "v2.1.0" }
```

- The config above assumes that you were using `vim-plug` for plugin installations.
- Adapt your `module` path according to the install location of your vim-rescript plugin.
- Save the configuration, run `:CocRestart` and open a (built) ReScript project and check your code for type-hints.

**Note:** Even if you are using COC, we recommend checking out the builtin commands that come with `vim-rescript` (`:h rescript-commands).

## Using vim-rescript's functionality (no vim-coc, no vim-ale, etc)
## Setup LSP

(`:h rescript-config`)
First you need install the language server for ReScript from npm

Vim comes with a set of useful functions that are completely self contained and work with any neovim setup without any plugins:
> **Note**
> If you are using [mason.nvim](https://github.com/williamboman/mason.nvim) you can install the ReScript Language Server using the command `MasonInstall rescript-language-server`

```sh
npm install -g @rescript/language-server
```
:h :RescriptFormat
:h :RescriptUpgradeFromReason
:h :RescriptBuild
:h :RescriptTypeHint
:h :RescriptJumpToDefinition
:h :RescriptInfo
```
Please refer to the [doc](./doc/rescript.txt) file for more details!

We don't come with any predefined keybindings, but provide a basic set of keymappings down below.
The binary is called `rescript-language-server`

### Basic Key Bindings
### Neovim LSP builtin

These bindings won't collide with any other mappings in your vimrc setup, since they are scoped to `rescript` buffers only:
Install the [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) package and setup the LSP

```vim
" Note that <buffer> allows us to use different commands with the same keybindings depending
" on the filetype. This is useful if to override your e.g. ALE bindings while working on
" ReScript projects.
autocmd FileType rescript nnoremap <silent> <buffer> <localleader>r :RescriptFormat<CR>
autocmd FileType rescript nnoremap <silent> <buffer> <localleader>t :RescriptTypeHint<CR>
autocmd FileType rescript nnoremap <silent> <buffer> <localleader>b :RescriptBuild<CR>
autocmd FileType rescript nnoremap <silent> <buffer> gd :RescriptJumpToDefinition<CR>
```
```lua
local lspconfig = require('lspconfig')

### Configure omnicomplete Support
lspconfig.rescriptls.setup{}
```

(`:h rescript-omnicomplete`)
For more details, see [server configuration](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rescriptls)

We support auto-completion with Vim's builtin `omnifunc`, which is triggered with `C-x C-o` in insert mode to look for autocomplete candidates.
### COC (Vim or Neovim)

> While omnicomplete's dialog is open, use `C-n` / `C-p` to navigate to the next / previous item
(`:h rescript-coc`)

```vim
" Hooking up the ReScript autocomplete function
set omnifunc=rescript#Complete
After the installation, open your coc config (`:CocConfig`) and add the following configuration:

" When preview is enabled, omnicomplete will display additional
" information for a selected item
set completeopt+=preview
```json
"languageserver": {
"rescript": {
"enable": true,
"module": "rescript-language-server",
"args": ["--node-ipc"],
"filetypes": ["rescript"],
"rootPatterns": ["rescript.json", "bsconfig.json"]
}
}
```

## Credits
Expand Down
Loading