
[19:53:42]: ==> {"id":"3","method":"analysis.updateContent","params":{"files":{"/Users/danny/Dev/Google/flutter/examples/hello_world/lib/main.dart":{"content":"import 'package:flutter/widgets.dart';\n\nvoid main() {\n runApp(\n Center(\n child: Text('Hello, world!', textDirection: TextDirection.ltr),\n ),\n );\n}\n\nvoid main2() => runApp(const Center(\n child: const Text('Hello, world!', textDirection: TextDirection.ltr)));\n","type":"add"}}}}
{
"message": "Wrap with new widget",
"edits": [
{
"file": "/Users/danny/Dev/Google/flutter/examples/hello_world/lib/main.dart",
"fileStamp": 0,
"edits": [
{
"offset": 68,
"length": 83,
"replacement": "new widget(\n child: Center(\n child: Text('Hello, world!', textDirection: TextDirection.ltr),\n ),\n )"
}
]
}
],
The indent looks correct coming back from the server when I tested (6 spaces) so I think this might be not playing nicely with Code's auto-indent, so the line ended up indented by 10 spaces.
Hmmm, this seemed to work fine!
export class AssistCodeActionProvider implements CodeActionProvider {
private analyzer: Analyzer;
constructor(analyzer: Analyzer) {
this.analyzer = analyzer;
}
public provideCodeActions(document: TextDocument, range: Range, context: CodeActionContext, token: CancellationToken): CodeAction[] {
return [this.convertResult(document, range)];
}
private convertResult(document: TextDocument, range: Range): CodeAction {
const edit = new WorkspaceEdit();
edit.insert(document.uri, range.start, "// not indented\r\n // four space indent\r\n // eight space indent\r\n");
return {
edit,
kind: CodeActionKind.Refactor,
title: "INSERT SOME FORMATTED TEXT",
};
}
}
Maybe unrelated to this, but found a strange bug with the code action request we get from Code while looking: https://github.com/Microsoft/vscode/issues/43957
@xster I can't repro this now! :(
Can you? If so, can you give me a copy of the exact file and where you invoked it?
I still can on 2.9.0-beta.1. It's on this line:
https://github.com/xster/flutter-test/blob/master/t69_flashing_sliver_padding/lib/main.dart#L73
Saw the same thing with override completion too (might be easier to repro with this one, code is simpler):
https://github.com/flutter/flutter-intellij/issues/1110#issuecomment-367258977
Made a small repro and opened https://github.com/Microsoft/vscode/issues/44200
The completion issue I mentioned above is being fixed, but it turned out this one was different. The new upstream issue is https://github.com/Microsoft/vscode/issues/63129.
It doesn't seem like this is ever going to be fixed in VS Code, as the issue was marked as a feature rather than a bug (!). I'm going to see if I can work around it by just subtracting the indenting I know VS Code will inject (we'll need to undo that if they ever to fix it though).
Unfortunately it turns out that the way I hoped to work around this won't work - in many of the edits the indentation we want is less than that of the current line, which means we can't just chop off the start what we know VS Code will insert, because in some cases it will insert more than there is in the source edit.
Seems like we'll have to wait for https://github.com/microsoft/vscode/issues/63129 to be fixed (I've pinged the issue again, but it's been around a long time with no response). I can't come up with another way to go into snippet-mode (as required for the tabstops) without using this (broken) function.
I'm having the same issue .. Wrap with widget adds 5 extra indents to the child attribute below

Yep, this is the same VS Code issue mentioned above. I might have a look at contributing the fix to VS Code - since completions already have a similar fix I'm hoping it won't be too difficult.
This issue doesn't occur in LSP as the edits are applied slightly differently. The goal is to enable LSP by default in an upcoming release and the non-LSP code eventually dropped.
Most helpful comment
Yep, this is the same VS Code issue mentioned above. I might have a look at contributing the fix to VS Code - since completions already have a similar fix I'm hoping it won't be too difficult.