Open all code files with errors action

When refactoring a major part of code, errors are created in many files. I use Visual Studio’s “go to next error” hotkey to jump from error to error and fix them. Problem is that this works only with opened files.

When switching back to Unity, console shows more errors in e.g. 20 different files. I would like to open all files with errors with one click. So I can quickly go through errors and fix them using Visual Studio “go to next error”, which only works on opened files. At the moment I open one file, fix the error, open next file etc. It is slow to switch between Unity and Visual Studio like that.

I couldn’t find a way to create Editor script that opens a file without “open file” dialogue. Or to list files with errors. Or to make Visual Studio recognize errors in all files even when “whole solution” is selected in the Error List panel.

Using Unity 2022.3.5, Visual Studio 2022 and c#.

1 Answer

1

Found a script and modified it. Alt + C now clears console and opens files for up to 10 errors.

[MenuItem("MyMenu/Clear Console and open errors &c", false, 1)] // ALT + C
    static void ClearConsoleAndOpenErrors()
    {
        var logEntries = System.Type.GetType("UnityEditor.LogEntries,UnityEditor.dll");
        var clearMethod = logEntries.GetMethod("Clear", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
		var doubleClickErrorIndexMethod = logEntries.GetMethod("RowGotDoubleClicked", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
        clearMethod.Invoke(null, null);
		for (int i = 0; i <10; i++)
			doubleClickErrorIndexMethod.Invoke(null, new object[] { i });
    }