Skip to content

Commit

Permalink
extract regexes to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
predrag-codetribe committed Dec 12, 2020
1 parent 2895ba0 commit 4c192a4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion plugin/core/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down
2 changes: 2 additions & 0 deletions plugin/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion plugin/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")


Expand Down
5 changes: 3 additions & 2 deletions plugin/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
)

0 comments on commit 4c192a4

Please sign in to comment.