Highlighting Spock test keywords in Eclipse
Asked Answered
U

2

8

I am using Eclipse for a Java project with some tests written in Groovy / Spock which uses the given: when: then: syntax. I would like these keywords to highlighted with some colour. Note: the spock plugin is supposed to this but doesn't work. So wanted to just do this myself.

Unbelieving answered 14/7, 2017 at 12:26 Comment(3)
Install plugins for the syntaxe you use. Preferences > install Software >....Steadman
Have you looked at the Groovy Eclipse plugin?Benghazi
@Benghazi yes, nothing thereUnbelieving
P
1

given:, when:, etc. are statement labels. There is currently no support for highlighting statement labels in Groovy-Eclipse. They are actually a bit tricky to pin down since they are not saved in the AST with source position information. org.codehaus.groovy.ast.stmt.Statement.getStatementLabels() returns List<String>. So it is possible to tell which statements have labels, but then the source range of the statement would need to be scanned to find the range of the label.

Pilau answered 31/7, 2017 at 18:40 Comment(0)
T
1

It seems like there is not any support for the label in Groovy. I have done some search but as @emilles said, there is nothing on the web.

If you have the grammar file or can get it somewhere (I did not find it after some search), transform it into a HRC File then follow the step under. See there (http://colorer.sourceforge.net/hrc-ref/index.html)

Now, you could just create the coloring for your language. There are many plugin out there for doing this like EclipseColorer. I have already use that one, so I gonna give you the step :

1 - Install the software (Help -> Install New Software)
2 - Search http://colorer.sf.net/eclipsecolorer/
3 - Once the plugin is installed and Eclipse is restart
4 - Copy the HRC file in the eclipse's folder
5 - Add the prototype file

The basic one :

<?xml version="1.0" encoding='Windows-1251'?>
 <!DOCTYPE hrc PUBLIC
 "-//Cail Lomecb//DTD Colorer HRC take5//EN"
 "http://colorer.sf.net/2003/hrc.dtd"
 >
 <hrc version="take5" xmlns="http://colorer.sf.net/2003/hrc"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://colorer.sf.net/2003/hrc http://colorer.sf.net/2003/hrc.xsd"
 ><annotation><documentation>
 'auto' is a place for include
 to colorer your own HRCs
</documentation></annotation>
<prototype name="d" group="main" description="D">
 <location link="types/d.hrc"/>
 <filename>/.(d)$/i</filename>
 </prototype>
</hrc>


6 - In Eclipse Window -> Preferences -> General -> Editors -> File Associations
7 - Add the filetype for your syntax
8 - Restart Eclipse and your good

If you dont have this kind of file is gonna be long and difficult, it's a domain specific language and you have to start from the beginning. So the only real method to do this, it's by creating a new coloring syntax for your need but it's very tricky to achieve.

You have some information there about it : http://www.mo-seph.com/projects/syntaxhighlighting

Tremble answered 4/8, 2017 at 12:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.