.. _Extract to Module:

Extract to Module
=================

A fragment of a module can be automatically extracted and encapsulated into a new instance.

The fragment must be a contiguous region containing only instances, always blocks and assignments.

**Select** the region in the editor, press :kbd:`Ctrl+1`, select **Extract to module** from the list of quick assist proposals and press  :kbd:`Enter`.

.. figure:: ../../images/common/sv_quick_assist_extract_to_module_list.png



The selected piece of code will be moved to a new module in a new file. Fill in the name of the new module and file.
    
.. figure:: ../../images/common/sv_quick_assist_extract_to_module_wizard.png



The initial selection is replaced with an instance of the new module:

.. figure:: ../../images/common/sv_quick_assist_extract_to_module_result.png



The ports of the new module are automatically computed and connected in the instantiation.

**Implementation notes**

-  the new file is \`included on the line above the declaration of the initial module
-  signals which are not referenced anywhere outside the selection will be marked with a // FIXME after the extraction  
-  currently busses are propagated through a single port even if accessed through bit selects; in such a case, a // FIXME comment can help you easily identify the unique bit selects which you might consider propagating through distinct ports

.. tip:: 

 You can also :kbd:`Right+Click` in the editor and go to **Refactor** > **Extract to module** to trigger this functionality.

.. figure:: ../../images/common/sv_quick_assist_extract_to_module_menu.png



 




