Open bbarker opened 4 years ago
Oh sorry. I've already written some spam directly to you Brandon on slack ;-)
Or is that even possible?
Yeah, it is possible, but codegen is not included at the moment in this lib. I've implemented some pieces of codegen based on this lib here:
https://github.com/dwhitney/purescript-react-basic-mui/tree/codegen-read-dts/codegen/src
This finally should be extracted from the above to a separate repo.
There are some dark / hacky corners of our current codegen. Like I've pointed this out on slack already here is the description of the main hack:
P.S. also union handling which is done in this module is not really smart and I want to improve it soon.
That would be wonderful if eventually it would be possible to leverage this repository https://github.com/DefinitelyTyped/DefinitelyTyped and create purescript FFI modules automatically :)
@flip111 Thanks for your interest and comment!
We are preparing some video meetup (currently @jvliwanag [GMT+8] and me [GMT +2]). Probably next week. Our ambitious plan is to form a community organization (I think here on github) which could be an umbrella for libraries related to PS codegen from TS. Probably we are going to make a small announcement on the forum too.
If you Guys (ping @bbarker) want to join you are very welcome!
Yes please write the details on how to join the video.
I'm in the middle of a project at the moment, but generally compiler stuff interest me a lot.
@flip111 Cool! I hope I will provide more details soon.
Hmmm, what's the status of this issue? I would like to generate binding to the vscode API using this library but I don't know where to start.
Hi @poscat0x04 two of the things that are still work in progress are to extract typescript types from definitions files (dts) and to generate purescript code based on this. At the moment both of these things are not ready yet. We welcome you to explore the purescript-codegen space, read issues and send in pull requests if you like. Otherwise please come back later :)
@poscat0x04 , @flip111 I would not say that type extraction is not ready at the moment. I would say that it works reliably on a subset of TS type constructions. Some of them can be seen here - in this test scenarios (in every test source
variable is a typescript module which we test against):
@poscat0x04 Could you please share/link some simple definitions which you want to process?
@paluh My ultimate goal is to write vscode extensions using purescript, which requires creating a binding to some subset of the api type definitions.
Tried to use build
and instantiation
but resulted in a failure:
unknown: Unknown type constructor: (Just "\"vscode\"")<Thenable>: then: {}
This is the code I used:
main :: Effect Unit
main = do
-- Test.runTest Test.ReadDTS.Instantiation.suite
e <- build { strictNullChecks: true } { path: "test/vscode.d.ts", source: Nothing }
case e of
Right r -> do
let
mts = extract $ runExceptT $ traverse (\tc -> I.instantiate tc []) r
case mts of
Right ts -> traverse_ print $ map pprint ts
Left e -> print $ show e
Left e -> print $ show e
@poscat0x04 I've started a branch on which I try to solve ambient module handling. I have hard time extracting declarations from it - this still doesn't work correctly:
https://github.com/purescript-codegen/purescript-read-dts/blob/ambient-modules/src/ReadDTS.ts#L176
I'm debugging it here:
https://github.com/purescript-codegen/purescript-read-dts/blob/ambient-modules/test/Main.purs#L24
If I leave for example only Command
declaration as a source
value this type extraction works fine.
I'm not sure when I find time to work on modules again. If you need some more debugging tips I can try to provide them here ;-)
So finally I'm able to somehow handle ambient module declarations. I'm able to build AST for this source:
https://github.com/purescript-codegen/purescript-read-dts/blob/ambient-modules/test/Main.purs#L25
There is still a problem with const
declaration. I'm going to work on it next (but I'm not sure when ;-)).
Currently "specialization for module type" has not much sens as far as I can tell... I think that given module declaration you should try to iterate over declarations and process (like specialize or something) them one by one. I have to warn you that AST unfolding has hard coded depth limit and it is known bug (it should be configurable):
To wrap it up:
Everything is still on ambient-modules
branch.
ReadDTS
allows you to attach visitor for module declarations on the level of visitors:
https://github.com/purescript-codegen/purescript-read-dts/blob/ambient-modules/src/ReadDTS.purs#L63
There is new declaration type ReadDTS.AST.Module
: https://github.com/purescript-codegen/purescript-read-dts/blob/ambient-modules/src/ReadDTS/AST.purs#L85
I've added module handling also on ReadDTS.Instantiation
level by providing Module
type there too, but I'm not sure if it is useful... Maybe I should drop it from there as it can be misleading.
I want to work on export const version: string;
declaration next as this is not handled by the current version.
Another missing piece which should be handled is class
declaration.
When I finish work on const
and class
I'm going to tag and release a new version probably.
I'm really happy to answer any other questions and help with debugging :-)
Tried to run the test on the vscode.d.ts
file but got the error "Variable not defined: T". Is there something I'm missing or are parametric functions not being supported right now?
@poscat0x04 I have to admit that @flip111 suggestion that this lib is not ready / stable yet was more insightful then mine opinion which was based mainly on emotions - I've just invested a lot of time in the research and TS compiler api exploration so I "felt" that this code should and is valuable. After a throughout review I've decided to rewrite main parts of the lib and build it on proper unit and regression test base (because TS is huge and the compiler API is even larger ;-)).
I'm starting this work on the rewrite
branch branch by establishing basic units tests infrastructure etc.
https://github.com/purescript-codegen/purescript-read-dts/blob/rewrite/test/ReadDTS.purs
Sorry that we are not able to meet your expectation at the moment. I hope that with this rewrite we would be able to provide better coverage and docs. I'm going to ping you back when this lib can "digest" vscode.d.ts
declarations :-)
Or is that even possible?
I certainly don't mind if it isn't perfect, but anything to get me a leg up on converting TypeScript type definitions to PureScript FFI files would be great.