noseglid / atom-build

:hammer: Build your project directly from the Atom editor
https://atom.io/packages/build
MIT License
248 stars 97 forks source link

Scope-specific build providers #451

Closed Gawdl3y closed 7 years ago

Gawdl3y commented 8 years ago

Proposition

There should be the ability for packages to specify scope-specific build providers, that are automatically checked for eligibility based on the current file that is open. The automatic check would just test to see if the active tab has the scope (example: .source.xml). When the user focuses on a different tab, the scope targets are refreshed for the new active file.

Alternatively, instead of scopes, file extensions could be used. They would be extension-specific providers, I suppose. Regardless, I'll refer to these as "scoped providers".

Details

{
    "normal": [SomeProviderClass, SomeOtherProviderClass],
    "scoped": [SomeScopedProviderClass]
}

Reasoning

This would allow providers to only provide build targets relevant to the currently-opened file if they're only applicable to certain file types/scopes, rather than providing a persistent target config that may not work at all on most files. The refreshing of scoped providers should be made as efficient as possible, since they'll get refreshed much more often.

If one were to replicate this functionality in a current build provider, it'd have to refresh all of the providers every time the user switches tabs, which is certainly not ideal from a performance standpoint. If multiple packages desire this behaviour, several refreshes could be triggered at once. Furthermore, it'd simply be a lot nicer to develop with this functionality built-in to the build package.

Gawdl3y commented 8 years ago

Updating consumeBuilder to take an object would actually be unnecessary; just an array of all builders would do. We could check to see if one is a scoped provider simply by checking for the existence of the scopes()/extensions() method.

Gawdl3y commented 8 years ago

As an example, I'd like to add assembly/disassembly support to my build-papyrus package. Assembly would only work on .source.papyrus/.psc files, and disassembly would only work on .source.compiled-papyrus/.pex files.

noseglid commented 8 years ago

I am sorry for taking ages to reply to this.

This is an interesting idea. I haven't thought too much about how to solve this, but would it be possible to simple include a scope key in build objects and those targets would only be available when a file with that scope (e.g. .source.papyrus) is open.

In your assembly/disassembly example it could look something like this:

{
  "cmd": "papyrus-disassemble",
  "args": [ "{FILE_ACTIVE}" ],
  "scope": ".source.papyrus"
}
noseglid commented 7 years ago

@Gawdl3y would that solve your use-case?