Add import extraction support to Structure#838
Open
dalemyers wants to merge 1 commit into
Open
Conversation
Collaborator
|
Thanks for the PR; I think the best way for applications to get this info is, instead of using SourceKitten, to use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ImportInfotype that extracts import statements from SourceKit syntax maps, including support for@testable/@_exportedattributes, submodule imports (e.g.Foundation.NSObject), and kind-qualified imports (e.g.import class Foundation.NSObject)Structurewith anextractImportsparameter that populates akey.importsarray in the structure dictionary--importsflag to thesourcekitten structureCLI commandDetails
Import information is currently lost when Structure strips the syntax map from the SourceKit response. This change optionally preserves it by extracting imports before discarding the syntax map.
The feature is opt-in (
extractImports: falseby default) so there are no changes to existing behavior.Each import entry includes:
key.name— full import path (e.g.Foundation.NSObject)key.offset/key.length— byte range covering the full statement including attributeskey.attributes— array of attributes like@testablewith their own offsets/lengthskey.import_kind— declaration kind for qualified imports (class,struct,func, etc.)key.module_name— first path component for dotted importsExample
demo.swift:
Output: