Yes.  The bankruptcy filing will discharge (eliminate) any dischargeable debts which are owed on the date the bankruptcy case is filed.

In most cases, the debt on something is owed before a lawsuit is filed.

The lawsuit is merely seeking a court judgment stating the amount that is owed and giving powers of collection to the creditor.

So, a debt can be discharged by filing a bankruptcy case either before, or after, a lawsuit is filed.