Editor Configuration 编辑

Introduction

This page contains techniques and advice for setting up text editors and IDEs that will help you to work with Mozilla projects like the gecko codebase.

General

Compilation database (compile_commands.json)

Several clang-based tools described below require a compilation database, which is a JSON file called compile_commands.json containing the parameters that need to be passed to the compiler to compile each source code file.

Using mach, this can be done via the following command, after configuration is run:

./mach build-backend -b CompileDB

Emacs

Mozilla Specific Packages

dxr.el

dxr.el is an elisp package that enables searching of DXR Code Indexer results from within emacs. Using this can sometimes be easier than doing localized code indexing with rtags, as rtags processing of code trees can be very processing intensive (similar to a clobber build).

dxr.el is available via github repo, or via the Marmalade package manager.

eslint

Mozilla uses eslint to automate various coding style checks for JavaScript sources.  See the devtools documentation that describes how to integrate this into Emacs.

C/C++ Development Packages

General Guidelines to Emacs C++ Programming

The following guides give an overview of the C++ editing capabilities of emacs. It is worth reading through these guides to see what features are available. The rest of this section is dedicated to Mozilla/Gecko specific setup for packages.

rtags (LLVM/Clang-based Code Indexing)

Instructions for the installation of rtags are available at the rtags github repo. rtags requires a compilation database as described above.

In order for rtags to index correctly, included files need to be copied and unified compilation files need to be created. Either run a full build of the tree, or if you only want indexes to be generated for the moment, run the following commands (assuming you're in the gecko repo root):

cd [gecko_build_directory]
make export
./config.status

To increase indexing speed, it's best to remove unified build files and test files from database updates. This can be done by creating a ~/.rdmrc file with the following contents, with [src_dir] replaced with either the repo or build directory for your checkout:

-X */[src_dir]/*Unified*;*/[src_dir]/*/test/*;*/[src_dir]/*/tests/*

Once the rdm daemon is running, the compilation database can be added to rtags like so:

rc -J [gecko_build_directory]/compile_commands.json

Note that this process will take a while initially. However, once the database is built, it will only require incremental updates. As long as the rdm daemon is running in the background, the database will be updated based on changes to files.

irony (LLVM/Clang-based Code Completion)

Instructions on the installation of irony-mode are available at the irony-mode github repo.

irony-mode requires a compilation database as described above.

Note that irony-mode, by default, uses elisp to parse the compile_commands.json file. As gecko is a very large codebase, this file can easily be multiple megabytes, which can make irony-mode take multiple seconds to load on a gecko file. It is recommended to use this fork of irony-mode, which requires the boost System and Filesystem libraries. Checking the bug to get this patch into the mainline of irony-mode is recommended, to see if the fork can be used or if the mainline repo can be used. Using the Boost version of the irony-mode server brings file load times to under 1s.

Projectile (Project Management)

Instructions on the installation of projectile are available at the projectile github repo.

Projectile comes preconfigured for many project types. Since, gecko uses its own special build system (mach), a new project type needs to be added. This can be done via adding the following elisp configuration command to your emacs configuration file.

    (projectile-register-project-type 'gecko
                                      '("mach" "moz.build")
                                      "python mach --log-no-times build"
                                      "python mach mochitest"
                                      "python mach run")

Assuming projectile-global-mode is on, this will allow projectile to run the correct commands whenever it is working in a gecko repo.

gdb

Emacs comes with great integration with gdb, especially when using gdb-many-windows. However, when gdb is invoked via mach, some special arguments need to be passed in order to make sure the correct display mode is used. To use M-x gdb with mach on firefox, use the following command:

[gecko_repo_directory]/mach run --debug --debugparams=-i=mi

In some cases you may still see symptoms that M-x gdb is not cooperating.  Symptoms include:

  • error message "Error: you did not specify -i=mi on GDB's command line!"
  • unexpected output in the "*gud*" buffer every time you hit RET at the (gdb) prompt

Directing file descriptor "2" (STDERR) to /dev/null has been shown to get M-x gdb to cooperate.  Therefore, the next thing to try is to put the following code into an executable script, then type the path to your script when prompted by M-x gdb:

#!/bin/bash
[gecko_repo_directory]/mach run --debug --debugger-args=-i=mi 2>/dev/null

Invoke the script in emacs:

Run gdb (like this): /home/user/bin/mach_run_debug.sh

vi

Visual Studio

You can generate Visual Studio solution file:

./mach build-backend --backend=VisualStudio

Visual Studio Code

For general information on using Visual Studio Code, see their home page, repo and guide to working with C++.

For IntelliSense to work properly, a compilation database as described above is required. When it is present when you open the mozilla source code folder, it will be automatically detected and Visual Studio Code will ask you if it should use it, which you should confirm.

Useful preferences

When setting the preference

"editor.formatOnSave": true

you might find that this isn't working on large source code files, but triggering formatting manually works. This is due to the default timeout for formatOnSave, which is quite short (750ms). You might want to increase this timeout, e.g.

"editor.formatOnSaveTimeout": 5000

Sublime text and Atom

For working with JSMs, HTML, and other Web-friendly formats.

Install JSCS linter and use Google's defaults. Please also install JSHint or ESLint and use it. Avoid trailing whitespace.

The Emacs-like Modelines package in Sublime Text will automatically set the correct indentation style according to the comments at the top of source files like:

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-

Eclipse CDT

See Eclipse CDT.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:130 次

字数:10207

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文