Skip to content

Instructed Suggestions

Introduced on 2024-09-12

Sometimes you may want the suggestions to complete or modify the code in the way you want. You can use instructed suggestions to achieve this.

There are two types of instructed suggestions:

  1. Keep Writing: This will guide the model to continue writing the code as instructed.
  2. Rewrite: This will guide the model to rewrite the current line to meet the instruction.

Keep Writing

For example, you have the following code:

struct Foo: View {
var body: some View {
Rectangle()
}
}

You may want the rectangle to have a specific size. So you keep writing the code in this way:

struct Foo: View {
var body: some View {
Rectangle()
.frame\\\ w 200 h 300
.frame\\> w 200 h 300
.frame//> w 200 h 300
}
}

And the app may generate the correct code for you .frame(width: 200, height: 300).

Rewrite

For rewrite, you can use another token \\< to tell the app to rewrite the current line.

For example, you have the following code:

struct Foo {
var 助手: String\\< english name
var 助手: String//< english name

And the app may generate the correct code for you var assistant: String.

If no instruction is provided, the app will try to use warning/error messages as the instruction.

For example, you have the following code:

func foo() async {
doSomethingAsync() //<
^ error: Expression is 'async' but is not marked with 'await'
}

The app may fix the code for you by adding await in the correct place.