BigBahss / vscode-cmantic

C/C++ code generation for VS Code: Generate Definitions, Getters, Setters, and much more.
https://bigbahss.github.io/vscode-cmantic/
MIT License
83 stars 9 forks source link

'Move Definition' doesn't account for changes in scope #6

Closed BigBahss closed 3 years ago

BigBahss commented 3 years ago

Currently, 'Move Definition' is basically a copy-and-paste after smart-placement is determined. It does not account for changes in scope at the target position. For instance, if the definition exists within a namespace block, and the target position is not within that same namespace, the definition will be lacking scope-resolution. For instance:

namespace foo {
    int bar() {
        return 42;
    }
}

If bar is moved to a position that is not within namespace foo, the definition should become:

int foo::bar() {
    return 42;
}

This is something I did not account for when I created the command, and it is being worked on. This will probably be fixed in the next feature release which will add moving a definition into/out of a class body (which also needs to account for the same thing, but with the class name).

BigBahss commented 3 years ago

Fixed on branch move-definition.

EnderShadow8 commented 2 years ago

I found an issue regarding namespace scope declarations. Consider this code:

namespace foo {
  void foo() {}
}

When I run the command "Add declaration", this is what my header file looks like:

void foo::foo();

This is illegal in C++, the correct code would be:

namespace foo {
  void foo();
}

I think this issue should be reopened.