AtomLinter / linter-glsl

Atom package that lints GLSL shaders on the fly.
https://atom.io/packages/linter-glsl
MIT License
15 stars 6 forks source link

Use helper module for temp files #14

Closed steelbrain closed 8 years ago

steelbrain commented 8 years ago
  static tempFile<T>(fileName:String, fileContents:String, Callback:Function<T>):Promise<T>

^ taken from README

Example Usage:

const Path = require('path')
const Helpers = require('atom-linter')
const linter = {
  ...
  lint: function(textEditor) {
    const fileName = Path.basename(textEditor.getPath())
    return Helpers.tempFile(fileName, textEditor.getBuffer().getText(), function(tempFile) {
      ... do something with it
      return [{type: 'Error', text: 'Le Error'}]
    })
  }
}
andystanton commented 8 years ago

Hi @steelbrain, I'd love to do this but I have a problem:

Firstly, am I missing something with the tempfile helper that might allow me to do this?

If so, great. If not, would a tempfiles helper be an acceptable addition to atom-linter? This function would accept a list of filename/content pairs, write them as temp files, execute some callback and then delete them all. The tempfile helper would then become a subset of this. I've attempted this here: https://github.com/AtomLinter/atom-linter/compare/master...andystanton:add-temp-files?expand=1

steelbrain commented 8 years ago

@andystanton The callback can provide a promise and then the helper would only delete the file when the promise has been resolved, and it already uses the filename we provide so the extension is not gonna be a problem. About creating multiple temp files at once, that's gonna be a bit tricky at the moment, You would have to do Path.dirname(tempFile) and then write another file in that dir and unlink it on deactivate.

The diff you provided to solve this looks nice, Thanks for doing that! But you have modified lib/helpers.js which is actually a babel compiled file of src/helpers.js :stuck_out_tongue:

steelbrain commented 8 years ago

I've just released atom-linter@4.3.0 with the helper you proposed

andystanton commented 8 years ago

Thanks @steelbrain I'll integrate the new helper with linter-glsl. Facepalm of my own at modifying the generated sources :)

andystanton commented 8 years ago

Merged #18

Code looks much nicer now: https://github.com/andystanton/linter-glsl/commit/01e6b5ed52e29f18e7ea15640c3c6ca61ddc7fce

steelbrain commented 8 years ago

:+1: