-
Notifications
You must be signed in to change notification settings - Fork 115
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
Bug: Type Parameters are not imported #241
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
622afa8
reproduce in E2E test, run example during CI
NyxCode 44998d4
implement proposed fix
NyxCode 9a385d2
adjust impl_wrapper!, fix clippy warning
NyxCode 8c9c2e4
fix CI for example
NyxCode ee733be
Implement TS::Generics
escritorio-gustavo 90ca381
Add TS::Generics to chrono types
escritorio-gustavo 1ae0341
Add T to impl_wrapper! generics method
escritorio-gustavo 2b7d25b
Proposed fix for Vec, HashMap, Option and Result
escritorio-gustavo 9043961
add test for #168 and #232, expand e2e dependencies test
NyxCode c24107c
fix tests
NyxCode f9bba02
rename TS::Generics to TS::WithoutGenerics
NyxCode 438b2ff
cargo +nightly fmt
escritorio-gustavo 8659267
Merge branch 'type-params-are-not-imported' of github.com:Aleph-Alpha…
escritorio-gustavo 02f47b8
cargo +nightly fmt
escritorio-gustavo 2506ff5
Improve atribute parse compiler error
escritorio-gustavo 4aab519
Update tests to use ts(export) except raw_idents
escritorio-gustavo ffa5113
Separatly update raw_idents as it would panic
escritorio-gustavo 67fe641
Fix usage of serde(skip)
escritorio-gustavo 75d2b7d
Fix usage of serde(skip) again...
escritorio-gustavo a0cee6c
Fix imports test to work with all features
escritorio-gustavo 3eda16f
Fix issue-70 test to generate valid TS
escritorio-gustavo fe5b375
cargo fmt
escritorio-gustavo 7bc2c87
Update CI to run tsc
escritorio-gustavo 1da87b5
Fix remaining dependency issues
escritorio-gustavo f4da385
enable globstar in CI
NyxCode e179efb
Update changelog
escritorio-gustavo 0367a6b
Merge branch 'type-params-are-not-imported' of github.com:Aleph-Alpha…
escritorio-gustavo f4572ea
self_referential.rs: Do not rename types
NyxCode cf01efc
Merge remote-tracking branch 'origin/type-params-are-not-imported' in…
NyxCode 8ea5cf0
Revert "self_referential.rs: Do not rename types"
NyxCode 6e09571
self_referential.rs: Rename types to unique names
NyxCode 22a8edc
Remove ts(export) from self referential internally tagged enum
escritorio-gustavo ed397da
Add tests for all impl_shadow! types
NyxCode 10c09ad
Implement `TS::generics()` within impl_shadow
NyxCode 2136c75
fix imports for TypeList in macros
NyxCode a177f89
CI: use tsc --strict in all jobs
NyxCode 535eeff
Test hashmap.rs: Change CustomKey to yield a valid TS Record
NyxCode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ pub struct LibraryType1 { | |
pub struct LibraryType2<T> { | ||
pub t: T | ||
} | ||
|
||
#[derive(TS)] | ||
pub struct LibraryType3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
use std::convert::TryFrom; | ||
|
||
use proc_macro2::{Ident, TokenStream}; | ||
use syn::{Attribute, Error, Expr, ExprLit, GenericParam, Generics, Lit, Meta, Result, spanned::Spanned}; | ||
use quote::quote; | ||
use syn::{ | ||
spanned::Spanned, Attribute, Error, Expr, ExprLit, GenericParam, Generics, Lit, Meta, Result, | ||
}; | ||
|
||
use crate::deps::Dependencies; | ||
|
||
macro_rules! syn_err { | ||
|
@@ -26,11 +29,16 @@ macro_rules! impl_parse { | |
fn parse($input: syn::parse::ParseStream) -> syn::Result<Self> { | ||
let mut $out = $i::default(); | ||
loop { | ||
let span = $input.span(); | ||
let key: Ident = $input.call(syn::ext::IdentExt::parse_any)?; | ||
match &*key.to_string() { | ||
$($k => $e,)* | ||
#[allow(unreachable_patterns)] | ||
_ => syn_err!($input.span(); "unexpected attribute") | ||
x => syn_err!( | ||
span; | ||
"Unknown attribute \"{x}\". Allowed attributes are: {}", | ||
[$(stringify!($k),)*].join(", ") | ||
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tell the user what attributes are accepted, since LSP autocomplete can't do that |
||
) | ||
} | ||
|
||
match $input.is_empty() { | ||
|
@@ -65,7 +73,7 @@ pub fn raw_name_to_ts_field(value: String) -> String { | |
let valid_chars = value | ||
.chars() | ||
.all(|c| c.is_alphanumeric() || c == '_' || c == '$'); | ||
|
||
let does_not_start_with_digit = value | ||
.chars() | ||
.next() | ||
|
@@ -140,7 +148,7 @@ pub fn parse_docs(attrs: &[Attribute]) -> Result<String> { | |
.map(|attr| { | ||
attr.map(|line| match line.trim() { | ||
"" => " *".to_owned(), | ||
_ => format!(" *{}", line.trim_end()) | ||
_ => format!(" *{}", line.trim_end()), | ||
}) | ||
}) | ||
.collect::<Result<Vec<_>>>()?; | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting the span before the key improves the location of the error:
Assignment attributes
Before, points at the equals sign:
After, points at the attribute's name:
Flag attributes:
Before, points at the token after the attribute (close bracket or comma):
After, points at the attribute's name:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it, great work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Btw, this is the first good look I've had at exactly how
impl_parse!
works, and I gotta say, I'm definetly using that for every proc_macro I make in the future lol. Awesome job man!