Skip to content

Commit 522eb06

Browse files
author
Kaushik Ghose
committed
Add in special handling for $import in hints
Also see common-workflow-language/common-workflow-language#896 for details. Closes #75
1 parent a8ee30a commit 522eb06

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

benten/cwl/anytype.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) 2019 Seven Bridges. See LICENSE
22

33
from .basetype import CWLBaseType, MapSubjectPredicate, TypeCheck
4+
from .importincludetype import CWLImportInclude
45

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

2425
def check(self, node, node_key: str=None, map_sp: MapSubjectPredicate=None) -> TypeCheck:
25-
# Special treatment for the any type. It agrees to everything
26-
return TypeCheck(self)
26+
if isinstance(node, dict) and "$import" in node:
27+
# Extra-special treatment for $imports
28+
return TypeCheck(CWLImportInclude(key="$import", import_context=""))
29+
else:
30+
# Special treatment for the any type. It agrees to everything
31+
return TypeCheck(self)

benten/cwl/lib.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,23 @@ def __init__(self, node, key_field, problems):
6060
self.as_dict[key] = _item
6161
self.key_ids[key] = get_range_for_value(_item, key_field)
6262
self.map_key_to_idx[key] = n
63-
else:
64-
problems += [
65-
Diagnostic(
66-
_range=get_range_for_value(node, n),
67-
message=f"Missing key field {key_field}",
68-
severity=DiagnosticSeverity.Error)
69-
]
63+
continue
64+
65+
# Exception to handle $import
66+
# see https://github.com/common-workflow-language/common-workflow-language/issues/896
67+
if "$import" in _item:
68+
key = "class"
69+
self.as_dict[key] = _item
70+
self.key_ids[key] = get_range_for_value(_item, "$import")
71+
self.map_key_to_idx[key] = n
72+
continue
73+
74+
problems += [
75+
Diagnostic(
76+
_range=get_range_for_value(node, n),
77+
message=f"Missing key field {key_field}",
78+
severity=DiagnosticSeverity.Error)
79+
]
7080

7181
def get_range_for_id(self, key):
7282
if self.was_dict:

benten/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Copyright (c) 2019-2020 Seven Bridges. See LICENSE
22

3-
__version__ = "2020.02.05"
3+
__version__ = "2020.02.06"

tests/cwl/misc/cl-hints-import.cwl

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class: CommandLineTool
2+
cwlVersion: v1.0
3+
inputs: []
4+
hints:
5+
- $import: does_not_exist.yml

tests/test_code_intelligence.py

+14
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,17 @@ def test_schemadef_include():
138138

139139
type_error = next(p for p in doc.problems if p.range.start.line == 4)
140140
assert type_error.message.startswith("Expecting one of")
141+
142+
143+
def test_hints_imports():
144+
this_path = current_path / "cwl" / "misc" / "cl-hints-import.cwl"
145+
doc = load(doc_path=this_path, type_dicts=type_dicts)
146+
147+
assert len(doc.problems) == 1
148+
149+
missing_error = next(p for p in doc.problems if p.range.start.line == 4)
150+
assert missing_error.message.startswith("Missing document:")
151+
152+
cmpl = doc.completion(Position(4, 20))
153+
assert "cl-schemadef-import.cwl" in [c.label for c in cmpl]
154+
# The completer should look for all files in the current directory

0 commit comments

Comments
 (0)