+
Skip to content

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

@moonshineBoy

Description

@moonshineBoy

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载