-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show default per-kind icons for all entries in Component Browser. (#3587
) Show default icons for all entries in the Component Browser. The icons are assigned to each entry depending on its kind. https://www.pivotaltracker.com/story/show/182584326 #### Visuals See below for a video showing entries of 5 different kinds in the Component Browser, each having a different icon. When watching the video, please note that the following are preexisting, known issues, not introduced by this PR: - Selection is misaligned when hovering the mouse over the "new" component in the "Mcdbg Group 1" group - reported as issue 2 [in comments to PR 3530](#3530 (review)). - [Names of Modules and Atoms displayed in Component Browser start with a small letter.](https://www.pivotaltracker.com/story/show/182745386) https://user-images.githubusercontent.com/273837/179016109-c3ebab5a-0205-4b44-85b8-df3129edd75d.mov # Important Notes - A new derive macro `ForEachVariant` is defined and added to the `enso-prelude` crate.
- Loading branch information
Showing
5 changed files
with
116 additions
and
3 deletions.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//! This module contains the [`derive`] function (implementing the [`crate::ForEachVariant`] derive | ||
//! macro) as well as its helper functions. | ||
use inflector::cases::snakecase::to_snake_case; | ||
use proc_macro2::TokenStream; | ||
use quote::quote; | ||
use syn::punctuated::Punctuated; | ||
use syn::Token; | ||
|
||
|
||
|
||
// ====================== | ||
// === ForEachVariant === | ||
// ====================== | ||
|
||
/// Implementation of the `ForEachVariant` derive macro. For details, see the documentation of the | ||
/// [`crate::derive_for_each_variant`] function. | ||
pub fn derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream { | ||
let decl = syn::parse_macro_input!(input as syn::DeriveInput); | ||
let ret = match decl.data { | ||
syn::Data::Enum(ref e) => derive_for_enum(&decl, e), | ||
_ => panic!("The `ForEachVariant` derive macro only works on enums."), | ||
}; | ||
proc_macro::TokenStream::from(ret) | ||
} | ||
|
||
fn derive_for_enum(decl: &syn::DeriveInput, data: &syn::DataEnum) -> TokenStream { | ||
let enum_name = &decl.ident; | ||
let enum_snake_name = to_snake_case(&enum_name.to_string()); | ||
let macro_name = quote::format_ident!("for_each_{}_variant", enum_snake_name); | ||
let variant_names: Punctuated<_, Token![,]> = data.variants.iter().map(|v| &v.ident).collect(); | ||
quote! { | ||
/// Calls `f!` passing to it a comma-separated list of names of variants of [`#enum_name`] | ||
/// enclosed in square brackets. The extra `args` are passed to `f!` verbatim after the | ||
/// closing square bracket. For more details, see the documentation of the | ||
/// [`ForEachVariant`] derive macro. | ||
#[macro_export] | ||
macro_rules! #macro_name { | ||
( $f:ident($( $args:tt )*) ) => { $f!([ #variant_names ] $($args)*) } | ||
} | ||
|
||
pub(crate) use #macro_name; | ||
} | ||
} |
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