Skip to content

Commit

Permalink
Bug 1646256 - Make rust-analyzer and YouCompleteMe work with mozilla-…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
emilio committed Jun 17, 2020
1 parent 24b4765 commit 4c5be84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .ycm_extra_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def _is_likely_cpp_header(filename):
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):
Expand Down
3 changes: 3 additions & 0 deletions docs/contributing/editor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ 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
~~~~~~

Expand Down

0 comments on commit 4c5be84

Please sign in to comment.