Thom1729 / YAML-Macros

A macro system for YAML files powered by Python. Intended for Sublime Text development.
MIT License
21 stars 3 forks source link

More obvious build system integration #23

Closed keith-hall closed 6 years ago

keith-hall commented 6 years ago

Hi,

Thanks for this great plugin. I wonder if we could make it slightly friendlier for new users by integrating with the build system a tiny bit more - specifically, I mean:

Thom1729 commented 6 years ago

Thanks for the feedback! Your timing is ideal -- I'm hoping to get 3.0 out in the next couple of days. Along with a couple of new features, the major priorities are usability and output quality.

I'm not sure how feasible this is, but it'd be great if, when a build fails, YAML-Macros wouldn't clear the contents of the .sublime-syntax file being generated

This will be fixed in 3.0. On a failed build, the destination file will not be touched.

it'd be handy if, when referencing a syntax for extension, the extend macro could automatically find it - even if it is contained in a .sublime-package file.

This might be tricky, because the CLI doesn't have access to Sublime's convenience functions for this. Porting those functions to a standalone module would be a prerequisite.

when building, it is not clear that anything happened, because I have "show_panel_on_build": true (as per the ST default), and no panel is displayed on success or failure.

currently, any exceptions that occur during the build are visible in the ST console. It'd be great if they could be caught and a more informative (where easily possible) error shown in the build panel.

Error handling is the last major item on my to-do list for 3.0, and the build output panel certainly sounds like the best place to put it. I'll see what I can get in before the release.

keith-hall commented 6 years ago

the CLI doesn't have access to Sublime's convenience functions for this. Porting those functions to a standalone module would be a prerequisite.

I've started work on this over at https://github.com/forkeith/YAML-Macros/commit/2f23ed1adbae4300bccc7bfb92691bafdd585a0e, but I had to base it off the latest release branch as almost any newer commits seemed to give me ZipLoader errors. I may or may not get time to complete it, so feel free to use or not use it as you see fit :)

Thom1729 commented 6 years ago

Thanks for the work on that.

In 3.0, I'm soft-deprecating the extend macro in favor of an apply macro that does less. As it stands, the following examples should do the same thing:

%YAML 1.2
%TAG ! tag:yaml-macros:YAMLMacros.lib.extend:
---
!extend
_base: foo.yaml
otherProp: test
%YAML 1.2
%TAG ! tag:yaml-macros:YAMLMacros.lib.extend:
---
!apply
- !include foo.yaml
- !merge
  otherProp: test

The new apply macro takes an array with an initial value and zero or more Operations. The Operations are applied in order to the initial value. To extend a file, you use the new include macro, which loads the file (applying any macros in that file).

The best way to integrate the sublime lookup functionality would probably be to have a new macro analogous to include. It could be used as follows:

%YAML 1.2
%TAG ! tag:yaml-macros:YAMLMacros.lib.extend:
---
!apply
- !sublime_resource foo.yaml
- !merge
  otherProp: test

This would allow users to include named files from built-in packages, installed packages, or user packages.

I'm a bit concerned that this could be brittle, though. An extension syntax will necessarily rely on internal implementation details of a specific version of another syntax. These details could change without warning. Two users could also have different versions of a dependency package installed, resulting in different builds. I think that if we bake in this kind of functionality, we have to solve that problem by specifying dependencies more strictly.

keith-hall commented 6 years ago

one thing I've noticed with using !apply instead of !extend is that Package Dev's syntax highlighting no longer works very well due to the extra indentation - I wonder what we can do about that?

image vs image

Thom1729 commented 6 years ago

It looks PackageDev assumes that context names will be indented by one or two spaces. I'll have to consider how best to handle this.

In the mean time, you can use !include to factor out the extension into its own file. You can give it a .sublime-syntax.yaml-macros extension to get the appropriate highlighting without Sublime picking it up as a new syntax. I may just update the example to do this.

keith-hall commented 6 years ago

Nice, I'm really happy with this now - thanks! Do you want to keep this issue open to track the resource dependency part of the issue or shall we close it? :)

Thom1729 commented 6 years ago

I think it's all set for now. I might slightly refactor the resource dependencies, but I think it's a complete feature as-is. Even if there are potential issues with importing resources blindly from other packages, it can be essential for importing resources from the same package.