Repository: sublimelsp/LSP

Issue:
Error panel pops up too fast
I'm finding that the error pane is popping up as I'm in the middle of typing a phrase. Obviously while the line is unfinished, the syntax is not correct, that's just distracting. As such, I think it would be helpful to add some kind of delay before triggering the error popup panel. Even better would be to make the delay configurable.


Discussion:
What language server is this?
Javascript
Agree that the panel (and the squiggly lines) showing up mid-statement can be distracting! 
I usually leave the error panel open for that reason.

Would you want a delay on:
* The panel opening
* Diagnostics updating in the panel
* Diagnostics updating in the panel _and_ the document?

Perhaps you can try the same edits in VS Code so we can see where the diagnostics handling differs?
I think the _most important_ delay would be on the panel opening, as that large movement within your field of vision is the biggest problem. I have my panel set to only open when there's a problem, and that's mainly to maximize editing real estate on my screen. 

I think it makes the most sense to have at least a slight delay on all of the things you mentioned. I don't have VSCode set up. 
I see two options:
* We add the file's diagnostics count to the status area, you would open the panel manually when you see the diagnostics there (no need to decide what delay suits you)
* We wait to hear if other users are interested in this delay (as I'd like to avoid adding a setting for just one user)
Automatically opening the panel, regardless of delays, is super annoying IMO. I'd rather have a hint (e.g. a counter) that tells me something is in there and then I can open it when I want to, and close it when I'm done. So, that first option sounds great to me.
I quite like the SublimeLinter behaviour, which has [lint modes](https://sublimelinter.readthedocs.io/en/latest/lint_modes.html). The save mode is super useful, since it only shows you the errors when they're relevant (i.e. when you're going to run the code).

That said, background mode is quite useful. SublimeLinter by default has [a delay of 0.25s](https://github.com/SublimeLinter/SublimeLinter3/blob/master/SublimeLinter.sublime-settings#L4) before it shows the errors. In terms of how that actually works, it appears to be handled in SL's [queueing](https://github.com/SublimeLinter/SublimeLinter3/blob/master/lint/queue.py).
I like the idea of a counter. 
LSP has a config option to turn off auto show of the diagnostics panel.
```json
"auto_show_diagnostics_panel": false,
```
When he does that, the only way he knows if he has errors is to open the diagnostic panel. 
A counter in the status bar could solve that problem. 

![output3](https://user-images.githubusercontent.com/22029477/37043316-a2f583f0-2160-11e8-8801-20d9c1c7770a.gif)

See the E: COUNT W: COUNT in the left of the status bar




Resolving patch:
diff --git a/plugin/core/settings.py b/plugin/core/settings.py
--- a/plugin/core/settings.py
+++ b/plugin/core/settings.py
@@ -40,6 +40,7 @@ def __init__(self):
         self.show_view_status = True
         self.auto_show_diagnostics_panel = True
         self.show_diagnostics_phantoms = False
+        self.show_diagnostics_count_in_view_status = False
         self.show_diagnostics_in_view_status = True
         self.only_show_lsp_completions = False
         self.diagnostics_highlight_style = "underline"
@@ -65,6 +66,8 @@ def update(self, settings_obj: sublime.Settings):
         self.show_view_status = read_bool_setting(settings_obj, "show_view_status", True)
         self.auto_show_diagnostics_panel = read_bool_setting(settings_obj, "auto_show_diagnostics_panel", True)
         self.show_diagnostics_phantoms = read_bool_setting(settings_obj, "show_diagnostics_phantoms", False)
+        self.show_diagnostics_count_in_view_status = read_bool_setting(settings_obj,
+                                                                       "show_diagnostics_count_in_view_status", False)
         self.show_diagnostics_in_view_status = read_bool_setting(settings_obj, "show_diagnostics_in_view_status", True)
         self.diagnostics_highlight_style = read_str_setting(settings_obj, "diagnostics_highlight_style", "underline")
         self.highlight_active_signature_parameter = read_bool_setting(settings_obj,
diff --git a/plugin/diagnostics.py b/plugin/diagnostics.py
--- a/plugin/diagnostics.py
+++ b/plugin/diagnostics.py
@@ -166,8 +166,37 @@ def update_diagnostics_in_view(view: sublime.View, diagnostics: 'List[Diagnostic
             update_diagnostics_regions(view, diagnostics, severity)
 
 
+def update_diagnostics_in_status_bar(window: sublime.Window):
+    errors = 0
+    warnings = 0
+
+    diagnostics_by_file = get_window_diagnostics(window)
+
+    if diagnostics_by_file:
+        for file_path, source_diagnostics in diagnostics_by_file.items():
+
+            if source_diagnostics:
+                for origin, diagnostics in source_diagnostics.items():
+                    for diagnostic in diagnostics:
+
+                        if diagnostic.severity == DiagnosticSeverity.Error:
+                            errors += 1
+                        if diagnostic.severity == DiagnosticSeverity.Warning:
+                            warnings += 1
+
+    count = 'E: {} W: {}'.format(errors, warnings)
+    view = window.active_view()
+    if view and settings.show_diagnostics_count_in_view_status:
+        view.set_status('lsp_errors_warning_count', count)
+
+
+def update_count_in_status_bar(view):
+    update_diagnostics_in_status_bar(view.window())
+
+
 Events.subscribe("document.diagnostics",
                  lambda update: handle_diagnostics(update))
+Events.subscribe("view.on_activated_async", update_count_in_status_bar)
 
 
 def handle_diagnostics(update: DiagnosticsUpdate):
@@ -176,6 +205,7 @@ def handle_diagnostics(update: DiagnosticsUpdate):
     if view:
         update_diagnostics_in_view(view, update.diagnostics)
     update_diagnostics_panel(window)
+    update_diagnostics_in_status_bar(window)
 
 
 class DiagnosticsCursorListener(sublime_plugin.ViewEventListener):
@@ -261,7 +291,7 @@ def update_diagnostics_panel(window: sublime.Window):
                                    {"panel": "output.diagnostics"})
         else:
             panel.run_command("lsp_clear_panel")
-            if settings.auto_show_diagnostics_panel and is_active_panel:
+            if is_active_panel:
                 window.run_command("hide_panel",
                                    {"panel": "output.diagnostics"})
         panel.set_read_only(True)


Test patch: