brandon1024 / cortado.vim

Import Java classes by name, find unused import statemens, and many other goodies!
MIT License
2 stars 0 forks source link

creating local variables #29

Closed brandon1024 closed 2 years ago

brandon1024 commented 2 years ago

Some IDEs are able to automatically insert local variables. Implementing a feature like this could be extremely difficult, given we don't know anything about the result of the method call. However, we can take a dumb approach that inserts a simple var (or final var) assignment at the beginning of the line.

For example, consider the following:

class Example {
    void method() {
        get(); // <- cursor is here
    }

    Object get() {
        return new Object();
    }
}

The plugin should expose a command that inserts var or final var at the beginning of the line, placing the cursor where the variable name would go.

class Example {
    void method() {
        final var <cursor> = get();
    }

    Object get() {
        return new Object();
    }
}

We should also expose configuration to enable or disable final declarations.

brandon1024 commented 2 years ago

If it's not too difficult, we should try and restore the cursor position afterwards.

brandon1024 commented 2 years ago

done!