diff --git a/src/termux_language_server/finders.py b/src/termux_language_server/finders.py index 22091e5..971c624 100644 --- a/src/termux_language_server/finders.py +++ b/src/termux_language_server/finders.py @@ -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, @@ -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 @@ -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 @@ -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() @@ -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: @@ -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. @@ -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. @@ -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]: @@ -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, @@ -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. diff --git a/src/termux_language_server/server.py b/src/termux_language_server/server.py index 96ebb34..527fd02 100644 --- a/src/termux_language_server/server.py +++ b/src/termux_language_server/server.py @@ -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 @@ -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], @@ -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], @@ -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", diff --git a/src/termux_language_server/utils.py b/src/termux_language_server/utils.py index db86890..d467019 100644 --- a/src/termux_language_server/utils.py +++ b/src/termux_language_server/utils.py @@ -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 @@ -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, @@ -111,8 +111,8 @@ def format( _format( _paths[filetype], [ - UnsortedNodesFinder(keywords[filetype]), - UnsortedPackageFinder(csvs[filetype]), + UnsortedKeywordFinder(keywords[filetype]), + UnsortedCSVFinder(csvs[filetype]), ], parse, )