ZenSharp
ZenSharp copied to clipboard
Any suggestion / feature request?
Is anyone except me using ZenSharp in production environment? Do you have any suggestion? I'm will be very happy to any feedback.
It will be nice to have a editor for all rules and also if you can add alias to these rules
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, 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
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.
You're doing it right.
but I the template doesn't show a name and it doesn't generate code.
What do you mean by that ?
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?
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.
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
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}
Окей я на первую проблему с мосивами ришения написал
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
А вот што касательно мульти параметров я хз
With those changes work like that
Okay great I done it.
Here how i done it. I still work on it.
But ZenSharp is great i fall in love with it
Now i want to made it work untill 5 variables and with ref out and params
Finally I done it support max 5 arguments modiffier of access and arrays
Here how it look like
Here the source if someone is intresting
Super simple
Also i extend primitive types a little bit
@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).
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 tabAnd after
Yes afto insted of pairs are working but after i press tab they are just gone
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.
So for me it good like that
Thanks for the great extension. Is there any templates for async methods generation?
@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
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 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.
Hello. I really enjoy your extension. Is there some way to detect in-method or in-property scope?
@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)
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;
)
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 😉