Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added project-specific Zed IDE settings #127793

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ChaiTRex
Copy link
Contributor

This repository currently has project-specific VS Code IDE settings in .vscode and compiler/rustc_codegen_cranelift/.vscode. Now there are equivalent project-specific Zed IDE settings alongside those.

This fixes rust-analyzer not being able to properly handle this project.

Note that:

  1. The contents of src/tools/rust-analyzer/.vscode could not be translated to Zed, as they aren't basic IDE settings.

  2. One of the VS Code settings in .vscode has no corresponding setting in Zed, and so this has been noted like this:

      "_settings_only_in_vs_code_not_yet_in_zed": {
        "git.detectSubmodulesLimit": 20
      },

@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2024

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 16, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2024

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@tgross35
Copy link
Contributor

I don't think this repo has a top-level .vscode, but it seems like x can generate that for you https://rustc-dev-guide.rust-lang.org/building/suggested.html#configuring-rust-analyzer-for-rustc. Maybe we could do the same here?

@rust-log-analyzer

This comment has been minimized.

@nnethercote
Copy link
Contributor

This repository currently has project-specific VS Code IDE settings in .vscode and compiler/rustc_codegen_cranelift/.vscode.

.vscode doesn't exist but compiler/rustc_codegen_cranelift/.vscode does exist. That's strange. (cc @bjorn3)

I don't know much about IDEs, but @tgross35's suggestion about generating the Zed settings seems reasonable.

@bjorn3
Copy link
Member

bjorn3 commented Jul 16, 2024

As @tgross35 said, for this repo, ./x.py has a command to generate .vscode/settings.json as well as update it when the user hasn't changed it themself (by keeping hashes of all previous versions). For Zed we should probably do something similar. As for compiler/rustc_codegen_cranelift, that is maintained in a separate repo (https://github.com/rust-lang/rustc_codegen_cranelift) which is periodically synced with this repo. It doesn't have a command for generating .vscode/settings.json. Instead I checked in my personal workspace settings, which should work fine for most people.

@ChaiTRex
Copy link
Contributor Author

OK, I'll examine x.py and rust-lang/rustc_codegen_cranelift and try to get it working through those.

@ChaiTRex
Copy link
Contributor Author

@bjorn3 said:

As for compiler/rustc_codegen_cranelift, that is maintained in a separate repo (https://github.com/rust-lang/rustc_codegen_cranelift) which is periodically synced with this repo. It doesn't have a command for generating .vscode/settings.json. Instead I checked in my personal workspace settings, which should work fine for most people.

Made rustc_codegen_cranelift pull request at rust-lang/rustc_codegen_cranelift#1517.

@ChaiTRex
Copy link
Contributor Author

@rustbot
Copy link
Collaborator

rustbot commented Jul 17, 2024

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Jul 17, 2024
@rust-log-analyzer

This comment has been minimized.

@@ -0,0 +1,48 @@
{
// The following commented-out VS Code settings are not supported by Zed yet.
// "git.detectSubmodulesLimit": 20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option was introduced for vscode in #120138. There is a fair chance that zed won't suffer from the same issue once it has a git ui anyway (they may not even add a hard limit on the amount of auto detected git submodules at all). I don't think there is any value in keeping this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be nicer to still keep one file for RA settings, then just delete this key via bootstrap (serde_json is already a dependency). So if there are future updates that work for both, they only need to happen in one file.

Copy link
Contributor Author

@ChaiTRex ChaiTRex Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to do this properly, I think we'll need three files: one shared file for rust-analyzer settings and one file each for the non-rust-analyzer IDE-specific settings.

Even IDE settings that do the same thing are different between the two IDEs. For example, to turn on format-on-save, VS Code wants "editor.formatOnSave": true, while Zed wants "format_on_save": "on",.

There are also JSON structure requirements that differ between the IDEs. For example, VS Code wants the rust-analyzer settings to use the standard dotted notation at the root of the JSON tree, like:

{
    "rust-analyzer.rustc.source": "discover"
}

Zed wants the rust-analyzer settings to live under a path through the JSON tree of "lsp", then "rust-analyzer", then "initialization_options", then the setting with the original dots signifying an increase in tree depth:

{
  "lsp": {
    "rust-analyzer": {
      "initialization_options": {
        "rustc": {
          "source": "discover"
        }
      }
    }
  }
}

So this means that we need to do JSON parsing of our three files, transformation of the structure, and JSON generation of the resulting .vscode/settings.json and .zed/settings.json files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also just have one rust source file with everything in json!, and build it dynamically

use serde_json::{json, Value};

fn base_settings() -> Value {
    json! {{
         // common settings 
    }}
}

fn vscode_settings() -> Value {
    let vscode_specific = json! {{ anything new}} 

    let mut inner = base_settings();
    inner.as_object_mut().unwrap().extend(vscode_specific);

    json! {{
         "lsp": {
             "rust_analyzer": /* other nesting */ inner,
         }
    }}
}

fn zed_settings() -> Value {
    // ...
}

Which would also be kind of nice because it's easy to cover any config file schema or format. E.g. I would appreciate a Helix config at some point, but that uses toml (easy to convert from serde_json to toml, both are already dependencies of bootstrap).

But 🤷, that may be overkill.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjorn3 Removed comment in Zed settings.json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tgross35 It looks like they've added some settings for a few more IDEs in the meantime (Emacs, Helix, and Vim/VS Code), but they put all the settings into each one.


/// Create a `.zed/settings.json` file for rustc development, or just print it
/// If this method should be re-called, it returns `false`.
fn create_zed_settings_maybe(config: &Config) -> io::Result<bool> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this function be deduplicated with the vscode version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nnethercote
Copy link
Contributor

I will defer on the review to either @bjorn3 or @tgross35, who clearly know much more about this stuff than I do :)

@tgross35
Copy link
Contributor

Should probably just see what bootstrap prefers here

r? bootstrap

@rustbot rustbot assigned Kobzol and unassigned nnethercote Jul 19, 2024
@tgross35 tgross35 removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 19, 2024
@onur-ozkan
Copy link
Member

Can Zed work with the VsCode configuration file somehow (like neovim)?

FWIW #120611 would solve the whole problem of maintaining IDE specific files.

@onur-ozkan
Copy link
Member

FWIW #120611 would solve the whole problem of maintaining IDE specific files.

Seems like we will also need rust-lang/rust-analyzer#13529 for that.

@bors
Copy link
Contributor

bors commented Sep 8, 2024

☔ The latest upstream changes (presumably #130091) made this pull request unmergeable. Please resolve the merge conflicts.

@tgross35
Copy link
Contributor

Okay well we added emacs and helix sample config files, so maybe just adding the zed file is fine here too :) #130932

@Kobzol
Copy link
Contributor

Kobzol commented Nov 18, 2024

FYI, we now have a dedicated x setup editor command for configuring setup for various IDEs (#131075). So Zed could be added as another IDE to that command.

@jieyouxu jieyouxu removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 11, 2025
@Dylan-DPC
Copy link
Member

@ChaiTRex any updates on this pr? thanks

* Order IDEs alphabetically so that manually searching for an IDE
  is easier, both when running `./x setup` and when editing the
  source code behind `./x setup`
* Prepare for IDEs with spaces in their names
* Allow explicitly typing 'none' for the IDE
* Change capitalization of `Vscode` to the more standard `VsCode`
* Make minor efficiency improvements
* Add `'static` annotations where they apply
@ChaiTRex ChaiTRex force-pushed the zed_support branch 2 times, most recently from c1c7d6e to 3422218 Compare February 15, 2025 22:25
@rust-log-analyzer

This comment has been minimized.

@ChaiTRex
Copy link
Contributor Author

@Dylan-DPC Sorry for the delay. I've rebased this on the new multi-IDE system we now have and made a few minor improvements, like double-checking the latest hashes for all IDEs rather than just VS Code, which caught a missing Helix hash.

@Kobzol
Copy link
Contributor

Kobzol commented Feb 17, 2025

Thanks! Could you also please add a mention of Zed to the suggested workflow page in rustc-dev-guide (https://github.com/rust-lang/rust/blob/fd911ea65a50c838f4334ef353c80ec46358c9e6/src/doc/rustc-dev-guide/src/building/suggested.md#helix)? You can do it directly with a commit in this PR, as rustc-dev-guide is now a subtree of rust-lang/rust.

@rustbot
Copy link
Collaborator

rustbot commented Feb 18, 2025

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @jieyouxu, @Kobzol

@rustbot rustbot added the A-rustc-dev-guide Area: rustc-dev-guide label Feb 18, 2025
@ChaiTRex ChaiTRex force-pushed the zed_support branch 2 times, most recently from 8131d95 to cd278aa Compare February 18, 2025 04:54
@ChaiTRex
Copy link
Contributor Author

@Kobzol Done. Please let me know if it needs improvement.

@Kobzol
Copy link
Contributor

Kobzol commented Feb 18, 2025

Thanks!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 18, 2025

📌 Commit 410331c has been approved by Kobzol

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 18, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Feb 18, 2025
Added project-specific Zed IDE settings

This repository currently has project-specific VS Code IDE settings in `.vscode` and `compiler/rustc_codegen_cranelift/.vscode`. Now there are equivalent project-specific Zed IDE settings alongside those.

This fixes `rust-analyzer` not being able to properly handle this project.

Note that:

1. The contents of `src/tools/rust-analyzer/.vscode` could not be translated to Zed, as they aren't basic IDE settings.
2. One of the VS Code settings in `.vscode` has no corresponding setting in Zed, and so this has been noted like this:

    ```json
      "_settings_only_in_vs_code_not_yet_in_zed": {
        "git.detectSubmodulesLimit": 20
      },
    ```
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 18, 2025
…llaumeGomez

Rollup of 11 pull requests

Successful merges:

 - rust-lang#127793 (Added project-specific Zed IDE settings)
 - rust-lang#134995 (Stabilize const_slice_flatten)
 - rust-lang#135767 (Future incompatibility warning `unsupported_fn_ptr_calling_conventions`: Also warn in dependencies)
 - rust-lang#136599 (librustdoc: more usages of `Joined::joined`)
 - rust-lang#136750 (Make ub_check message clear that it's not an assert)
 - rust-lang#137000 (Deeply normalize item bounds in new solver)
 - rust-lang#137126 (fix docs for inherent str constructors)
 - rust-lang#137151 (Install more signal stack trace handlers)
 - rust-lang#137161 (Pattern Migration 2024: fix incorrect messages/suggestions when errors arise in macro expansions)
 - rust-lang#137167 (tests: Also gate `f16::erfc()` doctest with `reliable_f16_math` cfg)
 - rust-lang#137177 (Update `minifier-rs` version to `0.3.5`)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 18, 2025
Added project-specific Zed IDE settings

This repository currently has project-specific VS Code IDE settings in `.vscode` and `compiler/rustc_codegen_cranelift/.vscode`. Now there are equivalent project-specific Zed IDE settings alongside those.

This fixes `rust-analyzer` not being able to properly handle this project.

Note that:

1. The contents of `src/tools/rust-analyzer/.vscode` could not be translated to Zed, as they aren't basic IDE settings.
2. One of the VS Code settings in `.vscode` has no corresponding setting in Zed, and so this has been noted like this:

    ```json
      "_settings_only_in_vs_code_not_yet_in_zed": {
        "git.detectSubmodulesLimit": 20
      },
    ```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 18, 2025
Added project-specific Zed IDE settings

This repository currently has project-specific VS Code IDE settings in `.vscode` and `compiler/rustc_codegen_cranelift/.vscode`. Now there are equivalent project-specific Zed IDE settings alongside those.

This fixes `rust-analyzer` not being able to properly handle this project.

Note that:

1. The contents of `src/tools/rust-analyzer/.vscode` could not be translated to Zed, as they aren't basic IDE settings.
2. One of the VS Code settings in `.vscode` has no corresponding setting in Zed, and so this has been noted like this:

    ```json
      "_settings_only_in_vs_code_not_yet_in_zed": {
        "git.detectSubmodulesLimit": 20
      },
    ```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 18, 2025
Added project-specific Zed IDE settings

This repository currently has project-specific VS Code IDE settings in `.vscode` and `compiler/rustc_codegen_cranelift/.vscode`. Now there are equivalent project-specific Zed IDE settings alongside those.

This fixes `rust-analyzer` not being able to properly handle this project.

Note that:

1. The contents of `src/tools/rust-analyzer/.vscode` could not be translated to Zed, as they aren't basic IDE settings.
2. One of the VS Code settings in `.vscode` has no corresponding setting in Zed, and so this has been noted like this:

    ```json
      "_settings_only_in_vs_code_not_yet_in_zed": {
        "git.detectSubmodulesLimit": 20
      },
    ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustc-dev-guide Area: rustc-dev-guide S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.