Skip to content

Commit c020c2f

Browse files
authored
Document how to get LSP support with rust-script (#20)
1 parent 8453522 commit c020c2f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,48 @@ At a high level, the crate provides helpers and data structures which are common
5353
environment, such as easy error handling, file reading, serialisation/deserialisation, etc.
5454
If you find something lacking, I encourage you to open a PR!
5555

56+
## Language Server Support
57+
58+
[`rscls`](https://github.com/MiSawa/rscls/) works as a middle-man LSP between rust-analyzer and
59+
rust-script.
60+
Below are instructions for getting LSP support using Neovim.
61+
62+
First, ensure you have `rscls` installed.
63+
```sh
64+
cargo install rscls
65+
```
66+
67+
Next, add the following to your configuration. Note this is for Neovim LSP config.
68+
69+
```lua
70+
-- Rust script LSP support through rscls
71+
local lsp_configs = require 'lspconfig.configs'
72+
if not lsp_configs.rscls then
73+
lsp_configs.rscls = {
74+
default_config = {
75+
cmd = { 'rscls' },
76+
filetypes = { 'rustscript' },
77+
root_dir = function(fname)
78+
return require'lspconfig'.util.path.dirname(fname)
79+
end,
80+
},
81+
}
82+
end
83+
require 'lspconfig'.rscls.setup {}
84+
```
85+
86+
Then, when you are wanting LSP support in a Rust file, set the file type to `rustscript` with a
87+
command.
88+
89+
```vim
90+
:set filetype=rustscript
91+
```
92+
93+
I generally do not bother with LSP support for small scripts, but it comes in handy for more
94+
complex ones!
95+
_Note that it will take a little bit to spool up the server and compile the script._
96+
97+
5698
## Versioning
5799
58100
Versioning does not follow semver as would a normal crate.

0 commit comments

Comments
 (0)