Snippets replace keywords default in snippet in code

SyntaxEditor for WPF Forum

Posted 1 year ago by Miguel A.
Version: 18.1.0672
Avatar

Hi,

is it possible to replace the default of keywords from a snippet before/after it has been accepted and ONLY when the user hasn't changed it himself? For example the snippet is

<![CDATA[for ($index$ = 0; $index$ < $count$; $index$++) {
$selected$$end$
}]]>

 

That I can replace $index$ with anything I like, except the user changed it himself, in code so it automatically becomes

for (replacedInCode = 0; replacedInCode < $count$; replacedInCode ++){

}

The idea is that I can set up predefined keywords the user can take when creating his own snippets which are generated on runtime.

Something like snippet environments which were added in January to VS Code: https://code.visualstudio.com/updates/v1_20#_more-snippet-variables

[Modified 1 year ago]

Comments (4)

Posted 1 year ago by Miguel A.
Avatar

Also is there a way to change the icons for snippets in the intellisense menu? The current doesn't look good at dark theme.

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Miguel,

There is an ICodeSnippetTemplateSessionEventSink language service you can install to receive events from code snippets like when they are opened, closed, or a declaration is changed, etc.  You could possibly watch those events and on close, if you determine something wasn't altered from the original open, perform another text change to alter the fields appropriately. 

You'd probably have to persist the original ITextSnapshot when the session opened, and where the fields were in that session.  Then translate those text ranges to the current snapshot when the session is closed.  You can get the fields (while the session is open) with this code:

this.View.Properties.TryGetValue(typeof(CodeSnippetFieldTagger), out tagger)

For your last question, I'm not sure there's a good intercept point to change the code snippet icon right now.  How would you like to see the built-in one altered to render better in dark theme? 


Actipro Software Support

Posted 1 year ago by Miguel A.
Avatar

Thanks, I'll take a look into the service.

Somehow the icon in your sample application looks better/right but on my application it's the same as the metro wite: https://imgur.com/a/d1B1ePh although I'm using the metro dark theme and everything else seems to be okay regarding styles / colors.

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Miguel,

I think I see the problem.  We ship with several image sets in SyntaxEditor but you must activate an appropriate one on theme changes.  Please see the "SyntaxEditor / User Interface Features / IntelliPrompt Features / Image Source Providers" topic in the documentation that comes with the product since that talks about the static DefaultImageSet property you can set.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.