can i use kotlinpoet to generate .kts files ? i wa...
# squarelibraries
n
can i use kotlinpoet to generate .kts files ? i was looking for a way to add toplevel statements but that seems to not be possible with kotlinpoet
e
hmm, that’s an interesting use case
would that be as simple as adding
addCode
to
FileSpec.Builder
? and maybe a few helper methods similar to other spec builders?
n
kotlin scripts are written as if you were writing a function body, so i think a
FileScriptSpec
that saves it as
.kts
and has a
addCode(CodeBlock)
function
it looks like a bunch oftop-level statements when looking at a kts script usually
e
not sure I like the idea of introducing a new spec for it.. can you still add types, funs and vals to a script?
n
also for resolving imports the script configuration would be important.. as that can have default imports that need not to be specified in the kts file anymore
all of those yes
imports are not super important.. just wanted to mention it
e
let me file an issue to discuss possible solutions
👍 1
e
thanks!
n
poke me with the issue or i can make the issue / feature request if you want ?
e
PRs welcome! but first let’s decide which way to go about it
n
i assume a dependency on the kotlin scripting stuff is not a option... too big and useless for anyone not doing scripting..
so the default imports coul be passed as a list of imports to add by default and remove in the generated code..
e
is the idea that you just set them up in a single file and don’t have to declare them again in other files? does this help avoid tons of import statements in scripts?
n
no its more like the ScriptCompilationConfiguration declares them and idea also respects that info for highlighting
e
trying to figure whether this is something we have to explicitly support
n
its declared by the code evaluating the scripts, if the imports are there it just deduplicates them on loading.. but it would be nice to have
e
yeah, you can generate that code with existing API though