Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f9348d4a46 | ||
![]() |
6f4e6b9227 | ||
![]() |
59135d5cea | ||
![]() |
4accf55b41 | ||
![]() |
fd3b01ef0f | ||
![]() |
5825c2b617 | ||
![]() |
328a8476a5 | ||
![]() |
1589665652 | ||
![]() |
08f15a6739 | ||
![]() |
b5e992b820 |
@@ -9,8 +9,8 @@
|
||||
"contributors": [
|
||||
"back2dos"
|
||||
],
|
||||
"version": "0.19.1",
|
||||
"releasenote": "More fine grained control over type normalization in BuildCache.",
|
||||
"version": "0.20.2",
|
||||
"releasenote": "Expose autocompletion contents. Work around metadata completion issue.",
|
||||
"tags": [
|
||||
"tink",
|
||||
"macro",
|
||||
|
@@ -8,6 +8,8 @@ using StringTools;
|
||||
|
||||
typedef Positions = tink.macro.Positions;
|
||||
typedef ExprTools = haxe.macro.ExprTools;
|
||||
typedef TypedExprTools = haxe.macro.TypedExprTools;
|
||||
typedef TypedExprs = tink.macro.TypedExprs;
|
||||
typedef Exprs = tink.macro.Exprs;
|
||||
typedef Functions = tink.macro.Functions;
|
||||
typedef Metadatas = tink.macro.Metadatas;
|
||||
@@ -52,9 +54,16 @@ class MacroApi {
|
||||
|
||||
static public var completionPoint(default, null):Option<{
|
||||
var file(default, never):String;
|
||||
var content(default, never):Null<String>;
|
||||
var pos(default, never):Int;
|
||||
}>;
|
||||
|
||||
static public function getBuildFields():Option<Array<haxe.macro.Expr.Field>>
|
||||
return switch completionPoint {
|
||||
case Some(v) if (v.content != null && (v.content.charAt(v.pos - 1) == '@' || (v.content.charAt(v.pos - 1) == ':' && v.content.charAt(v.pos - 2) == '@'))): None;
|
||||
default: Some(haxe.macro.Context.getBuildFields());
|
||||
}
|
||||
|
||||
static public var args(default, null):Iterable<String>;
|
||||
static var initialized = initArgs();
|
||||
|
||||
@@ -71,12 +80,15 @@ class MacroApi {
|
||||
params:{
|
||||
file:String,
|
||||
offset:Int,
|
||||
contents:String,
|
||||
}
|
||||
} = haxe.Json.parse(arg);
|
||||
|
||||
switch payload {
|
||||
case { jsonrpc: '2.0', method: 'display/completion' }:
|
||||
Some({
|
||||
file: payload.params.file,
|
||||
content: payload.params.contents,
|
||||
pos: payload.params.offset,
|
||||
});
|
||||
default: None;
|
||||
|
@@ -23,7 +23,10 @@ class ClassBuilder {
|
||||
target = Context.getLocalClass().get();
|
||||
|
||||
if (fields == null)
|
||||
fields = Context.getBuildFields();
|
||||
switch MacroApi.getBuildFields() {
|
||||
case None: target.pos.error('Impossible to get builds fields now. Possible cause: https://github.com/HaxeFoundation/haxe/issues/9853');
|
||||
case Some(_):
|
||||
}
|
||||
|
||||
this.initializeFrom = fields;
|
||||
this.target = target;
|
||||
@@ -192,10 +195,14 @@ class ClassBuilder {
|
||||
return m;
|
||||
}
|
||||
|
||||
static public function run(plugins:Array<ClassBuilder->Void>, ?verbose) {
|
||||
var builder = new ClassBuilder();
|
||||
for (p in plugins)
|
||||
p(builder);
|
||||
return builder.export(verbose);
|
||||
}
|
||||
static public function run(plugins:Array<ClassBuilder->Void>, ?verbose)
|
||||
return switch MacroApi.getBuildFields() {
|
||||
case None: null;
|
||||
case Some(fields):
|
||||
var builder = new ClassBuilder(fields);
|
||||
for (p in plugins)
|
||||
p(builder);
|
||||
return builder.export(verbose);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -95,8 +95,12 @@ class Sisyphus {
|
||||
TPath(toTypePath(baseType, params));
|
||||
case TFun(args, ret):
|
||||
TFunction(
|
||||
[ for (a in args) a.opt ? nullable(toComplexType(a.t)) : toComplexType(a.t) ],
|
||||
toComplexType(ret));
|
||||
[for (a in args) {
|
||||
var t = #if haxe4 TNamed(a.name, #else ( #end toComplexType(a.t));
|
||||
if (a.opt) TOptional(t) else t;
|
||||
}],
|
||||
toComplexType(ret)
|
||||
);
|
||||
case TAnonymous(_.get() => { fields: fields }):
|
||||
TAnonymous([ for (cf in fields) toField(cf) ]);
|
||||
case TDynamic(t):
|
||||
|
55
src/tink/macro/TypedExprs.hx
Normal file
55
src/tink/macro/TypedExprs.hx
Normal file
@@ -0,0 +1,55 @@
|
||||
package tink.macro;
|
||||
|
||||
import haxe.macro.Type;
|
||||
import haxe.ds.Option;
|
||||
using haxe.macro.Tools;
|
||||
|
||||
class TypedExprs {
|
||||
|
||||
static public function extractAll<T>(t:TypedExpr, f:TypedExpr->Option<T>):Array<T> {
|
||||
var out = [];
|
||||
function rec(t:TypedExpr)
|
||||
if (t != null) {
|
||||
switch f(t) {
|
||||
case Some(v): out.push(v);
|
||||
default:
|
||||
}
|
||||
t.iter(rec);
|
||||
}
|
||||
rec(t);
|
||||
return out;
|
||||
}
|
||||
|
||||
static public function extract<T>(t:TypedExpr, f:TypedExpr->Option<T>):Option<T> {
|
||||
try extractAll(t, function (t) {
|
||||
var ret = f(t);
|
||||
if (ret != None)
|
||||
throw ret;
|
||||
return ret;
|
||||
})
|
||||
catch (e:Option<Dynamic>) return cast e;
|
||||
return None;
|
||||
}
|
||||
|
||||
static public function isThis(t:TypedExpr):Bool
|
||||
return switch t {
|
||||
case null: false;
|
||||
case { expr: TConst(TThis) | TLocal({ name: '`this' })}: true;
|
||||
default: false;
|
||||
}
|
||||
|
||||
static public inline function hasThis(t)
|
||||
return contains(t, isThis);
|
||||
|
||||
static public function findAll(t:TypedExpr, f:TypedExpr->Bool):Array<TypedExpr>
|
||||
return extractAll(t, collect(f));
|
||||
|
||||
static public function find(t:TypedExpr, f:TypedExpr->Bool):Option<TypedExpr>
|
||||
return extract(t, collect(f));
|
||||
|
||||
static public function contains(t:TypedExpr, f:TypedExpr->Bool):Bool
|
||||
return find(t, f) != None;
|
||||
|
||||
static inline function collect(f)
|
||||
return function (t) return if (f(t)) Some(t) else None;
|
||||
}
|
@@ -258,8 +258,7 @@ class Types {
|
||||
return if (once) t else reduce(t, false);
|
||||
return switch type {
|
||||
case TAbstract(_.get() => { name: 'Null', pack: [] }, [t]): rec(t);
|
||||
case TLazy(f): rec(f());
|
||||
case TType(_, _): rec(Context.follow(type, once));
|
||||
case TLazy(_) | TType(_): rec(Context.follow(type, once));
|
||||
default: type;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user