Tatsuhiko Mizuno
Tatsuhiko Mizuno

Reputation: 457

vscode dart formatter doesn't work outside the workspace

I'm using a dart extension in my VS code. If I add a project folder to worlspace and create a new dart file in it, formatting will work automatically on save. However, if I create a new file outside the workspace, a syntax error or formatter will not work. Why doesn't the dart extension work when other extensions such as prettier are working?

in workspace↓(syntax error is work)

outside workspace ↓

after I click the "Debug" and "Run" at files outside the workspace,the formatter worked fine but I still don't see any syntax errors.

Upvotes: 0

Views: 346

Answers (1)

Danny Tuppeny
Danny Tuppeny

Reputation: 42343

When you have folders open, only the files in those folders are analyzed. There are couple of reasons for this, but a significant one is that VS Code does not tell extensions when you close a file (see https://github.com/microsoft/vscode/issues/15178 - a long standing request) so if errors were produced for files outside of your workspace and you closed those files, the errors would remain in the Problems view for up to three minutes (which is the time at which VS Code garbage collects closed documents and finally tells extensions about them). This can be quite confusing (and frustrating).

It's recommend to always open the folders that contain the files you are editing. There's a lot of the Dart/Flutter extensions that work assuming this is the case.

Note: Things are slightly different if you don't open any folders at all, in which case open folders may be inferred - but functionality will still be limited - the server supports this mode mainly for lightweight editors like Vim where it may be common to specifically open a single file rather than a folder/workspace.

Upvotes: 1

Related Questions