Skip to content

Commit 313a50f

Browse files
committed
add template project for autocomplete
1 parent 66cd1c3 commit 313a50f

File tree

6 files changed

+83
-1
lines changed

6 files changed

+83
-1
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,18 @@ The important take-aways here are:
189189
* Typically, DSL operations will block until the user input or Central System
190190
response has come, and will return this result as from the function call
191191

192-
### Expectations
192+
### Writing scripts with autocomplete in your favourite IDE
193+
194+
I admit it's quite inconvenient that in the script files you have the full power of Scala, but you don't have IDE support to help you suggest methods to call or highlight mistakes. So I've added a project in which you can edit your docile-charge-point script with IDE support.
195+
196+
How does that work? Well, docile-charge-point actually loads its script files by adding a bunch of imports and other boilerplate before and after the script file contents before the code is compiled. So you would have IDE support if you would be editing the file with the boilerplate in place. I don't want to make it the standard way of working to add this boilerplate in the scripts though, because that would make it harder to read the scripts for outsiders and it would lead to more version compatibility troubles between versions of docile-charge-point.
197+
198+
To still allow you to have your autocomplete, there is a special template project in which you can edit a script with the boilerplate included and also execute it. In that project, docile is loaded as a library so that it is possible to run the interpreter on your compiled code without running the script file loader that adds the boilerplate.
199+
200+
To use it, open the template project in the [autocomplete-template-project](autocomplete-template-project/) directory. The project already has an sbt file setting up the library dependencies
201+
on the docile-charge-point DSL core. IntelliJ IDEA will import this project just fine. You'll then find a file [TestScript.scala](autocomplete-template-project/src/main/scala/TestScript.scala) that contains all the boilerplate and a comment that says `// INSERT SCRIPT HERE`. If you start editing at the place where that comment is, you can type anything that you can also type in a script file without the boilerplate. IDEA will offer you all its suggestion magic. To run your code, just execute `TestScript` as a main class in IDEA. To distribute your code as a reusable docile-charge-point script, just copy the part you added out of the surrounding boilerplate and put it in a file of its own.
202+
203+
### Scripts with expectations
193204

194205
The semi-final line is interesting: `fail("Not authorized")`.
195206

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This project is a small sbt project that gives you an opportunity to write [docile-charge-point](https://github.com/NewMotion/docile-charge-point) scripts with autocomplete in IntelliJ IDEA.
2+
3+
Just open [TestScript.scala](src/main/scala/TestScript.scala) and start editing where it says `// INSERT SCRIPT HERE`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name := "docile-examples"
2+
3+
version := "0.1"
4+
5+
scalaVersion := "2.12.8"
6+
7+
resolvers += "TNM" at "https://nexus.thenewmotion.com/content/groups/public"
8+
9+
libraryDependencies += "com.newmotion" %% "docile-charge-point" % "0.5.1"
10+
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.0"
11+
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version = 1.3.13
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import java.net.URI
2+
3+
import com.thenewmotion.ocpp.messages.v1x._
4+
5+
import scala.language.postfixOps
6+
import scala.concurrent.duration._
7+
import scala.concurrent.ExecutionContext
8+
import scala.util.Random
9+
import java.time._
10+
11+
import com.typesafe.scalalogging.Logger
12+
import org.slf4j.LoggerFactory
13+
import chargepoint.docile.dsl.{AwaitTimeout, AwaitTimeoutInMillis}
14+
import chargepoint.docile.dsl.Randomized._
15+
import chargepoint.docile.test.{RunOnce, Runner, RunnerConfig, TestCase}
16+
import com.thenewmotion.ocpp.Version
17+
import javax.net.ssl.SSLContext
18+
19+
object Main extends App {
20+
val test = new chargepoint.docile.dsl.Ocpp1XTest with chargepoint.docile.dsl.Ocpp1XTest.V1XOps {
21+
22+
implicit val executionContext: ExecutionContext = ExecutionContext.global
23+
implicit val csmsMessageTypes = com.thenewmotion.ocpp.VersionFamily.V1XCentralSystemMessages
24+
implicit val csMessageTypes = com.thenewmotion.ocpp.VersionFamily.V1XChargePointMessages
25+
26+
private implicit val rand: Random = new Random()
27+
28+
def run(defaultAwaitTimeout: AwaitTimeout) {
29+
implicit val awaitTimeout: AwaitTimeout = defaultAwaitTimeout;
30+
31+
// INSERT SCRIPT HERE
32+
33+
// for example:
34+
//
35+
// say("going to send heartbeat...")
36+
// heartbeat()
37+
// say("heartbeat request sent and response received!")
38+
}
39+
}
40+
41+
val testCase = TestCase("the single autocomplete test", () => test)
42+
val runner = new Runner(Seq(testCase))
43+
44+
runner.run(RunnerConfig(
45+
number = 1,
46+
chargePointId = "reintest01",
47+
uri = new URI("ws://compliancy.ihomer.nl:9090"),
48+
ocppVersion = Version.V16,
49+
authKey = None,
50+
repeat = RunOnce,
51+
defaultAwaitTimeout = AwaitTimeoutInMillis(60000),
52+
sslContext = SSLContext.getDefault
53+
))
54+
}
55+
56+

0 commit comments

Comments
 (0)