Skip to content

Commit

Permalink
refactor: use native types and f-string (#2459)
Browse files Browse the repository at this point in the history
* refactor: use native types and f-string

Signed-off-by: Jack Cherng <[email protected]>

* refactor: remove unused import

Signed-off-by: Jack Cherng <[email protected]>

* fix: make flake8 happier

Signed-off-by: Jack Cherng <[email protected]>

* refactor: naive __all__ for boot.py

Signed-off-by: Jack Cherng <[email protected]>

* Update boot.py

Co-authored-by: deathaxe <[email protected]>

* chore: remove unused imports

Signed-off-by: Jack Cherng <[email protected]>

* revert: rollback to str.format for long lines (>120 chars)

Signed-off-by: Jack Cherng <[email protected]>

* revert: rollback intentional code alignment

Signed-off-by: Jack Cherng <[email protected]>

---------

Signed-off-by: Jack Cherng <[email protected]>
Co-authored-by: deathaxe <[email protected]>
  • Loading branch information
jfcherng and deathaxe authored Apr 24, 2024
1 parent a3867f4 commit 0ab7616
Show file tree
Hide file tree
Showing 69 changed files with 1,386 additions and 1,343 deletions.
88 changes: 81 additions & 7 deletions boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
from .plugin.configuration import LspDisableLanguageServerInProjectCommand
from .plugin.configuration import LspEnableLanguageServerGloballyCommand
from .plugin.configuration import LspEnableLanguageServerInProjectCommand
from .plugin.core.collections import DottedDict
from .plugin.core.css import load as load_css
from .plugin.core.open import opening_files
from .plugin.core.panels import PanelName
from .plugin.core.protocol import Error
from .plugin.core.registry import LspNextDiagnosticCommand
from .plugin.core.registry import LspOpenLocationCommand
from .plugin.core.registry import LspPrevDiagnosticCommand
Expand Down Expand Up @@ -86,10 +84,86 @@
from .plugin.tooling import LspOnDoubleClickCommand
from .plugin.tooling import LspParseVscodePackageJson
from .plugin.tooling import LspTroubleshootServerCommand
from typing import Any, Dict, List, Optional, Type
from typing import Any

__all__ = (
"DocumentSyncListener",
"Listener",
"LspApplyDocumentEditCommand",
"LspApplyWorkspaceEditCommand",
"LspCallHierarchyCommand",
"LspClearLogPanelCommand",
"LspClearPanelCommand",
"LspCodeActionsCommand",
"LspCodeLensCommand",
"LspCollapseTreeItemCommand",
"LspColorPresentationCommand",
"LspCommitCompletionWithOppositeInsertMode",
"LspCopyToClipboardFromBase64Command",
"LspDisableLanguageServerGloballyCommand",
"LspDisableLanguageServerInProjectCommand",
"LspDocumentSymbolsCommand",
"LspDumpBufferCapabilities",
"LspDumpWindowConfigs",
"LspEnableLanguageServerGloballyCommand",
"LspEnableLanguageServerInProjectCommand",
"LspExecuteCommand",
"LspExpandSelectionCommand",
"LspExpandTreeItemCommand",
"LspFoldAllCommand",
"LspFoldCommand",
"LspFormatCommand",
"LspFormatDocumentCommand",
"LspFormatDocumentRangeCommand",
"LspGotoDiagnosticCommand",
"LspHideRenameButtonsCommand",
"LspHierarchyToggleCommand",
"LspHoverCommand",
"LspInlayHintClickCommand",
"LspNextDiagnosticCommand",
"LspOnDoubleClickCommand",
"LspOpenLinkCommand",
"LspOpenLocationCommand",
"LspParseVscodePackageJson",
"LspPrevDiagnosticCommand",
"LspRefactorCommand",
"LspResolveDocsCommand",
"LspRestartServerCommand",
"LspRunTextCommandHelperCommand",
"LspSaveAllCommand",
"LspSaveCommand",
"LspSelectCompletionCommand",
"LspSelectionAddCommand",
"LspSelectionClearCommand",
"LspSelectionSetCommand",
"LspShowDiagnosticsPanelCommand",
"LspShowScopeNameCommand",
"LspSignatureHelpNavigateCommand",
"LspSignatureHelpShowCommand",
"LspSourceActionCommand",
"LspSymbolDeclarationCommand",
"LspSymbolDefinitionCommand",
"LspSymbolImplementationCommand",
"LspSymbolReferencesCommand",
"LspSymbolRenameCommand",
"LspSymbolTypeDefinitionCommand",
"LspToggleCodeLensesCommand",
"LspToggleHoverPopupsCommand",
"LspToggleInlayHintsCommand",
"LspToggleLogPanelLinesLimitCommand",
"LspToggleServerPanelCommand",
"LspTroubleshootServerCommand",
"LspTypeHierarchyCommand",
"LspUpdateLogPanelCommand",
"LspUpdatePanelCommand",
"LspWorkspaceSymbolsCommand",
"TextChangeListener",
"plugin_loaded",
"plugin_unloaded",
)

def _get_final_subclasses(derived: List[Type], results: List[Type]) -> None:

def _get_final_subclasses(derived: list[type], results: list[type]) -> None:
for d in derived:
d_subclasses = d.__subclasses__()
if len(d_subclasses) > 0:
Expand All @@ -99,7 +173,7 @@ def _get_final_subclasses(derived: List[Type], results: List[Type]) -> None:


def _register_all_plugins() -> None:
plugin_classes: List[Type[AbstractPlugin]] = []
plugin_classes: list[type[AbstractPlugin]] = []
_get_final_subclasses(AbstractPlugin.__subclasses__(), plugin_classes)
for plugin_class in plugin_classes:
try:
Expand All @@ -112,6 +186,7 @@ def _register_all_plugins() -> None:

def _unregister_all_plugins() -> None:
from LSP.plugin.core.sessions import _plugins

_plugins.clear()
client_configs.external.clear()
client_configs.all.clear()
Expand All @@ -132,7 +207,6 @@ def plugin_unloaded() -> None:


class Listener(sublime_plugin.EventListener):

def on_exit(self) -> None:
kill_all_subprocesses()

Expand Down Expand Up @@ -187,7 +261,7 @@ def on_pre_close(self, view: sublime.View) -> None:
tup[1](None)
break

def on_post_window_command(self, window: sublime.Window, command_name: str, args: Optional[Dict[str, Any]]) -> None:
def on_post_window_command(self, window: sublime.Window, command_name: str, args: dict[str, Any] | None) -> None:
if command_name == "show_panel":
wm = windows.lookup(window)
if not wm:
Expand Down
Loading

0 comments on commit 0ab7616

Please sign in to comment.