Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
  • Loading branch information
jabraham17 committed Jun 11, 2024
1 parent 494ec0c commit a9b926b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
21 changes: 16 additions & 5 deletions tools/chpl-language-server/src/chpl-language-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
chplcheck_path = os.path.join(chpl_home, "tools", "chplcheck", "src")
# Add chplcheck to the path, but load via importlib
sys.path.append(chplcheck_path)

def load_module(module_name: str):
file_path = os.path.join(chplcheck_path, module_name + ".py")
spec = importlib.util.spec_from_file_location(module_name, file_path)
Expand All @@ -163,6 +164,7 @@ def load_module(module_name: str):
raise ValueError(f"Could not load module from {file_path}")
spec.loader.exec_module(module)
return module

chplcheck = load_module("chplcheck")
chplcheck_lsp = load_module("lsp")
chplcheck_config = load_module("config")
Expand Down Expand Up @@ -992,7 +994,6 @@ def add_bool_flag(name: str, dest: str, default: bool):
if chplcheck_config:
chplcheck_config.Config.add_arguments(self.parser, "chplcheck-")


def _parse_end_markers(self):
self.args["end_markers"] = [
a.strip() for a in self.args["end_markers"].split(",")
Expand Down Expand Up @@ -1069,7 +1070,14 @@ def _setup_linter(self, clsConfig: CLSConfig):
"""
Setup the linter, if it is enabled
"""
if not (self.do_linting and chplcheck and chplcheck_lsp and chplcheck_config and chplcheck_driver and chplcheck_rules):
if not (
self.do_linting
and chplcheck
and chplcheck_lsp
and chplcheck_config
and chplcheck_driver
and chplcheck_rules
):
return

config = chplcheck_config.Config.from_args(clsConfig.args)
Expand All @@ -1083,7 +1091,6 @@ def _setup_linter(self, clsConfig: CLSConfig):
self.lint_driver.disable_rules(*config.disabled_rules)
self.lint_driver.enable_rules(*config.enabled_rules)


def get_deprecation_replacement(
self, text: str
) -> Tuple[Optional[str], Optional[str]]:
Expand Down Expand Up @@ -1197,7 +1204,9 @@ def build_diagnostics(self, uri: str) -> List[Diagnostic]:
# get lint diagnostics if applicable
if self.lint_driver:
assert chplcheck_lsp
lint_diagnostics = chplcheck_lsp.get_lint_diagnostics(fi.context.context, self.lint_driver, fi.get_asts())
lint_diagnostics = chplcheck_lsp.get_lint_diagnostics(
fi.context.context, self.lint_driver, fi.get_asts()
)
diagnostics.extend(lint_diagnostics)

return diagnostics
Expand Down Expand Up @@ -1758,7 +1767,9 @@ async def code_action(ls: ChapelLanguageServer, params: CodeActionParams):
# get lint fixits if applicable
if ls.lint_driver:
assert chplcheck_lsp
lint_actions = chplcheck_lsp.get_lint_actions(params.context.diagnostics)
lint_actions = chplcheck_lsp.get_lint_actions(
params.context.diagnostics
)
actions.extend(lint_actions)

return actions
Expand Down
8 changes: 6 additions & 2 deletions tools/chplcheck/src/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def _should_check_rule(
def _has_internal_name(self, node: chapel.AstNode):
if not hasattr(node, "name"):
return False
return any(node.name().startswith(p) for p in self.config.internal_prefixes)
return any(
node.name().startswith(p) for p in self.config.internal_prefixes
)

@staticmethod
def _is_unstable_module(node: chapel.AstNode):
Expand Down Expand Up @@ -202,7 +204,9 @@ def _check_advanced_rule(
# so we can't stop it from going into unstable modules. Instead,
# once the rule emits a warning, check by traversing the AST
# if the warning target should be skipped.
if self.config.skip_unstable and LintDriver._in_unstable_module(node):
if self.config.skip_unstable and LintDriver._in_unstable_module(
node
):
continue

yield (node, name, fixits)
Expand Down

0 comments on commit a9b926b

Please sign in to comment.