How does my visual addin studio detect compiler errors before building, much like "Delete and Sort Uses"?

I am making a refactoring tool that automates several more trivial styles of code related to StyleCop. One of the things that I would like to receive with the add-in (as an additional function that the developer can enable / disable) automatically calls the "Arrange usage → Delete and sort" function. This is a simple macro call.

However, my problem is that when I scan and recursively call a macro in each file without the .cs constructor in the solution, this particular macro checks for errors before executing. If there is a syntax error, and my add-in starts to call this functionality, it gives a dialog for each file.

What I would like to do is use the same method that the function uses to check for errors on the fly, and then if an error occurs that causes a dialog to appear, just pull out a one-time notification and skip calls for each file.

I know that my add-in can check the list of errors, however, I have found many times that errors that cause problems in "Delete and Sort" do not always appear in the list. I had a list empty, then I try to "Delete and Sort" and it tells me that there are problems. Then I create a solution and, of course, it fails and errors are populated. The only solution that I see is to use the same functions as Delete and Sort to check in advance.

Does anyone know how I can detect compiler errors before creating it in the same way as "Delete and Sort Uses"?

+4
source share
2 answers

It seems to be hacked, but if someone does not come up with a better solution, I am going to use error list checking because it is better than nothing.

In addition, I think I can experiment with putting a timer around the call in "Edit.RemoveAndSort", and if it takes some time, you will see a one-time dialog that says that it looks like RemoveAndSort is having problems and asking if it wants whether the user cancels or at least not cause deletion and sorting.

0
source

I'm not quite sure what errors you are talking about, I assume that these are those that the IntelliSense parser generates. Yes, this parser is not very reliable. It is not intended for a full-blown C # analyzer, it is optimized for a completely different job: providing context-sensitive help, even if the code is incomplete and cannot be compiled. There is not something you can do to make it more reliable than expecting the next version of VS.

But it seems to me that you can fix the wrong problem. The main problem is that your add-in seems to be removed using directives that should not be removed. The real solution is to improve the code analysis mechanism so that it reliably detects the true namespace dependencies. Trying to guess which ones matter, hoping IntelliSense is going to complain, just going to rip off your customer.

+1
source

Source: https://habr.com/ru/post/1301892/


All Articles