Skip to content

Commit

Permalink
Merge branch 'feature/hoverdocs'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaushik Ghose committed Mar 10, 2020
2 parents 87a748f + 17e024e commit b2cce9f
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 13 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This is a [language server] for
- Outline view (Symbols) + Step symbols
- Type validations
- Port validations
- Display language documentation on hover

![Benten + VS Code](https://raw.githubusercontent.com/rabix/benten/master/media/2019.12.03/full-window.png)

Expand Down
7 changes: 4 additions & 3 deletions benten/code/intelligence.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from typing import List
import pathlib

from ..langserver.lspobjects import (Position, Range, CompletionItem)
from ..langserver.lspobjects import (Position, Range, CompletionItem, Hover)
from .executioncontext import ExecutionContext

import logging
Expand All @@ -28,14 +28,15 @@ def __init__(self, loc: Range):

class IntelligenceNode:

def __init__(self, completions: List[str]=None):
def __init__(self, completions: List[str] = None, doc: str = ""):
self._completions = completions or []
self.doc = doc

def completion(self):
return [CompletionItem(label=c) for c in self._completions]

def hover(self):
pass
return Hover(self.doc, is_markdown=True)

def definition(self):
pass
Expand Down
3 changes: 3 additions & 0 deletions benten/cwl/arraytype.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def parse(self,
value_range: Range = None,
requirements=None):

if not isinstance(node, list):
return

for n, v in enumerate(node):
inferred_type = infer_type(v, self.types)
inferred_type.parse(
Expand Down
4 changes: 2 additions & 2 deletions benten/cwl/basetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class TypeCheck:

class CWLBaseType(IntelligenceNode):

def __init__(self, name):
super().__init__()
def __init__(self, name, doc: str = ""):
super().__init__(doc=doc)
self.name = name

def check(self, node, node_key: str=None, map_sp: MapSubjectPredicate=None) -> TypeCheck:
Expand Down
2 changes: 1 addition & 1 deletion benten/cwl/expressiontype.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _self_is_in_step(_path):
res = "Job inputs have not been filled out"

logger.debug(f"Guessing expression inputs are: {self.guess_inputs()}")
return Hover(res, self.range)
return Hover(res, self.range, wrap_as_code_block=True)

def definition(self):
# Hijacking this to show the sample inputs file
Expand Down
2 changes: 1 addition & 1 deletion benten/cwl/linkedfiletype.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def parse(self,
code_intel.add_lookup_node(ln)

def hover(self):
return Hover(self._contents)
return Hover(self._contents, wrap_as_code_block=True)

def definition(self):
if isinstance(self.full_path, pathlib.Path):
Expand Down
15 changes: 11 additions & 4 deletions benten/cwl/recordtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from typing import Dict

from .basetype import CWLBaseType, IntelligenceContext, Intelligence, MapSubjectPredicate, TypeCheck, Match
from .basetype import (CWLBaseType, IntelligenceContext, Intelligence, IntelligenceNode,
MapSubjectPredicate, TypeCheck, Match)
from .linkedfiletype import CWLLinkedFile
from .linkedschemadeftype import CWLLinkedSchemaDef
from .importincludetype import CWLImportInclude
Expand All @@ -23,8 +24,7 @@
class CWLRecordType(CWLBaseType):

def __init__(self, name: str, doc: str, fields: Dict[str, 'CWLFieldType']):
super().__init__(name)
self.doc = doc
super().__init__(name, doc=doc)
self.fields = fields
self.required_fields = set((k for k, v in self.fields.items() if v.required))
self.all_fields = set(self.fields.keys())
Expand Down Expand Up @@ -116,8 +116,15 @@ def parse(self,
value_range = get_range_for_value(node, k)

# key completer
_field = self.fields.get(k)
_key_doc = (_field.doc or "") if _field is not None else ""
_key_doc += "\n---\n## Sibling fields\n\n```" + \
"\n".join(f"- {k}" for k in self.fields.keys()) + \
"\n```\n"
_key_doc += f"\n---\n## {self.name or '-'}\n\n" + (self.doc or "")
ln = LookupNode(loc=key_range)
ln.intelligence_node = self
ln.intelligence_node = IntelligenceNode(
completions=list(self.fields.keys()), doc=_key_doc) # self
code_intel.add_lookup_node(ln)

# TODO: looks like this logic and the logic in lomtype can be combined
Expand Down
7 changes: 6 additions & 1 deletion benten/langserver/lspobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,17 @@ def __init__(self, name, kind, _range, selection_range, detail=None, children=No


class Hover(LSPObject):
def __init__(self, contents, _range=None, wrap_as_code_block=True):
def __init__(self, contents, _range=None, wrap_as_code_block=False, is_markdown=False):
if wrap_as_code_block:
self.contents = MarkupContent(
kind="markdown",
value="```\n" + contents + "\n```"
)
elif is_markdown:
self.contents = MarkupContent(
kind="markdown",
value=contents
)
else:
self.contents = contents

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.19"
__version__ = "2020.03.10"
6 changes: 6 additions & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@
<img src="https://github.com/rabix/benten/blob/master/media/2019.10.22/workflow-connection-validations.png"></img>
<figcaption>Port validations</figcaption>
</figure>
<hr/>

<figure>
<img src="https://github.com/rabix/benten/blob/master/media/2020.03.09/documentation-on-hover.png"></img>
<figcaption>Language documentation on hover</figcaption>
</figure>
Binary file added media/2020.03.09/documentation-on-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/test_code_intelligence.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,12 @@ def test_requirements_completion():

cmpl = doc.completion(Position(12, 5))
assert "dockerLoad" in [c.label for c in cmpl]


def test_docs_on_hover():
this_path = current_path / "cwl" / "misc" / "wf-when-input.cwl"
doc = load(doc_path=this_path, type_dicts=type_dicts)

hov = doc.hover(Position(10, 6))
assert "Sibling" in hov.contents.value
assert hov.contents.kind == "markdown"

0 comments on commit b2cce9f

Please sign in to comment.