tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

vscode.rst (7821B)


      1 Visual Studio Code
      2 ==================
      3 
      4 .. toctree::
      5   :maxdepth: 1
      6   :glob:
      7 
      8 General Knowledge
      9 -----------------
     10 
     11 `VSCode <https://code.visualstudio.com/>`__ is a multi-platform open-source programming editor developed by Microsoft and volunteers.
     12 It has support for many programming languages using extensions.
     13 This is the recommended editor for Firefox development.
     14 
     15 For more general information on the VSCode project see the `repository <https://github.com/Microsoft/vscode/>`__.
     16 
     17 Recommended extensions
     18 ----------------------
     19 
     20 VS Code provides number of extensions for JavaScript, Rust, etc. By default,
     21 Firefox source tree comes with its own set of recommendations of Visual Studio
     22 Code extensions. They will be offered when you first open the project.
     23 
     24 If you need to refer to them later, the extensions are listed in
     25 `.vscode/extensions.json <https://searchfox.org/mozilla-central/source/.vscode/extensions.json>`__.
     26 
     27 For Rust development, the `rust-analyzer <https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer>`__ extension is recommended.
     28 `See the manual <https://rust-analyzer.github.io/manual.html>`__ for more information.
     29 
     30 Getting setup
     31 -------------
     32 
     33 Close `VS Code` if it is already open, then build the configuration for `VS Code`
     34 by simply running from the terminal:
     35 
     36 .. code::
     37 
     38   ./mach ide vscode
     39 
     40 This will automatically set some of the recommended preferences for the workspace,
     41 and if you are set up for a full build, it will enable clangd and rust integrations.
     42 
     43 If successful, `VS Code` will open at the end. You do not need to run this command
     44 every time to open `VS Code`, you may open it in the normal way.
     45 
     46 If you are running full builds, the command above will set up the `Clangd`
     47 integration so that subsequent invocations of ``./mach build`` run and update the
     48 integration.
     49 
     50 .. note::
     51 
     52   If `VS Code` is already open with a previous configuration generated, please make sure to
     53   restart `VS Code` otherwise the new configuration will not be used, and the `compile_commands.json`
     54   needed by `clangd` server will not be refreshed. This is a known `bug <https://github.com/clangd/vscode-clangd/issues/42>`__
     55   in `clangd-vscode` extension
     56 
     57 .. note::
     58 
     59   The combination of rust-analyzer and clangd can be memory-intensive with the Firefox codebase.
     60   If you experience OOM issues or hangs, consider increasing swap space (e.g., to 16 GiB) or
     61   closing memory-heavy applications. On Linux, consider using `EarlyOOM <https://github.com/rfjakob/earlyoom>`__
     62   to mitigate the impact on your system.
     63 
     64 Ignore Files in VCS Repositories
     65 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     66 
     67 .. note::
     68 
     69   This is automatically done when running ``./mach ide vscode`` but may be
     70   changed manually.
     71 
     72 When using Git in mozilla-central, VS Code will treat your build directories as ordinary directories by default, causing some undesirable behavior including long indexing times, Go to Definition will open files in the build directory instead of the source tree, and Search Files by Name will find duplicate files from the source tree and the build directory (note: when using Git, VS Code will not do this since it reads ``.gitignore``). You can follow these directions to have VS Code largely ignore your build directories:
     73 
     74 #. Go to Preferences -> Settings
     75 #. Search "exclude" in the Settings
     76 #. (optional) Select "Workspace" below the search bar to only change this setting for the mozilla-central repository
     77 #. Under "Files: Exclude", click "Add Pattern", type ``obj-*`` (assuming your build directory names start with the default text, ``obj-``), and click "OK"
     78 #. Repeat the step above for the "Files: Watcher Exclude" setting
     79 #. Reload VS Code: the easiest way to do this is to quit and reopen it.
     80 
     81 Despite excluding the build directories above, Go to Definition will still correctly open files that only appear in the build directory such as generated source code.
     82 
     83 Recommended Preferences
     84 ~~~~~~~~~~~~~~~~~~~~~~~
     85 
     86 .. note::
     87 
     88   These are automatically set when running ``./mach ide vscode`` but may be
     89   changed manually. These are set only for particular file types.
     90 
     91 * ``"editor.formatOnSave": true``
     92    * This will turn on automatically fixing formatting issues when you save a file.
     93 * ``"editor.defaultFormatter": "esbenp.prettier-vscode"``
     94   * This sets the default formatter to prettier using the recommended prettier
     95     extension.
     96 
     97 ``*.jsm`` and ``*.sjs`` file extensions should also be associated with JavaScript:
     98 
     99 .. code::
    100 
    101   "files.associations": {
    102      "*.jsm": "javascript",
    103      "*.sjs": "javascript",
    104   },
    105 
    106 C/C++ Features and Support
    107 --------------------------
    108 
    109 For C++ support we offer an out of the box configuration based on
    110 `clangd <https://clangd.llvm.org>`__.
    111 
    112 Leveraging the `clang` toolchain compiler we now have support in the IDE for the following features:
    113 
    114 **1.** Syntax highlighting
    115 
    116 **2.** IntelliSense with comprehensive code completion and suggestion
    117 
    118 .. image:: ../img/auto_completion.gif
    119 
    120 **3.** Go-to definition and Go-to declaration
    121 
    122 .. image:: ../img/goto_definition.gif
    123 
    124 **4.** Find all references
    125 
    126 .. image:: ../img/find_references.gif
    127 
    128 **5.** Open type hierarchy
    129 
    130 .. image:: ../img/type_hierarchy.gif
    131 
    132 **6.** Rename symbol, all usages of the symbol will be renamed, including declaration, definition and references
    133 
    134 .. image:: ../img/rename_symbol.gif
    135 
    136 **7.** Code formatting, based on `clang-format` that respects our coding standard using the `.clang-format` and `.clang-format-ignore` files. Format can be performed on an entire file or on a code selection
    137 
    138 .. image:: ../img/format_selection.gif
    139 
    140 **8.** Inline parsing errors with limited auto-fix hints
    141 
    142 .. image:: ../img/diagnostic_error.gif
    143 
    144 **9.** Basic static-code analysis using `clang-tidy` and our list of enabled checkers. (This is still in progress not all checkers are supported by `clangd`)
    145 
    146 Clangd-specific Commands
    147 ------------------------
    148 
    149 Clangd supports some commands that are specific to C/C++:
    150 
    151 .. code::
    152 
    153    "clangd.switchheadersource"
    154 
    155 This command navigates from the currently open header file to its corresponding source file (if there is one), or vice versa.
    156 
    157 This command can be invoked from the command menu (activated via ``F1``), or using its keybinding of ``Alt+o`` (``Alt+cmd+o`` on Mac). The keybinding can also be customized in ``Keyboard Shortcuts``.
    158 
    159 Remote Development over SSH
    160 ---------------------------
    161 
    162 VS Code provides an `extension <https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh>`__ that lets you use any remote machine with a SSH server as your development environment. No matter if it's Linux based, macOS or Windows, as long as the target machine offers a SSH connection, it can be used for development.
    163 
    164 No source code needs to be on your local machine to use VS Code remotely since the extension runs commands and other extensions directly on the remote machine.
    165 
    166 In order to setup a connection please follow these steps:
    167 
    168 **1.** Open VS Code and select from the left side panel ``Remote Explorer``
    169 
    170 .. image:: ../img/remote_explorer.png
    171 
    172 **2.** From the ``Remote Explorer`` panel select ``SSH Targets`` and click on ``Add`` and enter the connection details
    173 
    174 .. image:: ../img/remote_explorer_add.png
    175 
    176 .. image:: ../img/remote_explorer_add_wind.png
    177 
    178 **3.** Click on the connection that you just configured at the previous step
    179 
    180 **4.** Finally you should be connected to the desired remote SSH server
    181 
    182 .. image:: ../img/connection_done.png
    183 
    184 Please note that during the first connection VS Code will install itself remotely and also install all of the needed dependencies.
    185 
    186 
    187 
    188 Filing Bugs
    189 -----------
    190 
    191 Bugs should be filed in the `Firefox Build System` product under `Developer Environment Integration`, preferably blocking `Bug 1662709 <https://bugzilla.mozilla.org/show_bug.cgi?id=1662709>`__.