3

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?

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

After quite a lot of digging, what I've found is that Microsoft's C# extension simply has no options to change its validation behavior. It can't be disabled, it can't be delayed, and it can't be postponed until the file is saved. If I'm wrong then please do correct me.
@BriBri I agree, I just looked through all the settings for csharp and omnisharp in vscode and found nothing simila to the validate only on save option or disable altogether.
1
+350

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.

4 Comments

This might be the best solution I've encountered so far. It's not truly what I want, since it only hides the squiggles and doesn't prevent the 'Problems' pane from updating, and ideally the errors and warnings would persist after I've saved but have started typing again. (Preferably the error would disappear if I start editing the line it applies to.) Obviously that's outside the purview of When File, though, and I think it might be good enough. It does certainly solve the problem of the distracting squiggles!
@BriBri Instead of using #ff000020 you can use #ff000000 to make them transparent
Yup, that's what I'm doing.
@BriBri you can hide the PROBLEMS panel so you don't see the changes, you can get the same info from the tooltips
0

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


1 Comment

This works for C/C++, but unfortunately not for C#.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.