There are three different categories of reports about the compilation of the Quran:
A) The Quran that we have possession of today with all its structure and compilation, the numbering of its verses, and the structure of its chapters and sections is the very same Quran that the Prophet Muhammad gathered, collated, compiled and structured for Muslims during his life at the instigation of Allah. Although he himself did not collect the verses but the Quran was compiled under his supervision. 
B) The Quran in its present form was collected and completed by the Commander of the Faithful, Ali (a.s) following the demise of the Holy Prophet (s). The compilation was done during the time when Ali (a) was confined to his house living a secluded life.
3) The Quran was compiled after the demise of the Prophet (s) by some of the companions (sahaba) other than Imam Ali (a).
A great many Shia scholars especially the contemporaries maintain that the Quran was compiled at the time of the Holy Prophet himself and under his supervision.
Some Shiite scholars subscribe to the second category of reports saying that the Commander of the Faithful, Ali (a) was the first to collect and compile the Quran in its present shape. Most of the Sunni scholars, however, have adopted the third viewpoint. The orientalists have also advocated the same, and they have added that the Quran which was compiled by Imam Ali (a) was rejected by the companions.
Obviously, according to the first and second viewpoints, the collection of the Quran is ascribed to God and that the creation, structuring and arrangement of the verses have been done in the light of the divine revelation because the Apostle of God (s) according to verses 2 and 3 of chapter of al-Najm did not speak of his own desire. "It is naught but revelation that is revealed." Whatever the Prophet (s) was saying in religious matters was with divine guidance. As for the Infallible Imams (a), they were not receiving revelations but they were carrying on the path of the prophets; they were inerrant and possessed divine knowledge.
Those who have accepted the third viewpoint (or the third category of verses) not only cannot prove that the chapters and their order have been created with divine guidance but they also negate them and consider the personal view of the companions to be involved in the compilation of the Quran and in the arrangement of its chapters.
Here it is necessary to make mention of a few points:
1. Allamah Muhammad Hussein Tabatabai says under verse 9 of Al-Hijr [«انا نحن نزلنا الذکر و انا له لحافظون»] the features which have been mentioned for the Quran such as eloquence, expressiveness, coherence and the miraculous nature of the Quranic verses entirely exist in the present Quran which we have possession of. He has concluded that this Quran is the very same Quran which was known during the Apostle of God – peace and blessing of Allah be upon him.
Although this saying negates any kind of distortions with the Quran, it cannot prove that this collection with its present form is revelatory. That is because the aforementioned features are not in a way such as to prove that the present collection of the verses which form the chapters, and also the order of the chapters which form the Quran are in the same way as existed in the time of the Prophet (s).
2. If one can prove the numerical miracle of the Quran over and above the Quranic syntactical and conceptual arrangement of the words and chapters of the Quran and if he can establish the numerical relations of the verses of one chapter with those of another (something which mankind is unable to do), he can prove that the Suras cum their order are revelatory but again the order of the all the Quranic verses in a single chapter being revelatory will not be proved.
3. It has been said in Majma' and al-Kashshaf that when the verse (And guard yourselves against a day…) was sent down, Gabriel said: "It is to be placed at the beginning of verse 280 of chapter al-Baqarah whereas chapter al-Baqarah was revealed in the beginning of the Hegira year and this verse was revealed in the tenth year during Hajjatul Weda' (the Farewell Pilgrimage). It has been said in Majma'ul Bayan that Chapter al-Baqarah was entirely revealed in Medina except for (And guard yourselves against a day…) which was revealed during Hajjatu Wed'ah.
Many arguments have been presented in favor of the first category of reports. Some of them are as under:
1. It has been quoted from Sayyid Murteza Alam al-Hoda in the preface to Majma' al-Bayan (Al-Fan al-Khāmis) that he said: "The Quran in its present form was compiled during the lifetime of the Prophet (s). That was why, the Holy Quran was being taught and memorized by Muslims and they used to show it to the Messenger of Allah – peace be upon him and his family – so as to seek his advice. They were reciting the Quran from their hearts and some people like Abdullah bin Mas'ud and Ubai bin Ka'b etc. read out the Quran to the Prophet (s) many times.
Hakim quotes Zaid bin Thabit in Mustadrak that he said:
(کنا عند رسول الله علیه و آله و سلم نولف القرآن من الرقاع)
"We were with the Messenger of Allah, peace be upon him and his family, compiling scattered copies of the Quran."
Allamah Khoei has also quoted the same in his Al-Bayan from Suyuti and Mustadrak considering it as a confirmed report.
This report is very frank implying that a group of the companions gathered round the Prophet (s) collected and prepared the scattered copies of the Quran. Nasai has a report based on authentic chain from Abdullah b. Umar who said:
"I gathered the Qur'an, and read it every night. The Prophet heard about it, so he said: "Read it in a month ..." 
This hadith also indicates that the Quran was collected and compiled in book form during the lifetime of the Prophet (s).
3. Shiites and Sunnis have unanimously reported that the Messenger of God – peace be upon him and his family – have said: لاصلاة الا بفاتحة الکتاب (No prayer is in order unless Chapter Fatiha is recited in it.). We all know that Chapter al-Hamd (or Fatiha) is not the first revealed Sura of the Quran. The word "Fatiha" which refers to Sura al-Hamd and which means the "beginning chapter" indicates that the Quran had been collected during the Prophet's lifetime and that Chapter al-Hamd had been placed in the beginning of the Quran.
4. Finally, the widely acknowledged and authentic tradition about thaqalayn leaves us with no doubt that the Qur'an existed in a complete book form. It is unlikely that prophet used the term book to refer to scribbles and scattered parchments.
5. It has been mentioned in a several traditions that a number of the companions of the Holy Prophet (s) such as Ali bin Abu Talib (a), Sa'd bin Ubaid, Abu al-Darra, Ma'az bin Jabal, Thabit bin Zaid bin Nu'man, Ubai bin Ka'ab and Zaid bin Thabit compiled the Quran. In his The History of the Quran Abdullah Zanjani has narrated many traditions from Bukhari and Itqan of Suyuti, Bayhaqi and Manaqib of Khawarzami. Those traditions have also been mentioned by Ayatollah Khoei in Al-Bayan (under the Collection of the Quran). All those reports explicitly indicate that the Quran was collected and compiled in book form under the supervision of the Holy Prophet (a).
6. Last but not least, the Infallible Imams – peace be upon them – have not made any objections to this arrangement and they have accepted it. If the present order of the chapters of the Quran had not been carried out during the lifetime of the Prophet (s), the Infallible Imams, peace be upon them, would have made mention of it. At least, they would have said that the present Quran is the same Quran that was revealed but the chapters had been structured and arranged after the Prophet (s).
Additionally, the great importance which the Prophet (s) attached to the Quran is by itself an indication that the Prophet (s) would have never left the Quran for Muslim in scattered pieces. 
Reference for further reading:
Hadavi Tehrani, Mahdi, Theological Foundations of Ijtihad, pg.54 – 55, Khana-e Kherad Cultural Institute, Qom 1st edition, 1998.
 - See: Sayyid Abdul Wahhab Taliqani, The Sciences of the Quran, pg.83.
 - See: Sayyid Muhammad Reza Jalali Naeni, History of the Compilation of the Quran, pg. 87
 - Majority of Sunni scholars subscribe to this view. Ibid, pg.19 – 51.
 - See: Sayyid Abdul Wahhab Taliqani, The Sciences of the Quran, pg83; Sayyid Ali Milani, Al-Tahqiq fi Nafi al-Tahrif 'Anil-Quran al-Sharif, pg.41 – 42 and pg. 46; Muhammad Hadi Ma'refat, Protection of the Quran from Distortion, pg.34.
 - See: Sayyid Muhammad Reza Jalali Naeni, History of the Compilation of the Quran, pg.80
 -«ما ینطق عن الهوى ان هو الا وحى یوحى» Al-Najm: 2 – 3
 - We have, without doubt, sent down the Message; and We will assuredly guard it (from corruption). [15:9]
 - See: Allamah Tabatabai, Tafsir Al-Mizan, vol.12, pg.104 and pg.106 and pg.138.
 - (ان القرآن کان على عهد رسول الله صلى الله علیه و آله مجموعا مؤ لفا على ما هو علیه الآن).
 - al-Mustadrak, vol.2, pg. 229, Kitab al-Tafsir.
 - Al-Bayan, pg. 269 – 273.
 - جمعت القرآن فقرات به کل لیله فبلغ النبى (ص ) فقال اقراه فى شهر، Al-Bayan, pg. 269.
 - انى تارک فیکم الثقلین کتاب الله و عترتى ...
 - See: A Look at the Quran, Sayyid Ali Akbar Qarashi, the Synthesis and Order of the Chapters of the Quran.