Code Lenses

Learn how to use Code Lenses for quick code actions and insights

Quick AI Actions with Code Lenses

Code Lenses in Windsurf provide one-click access to common AI features directly within your code, aiming to streamline tasks like code explanation, refactoring, and documentation.

How They Work:

  • Location: Appear above the relevant code block (e.g., function, class) your cursor is in, or directly above each semantic block in supported IDEs like IntelliJ.
  • Interaction: Simply click a Code Lens to trigger its AI-powered action.

Core Actions:

  1. 1.

    Explain:

    • Clicking "Explain" sends the selected code block to Cascade.
    • Cascade provides an explanation in a new conversation.
    • Useful for quickly understanding unfamiliar code.
  2. 2.

    Refactor:

    • Offers a list of refactoring options (e.g., "check for bugs and null pointers").
    • Applies changes directly as inline edits to your code.
  3. 3.

    Add Docstring:

    • Automatically generates and applies documentation (e.g., JSDoc, Python docstrings) for the selected code block, adhering to language standards.

Scope and Alternatives:

  • Focused Scope: Code Lens actions target the specific semantic block where your cursor is located.
  • Broader Scope:
    • For inline edits on a larger selection: Highlight code and press Cmd+I (Mac) or Ctrl+I (Windows/Linux).
    • To send a larger selection to Cascade: Highlight code and press Cmd+L (Mac) or Ctrl+L (Windows/Linux).

Availability:

Code Lenses are currently available in the Windsurf editor and IntelliJ for supported languages.

They offer a quick way to get AI assistance for common coding tasks.

Customization Options

Enable/Disable: Toggle Code Lenses on or off in settings.

Filter Actions: Choose which types of Code Lenses to display.

Best Practices

  • Use Code Lenses for quick code improvements during development
  • Generate tests early to maintain good code coverage
  • Add documentation as you write code for better maintainability
  • Use refactoring suggestions to improve code quality