You can check this link, it was useful for me:
https://huggingface.co/blog/personal-copilot
I guess you basically can create a JSONL file from your codes. Each line is a content of a file. And then fine-tune this file using libraries like hf-autotrain. And chose the textbook format.