rust analyzer

GNOME Builder ❤️ Rust Analyzer Part 2

As promised i wanted to show off the remaining features which found their way into GNOME Builder. Be warned this is a Video heavy post!

Goto definition

There are two 2 ways to trigger this action. First you can hold off Ctrl and hover the symbol you are interested in. Clicking brings you to that symbol definition.

The second option is, if you use the vim keyboard movements, to trigger gd in normal mode. As the real vim equivalent this brings you to the definition.

Show references

This is the opposite direction to Goto definition. Show references is triggered via the right click menu of a symbol. This could be a costly operation so you may have to wait some seconds for an solution.

Format via cargo fmt

Formatting the sourcefile is especially convenient in Rust as the formatter is built into cargo/rustc. Its possible to be triggered if you use the vim movement keybindings via gq.

Rename support

Renaming a symbol with all their references? This is possible now. Just hit Ctrl+Shift+R and a popup asks what the new name should look like. Hitting Enter considers all references of that symbol too.

Hover support

It is possible to show documentation when you hover a symbol or method. Due to not that perfect markdown support in a GtkLabel it is not perfect.

Workspace search provider

This is in my opinion the best feature right now. Searching symbols across the workspace is particular convenient if you remember the names of the symbol.

Roadmap

I have several ideas how to go from here:

  • Getting all diagnostic messages into the diagnostic sidebar for workspace wide diagnostic handling.
  • The Workspace search provider is currently a Rust Analyzer only feature but not restricted to it. I want to make the implementation generic enough to handle all LSP servers out there.
  • Rust Analyzer provides very useful CodeActions to refactor code in a convenient way. GNOME Builder does not support these right now therefore i want to try a design and elaborate how to go from there.

GNOME Builder ❤️ Rust Analyzer Part 1

In the last month i actively worked on something i would like to present in this blog post.

It all started with this reddit conversation:

matklad-reddit.png

This got me curious. I thought the LSP specification should be similar in most editors (without knowing a thing) and therefore i investigated my favourite editor: GNOME Builder. In fact i saw immediatly that there are still rough edges regarding the LSP implementation. And still no Rust Analyzer plugin available. This brought me to some lines of code by copying the RLS implementation.

Unsatisfied with the solution i made a complete rewrite as i was not confident enough for python (just occasionally write some lines). I started from scratch implementing a good Rust Analyzer plugin and sharpen the edges of the LSP implementation along the way.

Features Rust Analyzer in GNOME Builder

Speaking of features the first thing you will see if you open a vanilla GNOME Builder rust file in the editor is probably this:

Download offer directly in the IDE

ra_start.png

GNOME Builder will download the binary for you if not installed already. Note: Right now there is no version check implemented to re-download in case there is an update available. It’s on my todo list.

Progress support

Next Rust Analyzer gets started and downloads packages and compiles them in the background. We get a nice progress indicator for these information. This was my first enhancement of the LSP implementation. Implementing the progress/create request. Other LSP server get this now for free which is really nice.

ra_progress.png

Diagnostic for current file

If you have some problems in your opened rust source file you will immediatly see the triangle on the top indicating some errors.

ra_diagnostic.png

These diagnostic information are generated from cargo check called via Rust Analyzer. You can configure RA to use another diagnostic provider (at the moment i only know cargo clippy but its not restricted to that). Therefore i created the necessary plumbing to set this in GNOME Builder.

ra_settings.png

Autocompletion

Of course the plugin supports autocompletion via LSP. Watch it in action:

In my next post i want to show the remainding features like goto definition, show references, rename etc.