Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add telescope pickers for markdown files and grepping #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

clpi
Copy link
Owner

@clpi clpi commented Nov 19, 2024

Add telescope functionality, a default picker, and pickers for markdown files and grepping in markdown files.

  • Telescope Configuration:

    • Add setup_telescope function in lua/telescope/_extensions/word/init.lua to configure telescope pickers for markdown files and grepping in markdown files.
    • Update setup function to call setup_telescope.
    • Update exports table to include new pickers for markdown files and grepping in markdown files.
  • Configuration Options:

    • Add configuration options for the new telescope pickers in lua/telescope/_extensions/word/config/init.lua.
  • Core Functionality:

    • Add core functionality for the new telescope pickers in lua/telescope/_extensions/word/core/init.lua.
  • Data Handling:

    • Add data handling for the new telescope pickers in lua/telescope/_extensions/word/data/init.lua.
  • Finders:

    • Add a new finder for browsing markdown files in lua/telescope/_extensions/word/finders/browse.lua.
    • Add a new finder for finding markdown files in lua/telescope/_extensions/word/finders/files.lua.
    • Add a new finder for grepping in markdown files in lua/telescope/_extensions/word/finders/grep.lua.
    • Update the init function in lua/telescope/_extensions/word/finders/init.lua to include the new finders.
    • Add a new root finder for the new telescope pickers in lua/telescope/_extensions/word/finders/root.lua.
  • Pickers:

    • Add a new picker for the new telescope pickers in lua/telescope/_extensions/word/picker/init.lua.
  • Utility Functions:

    • Add utility functions for the new telescope pickers in lua/telescope/_extensions/word/util/init.lua.
  • Integration:

    • Update lua/word/init.lua to call the new telescope pickers.
    • Add treesitter integration for the new telescope pickers in lua/word/mod/treesitter/init.lua.
    • Add UI integration for the new telescope pickers in lua/word/mod/ui/init.lua.
    • Add workspace integration for the new telescope pickers in lua/word/mod/workspace/init.lua.
    • Add UI components for the new telescope pickers in lua/word/ui/init.lua.

For more details, open the Copilot Workspace session.

Summary by Sourcery

Add new telescope pickers for markdown files and integrate them with existing modules to enhance markdown file handling capabilities.

New Features:

  • Introduce new telescope pickers for browsing and grepping markdown files, enhancing the functionality of the word extension.

Enhancements:

  • Integrate treesitter, UI, and workspace modules with the new telescope pickers to provide a seamless user experience.

Add telescope functionality, a default picker, and pickers for markdown files and grepping in markdown files.

* **Telescope Configuration:**
  - Add `setup_telescope` function in `lua/telescope/_extensions/word/init.lua` to configure telescope pickers for markdown files and grepping in markdown files.
  - Update `setup` function to call `setup_telescope`.
  - Update `exports` table to include new pickers for markdown files and grepping in markdown files.

* **Configuration Options:**
  - Add configuration options for the new telescope pickers in `lua/telescope/_extensions/word/config/init.lua`.

* **Core Functionality:**
  - Add core functionality for the new telescope pickers in `lua/telescope/_extensions/word/core/init.lua`.

* **Data Handling:**
  - Add data handling for the new telescope pickers in `lua/telescope/_extensions/word/data/init.lua`.

* **Finders:**
  - Add a new finder for browsing markdown files in `lua/telescope/_extensions/word/finders/browse.lua`.
  - Add a new finder for finding markdown files in `lua/telescope/_extensions/word/finders/files.lua`.
  - Add a new finder for grepping in markdown files in `lua/telescope/_extensions/word/finders/grep.lua`.
  - Update the `init` function in `lua/telescope/_extensions/word/finders/init.lua` to include the new finders.
  - Add a new root finder for the new telescope pickers in `lua/telescope/_extensions/word/finders/root.lua`.

* **Pickers:**
  - Add a new picker for the new telescope pickers in `lua/telescope/_extensions/word/picker/init.lua`.

* **Utility Functions:**
  - Add utility functions for the new telescope pickers in `lua/telescope/_extensions/word/util/init.lua`.

* **Integration:**
  - Update `lua/word/init.lua` to call the new telescope pickers.
  - Add treesitter integration for the new telescope pickers in `lua/word/mod/treesitter/init.lua`.
  - Add UI integration for the new telescope pickers in `lua/word/mod/ui/init.lua`.
  - Add workspace integration for the new telescope pickers in `lua/word/mod/workspace/init.lua`.
  - Add UI components for the new telescope pickers in `lua/word/ui/init.lua`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/clpi/word.lua?shareId=XXXX-XXXX-XXXX-XXXX).
Copy link

sourcery-ai bot commented Nov 19, 2024

Reviewer's Guide by Sourcery

This PR implements telescope integration for markdown files by adding new pickers for browsing and grepping markdown files. The implementation includes configuration options, core functionality, data handling, and UI integration across multiple modules.

Class diagram for new Telescope pickers

classDiagram
    class TelescopeExtension {
        +setup_telescope()
        +setup()
        +custom_picker()
        +browse_markdown_files(opts)
        +grep_markdown_files(opts)
    }
    class MarkdownFilePicker {
        +markdown_files(opts)
        +grep_markdown_files(opts)
    }
    class Finder {
        +browse_markdown_files(opts)
        +find_markdown_files(opts)
        +grep_markdown_files(opts)
    }
    class UIIntegration {
        +browse_markdown_files(opts)
        +grep_markdown_files(opts)
    }
    class WorkspaceIntegration {
        +browse_markdown_files(opts)
        +grep_markdown_files(opts)
    }
    class DataHandler {
        +browse_markdown_files(opts)
        +grep_markdown_files(opts)
    }
    class Utility {
        +get_markdown_files()
        +grep_markdown_files(query)
    }
    TelescopeExtension --> MarkdownFilePicker
    MarkdownFilePicker --> Finder
    Finder --> UIIntegration
    Finder --> WorkspaceIntegration
    Finder --> DataHandler
    Finder --> Utility
    UIIntegration --> Utility
    WorkspaceIntegration --> Utility
    DataHandler --> Utility
Loading

File-Level Changes

Change Details Files
Added new telescope pickers for markdown files
  • Implemented markdown_files picker for browsing markdown files
  • Implemented grep_markdown_files picker for searching within markdown files
  • Added configuration options for picker themes and layouts
  • Integrated with telescope.builtin for file finding and live grep functionality
lua/telescope/_extensions/word/picker/init.lua
lua/telescope/_extensions/word/config/init.lua
lua/telescope/_extensions/word/core/init.lua
Implemented finder modules for telescope integration
  • Created browse.lua for markdown file browsing functionality
  • Created files.lua for markdown file finding functionality
  • Created grep.lua for markdown file searching functionality
  • Added root finder to coordinate between different finder types
lua/telescope/_extensions/word/finders/browse.lua
lua/telescope/_extensions/word/finders/files.lua
lua/telescope/_extensions/word/finders/grep.lua
lua/telescope/_extensions/word/finders/root.lua
lua/telescope/_extensions/word/finders/init.lua
Added UI integration across multiple modules
  • Implemented browse_markdown_files UI function
  • Implemented grep_markdown_files UI function
  • Added workspace integration for telescope pickers
  • Added utility functions for telescope operations
lua/word/ui/init.lua
lua/word/mod/ui/init.lua
lua/word/mod/workspace/init.lua
lua/word/util/init.lua
Updated telescope extension setup and configuration
  • Added setup_telescope function for picker configuration
  • Updated exports table with new picker functions
  • Added telescope extension loading in main setup
  • Integrated with telescope actions and state management
lua/telescope/_extensions/word/init.lua
lua/word/init.lua

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @clpi - I've reviewed your changes - here's some feedback:

Overall Comments:

  • There is significant code duplication of the telescope picker implementation across multiple files (browse.lua, files.lua, grep.lua, etc). This should be consolidated into a single implementation that other modules can import and reuse.
  • Several hardcoded paths like "path/to/markdown/files" need to be parameterized and made configurable. Consider adding these to the config options.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -8,4 +8,28 @@ function M.word(ns)
a.nvim_create_namespace(ns)
end

function M.get_markdown_files()
local markdown_files = {}
local handle = io.popen('find . -type f -name "*.md"')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Consider using vim.fn.systemlist() instead of io.popen for better performance and safety

io.popen can be slow for large directories and may have platform compatibility issues. vim.fn.systemlist() is the recommended approach in Neovim.

  local markdown_files = vim.fn.systemlist('find . -type f -name "*.md"')

vim.api.nvim_create_autocmd({ "BufDelete", "WinClosed" }, {
buffer = buf,
once = true,
callback = function()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Consider using vim.schedule() for autocmd cleanup to prevent race conditions

The buffer cleanup in autocmds should be scheduled to avoid race conditions when multiple events fire simultaneously.

            callback = function()
                vim.schedule(function()
                    pcall(vim.api.nvim_win_close, window, true)
                    pcall(vim.api.nvim_buf_delete, buf, { force = true })
                end)

@@ -1,21 +1,15 @@
local hastel, tel = pcall(require, "telescope")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Add consistent error handling for all required modules

While pcall is used for some requires, others are direct. Consider using pcall consistently for all external module requires.

local hastel, tel = pcall(require, "telescope")
local hasact, act = pcall(require, "telescope.actions")
local hasset, set = pcall(require, "telescope.actions.set")

@clpi clpi self-assigned this Nov 23, 2024
@clpi clpi added the enhancement New feature or request label Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant