ZenSharp icon indicating copy to clipboard operation
ZenSharp copied to clipboard

Any suggestion / feature request?

Open ulex opened this issue 10 years ago • 31 comments

Is anyone except me using ZenSharp in production environment? Do you have any suggestion? I'm will be very happy to any feedback.

ulex avatar Jan 15 '15 20:01 ulex

It will be nice to have a editor for all rules and also if you can add alias to these rules

adeel41 avatar Jan 16 '15 17:01 adeel41

how about adding DbSet short cut. I hate typing all that out.

public DbSet<T> Ts { get; set; }

aside: I'm doing a R# "magic show" talk next month, I'm going to be showcasing super cool stuff that people familiar with R# didn't know they could do. I plan to feature your plugin. Any thing that you think really shines above the rest, please let me know.

Eonasdan avatar Jul 23 '15 20:07 Eonasdan

@Eonasdan, DbSet is great example for ReSharper live templates, but not for ZenSharp.

Just create Live template as described here - https://www.jetbrains.com/resharper/help/Templates__Creating_and_Editing_Templates__Creating_a_Live_Template_from_Source_Code.html

ulex avatar Jul 26 '15 09:07 ulex

why do feel that way? ZenSharp already does property generation like that.

I tried

scope "InCSharpClass" {
  start    ::=  method | property | field | const | other

  other ::=
        //...
    | ""=dbset "public DBSet<" type " > " identifier "{get; set; }"

but I the template doesn't show a name and it doesn't generate code.

I'm trying to understand how to add custom items to your template.

Eonasdan avatar Jul 27 '15 13:07 Eonasdan

You're doing it right. paizbvn 1

but I the template doesn't show a name and it doesn't generate code.

What do you mean by that ?

ulex avatar Jul 27 '15 17:07 ulex

ah... I see now why you said that.

ZenSharp wouldn't be able to figure out that type is a Model class?

the generated code should be public DbSet<Person> Persons { get; set; }

Can I make ZenSharp do that or do I really just need a live template?

Eonasdan avatar Jul 27 '15 18:07 Eonasdan

Can I make ZenSharp do that or do I really just need a live template?

Looks like you really need just a live template. Create live template public DBSet<$T$> $T$s {get; set; } and disable reformat option.

ulex avatar Jul 27 '15 19:07 ulex

It will be nice to have a editor for all rules and also if you can add alias to these rules

@adeel41 , For implement it really cool and useful feature I need to rewrite ZenSharp from scratch. I'm using Nemerle PEG library for parse ZenSharp rules. It's really hard to do error recovery parsing with PEG parsers.

As workaround I can suggest syntax highlight rules for VIM -- https://github.com/ulex/ZenSharp/blob/126817389e719811869cbd4fd28eb1bd9d37f62c/ZenSharp.Core/ltg.vim

ulex avatar Jul 27 '15 19:07 ulex

Hello i would like to create method what return the array for example int array. And also i would like to add more then one parameter to that array Can we made something like that: pi[SomeName(s[Names,i[orderOfNames,t[ = public int[] SomeName(string[] Names, int[] orderOfNames, $type$ $name) {$END}

ComanGames avatar Oct 31 '15 03:10 ComanGames

Окей я на первую проблему с мосивами ришения написал image primType ::= "int []"="i[" | "string []"="s[" | "double []"= "d[" |string=s | byte=by | bool=b | "System.DateTime"=dt | decimal=dc | double=d | int=i | uint=ui | "System.Guid"=g | "System.Uri"=u | "System.Xml.Linq.XElement"=x А вот што касательно мульти параметров я хз

ComanGames avatar Oct 31 '15 03:10 ComanGames

With those changes work like that image

ComanGames avatar Oct 31 '15 03:10 ComanGames

Okay great I done it. image

ComanGames avatar Oct 31 '15 04:10 ComanGames

image image Here how i done it. I still work on it. But ZenSharp is great i fall in love with it

ComanGames avatar Oct 31 '15 04:10 ComanGames

Now i want to made it work untill 5 variables and with ref out and params

ComanGames avatar Oct 31 '15 04:10 ComanGames

Finally I done it support max 5 arguments modiffier of access and arrays Uploading image.png…

ComanGames avatar Oct 31 '15 05:10 ComanGames

image Here how it look like

ComanGames avatar Oct 31 '15 05:10 ComanGames

Here the source if someone is intresting image

ComanGames avatar Oct 31 '15 05:10 ComanGames

Super simple

ComanGames avatar Oct 31 '15 05:10 ComanGames

Also i extend primitive types a little bit image

ComanGames avatar Oct 31 '15 05:10 ComanGames

@GeorgeWolf, Thank you for your feedback!

Default templates allow you to enter array type by entering a symbol after type. For example, to get

public int[] Test()
{
}

you should type pmiaTest. This is not showed in documentation — I will fix it soon.

Nice idea with [ for array of specific type. But ZenSharp have bugs with ReSharper integration in this case. Highlighting goes crazy and auto inserted pair of brakets ruins template completion. (this is clearly seen on your screenshot)

Did you really find 5 parameters completion useful? From my point of view, much more effecient way to construct method parameters is using R# quick fixed Create parameter (from constructed method) and Add typed parameter (from method usage).

ulex avatar Nov 01 '15 11:11 ulex

Nice idea with [ for array of specific type. But ZenSharp have bugs with ReSharper integration in this case. Highlighting goes crazy and auto inserted pair of brakets ruins template completion. (this is clearly seen on your screenshot) -Yes but it sill working after i press tab it still making exactly what i want. Did you really find 5 parameters completion useful? From my point of view, much more effecient way to construct method parameters is using R# quick fixed Create parameter (from constructed method) and Add typed parameter (from method usage).

  • No it works very nice for me like usually i do method with one or two parameter what return array
  • Also how you see on my screenshot i add the method parameters modifier for me this one work super nice
    For me personally using of i[ is more natural way Here how it looks before i press tab image And after image Yes afto insted of pairs are working but after i press tab they are just gone

ComanGames avatar Nov 02 '15 06:11 ComanGames

By the way i am really big fun of using IDE so i rewrite almost vsVim for my self. To make it perfect. I would like to work on this project, the idea is super cool. I train my self to get use to it. Next what i would like to add is put throw new NotImplementException(); After method is generated.

ComanGames avatar Nov 02 '15 06:11 ComanGames

So for me it good like that image image

image

ComanGames avatar Nov 02 '15 07:11 ComanGames

Thanks for the great extension. Is there any templates for async methods generation?

olsh avatar Mar 16 '16 12:03 olsh

@olsh sorry for long answer.

Currently, async templates not included in predefined templates.

But they are pretty easy to add. For example, I can suggest use the following scheme: pmTsName -> public async Task<string> Name() { } pmTName -> public async Task Name{ }

this can be achieved by simple change in templates:

diff --git a/ZenSharp.Integration/Templates.ltg b/ZenSharp.Integration/Templates.ltg
index 7aef698..0eb368f 100644
--- a/ZenSharp.Integration/Templates.ltg
+++ b/ZenSharp.Integration/Templates.ltg
@@ -17,6 +16,7 @@ maybeType  ::= type | "void"
 type       ::= generic | primType ("?"="?")? ("[]"=a)? | suggType
 primType   ::= string=s | byte=by | bool=b | "System.DateTime"=dt | decimal=dc | double=d | int=i | uint=ui | "System.Guid"=g | "System.Uri"=u | "System.Xml.Linq.XElement"=x |
                object=o
+taskType   ::= "System.Threading.Tasks.Task"

 // Complex types:
 generic1 ::= (SCG "." ("IList"=l | "IEnumerable"="~")) "<" type ">"
@@ -40,7 +40,9 @@ methodAttributes ::=
     | "[NUnit.Framework.TearDownAttribute]"=td
     | "[NUnit.Framework.TestCaseAttribute]"=tc
     | "[NUnit.Framework.TestAttribute]"=t
-method ::= (methodAttributes)? access ("virtual "=vm | "abstract "=am | "static "=M | ""=m) (type | "void") space identifier methodArgs methodBody
+method_async ::= (methodAttributes)? access "async" space ("virtual "=vm | "abstract "=am | "static "=M | ""=m)   (taskType "<"=T type ">" | taskType ""=T) space identifier methodArgs methodBody
+method_generic ::= (methodAttributes)? access ("virtual "=vm | "abstract "=am | "static "=M | ""=m) (type | "void") space identifier methodArgs methodBody
+method ::= method_async | method_generic
 methodBody ::= " { " cursor " }"
 methodArgs ::=  "(" ((""="," | ""="(") arg)? ")"
 arg ::= primType " " identifier2

ulex avatar Mar 21 '16 09:03 ulex

I want to generate properties with PropertyChanged notifications. Here's the code transformation I want to achieve: ppsValue!+ converts to

    private string _value;
    public string Value
    {
        get { return _value; }
        set
        {
            if (value == _value) return;
            _value = value;
            OnPropertyChanged(nameof(Value));
        }
    }

Any way to do it with ZenSharp? I know it can be done with live templates or either with To Property With Change Notification conversion, but the way that ZenSharp proposes is more flexible IMO.

ilivit avatar Jun 07 '16 12:06 ilivit

@ilivit sorry, but currently it is not possible due bug in templates substitution (you need to substitute type twice in single template). Will look at this soon, thanks.

ulex avatar Jun 08 '16 18:06 ulex

Hello. I really enjoy your extension. Is there some way to detect in-method or in-property scope?

amadare42 avatar Aug 17 '16 09:08 amadare42

@amadare42 Unfortunately not. But it is very nice and flexible idea how scope may be defined - by enclosing AST node type (or combination of it)

ulex avatar Aug 17 '16 09:08 ulex

Hi! A suggestion here: How about implementing delimiter/separators? Like p\s\c\Testing will expand into public sealed class Testing{} (because pscTesting will expand into public string cTesting; image ) I used \ as it is easier to type, any other delimiters can be used.

Any idea? 😄

Edit: I wrote a post about ZenSharp templates with more examples: https://garyng.github.io/gtil-gitbook/ReSharper/resharper-plugin-zensharp.html 😉

garyng avatar Mar 27 '17 03:03 garyng