Skip to content

Commit

Permalink
🚚 Rename some classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Oct 22, 2023
1 parent 29c0293 commit f79320b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
39 changes: 19 additions & 20 deletions src/termux_language_server/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from .tree_sitter_lsp.finders import RequiresFinder, UnFixedOrderFinder


class InvalidNodeFinder(Finder):
r"""Invalidnodefinder."""
class InvalidKeywordFinder(Finder):
r"""Invalidkeywordfinder."""

def __init__(
self,
Expand All @@ -41,8 +41,8 @@ def __init__(
self.names = names

@staticmethod
def is_correct_uni_without_expansion(uni: UNI) -> bool:
r"""Is correct uni without expansion.
def is_correct_declaration(uni: UNI) -> bool:
r"""Is correct declaration.
:param uni:
:type uni: UNI
Expand Down Expand Up @@ -82,8 +82,8 @@ def is_array(uni: UNI) -> bool:
return False

@staticmethod
def is_correct_uni(uni: UNI) -> bool:
r"""Is correct uni.
def is_correct(uni: UNI) -> bool:
r"""Is correct.
:param uni:
:type uni: UNI
Expand All @@ -94,7 +94,7 @@ def is_correct_uni(uni: UNI) -> bool:
if parent is None:
return False
return (
InvalidNodeFinder.is_correct_uni_without_expansion(uni)
InvalidKeywordFinder.is_correct_declaration(uni)
or text.isupper()
and parent.type == "expansion"
or text.islower()
Expand All @@ -110,7 +110,7 @@ def __call__(self, uni: UNI) -> bool:
"""
text = uni.get_text()
return text in self.names and (
not self.is_correct_uni(uni) or self.is_array(uni)
not self.is_correct(uni) or self.is_array(uni)
)

def uni2diagnostic(self, uni: UNI) -> Diagnostic:
Expand All @@ -129,8 +129,8 @@ def uni2diagnostic(self, uni: UNI) -> Diagnostic:
return uni.get_diagnostic(self.message, self.severity, type=_type)


class RequireNodesFinder(RequiresFinder):
r"""Requirenodesfinder."""
class RequiredKeywordFinder(RequiresFinder):
r"""Requiredkeywordfinder."""

def filter(self, uni: UNI, require: str) -> bool:
r"""Filter.
Expand All @@ -142,14 +142,13 @@ def filter(self, uni: UNI, require: str) -> bool:
:rtype: bool
"""
text = uni.get_text()
return (
text == require
and InvalidNodeFinder.is_correct_uni_without_expansion(uni)
return text == require and InvalidKeywordFinder.is_correct_declaration(
uni
)


class UnsortedNodesFinder(UnFixedOrderFinder):
r"""Unsortednodesfinder."""
class UnsortedKeywordFinder(UnFixedOrderFinder):
r"""Unsortedkeywordfinder."""

def filter(self, uni: UNI) -> bool:
r"""Filter.
Expand All @@ -161,7 +160,7 @@ def filter(self, uni: UNI) -> bool:
text = uni.get_text()
return (
text in self.order
and InvalidNodeFinder.is_correct_uni_without_expansion(uni)
and InvalidKeywordFinder.is_correct_declaration(uni)
)

def get_text_edits(self, uri: str, tree: Tree) -> list[TextEdit]:
Expand All @@ -188,8 +187,8 @@ def get_text_edits(self, uri: str, tree: Tree) -> list[TextEdit]:
return []


class UnsortedPackageFinder(Finder):
r"""Unsortedpackagefinder."""
class UnsortedCSVFinder(Finder):
r"""Unsorted comma separated value finder."""

def __init__(
self,
Expand Down Expand Up @@ -269,8 +268,8 @@ def get_text_edits(self, uri: str, tree: Tree) -> list[TextEdit]:
return text_edits


class PackageFinder(UnsortedPackageFinder):
r"""Packagefinder."""
class CSVFinder(UnsortedCSVFinder):
r"""Comma separated value finder."""

def __init__(self, csvs: set[str]) -> None:
r"""Init.
Expand Down
24 changes: 12 additions & 12 deletions src/termux_language_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@

from .documents import get_document, get_filetype
from .finders import (
InvalidNodeFinder,
PackageFinder,
RequireNodesFinder,
UnsortedNodesFinder,
UnsortedPackageFinder,
CSVFinder,
InvalidKeywordFinder,
RequiredKeywordFinder,
UnsortedCSVFinder,
UnsortedKeywordFinder,
)
from .parser import parse
from .tree_sitter_lsp.diagnose import get_diagnostics
Expand Down Expand Up @@ -92,10 +92,10 @@ def did_change(params: DidChangeTextDocumentParams) -> None:
diagnostics = get_diagnostics(
DIAGNOSTICS_FINDERS
+ [
RequireNodesFinder(self.required[filetype]),
InvalidNodeFinder(set(self.keywords[filetype])),
UnsortedNodesFinder(self.keywords[filetype]),
UnsortedPackageFinder(self.csvs[filetype]),
RequiredKeywordFinder(self.required[filetype]),
InvalidKeywordFinder(set(self.keywords[filetype])),
UnsortedKeywordFinder(self.keywords[filetype]),
UnsortedCSVFinder(self.csvs[filetype]),
],
document.uri,
self.trees[document.uri],
Expand All @@ -116,8 +116,8 @@ def format(params: DocumentFormattingParams) -> list[TextEdit]:
document = self.workspace.get_document(params.text_document.uri)
return get_text_edits(
[
UnsortedNodesFinder(self.keywords[filetype]),
UnsortedPackageFinder(self.csvs[filetype]),
UnsortedKeywordFinder(self.keywords[filetype]),
UnsortedCSVFinder(self.csvs[filetype]),
],
document.uri,
self.trees[document.uri],
Expand All @@ -135,7 +135,7 @@ def document_link(params: DocumentLinkParams) -> list[DocumentLink]:
if filetype == "":
return []
document = self.workspace.get_document(params.text_document.uri)
return PackageFinder(self.csvs[filetype]).get_document_links(
return CSVFinder(self.csvs[filetype]).get_document_links(
document.uri,
self.trees[document.uri],
"https://github.com/termux/termux-packages/tree/master/packages/{{name}}/build.sh",
Expand Down
20 changes: 10 additions & 10 deletions src/termux_language_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

from .documents import get_document, get_filetype
from .finders import (
InvalidNodeFinder,
RequireNodesFinder,
UnsortedNodesFinder,
UnsortedPackageFinder,
InvalidKeywordFinder,
RequiredKeywordFinder,
UnsortedCSVFinder,
UnsortedKeywordFinder,
)
from .tree_sitter_lsp.diagnose import check as _check
from .tree_sitter_lsp.finders import ErrorFinder, MissingFinder
Expand Down Expand Up @@ -80,10 +80,10 @@ def check(
_paths[filetype],
DIAGNOSTICS_FINDERS
+ [
RequireNodesFinder(required[filetype]),
InvalidNodeFinder(set(keywords[filetype])),
UnsortedNodesFinder(keywords[filetype]),
UnsortedPackageFinder(csvs[filetype]),
RequiredKeywordFinder(required[filetype]),
InvalidKeywordFinder(set(keywords[filetype])),
UnsortedKeywordFinder(keywords[filetype]),
UnsortedCSVFinder(csvs[filetype]),
],
parse,
color,
Expand Down Expand Up @@ -111,8 +111,8 @@ def format(
_format(
_paths[filetype],
[
UnsortedNodesFinder(keywords[filetype]),
UnsortedPackageFinder(csvs[filetype]),
UnsortedKeywordFinder(keywords[filetype]),
UnsortedCSVFinder(csvs[filetype]),
],
parse,
)

0 comments on commit f79320b

Please sign in to comment.