Skip to content

Conversation

@Xuyuanp
Copy link
Owner

@Xuyuanp Xuyuanp commented Apr 29, 2025

No description provided.

@Xuyuanp
Copy link
Owner Author

Xuyuanp commented May 2, 2025

/gemini summary

@gemini-code-assist
Copy link

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

@Xuyuanp
Copy link
Owner Author

Xuyuanp commented May 2, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces several new features, including LSP API integration, improved context handling, and enhanced suggestion generation. The changes are substantial and touch various parts of the codebase. Overall, the code appears well-structured, but there are some areas that could benefit from further refinement and clarification.

Summary of Findings

  • Error Handling in with_token: The with_token function in lua/nes/api.lua uses a callback for error handling, but the error message is a simple string. Consider providing more context or a structured error object for better debugging.
  • Code Duplication: The code for removing specific lines (e.g., <next-version>, ```) is duplicated in lua/nes/core.lua and `lua/nes/context.lua`. This logic should be extracted into a utility function to improve maintainability.
  • Clarity of Context Class Fields: The purpose and usage of fields like original_code, edits, and current_version in the nes.Context class could be better documented to enhance understanding and maintainability.
  • Potential Performance Bottleneck: The generate_edits function in lua/nes/core.lua is called within a vim.schedule block. Ensure that this operation does not block the main thread, especially for large files or complex edits.

Merge Readiness

The pull request introduces significant functionality and is generally well-structured. However, addressing the identified issues related to error handling, code duplication, documentation, and potential performance bottlenecks would improve the code's robustness and maintainability. I am unable to directly approve the pull request, and other reviewers should review and approve this code before merging. I recommend addressing the high and medium severity issues before merging.

@Xuyuanp
Copy link
Owner Author

Xuyuanp commented May 2, 2025

/gemini summary

@gemini-code-assist
Copy link

Summary of Changes

This pull request introduces Language Server Protocol (LSP) support for the nes.nvim plugin, enabling features like inline code suggestions. The changes include adding a new LSP server implementation, modifying the core logic to fetch and apply suggestions as LSP edits, and updating the plugin's configuration and dependencies. The goal is to provide a more integrated and efficient code completion experience within Neovim.

Highlights

  • LSP Server Implementation: A new nes.lsp.server module is added, which handles LSP requests such as initialization, document synchronization, and inline edit requests. It manages a workspace of document contexts and uses nes.core to fetch suggestions.
  • Inline Edit Handling: The core logic in nes.core is modified to fetch suggestions and convert them into LSP TextEdit objects. These edits are then sent back to the client for application in the editor.
  • Context Management: The nes.context module is updated to provide more accurate context information for generating suggestions, including cursor position and code diffs. The cursor position is now 1-indexed.
  • Dependency Updates: The pull request removes the direct dependency on plenary.nvim and introduces mini.nvim for testing purposes. It also includes changes to the Makefile to manage dependencies and run tests.

Changelog

Click here to see the changelog
  • .gitignore
    • Added deps/ to ignore the dependencies directory.
  • Makefile
    • Added targets for running tests using mini.nvim.
    • Added a target to download mini.nvim as a dependency.
  • README.md
    • Removed nvim-lua/plenary.nvim from the list of dependencies.
    • Removed the dependencies section from the example configuration.
  • lsp/nes.lua
    • Added a new file to configure the LSP client, defining the command to start the server, the root directory, and the capabilities.
  • lua/nes/api.lua
    • Removed the dependency on plenary.curl and replaced it with a custom Curl implementation in nes.util.
    • Refactored the call function to use a token and handle API requests asynchronously with callbacks.
    • Added error handling and notifications for API request failures.
  • lua/nes/context.lua
    • Modified the Context class to use 1-indexed cursor positions.
    • Updated the new function to accept filename, original code, current code, cursor, and language as parameters.
    • Replaced get_current_version with _get_current_version to extract the current version of the code around the cursor.
    • Modified Context.new to use new_from_buffer.
  • lua/nes/core.lua
    • Modified parse_suggestion to not clear the suggestion.
    • Modified M.get_suggestion to clear the suggestion and display the next suggestion.
    • Added fetch_suggestions function to generate LSP edits from the suggested code.
    • Added generate_edits function to generate LSP edits from the suggested code.
  • lua/nes/init.lua
    • Removed highlight configurations.
  • lua/nes/lsp/server.lua
    • Added a new file to implement the LSP server, handling requests and notifications from the client.
    • Implemented handlers for initialize, initialized, textDocument/didOpen, textDocument/didSave, textDocument/didChange, textDocument/didClose, dollar_cancelRequest, and textDocument/copilotInlineEdit methods.
    • Implemented the on_inline_edit function to fetch and apply inline edits based on the current document context.
  • lua/nes/util.lua
    • Added a new file with utility functions, including notify for displaying notifications and text_edits_from_diff for generating LSP edits from diffs.
    • Added a custom Curl implementation for making HTTP requests.
  • plugin/nes.lua
    • Added highlight configurations.
  • scripts/minimal_init.lua
    • Added a script to set up mini.test for headless Neovim testing.
  • tests/test_core.lua
    • Added a basic test file for the core module.
  • tests/test_util.lua
    • Added a test file for the utility module, including tests for the text_edits_from_diff function.

Activity

  • Comment 1: Xuyuanp requested a summary from gemini.
  • Comment 2: gemini-code-assist[bot] noted that the installation is incomplete due to missing Terms of Service agreement.
  • Comment 3: Xuyuanp requested a review from gemini.
  • Comment 4: Xuyuanp requested a summary from gemini.

@Xuyuanp Xuyuanp force-pushed the feat/lsp-api branch 3 times, most recently from 22a3713 to 938e302 Compare May 7, 2025 11:50
@Xuyuanp Xuyuanp force-pushed the feat/lsp-api branch 5 times, most recently from d240f24 to c2aab54 Compare May 26, 2025 12:35
@Xuyuanp Xuyuanp force-pushed the feat/lsp-api branch 2 times, most recently from d6a5694 to 44d06c4 Compare June 9, 2025 02:32
@Xuyuanp Xuyuanp mentioned this pull request Jul 3, 2025
@aminroosta
Copy link

This looks really promising 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants