昨天我們順利將 code 進行改寫
但會有幾個問題要處理
首先,我們不打算複寫原本的檔案,反而只是在過程當中偷改 code
CursorInfo
只能給予 file path{
<key.request>: (UID) <source.request.cursorinfo>,
[opt] <key.sourcetext>: (string) // Source contents.
[opt] <key.sourcefile>: (string) // Absolute path to the file.
// **Require**: key.sourcetext or key.sourcefile
[opt] <key.offset>: (int64) // Byte offset of code point inside the source contents.
[opt] <key.usr>: (string) // USR string for the entity.
// **Require**: key.offset or key.usr
[opt] <key.compilerargs>: [string*] // Array of zero or more strings for the compiler arguments,
// e.g ["-sdk", "/path/to/sdk"]. If key.sourcefile is provided,
// these must include the path to that file.
[opt] <key.cancel_on_subsequent_request>: (int64) // Whether this request should be canceled if a
// new cursor-info request is made that uses the same AST.
// This behavior is a workaround for not having first-class
// cancelation. For backwards compatibility, the default is 1.
}
key.sourcefile: Target.swift
key.compilerargs:
- Target.swift
- file1.swift
- file2.swift
- xxx.swift
- other args
key.sourcetext: newCode
key.sourcefile: Target.swift
key.compilerargs:
- Target.swift
- file1.swift
- file2.swift
- xxx.swift
- other args
透過這樣的改動,我們可以對 SourceKit
說
我們現在要詢問的對象檔案是 Target.swift
並且 code 部分,是參照我們提供的 newCode