# Sublime Text 3 - Rust

Friday, April 3, 2020

Hello there!

Sublime Text 4 really close to release. Currently, I’m already using it as the main text editor.
You can check their changelog here click.

Download ST4 on top of ST3 you can here (It’s version 4070):
windows
linux deb
linux-sources
mac-os
I not really fan of vscode, which is written in js and launch time, traverse, animations. All is very slow (subjectively).
ST3 always was much faster and honestly, more minimal, what is also important for me (you even haven’t package manager when installing it).
After, when I installed the 4070 version it just skyrockets faster yay!.

Okay okay, let’s go-to Rust awesome integration.

rustup install stable-x86_64-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu
rustup install nightly
rustup default nightly


Okay, here we installed gnu support for windows (msvc just much more aggressive and it will cut a lot of variables even in debug mode), added nightly toolchain, made it default and installed src code for it.

Now we need one more step - rust-analyzer

git clone https://github.com/rust-analyzer/rust-analyzer.git && cd rust-analyzer


Now the environment is ready. Let’s go to sublime text.

Install packages:

1. LSP - auto suggestions, go to definition (uses rust analyzer behind)
2. Debugger - full debugging experiece (via lldb)
3. RustFmt - quick format or format on save
4. Rust Enhanced - syntax highlighting, test, bench and build support

Okay, with LSP everything is simple: ctrl + shift + p -> Enable Language server globally -> rust-analyzer. It should write in the bottom left (where is the status bar) that rust analyzer initialized and wait for ~40 sec.
After you can press Ctrl + Shift + M and see all warnings, errors (even from clippy, which is configurable) and jump at them.
With Debugger, you need to create .sublime-project (better save this file in the root of your directory because it has variables for relative path handling). After, you can tap on Debugger and press Open. Install Adapters -> vscode-lldb (exactly the same plugin, which is using in vscode). When it finishes the install, you have full debugger support. But I wanted more. I want to enter std library sources. For some reason it’s not handled automatically (check this). First, start the debugger and try to step inside std function or macros (like println!()). You will receive assembly and line kinda this /rustc/f509b26a7730d721ef87423a72b3fdf8724b4afa. This is path to your rust source code, but, you know, it’s a bit wrong. You need to find real source code path, it will look kinda this C:/Users/krupi/.rustup/toolchains/nightly-x86_64-pc-windows-gnu/lib/rustlib/src/rust. Just remap weird hashed path to correct one in your .sublime-project and that it.
Full sublime project source:

{
"folders":
[
{
"path": "C:\\Coding\\perftest"
}
],
"settings":
{
"debug.configurations":
[
{
"name": "Debug",
"type": "lldb",
"request": "launch",
"program": "\${workspaceFolder}/target/debug/perftest",
"sourceMap": {"/rustc/f509b26a7730d721ef87423a72b3fdf8724b4afa" : "C:/Users/krupi/.rustup/toolchains/nightly-x86_64-pc-windows-gnu/lib/rustlib/src/rust"}
},
]
}
}


Add this file to .gitignore and you can separate debug configurations per pc or add more sourceMaps into your json array. Now you can jump left and right to your variables, system functions, macroses, build from ST3, test, run benchmarks, format code, debug and basically everything that you need in development.
Just check showcase below:

Hope it helps someone, see you next time. As always, if you have found any mistakes or have some remarks, waiting for you in the comments :)

P.S. Don’t forget to remap keys in key preferences to adopt if for yourself:

    // Go To Definition
{"keys": ["ctrl+;"], "command": "lsp_symbol_definition", "context": [{"key": "setting.lsp_active"}]},
// Symbol Hover
{"keys": ["ctrl+h"], "command": "lsp_hover", "context": [{"key": "setting.lsp_active"}]},

rustsublimetips

Deploying Rust app on android.