feat: expose action contributions to plugins
This commit is contained in:
+48
-11
@@ -419,16 +419,38 @@ type FlatWorkspaceItem struct {
|
||||
Component string `json:"component"`
|
||||
}
|
||||
|
||||
type FlatAction struct {
|
||||
PluginID string `json:"pluginId"`
|
||||
ID string `json:"id"`
|
||||
Label string `json:"label"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Capability string `json:"capability,omitempty"`
|
||||
Handler string `json:"handler,omitempty"`
|
||||
}
|
||||
|
||||
type FlatContextMenuEntry struct {
|
||||
PluginID string `json:"pluginId"`
|
||||
ID string `json:"id"`
|
||||
Label string `json:"label"`
|
||||
Context string `json:"context"`
|
||||
Group string `json:"group,omitempty"`
|
||||
Capability string `json:"capability,omitempty"`
|
||||
Handler string `json:"handler,omitempty"`
|
||||
}
|
||||
|
||||
// ContributionSummary aggregates all contribution types for the frontend.
|
||||
type ContributionSummary struct {
|
||||
Views []FlatView `json:"views"`
|
||||
Commands []FlatCommand `json:"commands"`
|
||||
SearchProviders []FlatSearchProvider `json:"searchProviders"`
|
||||
SettingsPanels []FlatSettingsPanel `json:"settingsPanels"`
|
||||
SidebarItems []FlatSidebarItem `json:"sidebarItems"`
|
||||
StatusBarItems []FlatStatusBarItem `json:"statusBarItems"`
|
||||
OpenProviders []FlatOpenProvider `json:"openProviders"`
|
||||
WorkspaceItems []FlatWorkspaceItem `json:"workspaceItems"`
|
||||
Views []FlatView `json:"views"`
|
||||
Commands []FlatCommand `json:"commands"`
|
||||
SearchProviders []FlatSearchProvider `json:"searchProviders"`
|
||||
SettingsPanels []FlatSettingsPanel `json:"settingsPanels"`
|
||||
SidebarItems []FlatSidebarItem `json:"sidebarItems"`
|
||||
StatusBarItems []FlatStatusBarItem `json:"statusBarItems"`
|
||||
OpenProviders []FlatOpenProvider `json:"openProviders"`
|
||||
WorkspaceItems []FlatWorkspaceItem `json:"workspaceItems"`
|
||||
FileActions []FlatAction `json:"fileActions"`
|
||||
NoteActions []FlatAction `json:"noteActions"`
|
||||
ContextMenuEntries []FlatContextMenuEntry `json:"contextMenuEntries"`
|
||||
}
|
||||
|
||||
// buildContributionSummary creates a ContributionSummary from the registry.
|
||||
@@ -444,6 +466,9 @@ func buildContributionSummary(r *contribution.Registry) ContributionSummary {
|
||||
regStatusBar := r.StatusBarItems()
|
||||
regOpenProviders := r.OpenProviders()
|
||||
regWorkspaceItems := r.WorkspaceItems()
|
||||
regFileActions := r.FileActions()
|
||||
regNoteActions := r.NoteActions()
|
||||
regContextMenus := r.ContextMenus()
|
||||
|
||||
views := make([]FlatView, len(regViews))
|
||||
for i, v := range regViews {
|
||||
@@ -488,7 +513,19 @@ func buildContributionSummary(r *contribution.Registry) ContributionSummary {
|
||||
for i, v := range regWorkspaceItems {
|
||||
workspaceItems[i] = FlatWorkspaceItem{PluginID: v.PluginID, ID: v.Item.ID, Title: v.Item.Title, Icon: v.Item.Icon, Component: v.Item.Component}
|
||||
}
|
||||
return ContributionSummary{Views: views, Commands: cmds, SearchProviders: searchProviders, SettingsPanels: panels, SidebarItems: sidebar, StatusBarItems: statusBarItems, OpenProviders: openProviders, WorkspaceItems: workspaceItems}
|
||||
fileActions := make([]FlatAction, len(regFileActions))
|
||||
for i, v := range regFileActions {
|
||||
fileActions[i] = FlatAction{PluginID: v.PluginID, ID: v.Item.ID, Label: v.Item.Label, Icon: v.Item.Icon, Capability: v.Item.Capability, Handler: v.Item.Handler}
|
||||
}
|
||||
noteActions := make([]FlatAction, len(regNoteActions))
|
||||
for i, v := range regNoteActions {
|
||||
noteActions[i] = FlatAction{PluginID: v.PluginID, ID: v.Item.ID, Label: v.Item.Label, Icon: v.Item.Icon, Capability: v.Item.Capability, Handler: v.Item.Handler}
|
||||
}
|
||||
contextMenus := make([]FlatContextMenuEntry, len(regContextMenus))
|
||||
for i, v := range regContextMenus {
|
||||
contextMenus[i] = FlatContextMenuEntry{PluginID: v.PluginID, ID: v.Item.ID, Label: v.Item.Label, Context: v.Item.Context, Group: v.Item.Group, Capability: v.Item.Capability, Handler: v.Item.Handler}
|
||||
}
|
||||
return ContributionSummary{Views: views, Commands: cmds, SearchProviders: searchProviders, SettingsPanels: panels, SidebarItems: sidebar, StatusBarItems: statusBarItems, OpenProviders: openProviders, WorkspaceItems: workspaceItems, FileActions: fileActions, NoteActions: noteActions, ContextMenuEntries: contextMenus}
|
||||
}
|
||||
|
||||
// GetContributions returns all registered contributions flattened for the frontend.
|
||||
@@ -501,8 +538,8 @@ func (a *App) GetContributions() ContributionSummary {
|
||||
}
|
||||
summary := buildContributionSummary(a.contribRegistry)
|
||||
if a.debug {
|
||||
debug.Logf("[api] GetContributions: returning views=%d commands=%d searchProviders=%d sidebar=%d statusBar=%d settings=%d openProviders=%d",
|
||||
len(summary.Views), len(summary.Commands), len(summary.SearchProviders), len(summary.SidebarItems), len(summary.StatusBarItems), len(summary.SettingsPanels), len(summary.OpenProviders))
|
||||
debug.Logf("[api] GetContributions: returning views=%d commands=%d searchProviders=%d sidebar=%d statusBar=%d settings=%d openProviders=%d fileActions=%d noteActions=%d contextMenuEntries=%d",
|
||||
len(summary.Views), len(summary.Commands), len(summary.SearchProviders), len(summary.SidebarItems), len(summary.StatusBarItems), len(summary.SettingsPanels), len(summary.OpenProviders), len(summary.FileActions), len(summary.NoteActions), len(summary.ContextMenuEntries))
|
||||
}
|
||||
return summary
|
||||
}
|
||||
|
||||
@@ -1128,6 +1128,15 @@ func newBridgeTestApp(t *testing.T) *App {
|
||||
Commands: []plugin.ContributionCommand{
|
||||
{ID: "bridge.command", Title: "Bridge Command", Handler: "runBridgeCommand"},
|
||||
},
|
||||
FileActions: []plugin.ContributionAction{
|
||||
{ID: "bridge.file.action", Label: "Bridge File Action", Icon: "zap", Handler: "bridge.command"},
|
||||
},
|
||||
NoteActions: []plugin.ContributionAction{
|
||||
{ID: "bridge.note.action", Label: "Bridge Note Action", Icon: "zap", Handler: "bridge.command"},
|
||||
},
|
||||
ContextMenuEntries: []plugin.ContributionContextMenuEntry{
|
||||
{ID: "bridge.file.context", Label: "Bridge File Context", Context: "file", Group: "open", Handler: "bridge.command"},
|
||||
},
|
||||
StatusBarItems: []plugin.ContributionStatusBarItem{
|
||||
{ID: "bridge.status", Label: "Bridge Ready", Position: "right", Handler: "openBridgeStatus"},
|
||||
},
|
||||
@@ -1234,6 +1243,33 @@ func TestContributionSummaryIncludesSearchProviders(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContributionSummaryIncludesActionsAndContextMenus(t *testing.T) {
|
||||
app := newBridgeTestApp(t)
|
||||
|
||||
summary := app.GetContributions()
|
||||
if len(summary.FileActions) != 1 {
|
||||
t.Fatalf("FileActions count = %d, want 1", len(summary.FileActions))
|
||||
}
|
||||
fileAction := summary.FileActions[0]
|
||||
if fileAction.PluginID != "bridge.plugin" || fileAction.ID != "bridge.file.action" || fileAction.Label != "Bridge File Action" || fileAction.Handler != "bridge.command" {
|
||||
t.Fatalf("file action = %+v", fileAction)
|
||||
}
|
||||
if len(summary.NoteActions) != 1 {
|
||||
t.Fatalf("NoteActions count = %d, want 1", len(summary.NoteActions))
|
||||
}
|
||||
noteAction := summary.NoteActions[0]
|
||||
if noteAction.PluginID != "bridge.plugin" || noteAction.ID != "bridge.note.action" || noteAction.Label != "Bridge Note Action" || noteAction.Handler != "bridge.command" {
|
||||
t.Fatalf("note action = %+v", noteAction)
|
||||
}
|
||||
if len(summary.ContextMenuEntries) != 1 {
|
||||
t.Fatalf("ContextMenuEntries count = %d, want 1", len(summary.ContextMenuEntries))
|
||||
}
|
||||
menuEntry := summary.ContextMenuEntries[0]
|
||||
if menuEntry.PluginID != "bridge.plugin" || menuEntry.ID != "bridge.file.context" || menuEntry.Context != "file" || menuEntry.Handler != "bridge.command" {
|
||||
t.Fatalf("context menu entry = %+v", menuEntry)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkbenchOpenAndEditResourceRouteToProvider(t *testing.T) {
|
||||
app := newBridgeTestApp(t)
|
||||
app.contribRegistry.Register("disabled.plugin", &plugin.Contributions{
|
||||
|
||||
Reference in New Issue
Block a user