Snippets in VS 2017 RC .... some success ....

Public forum to share code snippets, screen shorts, experiences, etc.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

Snippets in VS 2017 RC .... some success ....

Post by Phil Hepburn »

Hi guys,

Well, it may not be possible (yet) to add our own snippets - BUT - I feel I am well on my way to be able to easily tell others how to do it when we get the newer versions of the VS 2017 integration.

The free download tool makes it quite easy to be able to ignore the XML script, as these images show :-
snippets_12.jpg
snippets_12.jpg (61.5 KiB) Viewed 702 times
and when the snippet is inserted it looks like this :-
snippets_11.jpg
snippets_11.jpg (52.82 KiB) Viewed 702 times
and this :-
snippets_13.jpg
snippets_13.jpg (25.51 KiB) Viewed 702 times
Oh! the big gotcha seems to be that we need to close and re-open the version of VS 2017 I currently have - then the new snippet shows up.

Here is the folder choice list :-
snippets_14.jpg
snippets_14.jpg (37.71 KiB) Viewed 702 times
Oh! - by the way, I am NOT doing this to compete with the #command efforts - just so we know how to do it as we will need other snippets too, and I may even be able to get the snippet to take parameters as well, a bit like the pre-processor approach.

So soon we may even have a choice of three ways, hand code, #command, and also snippet.
Hope this interests ;-0)

Phil.
Wales, UK.
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Snippets in VS 2017 RC .... some success ....

Post by wriedmann »

Hi Phil,
So soon we may even have a choice of three ways, hand code, #command, and also snippet.
Since I'm using XIDE, I have built my own snippets.

But I don't think snippets are a solution to the "properties" problem like the preprocessor.
Snippets are inserted in the code and this code is visible and is "clogging" the editor with over and over repeated code.
I agree the in the backgrounbd this code is needed, but I don't like to see more than one readable line of it.
The needed code should be generated in the background (like auto properties generate an invisible variable). If you need to see it for diagnose, it is another thing ( I have looked at Clippers .PPO files very few times).

We have to write less code possible to get things done, and snippets go to the other direction.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Snippets in VS 2017 RC .... some success ....

Post by FFF »

+1 !
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

Snippets in VS 2017 RC .... some success ....

Post by Phil Hepburn »

Hi Wolfgang,

I tend to agree with your analysis ;-0)

However, like you I also wish to be able to create and use snippets, but from with VS.

I have a feeling that we may find quite a few nice and useful ways to create and use #commands in our general coding. Maybe we could run a monthly competition - you know, #command of the month award !!!

Is the idea that we can each post our #commands in the Examples part of the public Forum ? So we can copy and paste ?

How easy will it be to have two forms of #command, one with and one without the change Notification method call?

Have a nice day,
Phil.
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Snippets in VS 2017 RC .... some success ....

Post by wriedmann »

Hi Phil,

yes, I agree with you <g>. Sharing #Command snippets is a great idea!

I'm looking forward to the new compiler version where this will be possible.

And even if I don't use the VS monster (sorry, could not resist <g>), I agree that snippets are a very important thing in VS.

Thank to the extension interface in XIDE I was able to build a textblock interface into it, and a textblock like this:

Code: Select all

begin namespace {DefaultNamespace}

class {Filename}

end class

end namespace
works very well when starting a new class.

Wolfgang

P.S. of course I'm willing to share the source of this plugin (that is far from being finished)
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Snippets in VS 2017 RC .... some success ....

Post by lumberjack »

Phil,
dr philip h. hepburn wrote:Hi Wolfgang,
How easy will it be to have two forms of #command, one with and one without the change Notification method call?
Quite easy

Copy and paste the #command and add CHANGE NOTIFY. Obviously in the original #command the OnPropertyChanged method need to be removed.
#command PROPERTY <n> AS <t> GETSET <v> =>;
PROPERTY <n> AS <t>;;
GET;;
RETURN SELF:<v>;;
END GET;;
SET;;
IF SELF:<v> <> VALUE
SELF:<v> := VALUE;;
ENDIF;;
END SET;;
END PROPERTY
#command PROPERTY <n> AS <t> GETSET <v> NOTIFY CHANGE =>;
PROPERTY <n> AS <t>;;
GET;;
RETURN SELF:<v>;;
END GET;;
SET;;
IF SELF:<v> <> VALUE;;
SELF:<v> := VALUE;;
SELF:NotifyPropertyChanged(<"n">);;
ENDIF;;
END SET;;
END PROPERTY
______________________
Johan Nel
Boshof, South Africa
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Snippets in VS 2017 RC .... some success ....

Post by lumberjack »

Ok,
As I hate this webinterface not going to go into the details, but one can easily change the #command to cater for various requirements:

PROPERTY x AS INT GET _x
PROPERTY x AS INT SET _x
PROPERTY x AS INT SET _x NOTIFY CHANGE

Just remove the non-required pieces of the command translation.
______________________
Johan Nel
Boshof, South Africa
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Snippets in VS 2017 RC .... some success ....

Post by robert »

Jac,

You probably know this already, but the single line syntax for properties is already supported by the compiler:

Code: Select all

PROPERTY x AS INT GET _x
PROPERTY x AS INT SET _x := Value
PROPERTY x AS INT GET _x SET _x := Value
The GET clause expects an expression, the SET clause expects an expression list.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Snippets in VS 2017 RC .... some success ....

Post by wriedmann »

Hi Robert,

means this we can use the command preprocessor directive on X# Beta 9?

I have now tried the following code (on a single line):

Code: Select all

#command PROPERTY <n> AS <t> GETSET <v> => ; property <n> as <t>;;; get;;; return self:<v>;;; end get;;; set;;; if self:<v> <> value;;; self:<v> := value;;; endif;;; end set;;; end property

Code: Select all

class File1      
  protect _cCmdProp as string

property myCmdProp as string GETSET _cCmdProp

end class
but it gives the error

Code: Select all

error XS9002: Parser: mismatched input 'GETSET'	16,30	File1.prg	PropertyTest
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Snippets in VS 2017 RC .... some success ....

Post by robert »

Wolfgang,

NO. The single line property syntax is built into the compiler.
You can expect (partial?) UDC support in beta 10.

But in stead of writing (using a UDC)

Code: Select all

PROPERTY myCmdProp AS String GETSET _cCmdProp
you can already write (using built in syntax)

Code: Select all

PROPERTY myCmdProp AS String GET _cCmdProp SET _cCmdProp := Value
This does not need END GET, END SET and END PROPERTY

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply