PitchHut logo
fold-logging.nvim
Automatically fold logging and debug-print statements in Neovim to declutter your code.
Pitch

fold-logging.nvim enhances the Neovim experience by automatically folding logging and debug-print statements while allowing for full compatibility with existing folding setups like Treesitter and LSP. Focus on writing code instead of managing folds, and customize your workflow with support for various languages and logging APIs.

Description

fold-logging.nvim

fold-logging.nvim is a Neovim plugin designed to automatically manage the folding of logging and debug-print statements, streamlining the code review process without disrupting existing folding configurations, like Treesitter or LSP setups.

Key Features

  • Automatically closes logging folds when opening supported files, ensuring a clean workspace.
  • Folds newly added logging statements upon file saves, while preserving manually opened folds.
  • Supports existing expr folds for functions, classes, and code blocks, integrating seamlessly with other systems.
  • Compatible with Treesitter folds, LSP folds, and nvim-origami.
  • Built-in support for Python logging calls and the option to fold standard debug-print calls such as print(...) and pprint(...).
  • Customizable minimum folded region size to control visibility of lone one-line calls while still folding adjacent logging blocks.
  • Extensible to custom languages and logging APIs using Lua patterns.
  • Provides an intuitive set of commands and Lua API for folding operations, including toggling, refreshing, and listing detections.

Usage Overview

Activating fold-logging.nvim is straightforward. Logging folds are automatically created and closed as files are opened, ensuring that developers face no distractions from logging statements. Manual control over folds can be achieved through various commands:

CommandAction
:FLFoldClose logging folds in the current buffer.
:FLUnfoldOpen logging folds in the current buffer.
:FLToggleToggle logging folds in the current buffer.
:FLRefreshRecompute logging folds after edits.
:FLListDisplay detected calls in the quickfix window.
:FLEnableRe-enable functionality for open buffers.
:FLDisableDisable and revert to previous folding methods.

Configuration Options

fold-logging.nvim can be customized via options passed through opts (or using require("fold-logging").setup{}). Here are the default settings:

{
  enable = true,
  auto_fold = true,
  fold_print = false,
  min_lines = 2,
  base_foldexpr = nil,
  languages = {
    python = {
      call_node_types = { "call" },
      patterns = {
        "%.debug$",
        "%.info$",
        "%.warning$",
        "%.warn$",
        "%.error$",
        "%.critical$",
        "%.exception$",
        "%.fatal$",
        "%.log$",
      },
      print_patterns = {
        "^print$",
        "^pprint$",
      },
    },
  },
}

Each option is designed to enhance the functionality:

  • enable: Master toggle for the plugin's operations.
  • auto_fold: Enables automatic folding of logging statements on file open and when the file is saved.
  • fold_print: Optionally includes basic print calls in folding behavior.
  • min_lines: Sets the minimum line count a logging region must have to be folded.
  • base_foldexpr: Custom folding expression that can be set if auto-detection is not desired.
  • languages: Allows the addition of custom pattern specifications for logging across multiple languages.

How to Extend Support for Additional Languages

To support new languages, fold-logging.nvim can define folding behavior for various Neovim filetypes. Each specification includes callable types and patterns relevant to that language:

opts = {
  languages = {
    go = {
      call_node_types = { "call_expression" },
      patterns = { "^fmt%.Print", "^log%.", "%.Debug$", "%.Info$" },
    },
  },
}

This setup allows the plugin to fold logging statements as defined by the custom patterns. For further customization, utilize :InspectTree to determine the appropriate call node types for new languages.

0 comments

No comments yet.

Sign in to be the first to comment.