FlaskLens
CodeLens support for Flask CLI commands in VS Code. FlaskLens uses fast
pattern matching to detect Flask CLI decorators, inline hints, and Python
entry points so you can run them directly from the editor. It also detects
terminal command blocks in Markdown files.
Features
- CodeLens for
@app.cli.command(...), @bp.cli.command(...), and
@bp.cli.group(...) decorators.
- CodeLens for inline hints like
# flask-cli: flask mycommand.
- CodeLens for
if __name__ == "__main__": blocks.
- CodeLens for terminal commands in Markdown fenced code blocks.
- Separate Run and Copy CodeLens actions for each detected command.
- Configurable Flask and Python executables plus extra arguments.
How It Works
FlaskLens scans Python files and comments for:
- Blueprint declarations like
bp = Blueprint("admin", __name__)
- CLI decorators like
@bp.cli.command("seed"), @app.cli.command(), and
@bp.cli.command(name="seed")
- Inline hints like
# flask-cli: flask db upgrade
- Main guards like
if __name__ == "__main__":
- Markdown fenced code blocks tagged as terminal languages like
bash, sh,
shell, zsh, terminal, console, powershell, pwsh, or cmd
It then adds Run and Copy CodeLens entries at those locations. Run sends the
related CLI command to the active terminal and executes it immediately. Copy
copies the command text to the system clipboard.
Quick Start
- Install the extension from the VS Code Marketplace.
- Open a Python or Markdown file in your Flask project.
- Hover above a CLI decorator, inline hint, main guard, or Markdown terminal
command and click the CodeLens.
Examples
Blueprint CLI command:
from flask import Blueprint
bp = Blueprint("admin", __name__)
@bp.cli.command("seed")
def seed():
...
App CLI command using the function name:
@app.cli.command()
def sync_users():
...
Inline CLI hint:
# flask-cli: flask db upgrade
Markdown terminal command:
```bash
$ flask db upgrade
npm test
```
Main guard:
if __name__ == "__main__":
print("abc")
Commands
FlaskLens: Open Route (flasklens.openRoute)
FlaskLens: Copy CLI Command (flasklens.copyCliCommand)
FlaskLens: Run CLI Command (flasklens.runCliCommand)
Configuration
FlaskLens exposes these settings:
flasklens.flaskExecutable: executable used for Flask CLI commands.
flasklens.flaskArgs: extra arguments inserted before detected Flask
subcommands.
flasklens.pythonExecutable: executable used for python current file.
flasklens.pythonArgs: extra arguments inserted before the current file
path.
Example:
{
"flasklens.flaskExecutable": "python",
"flasklens.flaskArgs": ["-m", "flask", "--app", "src/app.py"],
"flasklens.pythonExecutable": "python3",
"flasklens.pythonArgs": ["-X", "dev"]
}
Requirements
- VS Code 1.108.0 or newer
- Python files in your workspace
Release Notes
See CHANGELOG.md for version history.