external_editor.rst 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. .. _doc_external_editor:
  2. Using an external text editor
  3. =============================
  4. This page explains how to code using an external text editor.
  5. .. note::
  6. To code C# in an external editor, see
  7. :ref:`the C# guide to configure an external editor <doc_c_sharp_setup_external_editor>`.
  8. Godot can be used with an external text editor, such as Sublime Text or Visual
  9. Studio Code. Browse to the relevant editor settings:
  10. **Editor > Editor Settings > Text Editor > External**
  11. .. figure:: img/editor_external_editor_settings.webp
  12. :align: center
  13. :alt: Text Editor > External section of the Editor Settings
  14. **Text Editor > External** section of the Editor Settings
  15. There are two text fields: the executable path and command-line flags. The flags
  16. allow you to integrate the editor with Godot, passing it the file path to open
  17. and other relevant arguments. Godot will replace the following placeholders in
  18. the flags string:
  19. +---------------------+-----------------------------------------------------+
  20. | Field in Exec Flags | Is replaced with |
  21. +=====================+=====================================================+
  22. | ``{project}`` | The absolute path to the project directory |
  23. +---------------------+-----------------------------------------------------+
  24. | ``{file}`` | The absolute path to the file |
  25. +---------------------+-----------------------------------------------------+
  26. | ``{col}`` | The column number of the error |
  27. +---------------------+-----------------------------------------------------+
  28. | ``{line}`` | The line number of the error |
  29. +---------------------+-----------------------------------------------------+
  30. Some example **Exec Flags** for various editors include:
  31. +---------------------+-----------------------------------------------------+
  32. | Editor | Exec Flags |
  33. +=====================+=====================================================+
  34. | Geany/Kate | ``{file} --line {line} --column {col}`` |
  35. +---------------------+-----------------------------------------------------+
  36. | Atom | ``{file}:{line}`` |
  37. +---------------------+-----------------------------------------------------+
  38. | JetBrains Rider | ``{project} --line {line} {file}`` |
  39. +---------------------+-----------------------------------------------------+
  40. | Visual Studio Code | ``{project} --goto {file}:{line}:{col}`` |
  41. +---------------------+-----------------------------------------------------+
  42. | Vim (gVim) | ``"+call cursor({line}, {col})" {file}`` |
  43. +---------------------+-----------------------------------------------------+
  44. | Emacs | ``emacs +{line}:{col} {file}`` |
  45. +---------------------+-----------------------------------------------------+
  46. | Sublime Text | ``{project} {file}:{line}:{column}`` |
  47. +---------------------+-----------------------------------------------------+
  48. .. note::
  49. For Visual Studio Code on Windows, you will have to point to the ``code.cmd``
  50. file.
  51. For Emacs, you can call ``emacsclient`` instead of ``emacs`` if
  52. you use the server mode.
  53. Automatically reloading your changes
  54. ------------------------------------
  55. To have the Godot Editor automatically reload any script that has been changed by an external text editor,
  56. enable **Editor > Editor Settings > Text Editor > Behavior > Auto Reload Scripts on External Change**.
  57. Using External Editor in Debugger
  58. ---------------------------------
  59. Using external editor in debugger is determined by a separate option in settings.
  60. For details, see :ref:`Script editor debug tools and options <doc_debugger_tools_and_options>`.
  61. Official editor plugins
  62. -----------------------
  63. We have official plugins for the following code editors:
  64. - `Visual Studio Code <https://github.com/godotengine/godot-vscode-plugin>`_
  65. - `Emacs <https://github.com/godotengine/emacs-gdscript-mode>`_
  66. LSP/DAP support
  67. ---------------
  68. Godot supports the `Language Server Protocol <https://microsoft.github.io/language-server-protocol/>`_ (**LSP**) for code completion and the `Debug Adapter Protocol <https://microsoft.github.io/debug-adapter-protocol/>`_ (**DAP**) for debugging. You can check the `LSP client list <https://microsoft.github.io/language-server-protocol/implementors/tools/>`_ and `DAP client list <https://microsoft.github.io/debug-adapter-protocol/implementors/tools/>`_ to find if your editor supports them. If this is the case, you should be able to take advantage of these features without the need of a custom plugin.
  69. To use these protocols, a Godot instance must be running on your current project. You should then configure your editor to communicate to the running adapter ports in Godot, which by default are ``6005`` for **LSP**, and ``6006`` for **DAP**. You can change these ports and other settings in the **Editor Settings**, under the **Network > Language Server** and **Network > Debug Adapter** sections respectively.
  70. Below are some configuration steps for specific editors:
  71. Visual Studio Code
  72. ^^^^^^^^^^^^^^^^^^
  73. You need to install the official `Visual Studio Code plugin <https://github.com/godotengine/godot-vscode-plugin>`_.
  74. For **LSP**, follow `these instructions <https://github.com/godotengine/godot-vscode-plugin#gdscript_lsp_server_port>`_ to change the default LSP port. The connection status can be checked on the status bar:
  75. .. image:: img/lsp_vscode_status.png
  76. For **DAP**, specify the ``debugServer`` property in your ``launch.json`` file:
  77. .. code-block:: json
  78. {
  79. "version": "0.2.0",
  80. "configurations": [
  81. {
  82. "name": "GDScript Godot",
  83. "type": "godot",
  84. "request": "launch",
  85. "project": "${workspaceFolder}",
  86. "port": 6007,
  87. "debugServer": 6006,
  88. }
  89. ]
  90. }
  91. Emacs
  92. ^^^^^
  93. Check the official instructions to configure `LSP <https://github.com/godotengine/emacs-gdscript-mode#auto-completion-with-the-language-server-protocol-lsp>`_, and `DAP <https://github.com/godotengine/emacs-gdscript-mode#using-the-debugger>`_.