rust-lang / rust-lang/rust-analyzer

Scratch files

Open
#8,803 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

E-hard fun S-actionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I like to quickly try things out in scratch files to see if they type check, or to inspect the behavior of some code. My current workflow for is something like cargo new /tmp/asdf && cd /tmp/asdf && code src/main.rs, but that is pretty annoying to do often, especially if I want to link against the crate I am working on, because I then also have to edit the Cargo.toml.

For this use-case, Intellij has the concept of scratch files, which exist outside the project, but behave as if they are in its namespace. It would be great to have something similar using rust-analyzer.
In intellij these scratch files live on-disk in intellij's config directory. I usually use them only once anyway, so for ra they could just be in-memory, or live in the user's tmp dir and link against the crates in the current project (rustc accepts code through stdin, so in-memory might be feasible).

To achieve this, the standard LSP can be used, but using a textDocument uri of scratch:// or something similar. The vscode extension can gain a command New scratch file

WDYT?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing rust-analyzer's LSP handling and the VSCode extension entry points, then compare the proposed scratch:// URI and scratch-file storage options. Done should be a settled implementation plan for scratch files, including how they link against the current project and how the VSCode command would create them.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, vscode
Domain
developer-experience, devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.