Bug 1646256 - Make rust-analyzer and YouCompleteMe work with mozilla-central. r=sylvestre
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 17 Jun 2020 17:53:56 +0000
changeset 603904 a1c1439da7332bf80df0eeca03d5ecf625ebc53b
parent 603903 aac877eb7b1aafb2ede91a813c8f8386c9d8d79f
child 603905 e94d68cd516aadc85e1168c812f034504145ea09
push id2380
push userffxbld-merge
push dateMon, 20 Jul 2020 19:35:47 +0000
treeherdermozilla-release@df3ed76cf46b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssylvestre
bugs1646256
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1646256 - Make rust-analyzer and YouCompleteMe work with mozilla-central. r=sylvestre The default configuration recommended here[1], while being a good generic default, it doesn't quite work for mozilla-central as that peeks the closest ancestor directory with a `Cargo.toml`. For example, when editing under `servo/components/style`, it'd try to use that directory as a project root and fail like: ``` 0: Failed to run `cargo metadata --manifest-path /home/emilio/src/moz/gecko/servo/components/style/Cargo.toml` 1: Error during execution of `cargo metadata`: Updating crates.io index error: failed to get `servo_atoms` as a dependency of package `style v0.0.1 (/home/emilio/src/moz/gecko/servo/components/style)` Caused by: failed to load source for dependency `servo_atoms` ``` Instead, we want to override it using the `'project_directory'` setting so that we hit this path[2] and it works out of the box. [1]: https://rust-analyzer.github.io/manual.html#youcompleteme [2]: https://github.com/ycm-core/ycmd/blob/63db7ea37910a48addefe028fb5435c602acdec1/ycmd/completers/language_server/language_server_completer.py#L1914-L1916 Differential Revision: https://phabricator.services.mozilla.com/D79938
.ycm_extra_conf.py
docs/contributing/editor.rst
--- a/.ycm_extra_conf.py
+++ b/.ycm_extra_conf.py
@@ -31,17 +31,22 @@ def _is_likely_cpp_header(filename):
 
     cpp_file = filename[:-1] + 'cpp'
     return os.path.exists(cpp_file)
 
 
 def Settings(**kwargs):
     if kwargs[ 'language' ] == 'cfamily':
         return FlagsForFile(kwargs['filename'])
-    return {}
+    # This is useful for generic language server protocols, like rust-analyzer,
+    # to discover the right project root instead of guessing based on where the
+    # closest Cargo.toml is.
+    return {
+      'project_directory': '.',
+    }
 
 
 def FlagsForFile(filename):
     output = subprocess.check_output([path, 'compileflags', filename])
     output = output.decode('utf-8')
 
     flag_list = shlex.split(output)
 
--- a/docs/contributing/editor.rst
+++ b/docs/contributing/editor.rst
@@ -59,16 +59,19 @@ AutoCompletion
 
 There's C++ and Rust auto-completion support for VIM via
 `YouCompleteMe <https://github.com/ycm-core/YouCompleteMe/>`__.
 
 As long as that is installed and you have run :code:`./mach build` or
 :code:`./mach configure`, it should work out of the box. Configuration for this lives
 in :code:`.ycm_extra_conf` at the root of the repo.
 
+Rust auto-completion should work both with the default completer (RLS, as of
+this writing), or with `rust-analyzer <https://rust-analyzer.github.io/manual.html#youcompleteme>`__.
+
 ESLint
 ~~~~~~
 
 The easiest way to integrate ESLint with VIM is using the `Syntastic plugin
 <https://github.com/vim-syntastic/syntastic>`__.
 
 :code:`mach eslint --setup` installs a specific ESLint version and some ESLint
 plugins into the repositories' :code:`node_modules`.