From 4c192a4c2c265650381858637d0a24f6e3efcaac Mon Sep 17 00:00:00 2001 From: Predrag Nikolic Date: Sat, 12 Dec 2020 16:47:10 +0100 Subject: [PATCH] extract regexes to constants --- plugin/core/diagnostics.py | 3 ++- plugin/core/types.py | 2 ++ plugin/references.py | 3 ++- plugin/rename.py | 5 +++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/plugin/core/diagnostics.py b/plugin/core/diagnostics.py index f0f6ba4ca..e03fcd97a 100644 --- a/plugin/core/diagnostics.py +++ b/plugin/core/diagnostics.py @@ -2,12 +2,13 @@ from .protocol import Diagnostic from .protocol import Point from .sessions import SessionBufferProtocol +from .types import PANEL_FILE_REGEX, PANEL_LINE_REGEX from .typing import List, Tuple, Callable, Optional, Iterable import sublime def ensure_diagnostics_panel(window: sublime.Window) -> Optional[sublime.View]: - return ensure_panel(window, "diagnostics", r"(?!\s+\d+:\d+)(.*)(:)$", r"^\s+(\d+):(\d+)", + return ensure_panel(window, "diagnostics", PANEL_FILE_REGEX, PANEL_LINE_REGEX, "Packages/LSP/Syntaxes/Diagnostics.sublime-syntax") diff --git a/plugin/core/types.py b/plugin/core/types.py index c46b2988a..562f43608 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -17,6 +17,8 @@ TCP_CONNECT_TIMEOUT = 5 # seconds FEATURES_TIMEOUT = 300 # milliseconds +PANEL_FILE_REGEX = r"^(?!\s+\d+:\d+)(.*)(:)$" +PANEL_LINE_REGEX = r"^\s+(\d+):(\d+)" def basescope2languageid(base_scope: str) -> str: # This the connection between Language IDs and ST selectors. diff --git a/plugin/references.py b/plugin/references.py index a8cc29dd3..099ebf303 100644 --- a/plugin/references.py +++ b/plugin/references.py @@ -9,6 +9,7 @@ from .core.registry import windows from .core.settings import PLUGIN_NAME from .core.settings import userprefs +from .core.types import PANEL_FILE_REGEX, PANEL_LINE_REGEX from .core.typing import List, Dict, Optional, Tuple, TypedDict from .core.url import uri_to_filename from .core.views import get_line, text_document_position_params @@ -17,7 +18,7 @@ def ensure_references_panel(window: sublime.Window) -> 'Optional[sublime.View]': - return ensure_panel(window, "references", r"^(?!\s+\d+:\d+)(.*)(:)$", r"^\s+(\d+):(\d+)", + return ensure_panel(window, "references", PANEL_FILE_REGEX, PANEL_LINE_REGEX, "Packages/" + PLUGIN_NAME + "/Syntaxes/References.sublime-syntax") diff --git a/plugin/rename.py b/plugin/rename.py index 311fa9282..0af0af49f 100644 --- a/plugin/rename.py +++ b/plugin/rename.py @@ -8,6 +8,7 @@ from .core.registry import get_position from .core.registry import LspTextCommand from .core.registry import windows +from .core.types import PANEL_FILE_REGEX, PANEL_LINE_REGEX from .core.typing import Any, Optional, Dict, List from .core.views import range_to_region, get_line from .core.views import text_document_position_params @@ -185,7 +186,7 @@ def ensure_rename_panel(window: sublime.Window) -> Optional[sublime.View]: return ensure_panel( window=window, name=PanelName.Rename, - result_file_regex=r"^(?!\s+\d+:\d+)(.*)(:)$", - result_line_regex=r"^\s+(\d+):(\d+)", + result_file_regex=PANEL_FILE_REGEX, + result_line_regex=PANEL_LINE_REGEX, syntax="Packages/LSP/Syntaxes/References.sublime-syntax" )