├── README.md ├── assets └── haxe.png ├── build.hxml ├── demo.gif └── src ├── Assets.hx ├── AssetsMacro.hx └── Main.hx /README.md: -------------------------------------------------------------------------------- 1 | Just a small neat trick I invented for nice typed asset access IDE experience. Possible thanks to Haxe and VS Code. 2 | 3 | See comments in the code to figure out how it works, maybe it'll be useful for you ;-) 4 | 5 | ![](demo.gif) 6 | -------------------------------------------------------------------------------- /assets/haxe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nadako/haxe-vscode-asset-preview/5bdb27c623f2f8f5bff326ea1a784aa7d63a1381/assets/haxe.png -------------------------------------------------------------------------------- /build.hxml: -------------------------------------------------------------------------------- 1 | --class-path src 2 | --main Main 3 | --interp 4 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nadako/haxe-vscode-asset-preview/5bdb27c623f2f8f5bff326ea1a784aa7d63a1381/demo.gif -------------------------------------------------------------------------------- /src/Assets.hx: -------------------------------------------------------------------------------- 1 | // this class would be normally generated from your asset structure, 2 | // either statically (as part of the asset pipeline), or at macro-time 3 | 4 | // we specify image paths relative to the assets root as field documentation 5 | // and then run a very simple build macros on the class that turns that 6 | // into an absolute uri for the VS Code markdown hint renderer 7 | 8 | @:build(AssetsMacro.prepareImageLinks()) 9 | class Assets { 10 | /** 11 | haxe.png 12 | **/ 13 | public static var haxe:String; 14 | } 15 | -------------------------------------------------------------------------------- /src/AssetsMacro.hx: -------------------------------------------------------------------------------- 1 | #if macro 2 | import haxe.io.Path; 3 | import haxe.macro.Context; 4 | import haxe.macro.Expr; 5 | 6 | // we need this macro, because (as far as I know), VS Code markdown renderer does not 7 | // support relative paths for images and links in code hints, so we transform paths 8 | // relative to asset root given in field docs into absolute file:/// URIs based on the 9 | // current working directory (which is where you open the project) 10 | 11 | // we also add markdown link+image syntax here, because it's simplier :) 12 | 13 | class AssetsMacro { 14 | static final prefix = "file:///" + Path.normalize(Sys.getCwd()) + "/assets/"; 15 | 16 | static function prepareImageLinks():Array { 17 | var fields = Context.getBuildFields(); 18 | for (field in fields) { 19 | if (field.doc != null) { 20 | var filePath = StringTools.trim(field.doc); 21 | var fileUri = prefix + filePath; 22 | field.doc = '[![]($fileUri)]($fileUri)'; 23 | } 24 | } 25 | return fields; 26 | } 27 | } 28 | #end 29 | -------------------------------------------------------------------------------- /src/Main.hx: -------------------------------------------------------------------------------- 1 | class Main { 2 | static function main() { 3 | // try hovering this, and clicking the image 4 | // this also works for field completion \o/ 5 | Assets.haxe; 6 | } 7 | } 8 | --------------------------------------------------------------------------------