Bri Bri
Bri Bri

Reputation: 2268

In Visual Studio Code, is it possible to delay displaying inline errors when editing C# code, perhaps until I save the file?

I'm using Visual Studio Code primarily to edit C# code, and it automatically detects errors in the code as I type. However because it updates this every second or so, that means that the moment I start typing something on a line and pause even for a brief moment, I've technically introduced a syntax error and it highlights it with a red underline, until finally the whole line is typed.

This is very distracting! I like having it tell me where errors are, but I'd much rather have it wait until I've finished what I'm typing, or even better when I've saved the file, since at that point I expect the code to be correct.

Is there any way to configure VS Code to do this?

Upvotes: 3

Views: 1524

Answers (3)

rioV8
rioV8

Reputation: 28673

I have updated the extension When File v0.4.0.

Now you can change workbench colors when the file is dirty (not saved) (experimental)

This only works for files in a Workspace. The extension needs a workspace because it will not change the global workbench color customization.

Add the following to your settings (Global or Workspace)

  "whenFile.change": {
    "byLanguageId": {
      "csharp": {
        "whenDirty": {
          "editorError.foreground": "#ff000020",
          "editorWarning.foreground": "#ff000020",
          "editorInfo.foreground": "#ff000020"
        }
      }
    }
  }

When you start typing the squiggles will be very faint red. If you save the file they will get the theme colors back. Every theme uses different squiggles colors but faint red is not a problem. Also the icons in the PROBLEMS panel become transparent.

If you have customized these colors you have to put these in a theme group of workbench.colorCustomizations. But it can be that theme groups override the colors.

I will add a timer to reset this state when you haven't typed for x seconds.

If your theme uses the other colors in the groups editorError, editorWarning, editorInfo you can add these too.

Upvotes: 1

Mark
Mark

Reputation: 181349

I think the answer to this is that there is still no way to add a delay to the code validation. See Intellisense, Add an option to delay validation (and thus wavy lines in code).

The unsatisfactory solution provided there is to disable validation altogether until a save operation:

On second thought , this is exactly what tasks already do. Just disable the built-in js/ts validator using javascript.validate.enable: false + typescript.validate.enable: false and setup a task to build your project instead. It should only update errors when the file on disk changes (i.e. you save it). You can also configure autosave if wish to have this happen after a delay

You would have to see if your cSharp language server provides an option to run validation onSave or onType.

  • I just looked through all the settings for csharp and omnisharp in vscode and found nothing similar to the validate only on save option or to disable validation altogether.

For php there is such an option built-in: PHP > Validate: Run. onSave or onType.

Upvotes: 2

Master Of Disaster
Master Of Disaster

Reputation: 387


Open up the command palette (CTRL + SHIFT + P) - > c/c++: Disable Error Squiggles. This will disable all error warnings and highlighting.


Upvotes: 1

Related Questions