Function: bazel--complete-targets

bazel--complete-targets is a natively compiled function defined in bazel.el.

Signature

(bazel--complete-targets PREFIX ONLY-TESTS)

Documentation

Find all rule targets starting with the given PREFIX in the current buffer.

The current buffer should visit a BUILD file. Return a list of target names that start with PREFIX. If ONLY-TESTS is non-nil, restrict the returned targets to test targets.

The returned target name strings have a ‘bazel-target-kind’ property that specifies the rule kind if the target, if it can be determined.

Source Code

;; Defined in /nix/store/ws8pkszjvcad1rgzqw6wja7qxacylfhn-emacs-packages-deps/share/emacs/site-lisp/elpa/bazel-20261002.1510/bazel.el
(defun bazel--complete-targets (prefix only-tests)
  "Find all rule targets starting with the given PREFIX in the current buffer.
The current buffer should visit a BUILD file.  Return a list of
target names that start with PREFIX.  If ONLY-TESTS is non-nil,
restrict the returned targets to test targets.

The returned target name strings have a ‘bazel-target-kind’ property
that specifies the rule kind if the target, if it can be determined."
  (declare (ftype (function (string t) list)))
  (cl-check-type prefix string)
  (when (derived-mode-p 'bazel-mode)
    (let ((case-fold-search nil)
          (search-spaces-regexp nil)
          (targets ()))
      (save-excursion
        ;; We don’t widen here.  If the user has narrowed the buffer, it’s fair
        ;; to assume they only want completions within the narrowed portion.
        (goto-char (point-min))
        (while (re-search-forward
                (rx symbol-start "name" (* blank) ?= (* blank)
                    (group (any ?\" ?'))
                    (group (literal prefix) (* (not (any ?\" ?' ?\n))))
                    (backref 1))
                nil t)
          (let ((name (match-string-no-properties 2)))
            (unless (python-syntax-comment-or-string-p)
              (let ((kind (bazel--target-kind)))
                (when (or (not only-tests) (bazel--is-test-target-p kind))
                  (push (if kind (propertize name 'bazel-target-kind kind) name)
                        targets)))))))
      (nreverse targets))))