Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Project Dependency should check for duplicates #510

Open
dgr opened this issue Feb 13, 2022 · 1 comment
Open

Add Project Dependency should check for duplicates #510

dgr opened this issue Feb 13, 2022 · 1 comment

Comments

@dgr
Copy link

dgr commented Feb 13, 2022

I added a dependency to a project but forgot to :require it in the namespace form. A few days later, thinking that I needed it again, I re-added it via ap. Later, when looking at the dips.edn file, I noticed that it was added twice.

Expected behavior

It should just add it to the project file (deps.edn, project.clj, etc.) once. If a duplicate is detected, do not add it to the project file, and possibly inform the user so that she doesn't think that she needs to restart the REPL to include the "new" dependency.

Actual behavior

Adds the dependency to the project file more than once. I have not checked whether this happens to all types of project files (e.g., deps.edn and project.clj) or just deps.edn.

Steps to reproduce the problem

Add a project to the project file twice using ap.

Environment & Version information

clj-refactor.el version information

cli-refactor 3.3.2 (package 20220213.1906), refactor-nrepl 3.3.2

CIDER version information

;; CIDER 1.3.0-snapshot (package: 20220213.1329), nREPL 0.9.0
;; Clojure 1.10.3, Java 17.0.2

Leiningen or Boot version

Emacs version

Emacs 28.0.91

Operating system

MacOS 12.2.1

@vemv
Copy link
Member

vemv commented Feb 13, 2022

Sounds like a resaonsable request.

The code that does the insertion in question is

(defun cljr--insert-into-clj-dependencies (artifact version)
(re-search-forward ":deps")
(forward-sexp)
(backward-char)
(newline-and-indent)
(let ((artifact (if (string-match-p "^.+/.+$" artifact)
artifact
(format "%s/%s" artifact artifact))))
(insert artifact " {:mvn/version \"" version "\"}")))

Doing an artifact search between the beginning and the end of the :deps "block" doesn't seem too hard. You can use Paredit commands for determining these boundaries.

PR welcome otherwise this might linger for quite a while.

Cheers - V

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants