How did Luke's X-wing fly from Ahch-To? I thought it was damaged beyond repair.
While it's true that Luke's X-Wing is in bad shape (missing part of a wing as well as several other key components), it's worth pointing out that a lot of the major bits that are needed to get it into space, such as repulsorlifts, and the bits that are needed to get it into hyperspace, such as hyperdrive motivators, are housed inside the main body of the ship rather than on the wings. Rey doesn't need to fly it as a combat fighter, she just needs it to limp into orbit and not kill her when she lands at her destination.
Apparently the film's official novelisation concurs with my guess
It was old tech, and it had taken some fast thinking and even faster fingers to get it flight worthy - the wing patched with the door to Luke’s hut, shield panels scavenged from the TIE wreckage, and a hefty amount of rewiring.
It might never fight again - not without help from Rose and her parts-requisition channels.
It's also worthy of mention that we've seen that exact T-65b X-Wing submerged before and it worked just fine almost straight away afterwards. If anything, seawater would probably less damaging for a piece of fine electronics than swamp ooze.