joaotavora / sly

Sylvester the Cat's Common Lisp IDE
1.23k stars 139 forks source link

Fix search-import-from to not break package names having an argument as a prefix #643

Open svetlyak40wt opened 2 weeks ago

svetlyak40wt commented 2 weeks ago

When working with package-inferred systems, we have to deal with many packages and some of their names can be prefixes of another. Here is an example from a real-life application:

Now, let's imagine we are in the app/api/jobs package which already has a definition:

(uiop:define-package #:app/api/jobs
  (:use #:cl)
  (:import-from #:app/models/job-application
                #:some-func))
(in-package #:app/api/jobs)

(princ 'app/models/job:foo)

Now if we try to call M-x sly-import-symbol-at-point on app/models/job:foo symbol, then SLY will break the import-from form like this

(uiop:define-package #:app/api/jobs
  (:use #:cl)
  (:import-from #:app/models/job
                #:foo -application
                #:some-func))

This commit fixes the problem and after the fix, SLY will ignore import from app/models/job-application and will add a new import-from form.

For the minimal example to reproduce the problem I'm fixing, enter this code in the lisp buffer eval all package definitions and try to execute M-x sly-import-symbol-at-point command on foo:minor symbol:

(uiop:define-package #:foo-bar
  (:use #:cl)
  (:export #:blah
           #:minor))

(uiop:define-package #:foo
  (:use #:cl)
  (:export #:minor))

(uiop:define-package #:test-package
  (:use #:cl)
  (:import-from #:foo-bar
                #:blah)
  (:import-from #:foo))
(in-package #:test-package)

(princ-to-string 'foo:minor)