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

How to get the code by name using SourceKitten? #812

Open
moonshineBoy opened this issue Mar 30, 2024 · 0 comments
Open

How to get the code by name using SourceKitten? #812

moonshineBoy opened this issue Mar 30, 2024 · 0 comments

Comments

@moonshineBoy
Copy link

I have a main.swfit swift file like below:

import Foundation

func functest() {
  print(123)
}

I can use sourcekitten structure to get function names:

sourcekitten structure --file main.swift | jq '."key.substructure"[] | select(."key.kind" == "source.lang.swift.decl.function.free") | ."key.name"' 

and match the functions:

sourcekitten structure --file main.swift | jq '."key.substructure"[] | select(."key.kind" == "source.lang.swift.decl.function.free") '  

the result:
image

but how to get source code ?

I want to implement a function given the function name( functest ) then return the source code

func functest() {
  print(123)
}
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

1 participant