Function: bazel--target-completion-table-1

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

Signature

(bazel--target-completion-table-1 ROOT PACKAGE PATTERN ONLY-TESTS STRING)

Documentation

Return a completion table completing STRING to a Bazel target or pattern.

ROOT is the repository root directory, and PACKAGE is the current package name. If PATTERN is non-nil, complete target patterns and skip files. If ONLY-TESTS is non-nil, restrict rule target completion to test targets. 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-completion-table-1
    (root package pattern only-tests string)
  "Return a completion table completing STRING to a Bazel target or pattern.
ROOT is the repository root directory, and PACKAGE is the current
package name.  If PATTERN is non-nil, complete target patterns
and skip files.  If ONLY-TESTS is non-nil, restrict rule target
completion to test targets.  This is a helper function for
‘bazel--target-completion-table’."
  (declare (ftype (function (string string t t string) t)))
  (cl-check-type root string)
  (cl-check-type package string)
  (cl-check-type string string)
  ;; The cases below shouldn’t rebind the PACKAGE or ROOT parameters due to
  ;; https://bugs.gnu.org/53071.
  (pcase string
    ;; The following patterns should cover all potential target patterns from
    ;; https://bazel.build/run/build#specifying-build-targets as well as their
    ;; prefixes.  We are a bit more lenient than necessary to avoid convoluted
    ;; regular expressions.
    (""
     ;; By default, offer targets and subpackages of the current package, as
     ;; well as “//” to anchor the pattern at the root of the current
     ;; repository, since these are the most common patterns.  Also offer “@” to
     ;; select external repositories.
     (completion-table-merge
      (bazel--target-completion-table-2 root "" package pattern only-tests
                                        :colon)
      ;; Relative subpackages are only allowed in target patterns.
      (when pattern
        (bazel--target-package-completion-table root "" package pattern))
      '("//" "@")))
    ((rx bos (let prefix ?@) (* (not (any ?: ?/))) eos)
     ;; Completion for external repository names.  Also include the main (empty)
     ;; repository here.
     (bazel--completion-table-with-prefix prefix
       (completion-table-merge
        (when-let* ((dir (bazel--external-repository-dir root)))
          (bazel--target-repository-completion-table dir))
        '("//"))))
    ((rx bos (let prefix (* (not (any ?:))) "/...:"))
     ;; Combination of package wildcard and target wildcard.
     (when pattern
       (bazel--completion-table-with-prefix prefix
         '("all" "all-targets" "*"))))
    ((rx bos (let prefix (? ?@ (* (not (any ?: ?/))))) ?/ eos)
     ;; A single slash, optionally preceded by a repository reference, can only
     ;; be completed to “//”.
     (bazel--completion-table-with-prefix prefix '("//")))
    ((rx bos (? ?@ (let repository (* (not (any ?: ?/))))) "//" eos)
     ;; In the repository root, offer “:” to start completing rule targets, as
     ;; well as subpackages.
     (bazel--completion-table-with-prefix string
       (completion-table-merge
        '(":")
        (bazel--target-package-completion-table root (or repository "") ""
                                                pattern))))
    ((rx bos (let prefix (* (not (any ?:))) ?/) "..." eos)
     ;; A package wildcard may optionally be followed by a target wildcard.
     (when pattern
       (bazel--completion-table-with-prefix prefix '("..." "...:"))))
    ((rx bos (let prefix (* (not (any ?:))) ?/) (** 1 2 ?.) eos)
     ;; “/.” in a package name can only be completed to a package wildcard.
     (when pattern
       (bazel--completion-table-with-prefix prefix '("..."))))
    ((rx bos
         (? ?@ (let repository (+ (not (any ?: ?/))))) "//"
         (let pkg (+ (not (any ?:)))) ?/
         eos)
     ;; A full package name followed by a slash must be followed by a package
     ;; name or wildcard.
     (bazel--completion-table-with-prefix string
       (bazel--target-package-completion-table root (or repository "") pkg
                                               pattern)))
    ((rx bos
         (let prefix
           (? ?@ (let repository (* (not (any ?: ?/))))) "//"
           (let pkg (* (not (any ?:))))
           ?:)
         (* (not (any ?:)))
         eos)
     ;; Absolute target label prefix, including the colon.  Must complete to a
     ;; target label.
     (bazel--completion-table-with-prefix prefix
       (bazel--target-completion-table-2 root (or repository "") pkg pattern
                                         only-tests nil)))
    ((rx bos
         (let prefix (? ?@ (let repository (* (not (any ?: ?/))))) "//")
         (+ (not (any ?:)))
         eos)
     ;; Absolute package prefix, without colon.  Must complete to a package
     ;; name.
     (bazel--completion-table-with-prefix prefix
       (bazel--target-package-completion-table root (or repository "") ""
                                               pattern)))
    ((rx bos (let prefix ?:) (* (not (any ?:))) eos)
     ;; Target pattern relative to the current package.
     (bazel--completion-table-with-prefix prefix
       (bazel--target-completion-table-2 root "" package pattern
                                         only-tests nil)))
    ((rx bos (+ (not (any ?:))) ?/ eos)
     ;; Subpackage or subdirectory of the current package followed by a slash.
     ;; Normally followed by another package name or wildcard, but can also be a
     ;; target name containing a slash.  The interpretation of this clause
     ;; differs between target patterns and labels in BUILD files.
     (if pattern
         (bazel--target-package-completion-table root "" package pattern)
       (bazel--target-completion-table-2 root "" package pattern
                                         only-tests nil)))
    ((rx bos
         (let prefix (let subpackage (+ (not (any ?:)))) ?:)
         (* (not (any ?:)))
         eos)
     ;; Target pattern in a subpackage of the current package.  Must be
     ;; followed by a target name or wildcard.
     (when pattern
       (let ((pkg (if (string-empty-p package)
                      subpackage
                    (concat package "/" subpackage))))
         (bazel--completion-table-with-prefix prefix
           (bazel--target-completion-table-2 root "" pkg pattern
                                             only-tests nil)))))
    ((rx bos (+ (not (any ?:))) eos)
     ;; Something else, could be either a target or a subpackage of the current
     ;; package.  Prefer targets.
     (completion-table-merge
      (bazel--target-completion-table-2 root "" package pattern only-tests
                                        :colon)
      (when pattern
        (bazel--target-package-completion-table root "" package pattern))))))