madskristensen / AddAnyFile

A Visual Studio extension
Apache License 2.0
262 stars 119 forks source link

Attempt to fix #90 by registering adding the item as from a template. #101

Closed timheuer closed 2 years ago

timheuer commented 2 years ago

Making this change will now run any .editorconfig rules in the project and thus things like honoring file-scoped namespaces. Unknown other side-affects on other scenarios, but this works for .cs :-)

With this change and existence of .editorconfig the rules will apply. This loses the template caret position behavior however, but mimics existing behavior of item templates (add class) where caret position is at 0. It maintains the template behavior if not going through the formatter though.

kelps commented 2 years ago

Ok, I am impressed! Looks like a very simple fix. I really hope there are no side effects. There are 3 extensions I use almost every day and this is one of them.

The other ones are Open Command Line [ Alt + Space ] and Extension Manager. In my view, all 3 should already by built-in features in VS.

timheuer commented 2 years ago

Working through a side-effect issue right now in subfolders (and caret positioning is a secondary problem). May take a bit to debug why AddFromTemplate change is having an issue with subfolders :-(

timheuer commented 2 years ago

Blocked by this scenario bug: https://github.com/dotnet/roslyn/issues/58311

timheuer commented 2 years ago

Ok, this appears to work...now on to the caret placement logic change 🤔🤔🤔🤔 -- THANK YOU @davidwengier for helping to take a look and confirming where to change.

timheuer commented 2 years ago

@madskristensen I did a bunch of "works on my machine" testing but would be good for any other eyes on it. See note about the caret template capability though. Since formatting happens after project system adding, the placeholder caret positioner is already gone and the position is now invalid and will just go to index=0. This is the same behavior as item templates today in this same method.

madskristensen commented 2 years ago

It works in SDK style .NET projects, but not in .NET Framework legacy projects. Looking into it now...

timheuer commented 2 years ago

😡 CPS doesn't like a full path for AddFolder as it has a : char in it...

madskristensen commented 2 years ago

Yeah, I got it almost working with relative paths. It seems to work everywhere, except for multiple subfolders on legacy .NET projects

timheuer commented 2 years ago

It appears that AddFolder for legacy doesn't like a full new nested path eg folder1\folder2\folder3 whereas CPS allows this and will create all folders in the nested path. AddFile and AddFromTemplate seem to have diff behavior from legacy vs. CPS :-(

madskristensen commented 2 years ago

I'm doing a loop to add each subfolder individually before adding the file. That should work, but will be slower

davidwengier commented 2 years ago

Could also just be a timing thing. CPS will see the changes on disk and add the files/folders itself because of the default globs in the SDK, so if that happens first then AddFolder might not even be doing anything.