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

feat: preamble #212

Merged
merged 4 commits into from
Feb 28, 2025
Merged

feat: preamble #212

merged 4 commits into from
Feb 28, 2025

Conversation

jmbuhr
Copy link
Owner

@jmbuhr jmbuhr commented Feb 17, 2025

Refs

#99
#210
#208

@jmbuhr
Copy link
Owner Author

jmbuhr commented Feb 17, 2025

@0atman Maybe you can experiment with this with your rust expertise. This PR adds the #!/usr/bin/env -S cargo +nightly -Zscript line at the start of the the rust otter buffer, so a markdown file with

```rust
---cargo
[dependencies]
clap = { version = "4.2", features = ["derive"] }
---
```

```rust
use clap::Parser;

#[derive(Parser, Debug)]
#[clap(version)]
struct Args {
  #[clap(short, long, help = "Path to config")]
  config: Option<std::path::PathBuf>,
}

fn main() {
  let args = Args::parse();
  println!("{:?}", args);
}
```

Results in a rust buffer that looks exactly like the https://doc.rust-lang.org/cargo/reference/unstable.html#script example. See :b2.

However, I'm unable to get rust-analyzer to initialize without a complete cargo project around this.

@0atman
Copy link

0atman commented Feb 17, 2025

oh amazing, yeah, let me test this now

@0atman
Copy link

0atman commented Feb 17, 2025

I've run this branch locally, and can confirm the same behaviour here.

Reading the Rustaceanvim readme:

rust-analyzer has limited support for standalone files. Many diagnostics come from Cargo. If you're not in a Cargo project, you won't see any Cargo diagnostics.

I think cargo script is a dead end for otter, which is inherently LSP-based. I'm sorry I didn't realise this when I made the suggestion, and thank you for making this feature.

@0atman
Copy link

0atman commented Feb 17, 2025

Alternative implementation idea: Could otter accept a specially-formatted rust code block (same as cargo script's ---cargo, and write out an ephemeral Cargo.toml at the same time as the otter.rs files?

I imagine this won't be the only language that would be useful to have such a process in place for a project config file!

@0atman 0atman mentioned this pull request Feb 17, 2025
@jmbuhr jmbuhr merged commit b2e2d6a into main Feb 28, 2025
3 checks passed
@jmbuhr jmbuhr deleted the feat/preamble branch February 28, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants