Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] ASTRewrite rewrite


>         Migrating to CRefactoring2 might indeed allow you to refactor
>         on unsaved
>         files. This will however cause severe indexer issues (at least
>         for
>         refactorings which use the index, e.g. finding definitions
>         etc.). This
>         happens because the index is only refreshed on save action. So
>         as long
>         as the indexer does not provide the possibility to be updated
>         with
>         unsaved file contents (and necessarily reversion of those
>         changes on
>         possible drop of file-changes), refactorings using the index
>         will work
>         more or less in the "dark" because the indexer will (1) return
>         inaccurate node locations, (2) fail to return newly added
>         declarations/definitions/references or (3) return non-existing
>         declarations/definitions/references.
> 
> 
> These assertions are incorrect since node locations and bindings
> defined in unsaved files are obtained from ASTs of dirty editors, not
> from the index.

I would be very happy if indeed using the ASTs of dirty editors in
combination with an not-completely-up-to-date-index would be sufficient
to implement reliable refactoring. I will give you an example where even
CRenameRefactoring fails without an index which is up to date:

//foo.h //saved
void foo() { }

//main.cpp
#include "foo.h" //saved
void main() {
  foo();

//other.cpp //unsaved
#include "foo.h" 
void other() {
  foo(); //this line was added since last saved
}

now open file main.cpp and rename function-reference foo. this will
cause foo to be correctly renamed in both foo.h and also main.cpp but
will completely skip the foo-call in other.cpp because the foo-reference
originating from other.cpp is as jet missing in the index. (if helpful I
can open a bug-ticket on this issue?)

So I again state here that implementing fully reliable refactorings
which work in dirty editors as well, an index which is up do date is
mandatory. So as long as the index is not up to date, refactorings
should no be allowed to be run without saving.

Lukas



Back to the top