Skip to content

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.

1 participant