rust-analyzer is a modular compiler frontend for the Rust language

Related tags

IDEs rust lsp-server
Overview

rust-analyzer logo

rust-analyzer is a modular compiler frontend for the Rust language. It is a part of a larger rls-2.0 effort to create excellent IDE support for Rust.

Work on rust-analyzer is sponsored by

Ferrous Systems

Quick Start

https://rust-analyzer.github.io/manual.html#installation

Documentation

If you want to contribute to rust-analyzer or are just curious about how things work under the hood, check the ./docs/dev folder.

If you want to use rust-analyzer's language server with your editor of choice, check the manual folder. It also contains some tips & tricks to help you be more productive when using rust-analyzer.

Security and Privacy

See the corresponding sections of the manual.

Communication

For usage and troubleshooting requests, please use "IDEs and Editors" category of the Rust forum:

https://users.rust-lang.org/c/ide/14

For questions about development and implementation, join rust-analyzer working group on Zulip:

https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer

Quick Links

License

Rust analyzer is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

Comments
  • "cargo metadata failed: No such file or directory (os error 2)"

    I'm trying to work on a project that the RLS extension has no problem handling but I'm getting an odd error from rust-analyzer that is pretty unhelpful:

    rust-analyzer failed to load workspace: cargo metadata failed: No such file or directory (os error 2)
    

    What file or directory could not be found? Why couldn't it be found even though RLS works without a hitch?

    I'm running the VSCode extension remotely (Docker) with VSCode Insiders and rust-analyzer at commit 759100fb0dcb41518f2a593dae5de5bbedd07776.

    opened by samuela 66
  • rust-analyzer failed to load workspace

    rust-analyzer failed to load workspace

    I installed rust with brew on MacOS, and I'm noticing this error on a hello world project with VS Code:

    rust-analyzer failed to load workspace: 
        Failed to find sysroot for Cargo.toml file ./rust_new/Cargo.toml. 
        Is rust-src installed?: rustup component add rust-src failed
    

    I didn't install with rustup, and I figured I wouldn't need to. This suggests I must, but why? Does this suggest I need the complier source to use your package in my editor?

    opened by Redoubts 62
  • rust-analyzer is slow to compile

    rust-analyzer is slow to compile

    Both ra_hir and ra_ide_api are really slow to compiler, which makes fix & test loop rather frustrating. Note that tests are extremely fast themselves, it's compile time that hurts us badly.

    We need to do something with it...

    E-hard fun 
    opened by matklad 58
  • Theme loading and

    Theme loading and "editor.tokenColorCustomizations" support.

    Fixes: Issue#1294

    TODO:

    • [x] Load themes
    • [x] Load existing ralsp-prefixed overrides from "workbench.colorCustomizations".
    • [x] Load overrides from "editor.tokenColorCustomizations.textMateRules".
    • [x] Use RA tags to load vscode.DecorationRenderOptions (colors) from theme & overrides.
    • [x] Map RA tags to common TextMate scopes before loading colors.
    • [x] Add default scope mappings in extension.
    • [x] Cache mappings between settings updates.
    • [x] Add scope mapping configuration manifest in package.json
    • [x] Load configurable scope mappings from settings.
    • [x] Load JSON Scheme for text mate scope rules in settings.
    • [x] Update Readme.

    Borrowed the theme loading (scopes.ts) from Tree Sitter with some modifications to reading "editor.tokenColorCustomizations" for merging with loaded themes and had to remove the async portions to be able to load it from settings updates.

    ~Just a PoC and an idea I toyed around with a lot of room for improvement.~ For starters, certain keywords aren't part of the standard TextMate grammar, so it still reads colors from the ralsp prefixed values in "workbench.colorCustomizations".

    But I think there's more value making the extension work with existing themes by maping some of the decoration tags to existing key or keys.

    Screenshot 2019-11-09 at 17 43 18 Screenshot 2019-11-09 at 17 41 45 Screenshot 2019-11-09 at 17 40 29

    These will merge with the default ones coming with the extension, so you don't have to implement all of them and works well with overrides defined in settings.

        "editor.tokenColorCustomizations": {
            "textMateRules": [
                {
                    "scope": "keyword",
                    "settings": {
                        "fontStyle": "bold",
                    }
                },
            ]
        },
    

    Edit: The idea is to work with 90% of the themes out there by working within existing scopes available that are generally styled. It's not to say I want to erase the custom Rust scopes - those should still remain and eventually worked into a custom grammar bundle for Rust specific themes that target those, I just want to make it work with generic themes offered on the market place for now.

    A custom grammar bundle and themes for Rust specific scopes is out of... scope for this PR. We'll make another round to tackle those issues.

    Current fallbacks implemented

        [
            'comment',
            [
                'comment',
                'comment.block',
                'comment.line',
                'comment.block.documentation'
            ]
        ],
        ['string', ['string']],
        ['keyword', ['keyword']],
        ['keyword.control', ['keyword.control', 'keyword', 'keyword.other']],
        [
            'keyword.unsafe',
            ['storage.modifier', 'keyword.other', 'keyword.control', 'keyword']
        ],
        ['function', ['entity.name.function']],
        ['parameter', ['variable.parameter']],
        ['constant', ['constant', 'variable']],
        ['type', ['entity.name.type']],
        ['builtin', ['variable.language', 'support.type', 'support.type']],
        ['text', ['string', 'string.quoted', 'string.regexp']],
        ['attribute', ['keyword']],
        ['literal', ['string', 'string.quoted', 'string.regexp']],
        ['macro', ['support.other']],
        ['variable', ['variable']],
        ['variable.mut', ['variable', 'storage.modifier']],
        [
            'field',
            [
                'variable.object.property',
                'meta.field.declaration',
                'meta.definition.property',
                'variable.other'
            ]
        ],
        ['module', ['entity.name.section', 'entity.other']]
    
    opened by seivan 57
  • New versions not available on OpenVSX (platform-specific VSIXes)

    New versions not available on OpenVSX (platform-specific VSIXes)

    EDIT: see https://github.com/rust-analyzer/rust-analyzer/issues/11080#issuecomment-1010840901


    rust-analyzer version: "Rust Analyzer: Show RA Version" command does nor exist, extension install dir: matklad.rust-analyzer-0.2.867

    rustc version: rustc 1.56.0 (09c42c458 2021-10-18)

    OS Version: Ubuntu 18.04.6

    VS Code version: I use VSCodium 1.63.2

    Today, rust-analyzer updated itself and stop working with the error:

    INFO [12/21/2021, 11:18:12 AM]: Using server binary at /home/user/.vscode-oss/extensions/matklad.rust-analyzer-0.2.867/server/rust-analyzer
    ERROR [12/21/2021, 11:18:12 AM]: Bootstrap error [Error: Failed to execute /home/user/.vscode-oss/extensions/matklad.rust-analyzer-0.2.867/server/rust-analyzer --version
    	at j0 (/home/user/.vscode-oss/extensions/matklad.rust-analyzer-0.2.867/out/main.js:109:4032)
    	at processTicksAndRejections (internal/process/task_queues.js:93:5)
    	at async N0 (/home/user/.vscode-oss/extensions/matklad.rust-analyzer-0.2.867/out/main.js:109:1881)
    	at async I0 (/home/user/.vscode-oss/extensions/matklad.rust-analyzer-0.2.867/out/main.js:108:3977)
    	at async lC (/home/user/.vscode-oss/extensions/matklad.rust-analyzer-0.2.867/out/main.js:108:3808)
    	at async Promise.all (index 0)
    	at async v.$activate (/usr/share/codium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:100:20806)]
    

    The file /home/user/.vscode-oss/extensions/matklad.rust-analyzer-0.2.867/server/rust-analyzer but cannot be executed, even manually:

    $ /home/user/.vscode-oss/extensions/matklad.rust-analyzer-0.2.867/server/rust-analyzer --version
    bash: /home/user/.vscode-oss/extensions/matklad.rust-analyzer-0.2.867/server/rust-analyzer: No such file or directory
    

    While the file exists.

    But ldd on it shows the missing musl lib:

    ldd /home/user/.vscode-oss/extensions/matklad.rust-analyzer-0.2.867/server/rust-analyzer
            linux-vdso.so.1 (0x00007ffce3bfa000)
            libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5dc6a52000)
            libc.musl-x86_64.so.1 => not found
            libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5dc6661000)
            /lib/ld-musl-x86_64.so.1 => /lib64/ld-linux-x86-64.so.2 (0x00007f5dc8490000)
    

    I had a VSCodium update yesterday so it might be related.

    I have tried to uninstall the extension but it installs the same version.

    opened by romainreignier 54
  • [WIP] ra-fmt

    [WIP] ra-fmt

    Struct EditTree will more directly mutate the syntax tree by building up nodes with knowledge of Pattern's, checking as we walk the tokens and inserting edits marked with location and other meta info. When a diff is asked for the tree will know the amount, size and type of edit capable of producing a diff. relevant files: edit_tree the new way to directly mutate tree scratch just to get something to output to see what I'm doing otherwise everything so far is similar or stolen from nixpkgs-fmt :smile:

    Would it make sense for rowan node's to be able to insert tokens, or is keeping a vec of edits to create a diff which some other thing can interpret and build the appropriate string out of more the direction to go in.

    opened by DevinR528 52
  • Unresolved import for platform specific modules

    Unresolved import for platform specific modules

    I tried to search if it was reported but didn't found anything.

    When importing the platform specific modules in std::os rust-analyzer gives me the following error: unresolved import. Also those modules don't show up for auto-complete.

    When the module is used outside use statement, there is no error, but the semantic token are of the type unresolvedReference.

    RA version

    Latest master branch

    Example

    use std::os::unix;
    
    E-hard S-unactionable 
    opened by GrayJack 50
  • Rust-analyzer error on pre-release branch of vscode extension

    Rust-analyzer error on pre-release branch of vscode extension

    rust-analyzer version: rust-analyzer 2022-02-14 (installed via pacman)

    rustc version: rustc 1.58.1 (db9d1b20b 2022-01-20) (installed via rustup and branch is stable)

    Hello! I am taking this error on vscode.

    rust-analyzer failed to load workspace: "cargo" "--version" failed, exit status: 1
    stderr:
    error: no override and no default toolchain set
    

    I am using pre-release of vscode extension, that's why i open a issue despite your info about it. I tried adding CARGO path but it didn't work. I hope it'll be helpful bug report for you!

    S-unactionable 
    opened by rustacean112 47
  • Update manual now stable can be installed with rustup

    Update manual now stable can be installed with rustup

    rustup can now install rust-analyzer for the stable tool-chain. This commit removes the note that rustup can only install for the nightly branch and adjusts the command.

    I also added a note on how to find the path to the rust-analyzer binary when installed using rustup, and suggestions on how to work around it not being placed in ~/.cargo/bin.

    I thought it would be ideal to point everyone to use rustup run stable rust-analyzer to start rust-analyzer. That would make it trivial to switch to nightly however I could not get this to work in nvim therefore I left it as a suggestion at the end.

    opened by dvdsk 45
  • Rust analyzer marks proc macros as errors

    Rust analyzer marks proc macros as errors

    rust-analyzer version: v0.3.1091

    rustc version: rustc 1.61.0 (fe5b13d68 2022-05-18)

    When using IntEnum proc macro rust analyzer gives the error:

    proc macro IntEnum not expanded rust-analyzer unresolved-proc-macro

    C-support A-proc-macro 
    opened by saadjhk 44
  • = 2.28 in latest build.">

    "Bootstrap Error" rust-analyzer requires glibc >= 2.28 in latest build.

    rust-analyzer no longer will run on Ubuntu 18.04( which bundles glibc 2.27), and other distros which have a glibc older than 2.27.

    this issue manifests as a "Bootstrap Error" notably, the extension output will log something along the lines of:

    ERROR [2/28/2022, 8:46:56 AM]: Bootstrap error [Error: Failed to execute /home/newuser/.vscode/extensions/matklad.rust-analyzer-0.2.956/server/rust-analyzer --version
    

    when running the binary, we get the following error:

    /home/jake/.vscode-server-insiders/extensions/matklad.rust-analyzer-0.3.953/server/rust-analyzer: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.29' not found (required by /home/jake/.vscode-server-insiders/extensions/matklad.rust-analyzer-0.3.953/server/rust-analyzer)
    /home/jake/.vscode-server-insiders/extensions/matklad.rust-analyzer-0.3.953/server/rust-analyzer: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /home/jake/.vscode-server-insiders/extensions/matklad.rust-analyzer-0.3.953/server/rust-analyzer)
    

    current workarounds are mentioned in this comment: https://github.com/rust-analyzer/rust-analyzer/issues/11558#issuecomment-1054802255

    opened by jhgg 44
  • feat: Package Windows release artifacts as ZIP and add symbols file

    feat: Package Windows release artifacts as ZIP and add symbols file

    Closes #13872 CC #7747 CC #10371

    This allows us to ship a format that's easier to handle on Windows. As a bonus, we can also include the PDB, to get useful stack traces. Unfortunately, it adds a couple of dependencies to xtask, increasing the debug build times from 1.28 to 1.58 s (release from 1.60s to 2.20s) on my system.

    S-waiting-on-review 
    opened by lnicola 1
  • "Extract into Function" removes whitespace

    rust-analyzer version: rust-analyzer 1.67.0-nightly (83356b7 2022-11-17)

    rustc version: rustc 1.67.0-nightly (83356b78c 2022-11-17)

    relevant settings: nothing out of the ordinary, I think, but I'm using this in Helix


    Expected behavior: using the Extract into Function action extracts the highlighted code into a function exactly without changing whitespace/newlines.

    Behavior: it removes newlines.

    fn some_long_function() {
      let foo = bar();
      let bax = quux();
    
      // If I highlight from here ... {
      let foo2 = foo * 2;
    
      let frob = baz.frobnicate();
      frob.process();
      // } to here, and extract into function,
      // the newline after `let foo2 = foo*2` is removed.
    }
    

    I think it does make sense to auto-format the code because it'll format on save anyways (hopefully), but it is kind of weird for the newlines to disappear because then I have to go back and insert all the newlines again ... I'd imagine that's tricky to implement though (I don't know about rust-analyzer's internals but I'd imagine this action operates on the AST more than text).

    S-actionable A-assists C-bug 
    opened by gamma-delta 0
  • Type names used from prelude even when name is shadowed

    Type names used from prelude even when name is shadowed

    For example, if you start with the following code:

    use std::io::Result;
    fn main() {
        let f1 = std::fs::File::create("/tmp/test.txt");
    }
    

    Select Insert explicit type on f1. It inserts the type Result<std::fs::File, std::io::Error>, which fails to compile because the Result that is in scope only takes a single type parameter, not two.

    error[E0107]: this type alias takes 1 generic argument but 2 generic arguments were supplied
      --> src/main.rs:3:13
       |
    3  |     let f1: Result<std::fs::File, std::io::Error> = std::fs::File::create("/tmp/test.txt");
       |             ^^^^^^                -------------- help: remove this generic argument
       |             |
       |             expected 1 generic argument
       |
    

    The same issue can be observed with Extract into function and also with other types from the prelude, e.g. String, Vec etc - although those are less likely to be an issue because the standard library doesn't supply alternative items with those names like it does for Result.

    Expected behaviour would be that Result would be fully qualified as std::result::Result, since the prelude import isn't available.

    Observed with rust-analyzer built from head (f31733b1d 2022-12-31).

    S-actionable A-assists C-bug 
    opened by davidlattimore 0
  • [Packaging request] Using zip for windows archive

    [Packaging request] Using zip for windows archive

    Use .zip for rust-analyzer-x86_64-pc-windows-msvc instead of .gz using gz will require downloading some softwares like WinZip but I prefer not to and just use windows' explorer.

    opened by MordechaiHadad 2
  • type-mismatch false positive on unsizing coercion

    type-mismatch false positive on unsizing coercion

    rust-analyzer version: rust-analyzer version: 0.3.1334-standalone (74ae2dd30 2022-12-25)

    rustc version: rustc 1.66.0 (69f9c33d7 2022-12-12)

    relevant settings: in vscode's settings.json: "rust-analyzer.diagnostics.experimental.enable": true, "rust-analyzer.checkOnSave.enable": false (to opt-in into type checking diagnostics)

    This code:

    struct Foo<T: ?Sized> {
        leading: u32,
        trailing: T,
    }
    
    fn unsize(x: Box<Foo<[u32; 4]>>) -> Box<Foo<[u32]>> {
        x
    }
    

    compiles fine with rustc, but vscode shows type error from rust-analyzer:

    image

    A-ty S-unactionable C-bug 
    opened by jDomantas 1
Releases(nightly)
Owner
Building next-generation IDE tooling for Rust
null
Rust IDE support for Atom, powered by the Rust Language Server (RLS)

IDE-Rust Rust language support for Atom-IDE, powered by rust-analyzer. Features Auto-completion Diagnostics (errors and warnings from rustc) Document

The Rust Programming Language 239 Dec 14, 2022
Rust language support in Atom - LOOKING FOR MAINTAINER, see #144

Rust language support in Atom Adds syntax highlighting and snippets to Rust files in Atom. Install Install the package language-rust in Atom (Preferen

Andreas Neuhaus 118 Oct 11, 2022
RustDT is an Eclipse based IDE for the Rust programming language:

Project website: http://rustdt.github.io/ As of 2017, RustDT is no longer actively maintained, see this blog post for more information. If you are int

null 351 Aug 20, 2022
The official Sublime Text 3 package for the Rust Programming Language

Rust Enhanced About This is a Sublime Text 3 package which supports Rust starting with version 1.0, it makes no attempt at supporting earlier incompat

The Rust Programming Language 704 Jan 7, 2023
Repository for the Rust Language Server (aka RLS)

Rust Language Server (RLS) The RLS provides a server that runs in the background, providing IDEs, editors, and other tools with information about Rust

The Rust Programming Language 3.6k Dec 30, 2022
Kakoune Language Server Protocol Client

Kakoune Language Server Protocol Client kak-lsp is a Language Server Protocol client for Kakoune implemented in Rust. Installation Note kak-lsp.toml d

null 495 Dec 17, 2022
Language Server Protocol (LSP) support for vim and neovim.

For legacy python implementation, see branch master. LanguageClient-neovim Language Server Protocol support for vim and neovim. More recordings at Upd

Junfeng Li 3.5k Dec 29, 2022
An experimental proofreading and linting language server for markdown files ✍️

prosemd is an experimental proofreading and linting language server for markdown files. It aims to provide helpful and smart diagnostics when writing

Phil Pluckthun 132 Dec 14, 2022
AIDL Language Server Protocol (LSP) server

AIDL Language Server Protocol (LSP) server Experimental AIDL LSP server based on rust-aidl-parser. Features: diagnostics workspace symbols (Ctrl+T in

Benoit Walter 0 Jan 9, 2022
Experimental treesiter based language server, let's see how far this goes 😆.

tsls Tree-sitter based language server for general languages. Warning: It's in active development right now, and bug is expected. Features Go To Defin

Keyv Chan 16 Sep 11, 2022
A LSP (Language Server Protocol) server for OpenSCAD.

openscad-LSP A LSP (Language Server Protocol) server for OpenSCAD. inspired by dzhu/openscad-language-server Tested with VSCode on Mac and Windows. Te

Leathong 20 Dec 15, 2022
Fennel language server protocol (LSP) support.

fennel-language-server Fennel language server protocol (LSP) support. fennel-language-server is currently in a very early stage and unreliable. Use it

null 68 Dec 27, 2022
impl LSP (Language Server Protocol) Server for librime

rime-ls 为 rime 输入法核心库 librime (的部分功能) 实现 LSP 协议, 从而通过编辑器的代码补全功能输入汉字. 项目还处在早期阶段, 各方面都非常不成熟. 目标是提供 rime + LSP 的通用解决方案, 在不同编辑器内实现与其他 rime 前端类似的输入体验. Feat

zilch40 55 Jan 22, 2023
A brand-new language server for Typst, plus a VS Code extension

Typst LSP A brand-new language server for Typst. Features Syntax highlighting, error reporting, code completion, and function signature help Compiles

Nathan Varner 414 Apr 17, 2023
WIP: Asynchronous Language Server Protocol framework

async-lsp Asynchronous Language Server Protocol (LSP) framework based on tower. ⚠️ This project serves as a proof-of-concept for LSP with middlewares

null 9 Apr 11, 2023
IDE tools for writing pest grammars, using the Language Server Protocol for Visual Studio Code, Vim and other editors

Pest IDE Tools IDE support for Pest, via the LSP. This repository contains an implementation of the Language Server Protocol in Rust, for the Pest par

pest 20 Apr 8, 2023
Eclipse Corrosion - Rust edition in Eclipse IDE

Eclipse Corrosion Rust edition and debug in Eclipse IDE Corrosion is a Rust development plugin for the Eclipse IDE, providing a rich edition experienc

Eclipse Foundation 194 Dec 23, 2022
Emacs configuration for Rust

Table of Contents Introduction Installation Melpa Manual installation Feature guide Indentation Code formatting Running / testing / compiling code Cli

The Rust Programming Language 919 Jan 4, 2023
Rust development environment for Emacs

Rustic Table of Contents Rustic Intro Installation straight Compilation Faces rustc errors Rustfmt edition 2018 LSP Server Client eglot lsp-mode lsp-e

null 612 Dec 30, 2022