weakish / vscode-complete-statement

Complete Statement with semicolon in vscode.
BSD Zero Clause License
15 stars 3 forks source link
open-vsx vscode-extension vscodium

Complete Statement with semicolon in vscode.

Mimic IntelliJ's complete statement. In other words:

Works with languages with a C style syntax.

Status

This project is orphaned. I switched to Neovim as my mainly used editor. I still use vscode occasionally, but for languages not requiring a semicolon to end a statement.

Pull requests are still welcome, though. And if you want to maintain this project, please open an issue or send a pull request, I will add you to the collaborators of the source code repository.

Install

The version on marketplace is outdated. Please use the version on open-vsx.org (vscodium uses open-vsx by default). You can also download the vsix file at GitHub releases page, and manually install it via "vscode > Extensions > Install from VSIX...".

If you want to try the cutting-edge version (master), you can clone this repository, and package it yourself:

npx vsce package

Key binding

This extension uses ctrl+; (cmd+; on mac) since vscode already uses ctrl+shift+enter.

You can rebind extension.complete-statement to ctrl+shift+enter.

BTW, ctrl+; is easier to remember and type than ctrl+shift+enter. I myself use ctrl+enter since ctrl+; is hard to type in dvorak.

Example

We use ][ to represent cursor.

][
let a_number = 2][ # decide to specify type
let a_number: number][ = 2
// press `ctrl+;` (`cmd+;` on mac)
let a_number: number = 2;
][
let semicolon: string][ = "already exist";
// `ctrl+;`
let semicolon: string = "already exist";
][
function works_too(para: number][)
// `ctrl+;`
function works_too(para: number) {
    ][
}
// Respects `tabSize` setting. If `tabSize` unset, use 4 spaces.
function works_too(para: number) {
    if (a_number == 1][)
}
// `ctrl+;`
function works_too(para: number) {
    if (a_number == 1) {
        ][
    }
}

The above example uses TypeScript, but this extension works in most languages with a C like style, such as JavaScript, Java, Ceylon, and C itself. This extension also works in languages like Kotlin, Scala, Swift, and so on. But I recommend you only use it to complete complete structures, not single statement since it will append a semicolon (;) at the end.

Configuration

By default, complete-statement uses Java style (beginning brace on same line). To use Allman style (beginning brace on its own line), add the following line in settings:

    "complete-statement.allman": true

Bugs

License

0BSD