
Try Out Rust IDE Support in Visual Studio Code - Rusky
https://users.rust-lang.org/t/try-out-rust-ide-support-in-visual-studio-code/12407
======
modeless
I have been using this for a few weeks, as a newcomer to Rust. Although it has
some issues, I would not try to develop Rust code without it. It is incredibly
useful and works well enough for day-to-day use.

Some of the issues I've found:

* Code completion sometimes simply fails to work. For example, inside future handlers (probably because this involves a lot of type inference).

* When errors are detected only the first line of the compiler error message is accessible in the UI, often omitting critical information and making it impossible to diagnose the problem.

* It is often necessary to manually restart RLS, for example when your cargo.toml changes. It can take a very long time to restart if things need to be recompiled and there isn't much in the way of progress indication.

* This is more of a missing feature, but type inference is a huge part of Rust, and it's often difficult to know what type the type inference engine has chosen for parts of your code. There's no way to find out using RLS in VSCode that I've seen, or go to the definition of inferred types, etc.

Other issues I've seen as a newcomer to Rust:

* It's very easy to get multiple versions of the same dependency in your project by accident (when your dependencies have dependencies), and there is no compiler warning when you mix up traits coming from different versions of a crate. You just get impossible-seeming errors.

* Compiler speed is a big problem.

* The derive syntax is super clunky for such an essential part of the language. I think Rust guides should emphasize derive more, as it's unclear at first how essential it really is. Almost all of my types derive multiple traits.

* In general, Rust is _hard_. It requires a lot more thinking than e.g. Python or even C. As a result, my forward progress is much slower. The problems I have while coding in Rust don't even exist in other languages. I'm sure this will improve over time but I'm not sure it will ever get to the point where I feel as productive as I do in other languages.

~~~
piaste
> This is more of a missing feature, but type inference is a huge part of
> Rust, and it's often difficult to know what type the type inference engine
> has chosen for parts of your code. There's no way to find out using RLS in
> VSCode that I've seen, or go to the definition of inferred types, etc.

VS Code has a 'code lens' feature that allows extensions to display
annotations above each lines of code - you can see it in action if you install
e.g. the Git Blame extension.

Some language plugins use that feature to display inferred types; the Rust
plugin could do the same.

~~~
farnsworth
With TS/JS, it will show this when you hover the cursor over the variable (or
invoke it with a keyboard shortcut)

------
sushisource
Rust is not only a fantastic language, but the level of community involvement
from the devs is just completely unlike any other language I've seen in a very
long time. That really makes me excited that it will be adopted in the
industry over time and ideally replace some of the nightmare-level C++ code
out there.

~~~
penpapersw
I'm not that optimistic. In my experience, nightmare-level code will be
written by the person who wrote it no matter what language they use. Rust
doesn't look all that cleaner than C++, just that it has a few more safety
guarantees. I'm sure terrible code will be written in it. And I'm sure clean
code will be written in it that people without context will call terrible
code.

~~~
SamReidHughes
The way I'd put it is, I'd be much more confident in the ability of an open
source project to survive receiving contributions from the general public if
it were written in Rust rather than C++.

~~~
moosingin3space
Yes! This has been my view on Rust for a while -- it's a relatively
inexpensive way to boost productivity and general security of projects. This
is especially true when the alternative is formal verification, which is less
ergonomic than Rust and effectively would require a rewrite of C code anyway.

------
KenoFischer
I haven't had the chance to try the Rust language mode, but I've been using VS
Code for all my julia development lately, and I'm pretty impressed. It's quite
a nice editor. I avoided using it for a very long time because I thought it'd
match Atom's slowness due to their shared Electron heritage. But for some
reason VS Code feels a lot snappier. Not quite Sublime levels, but perfectly
usable.

~~~
look_lookatme
[Hijacking to talk about VS Code in general]

Moved to VS Code last week. Coming from JetBrains products, the performance is
wonderful. On the other hand the quality of language plugins varies quite a
bit, though I've gotten the debuggers and jump to definition to work in PHP
and Python. Oddly go to definition can be janky in Javascript [1].

There's also a very nice plugin called vscode-journal [2] that works great for
quick logging tasks and notes.

Compared to the JetBrains products I am not a fan of the Git interface, but I
think Atom shining in this respect could motivate VS Code to provide a more
coherent SCM interface.

I am happy to be back to one-editor-to-rule-them-all. For years I used Emacs,
but after using the JetBrains language specific IDEs with quality debuggers
built in, I gravitated to them. VS Code seems to strike a fine middle ground.

[1]
[https://github.com/Microsoft/vscode/issues/19942](https://github.com/Microsoft/vscode/issues/19942)
[2] [https://github.com/pajoma/vscode-
journal](https://github.com/pajoma/vscode-journal)

------
int_19h
It looks like code completion is _extremely_ basic. I tried this:

    
    
        struct Point { x: i32, y: i32 }
    
        fn main() {
            println!("Hello, world!");
    
            let pt = Point { x: 1, y: 2 };
            println!("{} {}", pt.x, pt.y);
    
            let v = vec![ pt ];
            let vpt = &v[0];
            println!("{} {}", vpt.x, vpt.y);
        }
    

And I can't get any dot-completions on vpt (but I can on pt). Which is also
kinda weird, because if I hover over vpt, it does know that it is a &Point...

Even more weird is that if I add a type declaration to "let vpt" (specifying
the same type that would be inferred), then completion works.

That sounds like a really basic scenario... I mean, type inference for locals
is pervasive in Rust.

~~~
saghm
> I can't get any dot-completions on vpt > Even more weird is that if I add a
> type declaration to "let vpt" (specifying the same type that would be
> inferred), then completion works

I'm fairly certain the reason for this is that RLS (and every other Rust
editor/tool I've tried) isn't able to handle completions for things coming
from macros (transitively or otherwise). Although the prevalence of the `vec!`
macro might make it seem like the completion is "extremely basic", variables
coming from macros are pretty much the _only_ case I've found that RLS can't
completely properly for. If you manually write the code that the macro would
produce (i.e. `{ let mut temp = Vec::new(); temp.push(pt); temp }`, I think it
should work fine.

~~~
tomjakubowski
It might also help to manually annotate the type of the binding being assigned
to.

    
    
                let v: Vec<i32> = vec![ pt ];
                let vpt = &v[0];

~~~
int_19h
Nope, doesn't help (corrected to Vec<Point>). The only thing that works is
annotating the vpt binding itself.

In any case, if you have to annotate all local bindings for completion to
work, that's not idiomatic Rust anymore.

Another interesting thing that I've noticed, is that it does know what vpt.x
and vpt.y are - when hovering over them, it correctly says that they're i32.
So the type inference works as it should. It's specifically completion that is
broken here for some unclear reason.

~~~
saghm
I wonder if this is an issue with the VSCode extension rather than the RLS
then; all RLS can do is provide information to the extension, so maybe the
extension just isn't using the information.

------
ericfrederich
Slashdot was running this story:

[http://cc.bingj.com/cache.aspx?d=1462716999241&mkt=de-
DE&set...](http://cc.bingj.com/cache.aspx?d=1462716999241&mkt=de-
DE&setlang=en-US&w=xEsMxqoa0KJSwMsTh3p_8w2qryykfDvB)

~~~
bennofs
That does sound like a bad UI though. Perhaps vscode could stage the files
before, so that they end up in Git's objects at least? Or somehow store them
in the reflog

~~~
Mad_Mac
It's pretty bad UI design, but pressing the discard button does open a
confirmation box that says "Are you sure you want to discard ALL changes? This
is IRREVERSIBLE!"

With that kind of a message, it's amazing how he didn't think twice about
discarding them. Especially when he didn't have a proper source control
before.

~~~
josteink
3 months of code work and no version control...

You have to wonder if he actually learnt a valuable lesson or just ran away
blaming Microsoft...

~~~
Vinnl
I'm not hopeful:

> I don't need to explain why I don't have a private repo with my stuff. It is
> the software's concern NOT to destroy the integrity of a computer like a
> damn virus. You come here, see my despair and berate me for something that
> was not my fault, and has happened to a lot of other people? Fuck you.

------
CSDude
I tried it, it works really nice. If you are looking for an alternative, the
Intellij IDEA works very well when you install Rust plugin.

~~~
saghm
I've recently switched to using Intellij for my Rust coding, and it's been
phenomenal. I'm not usually much of an IDE person, but the experience has sold
me enough on Jetbrains IDEs that I picked Gogland for my editor for the Go
code I'm starting to do at work now, and I've been very pleased with it.

------
alkonaut
The vscode rust support is progressing nicely and if vscode is already your
go-to editor it's the obvious choice.

However if you just want to dip your toes and get going with rust with minimal
fuss, I find IntelliJ community+Rust to be the best combo. Vscode+Rust is not
as polished yet.

------
RussianCow
Does this support macro expansion of any kind? I'm currently using the plugin
for IntelliJ IDEA, and it works really well aside from completely lacking
support for macros, which makes its type annotations and similar features
nearly useless for the project I'm working on.

~~~
saghm
At least the last time I tried it, RLS wasn't able to handle inference for
values coming from macros (e.g. completing methods on a variable initialized
with `vec![...]`. None of the Rust tooling/editors I've tried thus far have
been able to handle that, so I'm hoping that either RLS or Intellij's Rust
plugin add it soon.

~~~
muizelaar
I'm not sure when you last tried, but IntelliJ Rust handles completing methods
on a variable initialized with vec![] for me just fine.

------
rl3
Anyone here writing Rust on Windows and using WSL (Windows Subsystem for
Linux) in your workflow?

I've found using WSL's "bash -c" from my Rust project's working directory in
Windows to be a rather elegant way to compile and run code for a Linux target.

Theoretically it should be possible to remote debug Linux binaries in WSL from
an editor in Windows, but I haven't had time to explore this yet. Both GDB and
LLDB have remote debugging functionality.

~~~
TheCoreh
It is possible from Visual Studio:
[https://www.hanselman.com/blog/WritingAndDebuggingLinuxCAppl...](https://www.hanselman.com/blog/WritingAndDebuggingLinuxCApplicationsFromVisualStudioUsingTheWindowsSubsystemForLinux.aspx)

------
demarq
Autofix doesn't seem to trigger for me, would someone confirm it's not just
me?

try this in your editor

    
    
        let x = 4;
        if x = 5 {}
    

it should figure out you wanted x == 5.

~~~
nrc
This should work (it's my goto test case). You have to put the cursor in the
erroring code to see the possible fix icon in the margin. If you don't see it
please file an issue with the project you're trying this in and I'll
investigate.

~~~
demarq
my bad, in a new project it works just fine. I'll keep investigating.

------
tomc1985
I would love Rust support in Visual Studio proper...

~~~
steveklabnik
There is syntax highlighting, but that's it so far.

------
Dowwie
Is anyone working on support in Atom?

~~~
saghm
From looking at the README in Atom's languageclient (the editor side of the
language server protocol), it doesn't look like there's a dedicated Rust
plugin yet[1], although I'd like to think that there would be some way to use
it without needing a dedicated plugin given that it's the whole point of the
language server protocol.

[1]: [https://github.com/atom/atom-languageclient#available-
packag...](https://github.com/atom/atom-languageclient#available-packages)

