about summary refs log tree commit diff
path: root/src/tools/rust-analyzer
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-07-07 09:00:19 +0200
committerLukas Wirth <lukastw97@gmail.com>2024-07-07 09:00:19 +0200
commit58ec8b2028c52d8c7cd7eecb865fe4a6dd67d85b (patch)
tree33d5aaec461cffd3e836b83182cae45ce130637f /src/tools/rust-analyzer
parent2d14f47eb7ba10c740da2ae73a010ba19a826e27 (diff)
downloadrust-58ec8b2028c52d8c7cd7eecb865fe4a6dd67d85b.tar.gz
rust-58ec8b2028c52d8c7cd7eecb865fe4a6dd67d85b.zip
Drop sourcegen
Diffstat (limited to 'src/tools/rust-analyzer')
-rw-r--r--src/tools/rust-analyzer/Cargo.lock8
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml1
-rw-r--r--src/tools/rust-analyzer/crates/sourcegen/Cargo.toml19
-rw-r--r--src/tools/rust-analyzer/crates/sourcegen/src/lib.rs201
4 files changed, 0 insertions, 229 deletions
diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock
index ca442542c8c..0c105eb996d 100644
--- a/src/tools/rust-analyzer/Cargo.lock
+++ b/src/tools/rust-analyzer/Cargo.lock
@@ -1670,7 +1670,6 @@ dependencies = [
  "semver",
  "serde",
  "serde_json",
- "sourcegen",
  "stdx",
  "syntax",
  "test-fixture",
@@ -1870,13 +1869,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b"
 
 [[package]]
-name = "sourcegen"
-version = "0.0.0"
-dependencies = [
- "xshell",
-]
-
-[[package]]
 name = "span"
 version = "0.0.0"
 dependencies = [
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml
index c207c42b6de..93fb55ede8e 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml
@@ -81,7 +81,6 @@ xshell.workspace = true
 
 test-utils.workspace = true
 test-fixture.workspace = true
-sourcegen.workspace = true
 mbe.workspace = true
 
 [features]
diff --git a/src/tools/rust-analyzer/crates/sourcegen/Cargo.toml b/src/tools/rust-analyzer/crates/sourcegen/Cargo.toml
deleted file mode 100644
index d5ea4c39aa1..00000000000
--- a/src/tools/rust-analyzer/crates/sourcegen/Cargo.toml
+++ /dev/null
@@ -1,19 +0,0 @@
-[package]
-name = "sourcegen"
-version = "0.0.0"
-description = "TBD"
-publish = false
-
-authors.workspace = true
-edition.workspace = true
-license.workspace = true
-rust-version.workspace = true
-
-[lib]
-doctest = false
-
-[dependencies]
-xshell.workspace = true
-
-[lints]
-workspace = true
\ No newline at end of file
diff --git a/src/tools/rust-analyzer/crates/sourcegen/src/lib.rs b/src/tools/rust-analyzer/crates/sourcegen/src/lib.rs
deleted file mode 100644
index 307c214c61d..00000000000
--- a/src/tools/rust-analyzer/crates/sourcegen/src/lib.rs
+++ /dev/null
@@ -1,201 +0,0 @@
-//! rust-analyzer relies heavily on source code generation.
-//!
-//! Things like feature documentation or assist tests are implemented by
-//! processing rust-analyzer's own source code and generating the appropriate
-//! output. See `sourcegen_` tests in various crates.
-//!
-//! This crate contains utilities to make this kind of source-gen easy.
-
-use std::{
-    fmt, fs, mem,
-    path::{Path, PathBuf},
-};
-
-use xshell::{cmd, Shell};
-
-pub fn list_rust_files(dir: &Path) -> Vec<PathBuf> {
-    let mut res = list_files(dir);
-    res.retain(|it| {
-        it.file_name().unwrap_or_default().to_str().unwrap_or_default().ends_with(".rs")
-    });
-    res
-}
-
-pub fn list_files(dir: &Path) -> Vec<PathBuf> {
-    let mut res = Vec::new();
-    let mut work = vec![dir.to_path_buf()];
-    while let Some(dir) = work.pop() {
-        for entry in dir.read_dir().unwrap() {
-            let entry = entry.unwrap();
-            let file_type = entry.file_type().unwrap();
-            let path = entry.path();
-            let is_hidden =
-                path.file_name().unwrap_or_default().to_str().unwrap_or_default().starts_with('.');
-            if !is_hidden {
-                if file_type.is_dir() {
-                    work.push(path);
-                } else if file_type.is_file() {
-                    res.push(path);
-                }
-            }
-        }
-    }
-    res
-}
-
-#[derive(Clone)]
-pub struct CommentBlock {
-    pub id: String,
-    pub line: usize,
-    pub contents: Vec<String>,
-    is_doc: bool,
-}
-
-impl CommentBlock {
-    pub fn extract(tag: &str, text: &str) -> Vec<CommentBlock> {
-        assert!(tag.starts_with(char::is_uppercase));
-
-        let tag = format!("{tag}:");
-        let mut blocks = CommentBlock::extract_untagged(text);
-        blocks.retain_mut(|block| {
-            let first = block.contents.remove(0);
-            let Some(id) = first.strip_prefix(&tag) else {
-                return false;
-            };
-
-            if block.is_doc {
-                panic!("Use plain (non-doc) comments with tags like {tag}:\n    {first}");
-            }
-
-            id.trim().clone_into(&mut block.id);
-            true
-        });
-        blocks
-    }
-
-    pub fn extract_untagged(text: &str) -> Vec<CommentBlock> {
-        let mut res = Vec::new();
-
-        let lines = text.lines().map(str::trim_start);
-
-        let dummy_block =
-            CommentBlock { id: String::new(), line: 0, contents: Vec::new(), is_doc: false };
-        let mut block = dummy_block.clone();
-        for (line_num, line) in lines.enumerate() {
-            match line.strip_prefix("//") {
-                Some(mut contents) => {
-                    if let Some('/' | '!') = contents.chars().next() {
-                        contents = &contents[1..];
-                        block.is_doc = true;
-                    }
-                    if let Some(' ') = contents.chars().next() {
-                        contents = &contents[1..];
-                    }
-                    block.contents.push(contents.to_owned());
-                }
-                None => {
-                    if !block.contents.is_empty() {
-                        let block = mem::replace(&mut block, dummy_block.clone());
-                        res.push(block);
-                    }
-                    block.line = line_num + 2;
-                }
-            }
-        }
-        if !block.contents.is_empty() {
-            res.push(block);
-        }
-        res
-    }
-}
-
-#[derive(Debug)]
-pub struct Location {
-    pub file: PathBuf,
-    pub line: usize,
-}
-
-impl fmt::Display for Location {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        let path = self.file.strip_prefix(project_root()).unwrap().display().to_string();
-        let path = path.replace('\\', "/");
-        let name = self.file.file_name().unwrap();
-        write!(
-            f,
-            "https://github.com/rust-lang/rust-analyzer/blob/master/{}#L{}[{}]",
-            path,
-            self.line,
-            name.to_str().unwrap()
-        )
-    }
-}
-
-fn ensure_rustfmt(sh: &Shell) {
-    let version = cmd!(sh, "rustup run stable rustfmt --version").read().unwrap_or_default();
-    if !version.contains("stable") {
-        panic!(
-            "Failed to run rustfmt from toolchain 'stable'. \
-                 Please run `rustup component add rustfmt --toolchain stable` to install it.",
-        );
-    }
-}
-
-pub fn reformat(text: String) -> String {
-    let sh = Shell::new().unwrap();
-    ensure_rustfmt(&sh);
-    let rustfmt_toml = project_root().join("rustfmt.toml");
-    let mut stdout = cmd!(
-        sh,
-        "rustup run stable rustfmt --config-path {rustfmt_toml} --config fn_single_line=true"
-    )
-    .stdin(text)
-    .read()
-    .unwrap();
-    if !stdout.ends_with('\n') {
-        stdout.push('\n');
-    }
-    stdout
-}
-
-pub fn add_preamble(generator: &'static str, mut text: String) -> String {
-    let preamble = format!("//! Generated by `{generator}`, do not edit by hand.\n\n");
-    text.insert_str(0, &preamble);
-    text
-}
-
-/// Checks that the `file` has the specified `contents`. If that is not the
-/// case, updates the file and then fails the test.
-#[allow(clippy::print_stderr)]
-pub fn ensure_file_contents(file: &Path, contents: &str) {
-    if let Ok(old_contents) = fs::read_to_string(file) {
-        if normalize_newlines(&old_contents) == normalize_newlines(contents) {
-            // File is already up to date.
-            return;
-        }
-    }
-
-    let display_path = file.strip_prefix(project_root()).unwrap_or(file);
-    eprintln!(
-        "\n\x1b[31;1merror\x1b[0m: {} was not up-to-date, updating\n",
-        display_path.display()
-    );
-    if std::env::var("CI").is_ok() {
-        eprintln!("    NOTE: run `cargo test` locally and commit the updated files\n");
-    }
-    if let Some(parent) = file.parent() {
-        let _ = fs::create_dir_all(parent);
-    }
-    fs::write(file, contents).unwrap();
-    panic!("some file was not up to date and has been updated, simply re-run the tests");
-}
-
-fn normalize_newlines(s: &str) -> String {
-    s.replace("\r\n", "\n")
-}
-
-pub fn project_root() -> PathBuf {
-    let dir = env!("CARGO_MANIFEST_DIR");
-    let res = PathBuf::from(dir).parent().unwrap().parent().unwrap().to_owned();
-    assert!(res.join("triagebot.toml").exists());
-    res
-}