Skip to content

Commit

Permalink
Add in special handling for $import in hints
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaushik Ghose committed Feb 6, 2020
1 parent a8ee30a commit 522eb06
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
9 changes: 7 additions & 2 deletions benten/cwl/anytype.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2019 Seven Bridges. See LICENSE

from .basetype import CWLBaseType, MapSubjectPredicate, TypeCheck
from .importincludetype import CWLImportInclude

import logging
logger = logging.getLogger(__name__)
Expand All @@ -22,5 +23,9 @@ def all_possible_type_names(self):
return list(self.type_dict.keys())

def check(self, node, node_key: str=None, map_sp: MapSubjectPredicate=None) -> TypeCheck:
# Special treatment for the any type. It agrees to everything
return TypeCheck(self)
if isinstance(node, dict) and "$import" in node:
# Extra-special treatment for $imports
return TypeCheck(CWLImportInclude(key="$import", import_context=""))
else:
# Special treatment for the any type. It agrees to everything
return TypeCheck(self)
24 changes: 17 additions & 7 deletions benten/cwl/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,23 @@ def __init__(self, node, key_field, problems):
self.as_dict[key] = _item
self.key_ids[key] = get_range_for_value(_item, key_field)
self.map_key_to_idx[key] = n
else:
problems += [
Diagnostic(
_range=get_range_for_value(node, n),
message=f"Missing key field {key_field}",
severity=DiagnosticSeverity.Error)
]
continue

# Exception to handle $import
# see https://github.com/common-workflow-language/common-workflow-language/issues/896
if "$import" in _item:
key = "class"
self.as_dict[key] = _item
self.key_ids[key] = get_range_for_value(_item, "$import")
self.map_key_to_idx[key] = n
continue

problems += [
Diagnostic(
_range=get_range_for_value(node, n),
message=f"Missing key field {key_field}",
severity=DiagnosticSeverity.Error)
]

def get_range_for_id(self, key):
if self.was_dict:
Expand Down
2 changes: 1 addition & 1 deletion benten/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Copyright (c) 2019-2020 Seven Bridges. See LICENSE

__version__ = "2020.02.05"
__version__ = "2020.02.06"
5 changes: 5 additions & 0 deletions tests/cwl/misc/cl-hints-import.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class: CommandLineTool
cwlVersion: v1.0
inputs: []
hints:
- $import: does_not_exist.yml
14 changes: 14 additions & 0 deletions tests/test_code_intelligence.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,17 @@ def test_schemadef_include():

type_error = next(p for p in doc.problems if p.range.start.line == 4)
assert type_error.message.startswith("Expecting one of")


def test_hints_imports():
this_path = current_path / "cwl" / "misc" / "cl-hints-import.cwl"
doc = load(doc_path=this_path, type_dicts=type_dicts)

assert len(doc.problems) == 1

missing_error = next(p for p in doc.problems if p.range.start.line == 4)
assert missing_error.message.startswith("Missing document:")

cmpl = doc.completion(Position(4, 20))
assert "cl-schemadef-import.cwl" in [c.label for c in cmpl]
# The completer should look for all files in the current directory

0 comments on commit 522eb06

Please sign in to comment.