Skip to content
| Marketplace
Sign in
Visual Studio Code>Visualization>Code BlocksNew to Visual Studio Code? Get it now.

Code Blocks

Preview

Tom Selfin

|
56 installs
| (0) | Free
An extension for manipulating your code's syntax tree.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Code Blocks

Move your code blocks around!

This extension allows you to move your code as blocks, in any language*.

Rust (technically just cargo) is required for this extension to work, go to rust-lang.org to install it.

Installation

  1. Install the extension from:

    • Inside vscode, search for the selfint.code-blocks extension.
    • The vscode marketplace.
    • The GitHub releases page.
  2. Open a file with the Code Blocks Editor, the code-blocks-cli will need to be downloaded by the method of your choosing (using cargo or downloading from the latest release).

  3. Then the tree sitter grammar will be downloaded and compiled automatically.

That's it!

The next time you open a file in the same language, everything will already be setup.

If you open a file in a new language, the appropriate tree sitter grammar will be downloaded and compiled again.

Installation demo

installation video

Examples

TypeScript + JSX

example

Svelte

example

Rust

Code blocks moving function attributes and documentation

example

Code blocks not moving blocks between scopes

example

Python

example

*Supported languages

To support a language, tree-sitter querys are required to resolve blocks. This involves some manual labour for each language, but not much.

Also, to use a language, a tree-sitter grammar is required. There are many grammars already written, but to use them they need to be compiled. The extension will automatically download and compile the grammar for you, but it needs to know some metadata about each grammar.

For now, these are the default configured languages:

  • [x] Rust
  • [x] TypeScript
  • [x] TypeScript + JSX (typescriptreact)
  • [x] Svelte
  • [x] Python
  • [x] Java

Next up:

  • [ ] C#
  • [ ] C
  • [ ] C++
  • [ ] JavaScript

Adding a language

To add support for a language yourself, you'll need to:

  1. Configure the installation method of the grammar.

  2. Write the tree sitter queries for creating the blocks.

Here is an example of the configuration for Python:

"codeBlocks.languageSupport": {
    "python": {
        "parserInstaller": {
            "downloadCmd": "git clone https://github.com/tree-sitter/tree-sitter-python",
            "symbol": "language",
            "name": "tree_sitter_python"
        },
        "queries": [
            "(class_definition) @item",
            "(function_definition) @item",
            "(decorated_definition) @item"
        ]
    }
}

For figuring out how to write the queries, use the Tree-sitter playground.

  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2023 Microsoft