tgjones / HlslTools

A Visual Studio extension that provides enhanced support for editing High Level Shading Language (HLSL) files
http://timjones.io/blog/archive/2016/04/25/hlsl-tools-for-visual-studio-v1.0-released
Other
561 stars 97 forks source link

Unreal files with extension .usf and .ush not parsing correctly. #196

Closed PiezPiedPy closed 3 years ago

PiezPiedPy commented 3 years ago

Unreal shader files that are open in VS2019 will parse correctly when the solution is first opened but any other .ush .usf files that are then opened will not parse unless VS2019 is closed and then reopened.

Also when pasting text into an unreal shader file that appears to have parsed correctly, results in the text being pasted twice into the file.

I made a private build of HlslTools with the Unreal extensions added but it resulted in no change in outcome apart from the fact that I no longer need to add the extensions in VS2019 Text editor extension options.

Branch in my fork is here https://github.com/PiezPiedPy/HlslTools/tree/UE4

PiezPiedPy commented 3 years ago

After making some more changes to my build I have managed to fix the problem but only on the experimental build of VS2019.

When running on the normal version of VS2019 InvalidCastExceptions are thrown in Method TaskExtensions.cs:WaitAndGetResult_CanCallOnBackground at line 45 task.Wait(cancellationToken);

https://github.com/tgjones/HlslTools/blob/f0d81cbff28069cbf967bbb8868d873608fbfe16/src/ShaderTools.Utilities/Threading/TaskExtensions.cs#L41-L47

Strange that the code has no issues running in the experimental build.

PiezPiedPy commented 3 years ago

I have found the InvalidCastException, it was due to the GetOption method not being able to cast a String to an Enum.

I have now fixed this issue but .ush and .usf files are still not parsing in the standard version of VS2019. 🤦‍♂️

See commit https://github.com/PiezPiedPy/HlslTools/commit/66192dfb9ee7a31549dfda3b083da75fd0f7907f

Since I have no idea how VS Extensions work I am a bit stumped. I will continue to nose about in the source and hope I can work things out.

PiezPiedPy commented 3 years ago

I added some thread safety and it appeared to improve things, sometimes the files would parse other times they would not.

After looking at logs I noticed that when files would not parse another extension was loading at the same time, after removing the other extension the files would parse every time.

So it appears there is a conflict with other language extensions, whether or not it is only with this one extension I use or also with others I don't know.

The extension in question is called VS3 VHDL by ViDE-Software and is used for parsing the FPGA language VHDL. I will also let them know of this conflict.

Tbh I think the problem maybe related to some async methods not using await but using the Result methods to await return values, although I could be completely wrong.

If you would like me to make a PR then ask away as my changes improved things regarding the UE4 files annoying double pasting and the crash when opening the options which may only be related to the latest version of VS2019.

tgjones commented 3 years ago

@PiezPiedPy sorry for not replying before - but this is great, thank you! I fixed the enum option bug in a slightly different way - e51c249e943ff26c7030e216828c85304da2b406 - but I wouldn't have known what to fix without your commit, so thank you.

After looking at logs I noticed that when files would not parse another extension was loading at the same time, after removing the other extension the files would parse every time.

I'm not sure what to do here - I think the methods that directly call .Result are okay, if not ideal, but they're kind of necessary when calling from non-async to async code.

Unreal shader files that are open in VS2019 will parse correctly when the solution is first opened but any other .ush .usf files that are then opened will not parse unless VS2019 is closed and then reopened.

What were the actual errors (or incorrect behaviour) that you were seeing?

PiezPiedPy commented 3 years ago

What were the actual errors (or incorrect behaviour) that you were seeing?

@tgjones tbh I can't remember but the problem disappeared as soon as I removed the conflicting extension, the author of the conflicting extension also looked into it and could not solve the issue, I am assuming it is a problem with how VS loads the extensions, sorry I can't be of any more help but I don't have any experience with VS extensions.

tgjones commented 3 years ago

Fair enough - I'll close this for now, but please re-open if you experience the issue again. Thanks for your help with fixing the enum options bug 😄