SBT Plugin Developing, using value from anither task in parser exampels for tab completion

23 views
Skip to first unread message

Mateusz Jaje

unread,
Jan 27, 2015, 7:43:33 AM1/27/15
to simple-b...@googlegroups.com
Hello, I'm developing simple plugin for working with AWS S3,
and I want to pass to tab completion current list of buckets fetched from S3, I've taskKey s3FetchBuckets which does its work in console properly, but i have no idea what to use output from thins task in inputTask for provide tab completion...
my target is to 
s3Upload [tab] bucket1 busket2 itd

i tried so match ways, but i get or compile error (illegal reference to) or no work after press tab....
please help me, in google is so little help in developing sbt plugin... :(

Code is attached as file.

S3AutoPlugin.scala

Josh Suereth

unread,
Jan 27, 2015, 9:29:00 AM1/27/15
to simple-b...@googlegroups.com
A really good question I don't think is covered that well in our docs.


Basically here's the assumptions in sbt:

  • Tasks can take an unknown amount of time, which is why don't automatically run them at startup.
  • Autocompletion requests can occur MANY times from the user.  If you need to do a filesystem hit and/or compile for every time this happens, you're going to notice destroyed performance (at least in our experience).
SO, if you'd like to share task results in autocompletion, you'll want to do it via caching the result of the task and using the cache in the input parser on the other end.

Currently, w/ the presence of .previous this code is a bit in flex, in terms of where we'd like it, but here's the mechanism used for "testOnly" in sbt:

val savedBuckets = taskKey[Seq[String]]("saved-bucket-names")

// Create a new task triggered by the list buckets task which will *save* the list of bucket names in cache.  Note: This API I still hope to cleanup soon.
savedBuckets <<= listBuckets storeAs savedBuckets triggeredBy listBuckets

val parser = 
   Defaults.loadForParser(savedBuckets) { (state, optBucketNames) =>
       val bucketNames = optBucketNames.getOrElse(Nil)  // If we don't have a cache, we can provide default examples or alter the parser.
        ... parser goes here, use bucketNames as the 'examples' call....
   }

val fancyInputTask = Def.inputTask {
  val parsed =  parser.parsed
  ... do stuff ....
}


Hope that helps.






--
You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-build-t...@googlegroups.com.
To post to this group, send email to simple-b...@googlegroups.com.
Visit this group at http://groups.google.com/group/simple-build-tool.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages