Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword code assist #40

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app.hypermedia.testing.dsl.ide/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,32 @@
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/main/xtext-gen"/>
<classpathentry kind="src" path="src/main/xtend-gen"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/xtext-gen">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/xtend-gen">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
38 changes: 38 additions & 0 deletions app.hypermedia.testing.dsl.ide/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@
</resources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>initialize</phase>
<goals>
<goal>add-test-source</goal>
<goal>add-test-resource</goal>
</goals>
<configuration>
<sources>
<source>src/test/xtext-gen</source>
</sources>
<resources>
<resource>
<directory>src/test/xtext-gen</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -101,6 +122,23 @@
</build>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.testing</artifactId>
<version>${xtextVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>app.hypermedia.testing.dsl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
*/
package app.hypermedia.testing.dsl.ide

import app.hypermedia.testing.dsl.ide.editor.contentassist.CoreContentAssist
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider

/**
* Use this class to register ide components.
*/
class CoreIdeModule extends AbstractCoreIdeModule {
def Class<? extends IdeContentProposalProvider> bindIdeContentProposalProvider() {
return CoreContentAssist
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
*/
package app.hypermedia.testing.dsl.ide

import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider
import app.hypermedia.testing.dsl.ide.editor.contentassist.HydraContentAssist

/**
* Use this class to register ide components.
*/
class HydraIdeModule extends AbstractHydraIdeModule {
def Class<? extends IdeContentProposalProvider> bindIdeContentProposalProvider() {
return HydraContentAssist
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package app.hypermedia.testing.dsl.ide.editor.contentassist

import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor
import org.eclipse.xtext.RuleCall
import org.eclipse.xtext.Keyword

class CoreContentAssist extends IdeContentProposalProvider {
override dispatch void createProposals(RuleCall ruleCall, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
switch (ruleCall.rule.name) {
case "ClassBlock": {
val entry = proposalCreator.createProposal('With Class', context)
acceptor.accept(entry, proposalPriorities.getDefaultPriority(entry))
}
case "FollowStatement": {
val entry = proposalCreator.createProposal('Follow [uri]', context)
acceptor.accept(entry, proposalPriorities.getDefaultPriority(entry))
}
}
}

override protected filterKeyword(Keyword keyword, ContentAssistContext context) {
if (keyword.value == "Follow") {
return false
}

super.filterKeyword(keyword, context)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package app.hypermedia.testing.dsl.ide.editor.contentassist

import org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.RuleCall

class HydraContentAssist extends CoreContentAssist {
override dispatch void createProposals(RuleCall ruleCall, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
switch (ruleCall.rule.name) {
case "RelaxedOperationBlock": {
val entry = proposalCreator.createProposal('With Operation', context)
acceptor.accept(entry, proposalPriorities.getDefaultPriority(entry))
}
case "OperationBlock": {
var entry = proposalCreator.createProposal('With Operation', context)
acceptor.accept(entry, proposalPriorities.getDefaultPriority(entry))
entry = proposalCreator.createProposal('Expect Operation', context)
acceptor.accept(entry, proposalPriorities.getDefaultPriority(entry))
}
default: {
super._createProposals(ruleCall, context, acceptor)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package app.hypermedia.testing.dsl.ide.tests.editor.contentassist

import org.junit.jupiter.api.Test
import org.eclipse.xtext.testing.AbstractLanguageServerTest

class CoreCompletionTest extends AbstractLanguageServerTest {

new() {
super("api")
}

@Test
def void testCompletion_01() {
testCompletion [
model = ''
expectedCompletionItems = '''
With Class -> With Class [[0, 0] .. [0, 0]]
'''
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package app.hypermedia.testing.dsl.ide.tests.editor.contentassist

import org.junit.jupiter.api.Test
import org.eclipse.xtext.testing.AbstractLanguageServerTest

class HydraCompletionTest extends AbstractLanguageServerTest {

new() {
super("hydra")
}

@Test
def void testCompletion_01() {
testCompletion [
model = ''
expectedCompletionItems = '''
With Class -> With Class [[0, 0] .. [0, 0]]
With Operation -> With Operation [[0, 0] .. [0, 0]]
'''
]
}
}
2 changes: 1 addition & 1 deletion app.hypermedia.testing.dsl.web/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<h1>Example Hypertest DSL Web Editor</h1>
<form method="GET" action="">
<select id="language" name="language">
<option value="core">Core grammar</option>
<option value="api">Core grammar</option>
<option value="hydra">Hydra</option>
</select>
<input type="submit" value="Switch language">
Expand Down