Skip to content

Do not restore loose files which lack file-based app directives #81252

@RikkiGibson

Description

@RikkiGibson

We made a change in #80743 to use a "canonical misc files project", instead of restoring as a file-based app, for files which meet the following conditions:
(1) Not part of any loaded project, AND
(2) No top-level statements, AND
(3) No #!/#: directives

I am proposing to delete criteria (2), and to ensure that a file is only ever restored and treated as a file-based app, when it has #!/#: directives. More background/details below:

Background

The previous state of affairs, was causing frequent unwanted restore popups, because (1) is a condition which changes "ambiently" over time. When the workspace is first opened, the projects aren't loaded yet. When files are created or moved, the project needs to be design-time built in order to realize the file is part of a project. And so on.

Using a single canonical misc project instead, allows us to avoid the unwanted restore popups (including the one for Canonical.cs itself in #81233), as well as unwanted artifacts appearing in the user's repo under certain conditions, while continuing to provide the "rich misc files" experience, including semantic errors, completions and Quick Info for the core library.


The case that remains, where unwanted restore popups can still occur, is the following, where there are no #!/#: directives at all, yet the file is part of an ordinary project:

Console.WriteLine("Hello World!");

With the proposed change to delete the "no top-level statements" condition above, this file is never treated as a file-based app by the editor. It will never be restored as a file-based app. Rather it just gets errors/completions/classification/etc for the standard library.

Essentially, the above sample can only ever be either a misc file, or, part of an ordinary project.

In order to actually treat the above as a file-based app in the editor, the user will need to do something like the following:

#!/usr/bin/env dotnet
Console.WriteLine("Hello World");

OR

#:sdk Microsoft.Net.Sdk // or ANY #: directive
Console.WriteLine("Hello World");

I want the presence of the directive(s) to serve as a signal for both the IDE and the reader, that this is affirmatively meant to be a file-based app, before we start restoring it.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions