Skip to content

Commit

Permalink
Improve type stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
jwortmann authored and rchl committed Dec 5, 2023
1 parent fe32c17 commit 34c49dd
Show file tree
Hide file tree
Showing 7 changed files with 3,039 additions and 517 deletions.
3 changes: 2 additions & 1 deletion plugin/core/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def update(self, updated_config_name: Optional[str] = None) -> None:
self._reload_configs(updated_config_name, notify_listeners=True)

def _reload_configs(self, updated_config_name: Optional[str] = None, notify_listeners: bool = False) -> None:
project_settings = (self._window.project_data() or {}).get("settings", {}).get("LSP", {})
project_data = self._window.project_data()
project_settings = project_data.get("settings", {}).get("LSP", {}) if isinstance(project_data, dict) else {}
if updated_config_name is None:
self.all.clear()
for name, config in self._global_configs.items():
Expand Down
12 changes: 10 additions & 2 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,16 @@

def is_regular_view(v: sublime.View) -> bool:
# Not from the quick panel (CTRL+P), and not a special view like a console, output panel or find-in-files panels.
is_widget = v.settings().get('is_widget')
return not v.sheet().is_transient() and v.element() is None and not is_widget
if v.element() is not None:
return False
if v.settings().get('is_widget'):
return False
sheet = v.sheet()
if not sheet:
return False
if sheet.is_transient():
return False
return True


def previous_non_whitespace_char(view: sublime.View, pt: int) -> str:
Expand Down
25 changes: 16 additions & 9 deletions plugin/goto_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .core.settings import userprefs
from .core.types import ClientConfig
from .core.typing import Any, Dict, Iterator, List, Optional, Tuple, Union
from .core.typing import cast
from .core.url import parse_uri, unparse_uri
from .core.views import diagnostic_severity
from .core.views import format_diagnostic_for_html
Expand Down Expand Up @@ -193,8 +194,10 @@ def description(self, value: DocumentUri, text: str) -> str:
return self._project_path(parse_uri(value))

def cancel(self) -> None:
if self._preview is not None and self._preview.sheet().is_transient():
self._preview.close()
if self._preview is not None:
sheet = self._preview.sheet()
if sheet and sheet.is_transient():
self._preview.close()
self.window.focus_view(self.view)

def preview(self, value: Optional[DocumentUri]) -> str:
Expand Down Expand Up @@ -246,7 +249,7 @@ def list_items(self) -> List[sublime.ListInputItem]:
text = "{}: {}".format(format_severity(diagnostic_severity(diagnostic)), first_line)
annotation = format_diagnostic_source_and_code(diagnostic)
kind = DIAGNOSTIC_KINDS[diagnostic_severity(diagnostic)]
list_items.append(sublime.ListInputItem(text, (i, diagnostic), annotation=annotation, kind=kind))
list_items.append(sublime.ListInputItem(text, [i, diagnostic], annotation=annotation, kind=kind))
return list_items

def placeholder(self) -> str:
Expand All @@ -255,10 +258,11 @@ def placeholder(self) -> str:
def next_input(self, args: dict) -> Optional[sublime_plugin.CommandInputHandler]:
return None if args.get("diagnostic") else sublime_plugin.BackInputHandler() # type: ignore

def confirm(self, value: Optional[Tuple[int, Diagnostic]]) -> None:
def confirm(self, value: Optional[list]) -> None:
if not value:
return
i, diagnostic = value
i = cast(int, value[0])
diagnostic = cast(Diagnostic, value[1])
session = self.sessions[i]
location = self._get_location(diagnostic)
scheme, _ = self.parsed_uri
Expand All @@ -268,14 +272,17 @@ def confirm(self, value: Optional[Tuple[int, Diagnostic]]) -> None:
sublime.set_timeout_async(functools.partial(session.open_location_async, location))

def cancel(self) -> None:
if self._preview is not None and self._preview.sheet().is_transient():
self._preview.close()
if self._preview is not None:
sheet = self._preview.sheet()
if sheet and sheet.is_transient():
self._preview.close()
self.window.focus_view(self.view)

def preview(self, value: Optional[Tuple[int, Diagnostic]]) -> Union[str, sublime.Html]:
def preview(self, value: Optional[list]) -> Union[str, sublime.Html]:
if not value:
return ""
i, diagnostic = value
i = cast(int, value[0])
diagnostic = cast(Diagnostic, value[1])
session = self.sessions[i]
base_dir = None
scheme, path = self.parsed_uri
Expand Down
2 changes: 1 addition & 1 deletion plugin/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _show_references_in_output_panel(self, word: str, session: Session, location
})
# highlight all word occurrences
regions = panel.find_all(r"\b{}\b".format(word))
panel.add_regions('ReferenceHighlight', regions, 'comment', flags=sublime.DRAW_OUTLINED)
panel.add_regions('ReferenceHighlight', regions, 'comment', flags=sublime.DRAW_NO_FILL)


def _get_relative_path(base_dir: Optional[str], file_path: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion plugin/session_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ def get_language_id(self) -> Optional[str]:
return listener.get_language_id() if listener else None

def get_view_for_group(self, group: int) -> Optional[sublime.View]:
return self.view if self.view.sheet().group() == group else None
sheet = self.view.sheet()
return self.view if sheet and sheet.group() == group else None

def get_capability_async(self, capability_path: str) -> Optional[Any]:
return self.session_buffer.get_capability(capability_path)
Expand Down
Loading

0 comments on commit 34c49dd

Please sign in to comment.