Skip to content

Conversation

@sudo-tee
Copy link
Owner

@sudo-tee sudo-tee commented Jan 6, 2026

… priority handling

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the completion engine integration to standardize the interface across different completion systems (nvim-cmp, blink.cmp, and vim's built-in completion). The refactoring introduces a base CompletionEngine class that provides common functionality and a unified API for all engines.

Key Changes:

  • Introduced CompletionEngine base class with standardized methods for setup, trigger, and completion callbacks
  • Refactored all completion engines to inherit from the base class and use centralized priority handling
  • Added engine factory pattern in completion.lua for consistent engine instantiation

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
lua/opencode/ui/input_window.lua Added type annotation cast and removed commented code for cleaner implementation
lua/opencode/ui/completion/engines/vim_complete.lua Converted to class-based structure inheriting from CompletionEngine, using shared priority handling
lua/opencode/ui/completion/engines/nvim_cmp.lua Refactored to class-based structure with standardized trigger and completion methods
lua/opencode/ui/completion/engines/blink_cmp.lua Converted to class-based structure with dual interface pattern supporting both engine and provider modes
lua/opencode/ui/completion.lua Added engine factory with configuration mapping and centralized engine lifecycle management
Comments suppressed due to low confidence (1)

lua/opencode/ui/completion/engines/blink_cmp.lua:151

  • The Source:get_completions method doesn't use the refactored priority handling like the BlinkCmpEngine. It directly fetches completion_sources and manually builds items with priority formatting, rather than using the base class's get_completion_items method which returns wrapped items with normalized priorities. This means the Source provider path (used by blink.cmp) and the BlinkCmpEngine path diverge in their implementation, creating code duplication and potential inconsistencies in priority handling.
    local items = {}
    for _, source in ipairs(completion_sources) do
      local source_items = source.complete(context):await()
      for i, item in ipairs(source_items) do
        local insert_text = item.insert_text or item.label
        table.insert(items, {
          label = item.label,
          kind = item.kind,
          kind_icon = item.kind_icon,
          kind_hl = item.kind_hl,
          detail = item.detail,
          documentation = item.documentation,
          filterText = item.filter_text or item.label,
          insertText = insert_text,
          sortText = string.format('%02d_%02d_%02d_%s', source.priority or 999, item.priority or 999, i, item.label),
          score_offset = -(source.priority or 999) * 1000 + (item.priority or 999),
          data = {
            original_item = item,
          },
        })
      end
    end

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

epheien pushed a commit to epheien/opencode.nvim that referenced this pull request Jan 8, 2026
… integration and source priority handling
… priority handling

- Standardized trigger, setup, and completion callbacks for all engines.
- Fix blink opening path completion sometimes this should fix #130
- Change trigger pattern to match from end of string only, preventing false triggers
- Remove redundant CompletionEngine require calls in blink_cmp source methods
@sudo-tee sudo-tee force-pushed the fix/issue-130-completion-false-trigger branch from 8dd1332 to 965bc68 Compare January 13, 2026 13:53
…sues

- Fix blink_cmp execute to use correct method call syntax
- Add augroup to vim_complete for proper autocmd cleanup
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

lua/opencode/ui/completion/engines/blink_cmp.lua:147

  • The Source:get_completions method manually iterates through completion sources instead of using the centralized engine:get_completion_items method. This creates inconsistency with nvim_cmp and vim_complete engines which both use the centralized method. This duplication makes the code harder to maintain and could lead to behavior differences between engines. Consider refactoring to use a shared approach, possibly by making the engine instance accessible to the Source object through a closure or module-level variable, similar to how nvim_cmp handles it.
    local items = {}
    for _, source in ipairs(completion_sources) do
      local source_items = source.complete(context):await()
      for i, item in ipairs(source_items) do
        local insert_text = item.insert_text or item.label
        table.insert(items, {
          label = item.label,
          kind = item.kind,
          kind_icon = item.kind_icon,
          kind_hl = item.kind_hl,
          detail = item.detail,
          documentation = item.documentation,
          filterText = item.filter_text or item.label,
          insertText = insert_text,
          sortText = string.format('%02d_%02d_%02d_%s', source.priority or 999, item.priority or 999, i, item.label),
          score_offset = -(source.priority or 999) * 1000 + (item.priority or 999),
          data = {
            original_item = item,
          },
        })
      end
    end

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@sudo-tee sudo-tee merged commit f52a22d into main Jan 13, 2026
10 checks passed
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.

/ won't trigger commands sometimes

2 participants