This test checks completion of Go keywords.

-- flags --
-ignore_extra_diags
-filter_keywords=false

-- settings.json --
{
	"completeUnimported": false,
	"matcher": "caseInsensitive",
	"experimentalPostfixCompletions": false
}

-- keywords.go --
package keywords

//@rank("", type),rank("", func),rank("", var),rank("", const),rank("", import)

func _() {
	var test int //@rank(re"() \\/\\/", int, interface)
	var tChan chan int
	var _ m //@complete(re"() \\/\\/", map)
	var _ f //@complete(re"() \\/\\/", func)
	var _ c //@complete(re"() \\/\\/", chan)

	var _ str //@rank(re"() \\/\\/", string, struct)

	type _ int //@rank(re"() \\/\\/", interface, int)

	type _ str //@rank(re"() \\/\\/", struct, string)

	switch test {
	case 1: // TODO: trying to complete case here will break because the parser won't return *ast.Ident
		b //@complete(re"() \\/\\/", break)
	case 2:
		f //@complete(re"() \\/\\/", fallthrough, for)
		r //@complete(re"() \\/\\/", return)
		d //@complete(re"() \\/\\/", default, defer)
		c //@complete(re"() \\/\\/", case, const)
	}

	switch test.(type) {
	case fo: //@complete(re"():")
	case int:
		b //@complete(re"() \\/\\/", break)
	case int32:
		f //@complete(re"() \\/\\/", for)
		d //@complete(re"() \\/\\/", default, defer)
		r //@complete(re"() \\/\\/", return)
		c //@complete(re"() \\/\\/", case, const)
	}

	select {
	case <-tChan:
		b //@complete(re"() \\/\\/", break)
		c //@complete(re"() \\/\\/", case, const)
	}

	for index := 0; index < test; index++ {
		c //@complete(re"() \\/\\/", const, continue)
		b //@complete(re"() \\/\\/", break)
	}

	for range []int{} {
		c //@complete(re"() \\/\\/", const, continue)
		b //@complete(re"() \\/\\/", break)
	}

	// Test function level keywords

	//Using 2 characters to test because map output order is random
	sw //@complete(re"() \\/\\/", switch)
	se //@complete(re"() \\/\\/", select)

	f //@complete(re"() \\/\\/", for)
	d //@complete(re"() \\/\\/", defer)
	g //@rank(re"() \\/\\/", go),rank(re"() \\/\\/", goto)
	r //@complete(re"() \\/\\/", return)
	i //@complete(re"() \\/\\/", if)
	e //@complete(re"() \\/\\/", else)
	v //@complete(re"() \\/\\/", var)
	c //@complete(re"() \\/\\/", const)

	for i := r //@complete(re"() \\/\\/", range)
}

/* package */ //@item(package, "package", "", "keyword")
/* import */ //@item(import, "import", "", "keyword")
/* func */ //@item(func, "func", "", "keyword")
/* type */ //@item(type, "type", "", "keyword")
/* var */ //@item(var, "var", "", "keyword")
/* const */ //@item(const, "const", "", "keyword")
/* break */ //@item(break, "break", "", "keyword")
/* default */ //@item(default, "default", "", "keyword")
/* case */ //@item(case, "case", "", "keyword")
/* defer */ //@item(defer, "defer", "", "keyword")
/* go */ //@item(go, "go", "", "keyword")
/* for */ //@item(for, "for", "", "keyword")
/* if */ //@item(if, "if", "", "keyword")
/* else */ //@item(else, "else", "", "keyword")
/* switch */ //@item(switch, "switch", "", "keyword")
/* select */ //@item(select, "select", "", "keyword")
/* fallthrough */ //@item(fallthrough, "fallthrough", "", "keyword")
/* continue */ //@item(continue, "continue", "", "keyword")
/* return */ //@item(return, "return", "", "keyword")
/* goto */ //@item(goto, "goto", "", "keyword")
/* struct */ //@item(struct, "struct", "", "keyword")
/* interface */ //@item(interface, "interface", "", "keyword")
/* map */ //@item(map, "map", "", "keyword")
/* chan */ //@item(chan, "chan", "", "keyword")
/* range */ //@item(range, "range", "", "keyword")
/* string */ //@item(string, "string", "", "type")
/* int */ //@item(int, "int", "", "type")

-- accidental_keywords.go --
package keywords

// non-matching candidate - shouldn't show up as completion
var apple = "apple"

func _() {
	foo.bar() // insert some extra statements to exercise our AST surgery
	variance := 123 //@item(kwVariance, "variance", "int", "var")
	foo.bar()
	println(var) //@complete(re"()\\)", kwVariance)
}

func _() {
	foo.bar()
	var s struct { variance int } //@item(kwVarianceField, "variance", "int", "field")
	foo.bar()
	s.var //@complete(re"() \\/\\/", kwVarianceField)
}

func _() {
	channel := 123 //@item(kwChannel, "channel", "int", "var")
	chan //@complete(re"() \\/\\/", kwChannel)
	foo.bar()
}

func _() {
	foo.bar()
	var typeName string //@item(kwTypeName, "typeName", "string", "var")
	foo.bar()
	type //@complete(re"() \\/\\/", kwTypeName)
}
-- empty_select.go --
package keywords

func _() {
	select {
		c //@complete(re"() \\/\\/", case)
	}
}
-- empty_switch.go --
package keywords

func _() {
	switch {
		//@complete("", case, default)
	}

	switch test.(type) {
		d //@complete(re"() \\/\\/", default)
	}
}

-- default_name_var_switch.go --
package keywords

func _() {
	var defaultVar int //@item(defaultVar, "defaultVar", "int", "var")
	switch defaultVar {
		case 1:
			println("helloworld")
		d //@complete(re"() \\/\\/", default, defaultVar, defer)
	}
	switch defaultVar {
		default:
		d //@complete(re"() \\/\\/", defaultVar, defer)
	}
	var nested int
	switch defaultVar {
		case 1:
			switch nested {
				default:
					println("")
			}
		d //@complete(re"() \\/\\/", default, defaultVar, defer)
	}
}

-- return_different_func.go --
package keywords

/* return  */ //@item(returnWithSpace, "return ", "", "keyword")


func _ () int {
	r //@complete(re"() \\/\\/", returnWithSpace)
}

func _ () (int, int) {
	r //@complete(re"() \\/\\/", returnWithSpace)
}

func _ () (_ int) {
	r //@complete(re"() \\/\\/", returnWithSpace)
}

func _ () (_ int) {
	r //@complete(re"() \\/\\/", returnWithSpace)
}

func _ () (_, _ int) {
	r //@complete(re"() \\/\\/", returnWithSpace)
}

func _ () (_, a int) {
	r //@complete(re"() \\/\\/", return)
}

func _ () {
	r //@complete(re"() \\/\\/", return)
}

func _ () (a int) {
	r //@complete(re"() \\/\\/", return)
}

func _ () (a, b int) {
	r //@complete(re"() \\/\\/", return)
}

func _ () (a, b int, c string) {
	r //@complete(re"() \\/\\/", return)
}

func _ () (a int) {
	_ = func (){
		r //@complete(re"() \\/\\/", return)
	}
	return
}

func _ () int {
	_ = func () (a int) {
		// func lit will be affected by outer function.
		r //@complete(re"() \\/\\/", returnWithSpace)
	}
	return
}

func _ () {
	_ = func () int {
		// func lit will be affected by outer function.
		r //@complete(re"() \\/\\/", return)
	}
	return
}
