kritzcreek / pscid

A lightweight, fast and unintrusive PureScript file-watcher
GNU Lesser General Public License v3.0
133 stars 16 forks source link

Add Output/Formatting Option for External Tools #47

Closed prikhi closed 4 years ago

prikhi commented 5 years ago

Hey, been using pscid & I think it's great. I've got a build script that calls pscid in a separate thread, along with some other "watchers".

It would be awesome to have a flag like --output=json that printed a line of JSON that describes the status change(success, errors, etc.), instead of clearing the screen & printing the pretty version for users. That way I could parse each line & output them however I like.

Also, it would be great if this mode was able to operate with an empty stdin. E.g., these cause pscid to throw an exception: echo "" | npx pscid, npx pscid < /dev/null. Which means I have to pass in the stdin of my build script to pscid.

$ npx pscid < /dev/null
TypeError: process.stdin.setRawMode is not a function
    at Object.exports.initializeKeypresses (/home/some-path/client/node_modules/pscid/output/Pscid.Keypress/foreign.js:7:17)
    at __do (/home/some-path/client/node_modules/pscid/output/Main/index.js:229:48)
    at runSync (/home/some-path/client/node_modules/pscid/output/Effect.Aff/foreign.js:90:20)
    at run (/home/some-path/client/node_modules/pscid/output/Effect.Aff/foreign.js:318:22)
    at /home/some-path/client/node_modules/pscid/output/Effect.Aff/foreign.js:338:19
    at drain (/home/some-path/client/node_modules/pscid/output/Effect.Aff/foreign.js:120:9)
    at Object.enqueue (/home/some-path/client/node_modules/pscid/output/Effect.Aff/foreign.js:141:11)
    at /home/some-path/client/node_modules/pscid/output/Effect.Aff/foreign.js:329:27
    at Socket.<anonymous> (/home/some-path/client/node_modules/pscid/output/PscIde/foreign.js:16:23)
    at Socket.emit (events.js:202:15)
kritzcreek commented 5 years ago

Hey sorry for getting back to you this late. I have some thoughts on this, but the TLDR is: I think you're better off scripting something yourself, as the responses we get from the ide server are essentially in the json format you'd care about.

In more details here are the things pscid does:

  1. Watch sourcefiles for changes
  2. Start an IDE server
  3. Send the appropriate rebuild command to the server when files change
  4. Formatting and outputting errors one at a time
  5. Applying compiler suggestions

If you've already got watchers and build things set up and don't care about the formatting aspect, pscid only does 2-3 for you. If your editor already starts an IDE server you don't need to worry about that either, so we're down to just composing a bit of json and sending it over a socket.

prikhi commented 5 years ago

Hey sorry for getting back to you this late.

All good, in no hurry over here. The current setup is working relatively fine.

I think you're better off scripting something yourself, as the responses we get from the ide server are essentially in the json format you'd care about.

Ah, I'm pretty new to the purescript world & didn't realize the ide server was doing the majority of the work. I saw the "starting ide server..." message but assumed that was for editor integration.

If you've already got watchers and build things set up and don't care about the formatting aspect, pscid only does 2-3 for you. If your editor already starts an IDE server you don't need to worry about that either.

I'm using spago build & stack build for production builds, but the "watcher" bit of the script just forks ghcid & pscid - I'm not actually doing any file watching or ide-server starting myself(or via my editor).

Once I have more time to work on the build script, I might just go that route though(with a simple haskell client that sends the load/rebuild commands & parses the responses?). But it feels like I'd be re-implementing what pscid does, so it seemed sensible to see if there was interest in making pscid more flexible instead.

kritzcreek commented 5 years ago

What editor are you using? If you're using any of the autocompletion/auto-import features you've already started an IDE server. (If you're not using those I'd strongly recommend them)

kritzcreek commented 5 years ago

Either way, I'll see if I can extract a small PureScript program that would do what you need.

kritzcreek commented 4 years ago

I'm doing a bit of spring cleaning, and there's not been activity here for a long time, and I don't intend on making pscid a scriptable tool, so I'll close this. If you want to be able to script the functionality pscid is giving you, you're probably better off using the ide server directly.