Skip to content

Commit

Permalink
Feature: inline completions (#4623)
Browse files Browse the repository at this point in the history
* fix: avoid calling line-number-at-pos with a value past the end of the buffer

When a overlay is displayed at the end of the buffer, (window-end) may return
a value that is past the end of the buffer. Calling line-number-at-pos with a
value outside of the buffer bounds raises an error.

* feat: Inline Completion support

Only the parser

* feat: Inline Completion default UI

* feat: do not consume the key used to cancel the current inline completion

* feat: better positioning of the cursor when the inline completion is displayed

* chore: do not warn of no suggestions when implicit

* feat: provide a minor mode for auto activating inline completions

* chore: avoid linter errors

* feat: better cursor positioning on accept

* fix: forward prefix arg

* fix: wrong function name

* fix: wrong number of arguments

* chore: use cl-map to avoid linting issues

* fix: avoid weird interactions with company-mode

Check if company is active before displaying the overlay -- hide it if so

* refactor: split parse and request -- may be handy in async

* fix: use current active map instead of global map

* fix: add external references

* feat: provide a method to inhibit inline completion mode

Add a list of predicates that can inhibit triggering inline completions --
e.g.:

    ```elisp
    (defun lsp-inline-completion-inhibit-if-company-active ()
        (and (bound-and-true-p company-mode) (company--active-p)))

      (push 'lsp-inline-completion-inhibit-if-company-active lsp-inline-completion-inhibit-predicates)
    ```

* chore: remove debug

* chore: keep interfaces sorted in lsp-protocol.el

* refactor: declare and use InlineCompletionParams and InlineCompletionContext

* fix: do not assume that the server response is a hash table

Also, refactor how we parse the response, using pcase for a more explicit approach

* refactor: move lsp-inline-completion-mode outside of lsp-mode.el

* refactor: extract company integration to a minor mode

Users can enable the lsp-inline-completion-company-integration-mode if they
see fit.

Other completion frontends may be customized via hooks, just as this minor
mode does

* refactor: use autoload to configure inline completions mode

* fix: ensure the callback is still executing in the context of the original buffer

* chore: use local variables for the company integration minor mode

* chore: remove ht as dependency

* fix: variable name

* fix: define minor mode before the functions that need to check for it

* chore: add missing type to custom variable

* fix: declare company--begin-inhibit-commands as a variable

* chore: do not use make-variable-buffer-local

* fix: use cl-map to make the compiler happy

* fix: ensure no state changes before triggering inline completion

lsp-inline-completion--after-change, added to lsp on-change hooks, is
triggered on a timer by `lsp--after-change`. The inline completion
maybe-display function is also triggered on a timer and it must check if the
position and current buffer did not change since the change as actually
occurred.

We can not store this state in lsp-inline-completion--after-change because the
user may have clicked somewhere before the timer activated it.

This commit introduces a `lsp--after-change-vals` plist to store the context
before the timers have been started.

lsp-inline-completion--after-change then fetches these values and forward as
arguments to the timer invocation of maybe-display, which then ensures that
the state has not changed.

* chore: no spinner on implicit inline completions

It is a distraction.

* chore: always cancel timer

* chore: autoload keymap

* chore: always show keys/status during active completion

* fix: autoload minor modes

* chore: fix indentation

Auto-substitution of tabs to space did not use the correct number of spaces

* chore: lsp--info when explicit completion request did not return

* chore: make show-keys private

* chore: update default keymap

* feat: on click, place the cursor at the correct point after completion

* chore: make suggestion insertion undoable
  • Loading branch information
kassick authored Dec 1, 2024
1 parent 5ac89ea commit 57ea512
Show file tree
Hide file tree
Showing 3 changed files with 575 additions and 5 deletions.
Loading

0 comments on commit 57ea512

Please sign in to comment.