Thor's powers come from Asgard. Or as Ragnarok clarified, the Asgardians themselves. When Thanos first attacked, Thor likely could have used his lightning and perhaps did. We only see the immediate moments before in Ragnarok, and the aftermath in Infinity War.
By the time Infinity War begins, mosthalf of the Asgardians are dead, and with them the source of Thor's godly power. At that point he was limited to just his Asgardian strength and durability.
He only got those powers back when we aquired a new source for those powers when he helped forge the Axe Stormbreaker.