Skip to content

An unofficial LSP client for gitlab-lsp / Gitlab Duo Code Suggestions

License

Notifications You must be signed in to change notification settings

kassick/gitlab-lsp.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Emacs Gitlab-LSP client for lsp-mode

Gitlab Duo Code Assistant completions via Gitlab LSP

Installing

Via Use-Package

(use-package gitlab-lsp
  :quelpa (gitlab-lsp :fetcher github
                      :repo "kassick/gitlab-lsp.el"
                      :branch "main"
                      :files ("*.el"))
  :config

  ;; speed up completions
  (setq gitlab-lsp-show-completions-with-other-clients nil)

  (add-hook 'gitlab-lsp-complete-before-complete-hook
            (lambda ()
              ;; scroll to top so preview can show the snippet
              (recenter-top-bottom 4)

              ;; Show something, since we can not spin ...
              (message "Asking for suggestions ...")))

  (define-key global-map
              (kbd "C-*") '("Complete with Gitlab Duo" . gitlab-lsp-complete))
)

Spacemacs

;; In dotspacemacs/layers:

(setq-default
 ;; ...
 dotspacemacs-additional-packages
 '(
   ;; ...
   (gitlab-lsp :location (recipe
                          :fetcher github
                          :repo "kassick/gitlab-lsp.el"
                          :files ("*.el")))
   ;; ...
   )
 ;; ...
 )


;; In dotspacemacs/user-config:

(require 'gitlab-lsp)

;; speed up completions
(setq gitlab-lsp-show-completions-with-other-clients nil)

;; Scroll the buffer so we have more space for company preview frontend
(add-hook 'gitlab-lsp-complete-before-complete-hook
          (lambda ()
            ;; scroll to top so preview can show the snippet
            (recenter-top-bottom 4)

            ;; Show something, since we can not spin ...
            (message "Asking for suggestions ...")))

(define-key global-map
            (kbd "C-*") '("Complete with Gitlab Duo" . gitlab-lsp-complete))

Setup

Install the LSP Server

Run lsp-install-server <RET> gitlab-lsp to have lsp-mode download and install the server for you.

You can also manually install the server anywhere in your $PATH or adjust gitlab-lsp-executable to have lsp-mode use the external command.

Generate an Access Token

You must generate either a Personal Access Token or an OAuth Token to access your gitlab instance. The token must have the api scope.

Configure the LSP Client

  • Option 1: Secrets (GNOME Keyring or KDE Wallet): Simply open a file (of one of the supported modes) and you will be prompted for the Gitlab instance URL and token.

    You can also M-x gitlab-lsp-setup at any time to create or update the token and URL.

  • Option 2: Emacs Custom Variables: You can M-x customize-group <RET> gitlab-lsp and adjust the values of gitlab-lsp-server-url and gitlab-lsp-token.

  • Option 3: You may set the environment variables GITLAB_LSP_BASE_URL and GITLAB_LSP_TOKEN and the client will pick them up.

By default, gitlab-lsp will try to find the values in the environment variables, then custom variables, and finally secrets.

If you have your URL and token stored via secrets and then either (setenv "GITLAB_LSP_BASE_URL" "https://localhost:8080") or (setq gitlab-lsp-server-url "https://localhost:8080"), then the client will use the URL from the environment and the token from secrets.

Usage

Type your prompt and then either trigger company-mode completion (or wait on the timer). company-capf will call lsp-mode to provide completions, and then the configured gitlab instance will be contacted.

You can also bind gitlab-lsp-complete and use it to ask for Gitlab LSP completions only.

If you do not want every completion request going to gitlab-lsp, you can set gitlab-lsp-show-completions-with-other-clients to nil and use only gitlab-lsp-complete.

Known issues / limitations:

  1. Completion is slow -- yeah, the LSP server may take a while to complete. You may have to customize lsp-response-timeout.
  2. Now my other completions from (insert other LSP server here) take forever to show -- Yeah, the tooltip may be delayed until gitlab-lsp has returned results. You can (setopt gitlab-lsp-show-completions-with-other-clients nil) and bind gitlab-lsp-complete. This way, your standard, semantic completions work as expected, and you can still ask for code suggestions.
  3. How can I manually trigger only gitlab-lsp -- use gitlab-lsp-complete
  4. I only get no completions found -- make sure your lsp server has started correctly -- check the *gitlab-lsp::stderr* buffer and make sure that you see a Token is valid message.
  5. The single candidate appears as a very long line / The completion list obscures the code snippet to be inserted-- That's because company-mode is using the same UI for candidates and standard completions. This is a frontend issue, to be solved elsewhere.

About

An unofficial LSP client for gitlab-lsp / Gitlab Duo Code Suggestions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published