Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discard diagnostics in a few cases #1816

Merged
merged 5 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def get_project_path(self, file_path: str) -> Optional[str]:
"""
pass

@abstractmethod
def should_present_diagnostics(self, uri: DocumentUri) -> Optional[str]:
"""
Should the diagnostics for this URI be shown in the view? Return a reason why not
"""

# Mutators

@abstractmethod
Expand Down Expand Up @@ -1275,9 +1281,18 @@ def m_workspace_applyEdit(self, params: Any, request_id: Any) -> None:
def m_textDocument_publishDiagnostics(self, params: Any) -> None:
"""handles the textDocument/publishDiagnostics notification"""
uri = params["uri"]
mgr = self.manager()
if not mgr:
# debug("ignoring diagnostics for", uri, "due to missing window manager")
return
reason = mgr.should_present_diagnostics(uri)
if isinstance(reason, str):
return debug("ignoring unsuitable diagnostics for", uri, "reason:", reason)
sb = self.get_session_buffer_for_uri_async(uri)
if sb:
sb.on_diagnostics_async(params["diagnostics"], params.get("version"))
if not sb:
# debug("ignoring diagnostics for", uri, "due to missing session buffer")
rwols marked this conversation as resolved.
Show resolved Hide resolved
return
sb.on_diagnostics_async(params["diagnostics"], params.get("version"))

def m_client_registerCapability(self, params: Any, request_id: Any) -> None:
"""handles the client/registerCapability request"""
Expand Down
31 changes: 31 additions & 0 deletions plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .promise import Promise
from .protocol import Diagnostic
from .protocol import DiagnosticSeverity
from .protocol import DocumentUri
from .protocol import Error
from .protocol import Location
from .sessions import get_plugin
Expand All @@ -21,6 +22,7 @@
from .transports import create_transport
from .types import ClientConfig
from .typing import Optional, Any, Dict, Deque, List, Generator, Tuple, Iterable, Sequence, Union
from .url import parse_uri
from .views import extract_variables
from .views import make_link
from .workspace import ProjectFolders
Expand All @@ -32,6 +34,7 @@
from time import time
from weakref import ref
from weakref import WeakSet
import fnmatch
import functools
import json
import os
Expand Down Expand Up @@ -437,6 +440,34 @@ def get_project_path(self, file_path: str) -> Optional[str]:
candidate = folder
return candidate

def should_present_diagnostics(self, uri: DocumentUri) -> Optional[str]:
scheme, path = parse_uri(uri)
if scheme != "file":
return None
if not self._workspace.contains(path):
return "not inside window folders"
view = self._window.active_view()
if not view:
return None
settings = view.settings()
if self._matches_glob(path, settings.get("binary_file_patterns")):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this in my project:

Screenshot 2021-08-01 at 10 24 10

and this are the view settings (the view is within the workspace):

>>> view.settings().get('folder_exclude_patterns')
['.svn', '.git', '.hg', 'CVS', '.mypy_cache', 'node_modules']

It looks like the .nuxt is missing (node_modules comes from global override). So are the view settings not actually updated with project overrides?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I can reproduce this behavior here as well. Seems broken to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return "matches a glob in binary_file_patterns"
if self._matches_glob(path, settings.get("file_exclude_patterns")):
return "matches a glob in file_exclude_patterns"
if self._matches_glob(path, settings.get("folder_exclude_patterns")):
return "matches a glob in folder_exclude_patterns"
return None

def _matches_glob(self, path: str, patterns: Any) -> bool:
if not isinstance(patterns, list):
return False
for pattern in patterns:
if not isinstance(pattern, str):
continue
if fnmatch.fnmatch(path, pattern):
return True
return False
rwols marked this conversation as resolved.
Show resolved Hide resolved

def on_post_exit_async(self, session: Session, exit_code: int, exception: Optional[Exception]) -> None:
self._sessions.discard(session)
for listener in self._listeners:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from LSP.plugin.core.collections import DottedDict
from LSP.plugin.core.protocol import Diagnostic
from LSP.plugin.core.protocol import DocumentUri
from LSP.plugin.core.protocol import Error
from LSP.plugin.core.protocol import TextDocumentSyncKindFull
from LSP.plugin.core.protocol import TextDocumentSyncKindIncremental
Expand Down Expand Up @@ -32,6 +33,9 @@ def sessions(self, view: sublime.View, capability: Optional[str] = None) -> Gene
def get_project_path(self, file_name: str) -> Optional[str]:
return None

def should_present_diagnostics(self, uri: DocumentUri) -> Optional[str]:
return None

def start_async(self, configuration: ClientConfig, initiating_view: sublime.View) -> None:
pass

Expand Down