Repository: rsteube/carapace (go)

Issue:
gopls autocast feature interferes with Action.Invoke()
The new autocast feature of [gopls](https://pkg.go.dev/golang.org/x/tools/gopls) automatically wraps code in an `carapace.Action(...)` cast when `Action.Invoke()` is completed.
This interferes with the workflow though as `InvokedAction.ToA()` is meant to be used to cast it and the generated code needs to be removed each time.
Prevent this behaviour by using composition instead of the aliased type.


Pull request:
InvokedAction: use composition
fix #366

Patch:
diff --git a/action.go b/action.go
index 816bcec..aee6aa4 100644
--- a/action.go
+++ b/action.go
@@ -68,7 +68,7 @@ func (a Action) Invoke(c Context) InvokedAction {
 	if c.Parts == nil {
 		c.Parts = []string{}
 	}
-	return InvokedAction(a.nestedAction(c, 10))
+	return InvokedAction{a.nestedAction(c, 10)}
 }
 
 func (a Action) nestedAction(c Context, maxDepth int) Action {
diff --git a/invokedAction.go b/invokedAction.go
index 6940a3e..a02d752 100644
--- a/invokedAction.go
+++ b/invokedAction.go
@@ -17,7 +17,9 @@ import (
 )
 
 // InvokedAction is a logical alias for an Action whose (nested) callback was invoked
-type InvokedAction Action
+type InvokedAction struct {
+	Action
+}
 
 // Filter filters given values (this should be done before any call to Prefix/Suffix as those alter the values being filtered)
 //   a := carapace.ActionValues("A", "B", "C").Invoke(c)
@@ -33,7 +35,7 @@ func (a InvokedAction) Filter(values []string) InvokedAction {
 			filtered = append(filtered, rawValue)
 		}
 	}
-	return InvokedAction(actionRawValues(filtered...).noSpace(a.nospace).skipCache(a.skipcache))
+	return InvokedAction{actionRawValues(filtered...).noSpace(a.nospace).skipCache(a.skipcache)}
 }
 
 // Merge merges InvokedActions (existing values are overwritten)
@@ -56,7 +58,7 @@ func (a InvokedAction) Merge(others ...InvokedAction) InvokedAction {
 	for _, c := range uniqueRawValues {
 		rawValues = append(rawValues, c)
 	}
-	return InvokedAction(actionRawValues(rawValues...).noSpace(nospace).skipCache(skipcache))
+	return InvokedAction{actionRawValues(rawValues...).noSpace(nospace).skipCache(skipcache)}
 }
 
 // Prefix adds a prefix to values (only the ones inserted, not the display values)
@@ -81,7 +83,7 @@ func (a InvokedAction) Suffix(suffix string) InvokedAction {
 
 // ToA casts an InvokedAction to Action
 func (a InvokedAction) ToA() Action {
-	return Action(a)
+	return a.Action
 }
 
 // ToMultiPartsA create an ActionMultiParts from values with given divider


Test patch:
diff --git a/action_test.go b/action_test.go
index 766f3b2..6025cb8 100644
--- a/action_test.go
+++ b/action_test.go
@@ -26,9 +26,11 @@ func TestActionCallback(t *testing.T) {
 		})
 	})
 	expected := InvokedAction{
-		rawValues: common.RawValuesFrom("a", "b", "c"),
-		nospace:   false,
-		skipcache: false,
+		Action{
+			rawValues: common.RawValuesFrom("a", "b", "c"),
+			nospace:   false,
+			skipcache: false,
+		},
 	}
 	actual := a.Invoke(Context{})
 	assertEqual(t, expected, actual)
diff --git a/batch_test.go b/batch_test.go
index 067f046..1a86813 100644
--- a/batch_test.go
+++ b/batch_test.go
@@ -13,9 +13,11 @@ func TestBatch(t *testing.T) {
 		ActionValues("C", "D"),
 	)
 	expected := InvokedAction{
-		rawValues: common.RawValuesFrom("A", "B", "C", "D"),
-		nospace:   false,
-		skipcache: false,
+		Action{
+			rawValues: common.RawValuesFrom("A", "B", "C", "D"),
+			nospace:   false,
+			skipcache: false,
+		},
 	}
 	actual := b.Invoke(Context{}).Merge()
 	assertEqual(t, expected, actual)
@@ -26,9 +28,11 @@ func TestBatchSingle(t *testing.T) {
 		ActionValues("A", "B"),
 	)
 	expected := InvokedAction{
-		rawValues: common.RawValuesFrom("A", "B"),
-		nospace:   false,
-		skipcache: false,
+		Action{
+			rawValues: common.RawValuesFrom("A", "B"),
+			nospace:   false,
+			skipcache: false,
+		},
 	}
 	actual := b.Invoke(Context{}).Merge()
 	assertEqual(t, expected, actual)
@@ -37,9 +41,11 @@ func TestBatchSingle(t *testing.T) {
 func TestBatchNone(t *testing.T) {
 	b := Batch()
 	expected := InvokedAction{
-		rawValues: common.RawValuesFrom(),
-		nospace:   false,
-		skipcache: false,
+		Action{
+			rawValues: common.RawValuesFrom(),
+			nospace:   false,
+			skipcache: false,
+		},
 	}
 	actual := b.Invoke(Context{}).Merge()
 	assertEqual(t, expected, actual)
@@ -52,9 +58,11 @@ func TestBatchToA(t *testing.T) {
 		ActionValues("C", "D"),
 	)
 	expected := InvokedAction{
-		rawValues: common.RawValuesFrom("A", "B", "C", "D"),
-		nospace:   false,
-		skipcache: false,
+		Action{
+			rawValues: common.RawValuesFrom("A", "B", "C", "D"),
+			nospace:   false,
+			skipcache: false,
+		},
 	}
 	actual := b.ToA().Invoke(Context{})
 	assertEqual(t, expected, actual)