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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

svetlyak40wt
Copy link
Contributor

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:

  • app/models/job
  • app/models/job-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)

…as a prefix

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:

- app/models/job
- app/models/job-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)
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

Successfully merging this pull request may close these issues.

None yet

1 participant