Function: bazel--target-repository-completion-table

bazel--target-repository-completion-table is a natively compiled function defined in bazel.el.

Signature

(bazel--target-repository-completion-table ROOT)

Documentation

Return a target completion table for external repository names.

ROOT is the parent directory of the external repositories as returned by ‘bazel--external-repository-dir’. This is a helper function for ‘bazel--target-completion-table’.

Source Code

;; Defined in /nix/store/ws8pkszjvcad1rgzqw6wja7qxacylfhn-emacs-packages-deps/share/emacs/site-lisp/elpa/bazel-20261002.1510/bazel.el
(defun bazel--target-repository-completion-table (root)
  "Return a target completion table for external repository names.
ROOT is the parent directory of the external repositories as
returned by ‘bazel--external-repository-dir’.  This is a helper
function for ‘bazel--target-completion-table’."
  (declare (ftype (function (string) t)))
  (cl-check-type root string)
  (lambda (string predicate action)
    (cl-check-type string string)
    (cl-check-type predicate (or null function))
    ;; Restrict completions to valid repository names.
    (let ((completion-regexp-list
           (cons (rx bos (+ (any "A-Z" "a-z" "0-9" ?_ ?- ?.)) eos)
                 completion-regexp-list)))
      (bazel--make-conjunction predicate candidate
        (bazel--target-completion-directory-p candidate))
      ;; The file name completion functions return directory names for
      ;; directories, so we turn them back into directory filenames, otherwise
      ;; the target syntax ‘@foo’ wouldn’t work.
      (ignore-error file-error
        (pcase action
          ('nil
           (when-let* ((name (file-name-completion string root predicate)))
             (let ((result (directory-file-name name)))
               ;; Fulfill the contract of ‘try-completion’.
               (if (string-equal result string) t result))))
          ('t
           (pcase (cl-loop for cand in (file-name-all-completions string root)
                           if (funcall predicate cand)
                           collect (directory-file-name cand))
             (`(,(and candidate (pred (string-equal string))))
              ;; A single exact match; offer root package as well.
              (list candidate (concat candidate "//")))
             (candidates candidates)))
          ('lambda
            ;; The target ‘@foo’ is a shorthand for ‘@foo//:foo’.  We don’t
            ;; check for the existence of the ‘foo’ target here.
            (and (not (string-empty-p string))
                 (not (directory-name-p string))
                 (file-accessible-directory-p
                  (expand-file-name string root))
                 (funcall predicate (file-name-as-directory string))))
          (`(boundaries . ,suffix)
           `(boundaries 0 . ,(string-match-p (rx (any ?/ ?:)) suffix))))))))