I'm getting mixed results with xref-js2 and want to confirm if what I'm seeing is expected or not. I'm using Emacs 27, and I have the following config:

(require 'ripgrep)
(require 'js2-mode)
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
(require 'xref-js2)
(setq xref-js2-search-program 'rg)
(add-hook 'js2-mode-hook (lambda ()
  (define-key js2-mode-map (kbd "M-.") nil)  
  (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t)))

When I call xref-find-definitions M+., sometimes it will jump right to the correct definition, but sometimes it doesn't. For example, when trying to locate the definition for a function selectStepGroups, I get this result:

139: groups: selectStepGroups(state),
68: const stepGroups = selectStepGroups(allState);
20: export const selectStepGroups = state => state[TYPE];
12: expect(selectStepGroups(transformed)).toBe(transformed.stepGroups);

From this result, I think it means that the xref backend is found, and it's using ripgrep. However it doesn't seem like it's filtering results based on the JS2 AST, as only the third result is a valid definition (the rest are just string matches.)

Is this the expected behavior? If not, have I misconfigured something?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.