haxe-sublime-bundle icon indicating copy to clipboard operation
haxe-sublime-bundle copied to clipboard

Autocompletion doesn't work in macro-generated constructor

Open ciscoheat opened this issue 9 years ago • 0 comments

As the title says, there seems to be a problem with autocompletion for parameters in a macro-generated constructor, especially for anonymous types. Minimal example:

Main.hx

class Main 
{	
	static function main() {
		// Autocompletion works fine with a normal constructor:
		new AnotherPerson(...
		
		// But autocompletion doesn't work in a 
		// macro-generated constructor with an anonymous type
		new Person(...
		
		var p = new Person({birthYear: 1978, name: "Andreas"});		
		// But it works in a macro-generated method:
		p.ageInYear(...
	}	
}

@:build(AddConstructor.run())
class Person
{
	public var birthYear : Int;
	public var name : String;
}

class AnotherPerson
{
	public var birthYear : Int;
	public var name : String;
	
	public function new(data : { birthYear: Int, name: String }) {
		this.birthYear = data.birthYear;
		this.name = data.name;
	}
}

AddConstructor.hx

import haxe.macro.Context;
import haxe.macro.Expr;

class AddConstructor
{
	static public function run() {
		var fields = Context.getBuildFields();
		
		var constructor = {
			name: 'new',
			doc: null,
			meta: [],
			access: [APublic],
			kind: FFun({
				args: [{
					meta: null,
					name: 'data',
					opt: false,
					type: macro : {birthYear: Int, name: String},
					value: null
				}],
				expr: macro {
					this.birthYear = data.birthYear;
					this.name = data.name;
				},
				params: null,
				ret: null
			}),
			pos: Context.currentPos()
		};

		var ageInYear = {
			name: 'ageInYear',
			doc: null,
			meta: [],
			access: [APublic],
			kind: FFun({
				args: [{
					meta: null,
					name: 'year',
					opt: false,
					type: macro : Int,
					value: null
				}],
				expr: macro return year - birthYear,
				params: null,
				ret: macro : Int
			}),
			pos: Context.currentPos()
		};

		fields.push(constructor);
		fields.push(ageInYear);
		
		return fields;
	}
}

I've tested on Sublime 3 with the latest Haxe package, also on HaxeDevelop 5.2.0.3. For anonymous types, it doesn't work in any of them. A simpler type like macro : Int works in Sublime.

Cross-posted issue: https://github.com/HaxeFoundation/haxe/issues/5968

ciscoheat avatar Jan 30 '17 01:01 ciscoheat