rscls

Crates.iorscls
lib.rsrscls
version0.2.2
sourcesrc
created_at2023-04-09 13:37:03.538512
updated_at2023-10-21 12:16:52.111454
descriptionA language server for rust-script
homepage
repositoryhttps://github.com/MiSawa/rscls
max_upload_size
id834233
size71,632
(MiSawa)

documentation

README

crates.io

RSCLS

A language server for rust-script.

How it works

Internally, RSCLS spawns an instance of rust-analyzer with no package configuration. Every time RSCLS receives textDocument/didOpen request from the client with rust-script, rust_script or rustscript language id, it changes the language id to rust, run rust-script to obtain the project directory and setup linkedProject for the project.

What doesn't work

  • Does NOT work on templated rust-scripts, including those need main function added.
    • Current implementation doesn't translate file paths nor positions in a file. Since templated rust-scripts are not valid as rust program, we can't handle them directly.
  • Commands may not work properly.
  • Currently, minimum supported rust-script version is 0.28.0.

Install

cargo install rscls

You can alternatively clone this repository to your local, maybe modify some code and run

cargo install --path path-to-cloned-dir

to install locally modified version of the code.

Uninstall

cargo uninstall rscls

Example configuration

Here's an example configuration for nvim-lspconfig. I don't use other editor/IDEs, so please figure them out on your own. Pull requests are welcomed!

-- Assumes `autocmd BufEnter *.ers  setlocal filetype=rustscript` or similar
local lsp_configs = require 'lspconfig.configs'
if not lsp_configs.rlscls then
    lsp_configs.rlscls = {
        default_config = {
            cmd = { 'rscls' },
            filetypes = { 'rustscript' },
            root_dir = function(fname)
                return lspconfig.util.path.dirname(fname)
            end,
        },
        docs = {
            description = [[
https://github.com/MiSawa/rscls

rscls, a language server for rust-script
]],
        }
    }
end
lspconfig.rlscls.setup {
    settings = {
        ['rust-analyzer'] = {
            imports = {
                group = {
                    enable = true,
                },
                granularity = {
                    enforce = true,
                    group = "crate",
                },
            },
            cargo = {
                buildScripts = {
                    enable = true,
                },
            },
            procMacro = {
                enable = true,
            },
        },
    }
}

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed under the terms of both the Apache License, Version 2.0 and the MIT license without any additional terms or conditions.

Commit count: 35

cargo fmt