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

improve rspc integration #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ description = "Parse jetbrains .http/.rest http client formatted files into a mo
[features]
default = ["serde"]
serde = ["dep:serde", "dep:serde_json"]
rspc = ["dep:rspc"]
specta = ["dep:specta"]

[dependencies]
http = "0.2.9"
regex = "1.7.3"
serde_json = {version = "1.0.96", optional = true}
serde = {version = "1.0.160", features = ["derive"], optional = true}
rspc = { version = "0.1.3", optional = true}
serde_json = { version = "1.0.96", optional = true }
serde = { version = "1.0.160", features = ["derive"], optional = true }
specta = { version = "1.0.5", optional = true }
url = "2.4.0"
thiserror = "1.0.43"

Expand Down
7 changes: 3 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(feature = "rspc")]
use rspc::Type;
#[cfg(feature = "specta")]
use specta::Type;

use std::path::PathBuf;

Expand All @@ -9,10 +9,9 @@ use thiserror::Error;
use crate::model::PartialRequest;

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
#[derive(Error, Debug, PartialEq, Eq, Clone)]
pub enum ParseError {

#[error("Could not read the file: '{0}'.")]
CouldNotReadRequestFile(PathBuf),

Expand Down
38 changes: 19 additions & 19 deletions src/model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(feature = "rspc")]
use rspc::Type;
#[cfg(feature = "specta")]
use specta::Type;

use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -152,7 +152,7 @@ impl<T: std::cmp::PartialEq> PartialEq for WithDefault<T> {
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub enum HttpMethod {
#[default]
GET,
Expand Down Expand Up @@ -204,7 +204,7 @@ impl HttpMethod {

#[derive(PartialEq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub enum RequestTarget {
RelativeOrigin { uri: String },
Absolute { uri: String },
Expand All @@ -215,7 +215,7 @@ pub enum RequestTarget {

#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub enum SettingsEntry {
NoRedirect,
NoLog,
Expand All @@ -225,7 +225,7 @@ pub enum SettingsEntry {

#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub struct RequestSettings {
pub no_redirect: Option<bool>,
pub no_log: Option<bool>,
Expand Down Expand Up @@ -272,7 +272,7 @@ impl RequestSettings {

#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub struct DispositionField {
pub name: String,
pub filename: Option<String>,
Expand Down Expand Up @@ -305,7 +305,7 @@ impl DispositionField {

#[derive(PartialEq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub struct Multipart {
pub data: DataSource<String>,
pub disposition: DispositionField,
Expand All @@ -314,7 +314,7 @@ pub struct Multipart {

#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub enum DataSource<T> {
Raw(T),
FromFilepath(String),
Expand All @@ -331,7 +331,7 @@ impl ToString for DataSource<String> {

#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub struct UrlEncodedParam {
pub key: String,
pub value: String,
Expand All @@ -352,7 +352,7 @@ impl UrlEncodedParam {

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub enum RequestBody {
None,

Expand Down Expand Up @@ -489,7 +489,7 @@ impl RequestTarget {

#[derive(PartialEq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub struct Header {
pub key: String,
pub value: String,
Expand All @@ -514,7 +514,7 @@ impl ToString for Header {

#[derive(PartialEq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub enum HttpRestFileExtension {
Http,
Rest,
Expand Down Expand Up @@ -561,7 +561,7 @@ pub struct HttpRestFile {
}

#[derive(PartialEq, Debug, Clone, Eq)]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum PreRequestScript {
FromFilepath(String),
Expand All @@ -581,15 +581,15 @@ impl ToString for PreRequestScript {

#[derive(PartialEq, Debug, Clone, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub enum ResponseHandler {
FromFilepath(String),
Script(String),
}

#[derive(PartialEq, Debug, Clone, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
///https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html#redirect-output-to-a-custom-file-or-directory
pub enum SaveResponse {
// save the response into a new file if there exists already an existing save (use incremental
Expand Down Expand Up @@ -631,7 +631,7 @@ impl Default for Request {

#[derive(PartialEq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub enum CommentKind {
// //
DoubleSlash,
Expand Down Expand Up @@ -665,7 +665,7 @@ impl std::str::FromStr for CommentKind {

#[derive(PartialEq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub struct Comment {
pub value: String,
pub kind: CommentKind,
Expand All @@ -683,7 +683,7 @@ impl ToString for Comment {

#[derive(PartialEq, Debug, Clone, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "rspc", derive(Type))]
#[cfg_attr(feature = "specta", derive(Type))]
pub struct HttpVersion {
pub major: u32,
pub minor: u32,
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Parser {}
type ParseResult<T> = Result<(T, Vec<ParseErrorDetails>), ParseErrorDetails>;

impl Parser {
pub const REST_FILE_EXTENSIONS: [&str; 2] = ["http", "rest"];
pub const REST_FILE_EXTENSIONS: [&'static str; 2] = ["http", "rest"];
Copy link
Author

Choose a reason for hiding this comment

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

As a heads up this changed is inspired by the compiler output.

➜ cargo check --all --all-features
warning: `&` without an explicit lifetime name cannot be used here
  --> src/parser.rs:26:38
   |
26 |     pub const REST_FILE_EXTENSIONS: [&str; 2] = ["http", "rest"];
   |                                      ^
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>
   = note: `#[warn(elided_lifetimes_in_associated_constant)]` on by default
help: use the `'static` lifetime
   |
26 |     pub const REST_FILE_EXTENSIONS: [&'static str; 2] = ["http", "rest"];
   |


#[allow(dead_code)]
pub fn has_valid_extension<T: AsRef<std::path::Path>>(path: &T) -> bool {
Expand Down