func()

in src/ulsp/controller/quick-actions/quick_actions.go [246:298]


func (c *controller) executeCommand(ctx context.Context, params *protocol.ExecuteCommandParams) error {
	s, err := c.sessions.GetFromContext(ctx)
	if err != nil {
		return fmt.Errorf("getting session for code action: %w", err)
	}

	for _, currentAction := range c.enabledActions[s.UUID] {
		if currentAction.CommandName() != params.Command {
			continue
		}

		if len(params.Arguments) != 1 {
			return fmt.Errorf("invalid args format, expected all args data as a raw json message in the first entry")
		}
		args, ok := params.Arguments[0].([]uint8)
		if !ok {
			return fmt.Errorf("invalid args type, should be provided as raw json")
		}

		commandName := currentAction.CommandName()
		// Do nothing if token exists
		if c.pendingActionRuns.TokenExists(s.UUID, commandName, string(args)) {
			return nil
		}

		progressToken := c.pendingActionRuns.AddInProgressAction(s.UUID, commandName, string(args))
		defer c.pendingActionRuns.DeleteInProgressAction(s.UUID, commandName, string(args))

		params := &action.ExecuteParams{
			Sessions:      c.sessions,
			Executor:      c.executor,
			IdeGateway:    c.ideGateway,
			ProgressToken: progressToken,
			FileSystem:    c.fs,
		}

		progressInfoParams, err := currentAction.ProvideWorkDoneProgressParams(ctx, params, args)
		if err != nil {
			return err
		}
		c.startWorkDoneProgressMessage(ctx, params, progressInfoParams)
		defer c.endWorkDoneProgressMessage(ctx, params, progressInfoParams)

		ctx, cancelFunc := context.WithCancel(ctx)
		defer cancelFunc() // call to avoid context leak

		c.pendingCmds[*progressToken] = cancelFunc

		return currentAction.Execute(ctx, params, args)
	}

	return nil
}