Skip to content
This repository was archived by the owner on Apr 13, 2024. It is now read-only.

Conversation

feltech
Copy link

@feltech feltech commented Mar 4, 2018

Background

vim-rtags is the only vim plugin I could find that has the killer "rename symbol" feature for C++, as well as other great features, e.g. class hierarchy. However, diagnostics and completions were nowhere near as friendly as YouCompleteMe and ALE.

Because of the aforementioned two plugins, I already had two clang builds of my project(s) going on at any one time, and with vim-rtags that made three, which is just plain wasteful. vim-rtags was close to replacing all three with a single solution, so I set about adding some tweaks here and there. It's culminated in quite a refactor, especially for the python code (which I am much more familiar with than vimscript).

Highlights

  • Diagnostics are now shown automatically in the sign gutter, with improved rendering, and with the diagnostic message showing in the message window when the cursor is over that line. It uses simple polling to update diagnostics by default, with care taken to do as little work as possible.
  • Fixits are now supported. All fixits available for the current buffer are applied at once via <leader>rx. Errors with fixits available are marked in the sign column by Fx and suffixed in the diagnostics lists by [FIXIT].
  • Completions include more information (signature, Doxygen docs) and set the omnifunc by default. This allows for trivial compatibility with YouCompleteMe by simply disabling their built-in cpp completion.
  • Added support for --diagnostics-all via <leader>rD, to show all errors for the entire project.

Fixes

  • Remove shell=True for python 3.5+ subprocess, since shell=True means arguments are passed to the shell process, rather than RTags.
  • Use lists for commands ultimately sent to subprocess rather than spliting a string, which is better for e.g. filenames with spaces.

Tweaks

  • Sort diagnostics in the location list/quickfix list with errors at the top.
  • Added extra error messages in a few places so it's clearer if e.g. vim-rtags is having problems communicating with rc / rdm.
  • Logging is improved, including logging rdm output (if started by vim-rtags). Everything is logged to tempnames by default.

Misc

  • I've added appropriate toggles for most of the new features, i.e. g:rtagsAutoDiagnostics, g:rtagsDiagnosticsPollingInterval, g:rtagsCppOmnifunc, g:rtagsRdmLog.
  • Unit tests for the python code are included.
  • Vim documentation and README updated (a bit).
  • See the commit messages for more info. I've tried to keep them reasonable, but there is one rather large commit (70f126b) where most of the python refactor takes place, sorry about that.
  • I'm sure there's some controversial changes, and probably edge cases and other things that I've missed. I'm happy to work with you to make any changes.

* `shell=True` means arguments are passed to the *shell* process, rather
than RTags.
* This breaks `get_diagnostics`, because `rc` just gets a blank list of
arguments.
* Add `rtags#DiagnosticsAll` function (default keymap `rD`) to show
diagnostics for all files in the quickfix list.
* Only files that are currently open in buffers will have their gutter
updated with `E`/`W` symbols.
* Assume there is always an active buffer.
* Echo messages on success/fail for getting diagnostics.
* Detect unindexed file "error" from RTags and handle it as if it was a
non-zero exit code.
* Add automatic diagnostics for files:
  - Enabled by default, toggled using `g:rtagsAutoDiagnostics`.
  - Relies mostly on `CursorHold` event, rather than any clever
async/polling.
  - Use nice title in location list - dual use as a tag to determine
whether to update list at top of stack or create a new one.
* Show current line's diagnostic message in message window.
* Add support for RTags fixits
  - Applies only to current buffer.
  - Opens loclist with list of fixits applied.
  - Default keymap `<Leader>rx`.
* Support preferring omnifunc for cpp filetypes
  - Preferred by default, toggled using `g:rtagsCppOmnifunc`.
  - Otherwise sets completefunc, but still only if it's available to be
used.
* Improve rendering of diagnostic gutter signs.
  - Make the background of the sign "transparent" (i.e. match the
background of the sign column). Took the algorithm from vim-gitgutter,
just converted to python.
  - Keep a record of placed signs and only unplace those when updating
diagnostics, so we don't splat other plugins.
* Improved error messages.
  - Jump to definition/symbol/etc will notify if file is not indexed.
  - Show errors if rc returns no valid content.
* Improved completion popup text to include parent and signature (i.e.
class and function with arguments).
* Support logging rdm output to a file if `g:rtagsAutoLaunchRdm` is
used.
  - Defaults to /dev/null.  Set path using `g:rtagsRdmLogFile`.
* Improve python logging
  - Don't use root logger, so we don't splat config of other plugins.
  - Include timestamp and log level in messages.
* Group buffer related commands and events into a `Buffer` class.
  - Maintain a cache of `Buffer` objects wrapping vim `buffer` objects,
keyed by buffer number, and periodically lazily cleaned of wiped-out
buffers.
  - Get the RTags "project" used for the current buffer, for use in
determining if the index has been updated since last checked.
  - `Buffer.on_idle` is triggered on `CursorHold` autocmd to update the
diagnostics or reindex the (dirty) buffer.
* Wrap quickfix/gutter sign RTags diagnostics using `Diagnostic` class,
with convenience methods to convert from/to rtags/quickfix+signs.
* Wrap RTags project in `Project` class, with method to determine if it
has been updated on disk.
* Fix utf8 encoding when sending buffer contents to rc over stdin in
python 3.5+.
* Handy util function to get string output of a command (as opposed to
result of evaluating an expression) `rtags#getCommandOutput`.
* RTags returns the last used project if given a blank filename, but we
want no project in this case.
* Was being sorted with errors at bottom, for some reason.
* Add error `nr`, which shows up in the qlist, and is maybe useful for
navigation.
* Revert error `type` to a choice of "E" or "W", since "F" shows up as a
single character, rather than a word, unlike "E"=>"error" and
"E"=>"warning".
* Append "FIXIT" to the end of error messages for errors with a fixit
available.
* In particular, this allows support for filenames with spaces.
* Also removed some debug logging spam.
* "0" is truthy, so `int(` it.
* Stop linter complaining
* Add error message displayed to user when no jump to symbols found.
* Log vim and python to same file.
* Default log file to vim `tempname`.
* Add timestamp to vim logs, like python, and add a tag to show whether
the log comes from vim or from python.
* Rename rdm log file var to be in line with standard log file var.
* Remove some of the more spammy logs.
* Try to include more relevant info, such as function signatures and
Doxygen docstrings.
* `keys()` in python3 returns an iterator, so it's not safe to delete
items whilst iterating through them.
* So take a copy and iterate over that.
* File name is no longer determined within python, it's an option, so
use that.
* Add regular polling for updated diagnostics, with interval configured
by `g:rtagsDiagnosticsPollingInterval` (set to <=0 to disable).
* Move auto launch rdm, python init and autocmd definitions to bottom of
`rtags.vim` file, so all functions are already defined by the time they
are called.  Just good practice, and needed for the new `Poll` call.
* Don't re-use `id_` variable, we still need it!
* Maybe useful if e.g the user creates a project during a vim session.
feltech and others added 10 commits March 4, 2018 01:12
* The rtags "project" file doesn't always update when files are
re-indexed.
* But some files in the project's directory do.
* So find the most recently updated file/directory and use that file's
modification time as the project's last updated time.
* If the project has been deleted/moved then we're in a bad state, so
reset internal caches of diagnostics etc in that case.
@konstheo
Copy link

@feltech It appears you've put a lot of effort on this pull request -- it really looks excellent work. I'll try it and give some feedback.

@konstheo
Copy link

konstheo commented Sep 3, 2018

Haven't been able to test on my workstation. Vim is compiled to support only python2 and sadly most plugins I use work only with python 2 -- so recompiling for python 3 support will kinda make my system not really usable for developing. Do you have plans, @feltech , to also support python2?

@feltech
Copy link
Author

feltech commented Sep 10, 2018

Hey, thanks for taking a look. I'll try to find some time to ensure it's python2 compatible. I've also done some follow-up work that I'm yet to PR, since it's based on this stuff, so it would be nice to get this reviewed.

@konstheo
Copy link

In fact @feltech I was mistaken thinking that your pull request isn't Python 2 compatible. After paying attention to the errors I received, I was able to make it work with a couple of tweaks in your code and it works pretty ok so far. I'll open an issue on your side of things regarding those tweaks.

@xim
Copy link

xim commented Sep 19, 2019

I did some testing with this (rtags 2.33) and saw some minor issues;

  • There is a rather spammy "RTags caches have been reset" status being printed all the time, to the point where other status messages are hard to catch.
  • Vim feels less responsive, especially while rdm is reindexing files.
  • While running a large reindex triggered by rc -J, vim hangs for some time on trying to query rdm (without me having done any changes to warrant a query for status)
  • When I switch from the location list to file contents, the little sidebar thing with W/E markers disappears.

Note: If it matters, I was running with this branch rebased on top of the current master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants