Skip to content

Commit

Permalink
add support for global endpoint uri completion #121
Browse files Browse the repository at this point in the history
Signed-off-by: Lars Heinemann <lhein.smx@gmail.com>
  • Loading branch information
lhein committed Aug 6, 2018
1 parent c472f12 commit d76c821
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public abstract class ParserFileHelper {

protected static final List<String> CAMEL_POSSIBLE_TYPES = Arrays.asList("to", "from");
protected static final List<String> CAMEL_POSSIBLE_TYPES = Arrays.asList("to", "from", "endpoint");

public String getLine(TextDocumentItem textDocumentItem, Position position) {
int line = position.getLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ public class ParserXMLFileHelper extends ParserFileHelper {
private static final String NAMESPACEURI_CAMEL_BLUEPRINT = "http://camel.apache.org/schema/blueprint";
private static final String NAMESPACEURI_CAMEL_SPRING = "http://camel.apache.org/schema/spring";
private static final List<String> DOCUMENT_SYMBOL_POSSIBLE_TYPES = Arrays.asList(ATTRIBUTE_CAMEL_CONTEXT, ATTRIBUTE_ROUTE);
private static final String URI_PARAM = "uri=\"";

public String getCamelComponentUri(String line, int characterPosition) {
int uriAttribute = line.indexOf("uri=\"");
int uriAttribute = line.indexOf(URI_PARAM);
if(uriAttribute != -1) {
int nextQuote = line.indexOf('\"', uriAttribute + 5);
if (isBetween(characterPosition, uriAttribute + 5, nextQuote)) {
return line.substring(uriAttribute + 5, nextQuote);
int firstQuote = line.indexOf('\"', uriAttribute);
int nextQuote = line.indexOf('\"', firstQuote+1);
if (isBetween(characterPosition, firstQuote, nextQuote)) {
return line.substring(firstQuote+1, nextQuote);
}
}
return null;
Expand Down Expand Up @@ -147,5 +149,4 @@ public CamelURIInstance createCamelURIInstance(TextDocumentItem textDocumentItem
public int getPositionInCamelURI(TextDocumentItem textDocumentItem, Position position) {
return position.getCharacter() - getLine(textDocumentItem, position).indexOf("uri=") - 5;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
@RunWith(Parameterized.class)
public class CamelEndpointUriCompletionTest extends AbstractCamelLanguageServerTest {

@Parameters(name="{4} - Position ({1},{2}) - {6}")
@Parameters(name="{4} - Position ({1},{2}) - {6} - ({0})")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {

// test the component schemes
// test the component schemes - FROM
{ "<from uri=\"\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 11, "Empty component scheme", null, 300, ".xml"},
{ "<from uri=\"f\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 12, "URI with component scheme f", "f", 8, ".xml"},
{ "<from uri=\"fi\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 13, "URI with component scheme fi", "fi", 1, ".xml"},
Expand All @@ -53,7 +53,7 @@ public static Collection<Object[]> data() {
{ "<from uri=\"file\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 12, "URI with component scheme file", "f", 8, ".xml"},
{ "from(\"file\")//camel", 0, 7, "URI with component scheme file for Java", "f", 8, ".java"},

// test the path params
// test the path params - FROM
{ "<from uri=\"ahc:\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 15, "Empty path param", "ahc:", 1, ".xml"},
{ "<from uri=\"ahc:h\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 16, "URI with path param h", "ahc:h", 1, ".xml"},
{ "<from uri=\"ahc:ht\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 17, "URI with path param ht", "ahc:ht", 1, ".xml"},
Expand All @@ -62,9 +62,9 @@ public static Collection<Object[]> data() {
{ "<from uri=\"ahc:httpUri\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 15, "URI with path param http", null, 1, ".xml"},
{ "from(\"ahc:httpUri\")//camel", 0, 10, "URI with path param http for java", null, 1, ".java"},

// test the uri options
{ "<from uri=\"file:bla?\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 20, "Empty option", null, 70, ".xml"},
// test the uri options - FROM
{ "from(\"file:bla?\")//camel", 0, 15, "Empty option for Java", null, 70, ".java"},
{ "<from uri=\"file:bla?\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 20, "Empty option", null, 70, ".xml"},
{ "<from uri=\"file:bla?n\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 21, "URI with option n", "n", 1, ".xml"},
{ "<from uri=\"file:bla?no\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 22, "URI with option no", "no", 1, ".xml"},
{ "<from uri=\"file:bla?noo\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 23, "URI with option noo", "noo", 1, ".xml"},
Expand All @@ -76,8 +76,50 @@ public static Collection<Object[]> data() {
{ "<from uri=\"file:bla?noop=false\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 25, "URI with option noop", null, 2, ".xml"},
{ "<from uri=\"file:bla?noop=false\" xmlns=\"http://camel.apache.org/schema/blueprint\"/>\n", 0, 21, "Param Key Completion", "n", 1, ".xml"},
{ "<from uri=\"file:bla?noop=false\" xmlns=\"http://camel.apache.org/schema/blueprint\"/>\n", 0, 22, "Param Key Completion", "no", 1, ".xml"},
{ "<from uri=\"file:bla?noop=false&amp;\" xmlns=\"http://camel.apache.org/schema/blueprint\"/>\n", 0, 35, "Second option", null, 70, ".xml"}
{ "<from uri=\"file:bla?noop=false&amp;\" xmlns=\"http://camel.apache.org/schema/blueprint\"/>\n", 0, 35, "Second option", null, 70, ".xml"},

// test the component schemes - TO
{ "<to uri=\"\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 9, "Empty component scheme", null, 300, ".xml"},
{ "<to uri=\"f\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 10, "URI with component scheme f", "f", 8, ".xml"},
{ "<to uri=\"fi\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 11, "URI with component scheme fi", "fi", 1, ".xml"},
{ "<to uri=\"fil\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 12, "URI with component scheme fil", "fil", 1, ".xml"},
{ "<to uri=\"file\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 13, "URI with component scheme file", "file", 1, ".xml"},
{ "<to uri=\"file\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 9, "URI with component scheme file", null, 300, ".xml"},
{ "<to uri=\"file\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 10, "URI with component scheme file", "f", 8, ".xml"},
{ "to(\"file\")//camel", 0, 5, "URI with component scheme file for Java", "f", 8, ".java"},

// test the path params - TO
{ "<to uri=\"ahc:\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 13, "Empty path param", "ahc:", 1, ".xml"},
{ "<to uri=\"ahc:h\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 14, "URI with path param h", "ahc:h", 1, ".xml"},
{ "<to uri=\"ahc:ht\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 15, "URI with path param ht", "ahc:ht", 1, ".xml"},
{ "<to uri=\"ahc:htt\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 16, "URI with path param htt", "ahc:htt", 1, ".xml"},
{ "<to uri=\"ahc:http\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 17, "URI with path param http", "ahc:http", 1, ".xml"},
{ "<to uri=\"ahc:httpUri\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n", 0, 13, "URI with path param http", null, 1, ".xml"},
{ "to(\"ahc:httpUri\")//camel", 0, 10, "URI with path param http for java", null, 1, ".java"},

// test endpoint
{ "<endpoint uri=\"\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 15, "Empty component scheme", null, 300, ".xml"},
{ "<endpoint uri=\"f\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 16, "URI with component scheme f", "f", 8, ".xml"},
{ "<endpoint uri=\"fi\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 17, "URI with component scheme fi", "fi", 1, ".xml"},
{ "<endpoint uri=\"fil\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 18, "URI with component scheme fil", "fil", 1, ".xml"},
{ "<endpoint uri=\"file\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 19, "URI with component scheme file", "file", 1, ".xml"},
{ "<endpoint uri=\"file\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 15, "URI with component scheme file", null, 300, ".xml"},
{ "<endpoint uri=\"file\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 16, "URI with component scheme file", "f", 8, ".xml"},
// test the endpoint path params
{ "<endpoint uri=\"ahc:\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 19, "Empty path param", "ahc:", 1, ".xml"},
{ "<endpoint uri=\"ahc:h\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 20, "URI with path param h", "ahc:h", 1, ".xml"},
{ "<endpoint uri=\"ahc:ht\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 21, "URI with path param ht", "ahc:ht", 1, ".xml"},
{ "<endpoint uri=\"ahc:htt\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 22, "URI with path param htt", "ahc:htt", 1, ".xml"},
{ "<endpoint uri=\"ahc:http\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 23, "URI with path param http", "ahc:http", 1, ".xml"},
{ "<endpoint uri=\"ahc:httpUri\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 19, "URI with path param http", null, 1, ".xml"},
// endpoint uri options
{ "<endpoint uri=\"file:bla?\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 24, "Empty option", null, 70, ".xml"},
{ "<endpoint uri=\"file:bla?n\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 25, "URI with option n", "n", 1, ".xml"},
{ "<endpoint uri=\"file:bla?no\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 26, "URI with option no", "no", 1, ".xml"},
{ "<endpoint uri=\"file:bla?noo\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 27, "URI with option noo", "noo", 1, ".xml"},
{ "<endpoint uri=\"file:bla?noop\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 28, "URI with option noop", "noop", 1, ".xml"},
{ "<endpoint uri=\"file:bla?noop\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 24, "URI with option noop", null, 10, ".xml"},
{ "<endpoint uri=\"file:bla?noop=f\" xmlns=\"http://camel.apache.org/schema/blueprint\"></endpoint>\n", 0, 30, "URI with option noop", "f", 1, ".xml"},
});
}

Expand All @@ -99,7 +141,6 @@ public static Collection<Object[]> data() {
@Test
public void testProvideCompletionForCamelBlueprintNamespace() throws Exception {
CamelLanguageServer camelLanguageServer = initializeLanguageServer(textToTest, extension);

CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(line, character));
List<CompletionItem> items = completions.get().getLeft();
assertThat(items.size()).isGreaterThanOrEqualTo(expectedMinResultSetSize);
Expand Down

0 comments on commit d76c821

Please sign in to comment.