forked from finos/rune-dsl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Copied changes from enum-extensions branch * Fixed static compilation errors * Cleaned * Cleaned * Added tests * Fixed * Added hover for enum type
- Loading branch information
1 parent
f4d4790
commit bfc2739
Showing
9 changed files
with
274 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
rosetta-ide/src/main/java/com/regnosys/rosetta/ide/hover/RosettaHoverContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.regnosys.rosetta.ide.hover; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.util.EcoreUtil; | ||
import org.eclipse.xtext.ide.server.Document; | ||
import org.eclipse.xtext.ide.server.hover.HoverContext; | ||
import org.eclipse.xtext.resource.XtextResource; | ||
import org.eclipse.xtext.util.ITextRegion; | ||
|
||
public class RosettaHoverContext extends HoverContext { | ||
|
||
private final EObject owner; | ||
|
||
public RosettaHoverContext(Document document, XtextResource resource, int offset, ITextRegion region, EObject element, EObject owner) { | ||
super(document, resource, offset, region, element); | ||
this.owner = owner; | ||
} | ||
|
||
public EObject getOwner() { | ||
return owner; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RosettaHoverContext [document=" + getDocument() + ", resource=" + (getResource() == null ? "null" : getResource().getURI()) | ||
+ ", offset=" + getOffset() + ", region=" + getRegion() + ", element=" | ||
+ (getElement() == null ? "null" : EcoreUtil.getURI(getElement())) + ", owner=" | ||
+ (getOwner() == null ? "null" : EcoreUtil.getURI(getOwner())) + "]"; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
rosetta-ide/src/main/java/com/regnosys/rosetta/ide/hover/RosettaHoverService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.regnosys.rosetta.ide.hover; | ||
|
||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.lsp4j.Hover; | ||
import org.eclipse.lsp4j.HoverParams; | ||
import org.eclipse.lsp4j.MarkupContent; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.xtext.ide.server.Document; | ||
import org.eclipse.xtext.ide.server.hover.HoverService; | ||
import org.eclipse.xtext.ide.server.hover.IHoverService; | ||
import org.eclipse.xtext.nodemodel.ILeafNode; | ||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; | ||
import org.eclipse.xtext.parser.IParseResult; | ||
import org.eclipse.xtext.resource.EObjectAtOffsetHelper; | ||
import org.eclipse.xtext.resource.ILocationInFileProvider; | ||
import org.eclipse.xtext.resource.XtextResource; | ||
import org.eclipse.xtext.util.CancelIndicator; | ||
import org.eclipse.xtext.util.ITextRegion; | ||
|
||
import com.google.common.collect.Streams; | ||
|
||
public class RosettaHoverService extends HoverService { | ||
@Inject | ||
private EObjectAtOffsetHelper eObjectAtOffsetHelper; | ||
|
||
@Inject | ||
private ILocationInFileProvider locationInFileProvider; | ||
|
||
@Inject | ||
private RosettaDocumentationProvider documentationProvider; | ||
|
||
@Override | ||
public Hover hover(Document document, XtextResource resource, HoverParams params, CancelIndicator cancelIndicator) { | ||
int offset = document.getOffSet(params.getPosition()); | ||
RosettaHoverContext context = createContext(document, resource, offset); | ||
return hover(context); | ||
} | ||
|
||
protected RosettaHoverContext createContext(Document document, XtextResource resource, int offset) { | ||
EObject crossLinkedEObject = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, offset); | ||
if (crossLinkedEObject != null) { | ||
if (crossLinkedEObject.eIsProxy()) { | ||
return null; | ||
} | ||
IParseResult parseResult = resource.getParseResult(); | ||
if (parseResult == null) { | ||
return null; | ||
} | ||
ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset); | ||
if (leafNode != null && leafNode.isHidden() && leafNode.getOffset() == offset) { | ||
leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset - 1); | ||
} | ||
if (leafNode == null) { | ||
return null; | ||
} | ||
ITextRegion leafRegion = leafNode.getTextRegion(); | ||
EObject owner = NodeModelUtils.findActualSemanticObjectFor(leafNode); | ||
return new RosettaHoverContext(document, resource, offset, leafRegion, crossLinkedEObject, owner); | ||
} | ||
EObject element = eObjectAtOffsetHelper.resolveElementAt(resource, offset); | ||
if (element == null) { | ||
return null; | ||
} | ||
ITextRegion region = locationInFileProvider.getSignificantTextRegion(element); | ||
return new RosettaHoverContext(document, resource, offset, region, element, element); | ||
} | ||
|
||
protected Hover hover(RosettaHoverContext context) { | ||
if (context == null) { | ||
return IHoverService.EMPTY_HOVER; | ||
} | ||
MarkupContent contents = getMarkupContent(context); | ||
if (contents == null) { | ||
return IHoverService.EMPTY_HOVER; | ||
} | ||
Range range = getRange(context); | ||
if (range == null) { | ||
return IHoverService.EMPTY_HOVER; | ||
} | ||
return new Hover(contents, range); | ||
} | ||
|
||
protected MarkupContent getMarkupContent(RosettaHoverContext ctx) { | ||
return toMarkupContent(getKind(ctx), getContents(ctx.getElement(), ctx.getOwner())); | ||
} | ||
|
||
public String getContents(EObject element, EObject owner) { | ||
Stream<String> allDocs = Stream.empty(); | ||
if (element != null) { | ||
allDocs = Streams.concat(allDocs, documentationProvider.getDocumentationFromReference(element).stream()); | ||
} | ||
if (owner != null) { | ||
allDocs = Streams.concat(allDocs, documentationProvider.getDocumentationFromOwner(owner).stream()); | ||
} | ||
return allDocs.collect(Collectors.joining("\n\n")); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...a-ide/src/test/java/com/regnosys/rosetta/ide/hover/RosettaDocumentationProviderTest.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.regnosys.rosetta.ide.hover | ||
|
||
import com.regnosys.rosetta.ide.tests.AbstractRosettaLanguageServerTest | ||
import org.junit.jupiter.api.Test | ||
|
||
class RosettaDocumentationProviderTest extends AbstractRosettaLanguageServerTest { | ||
@Test | ||
def testMultiCardinalityDocs() { | ||
testHover[ | ||
val model = ''' | ||
namespace foo.bar | ||
type Foo: | ||
attr int (2..3) | ||
''' | ||
it.model = model | ||
it.line = 3 | ||
it.column = 1 | ||
it.assertHover = [ | ||
val expected = ''' | ||
[[3, 1] .. [3, 5]] | ||
kind: markdown | ||
value: **Multi cardinality.** | ||
''' | ||
assertEquals(expected, toExpectation) | ||
] | ||
] | ||
} | ||
|
||
@Test | ||
def testImplicitEnumDocs() { | ||
testHover[ | ||
val model = ''' | ||
namespace foo.bar | ||
enum MyEnum: | ||
VALUE | ||
func Foo: | ||
output: | ||
result MyEnum (1..1) | ||
set result: | ||
VALUE | ||
''' | ||
it.model = model | ||
it.line = 10 | ||
it.column = 2 | ||
it.assertHover = [ | ||
val expected = ''' | ||
[[10, 2] .. [10, 7]] | ||
kind: markdown | ||
value: MyEnum | ||
''' | ||
assertEquals(expected, toExpectation) | ||
] | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters