diff --git a/src/main/java/com/github/cameltooling/lsp/internal/parser/ParserFileHelper.java b/src/main/java/com/github/cameltooling/lsp/internal/parser/ParserFileHelper.java index 1f68c07f6..7265858af 100644 --- a/src/main/java/com/github/cameltooling/lsp/internal/parser/ParserFileHelper.java +++ b/src/main/java/com/github/cameltooling/lsp/internal/parser/ParserFileHelper.java @@ -26,7 +26,7 @@ public abstract class ParserFileHelper { - protected static final List CAMEL_POSSIBLE_TYPES = Arrays.asList("to", "from"); + protected static final List CAMEL_POSSIBLE_TYPES = Arrays.asList("to", "from", "endpoint"); public String getLine(TextDocumentItem textDocumentItem, Position position) { int line = position.getLine(); diff --git a/src/main/java/com/github/cameltooling/lsp/internal/parser/ParserXMLFileHelper.java b/src/main/java/com/github/cameltooling/lsp/internal/parser/ParserXMLFileHelper.java index 15f93dc55..21c7eb17a 100644 --- a/src/main/java/com/github/cameltooling/lsp/internal/parser/ParserXMLFileHelper.java +++ b/src/main/java/com/github/cameltooling/lsp/internal/parser/ParserXMLFileHelper.java @@ -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 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; @@ -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; } - } diff --git a/src/test/java/com/github/cameltooling/lsp/internal/completion/CamelEndpointUriCompletionTest.java b/src/test/java/com/github/cameltooling/lsp/internal/completion/CamelEndpointUriCompletionTest.java index fb89a09cf..6d7efb97f 100644 --- a/src/test/java/com/github/cameltooling/lsp/internal/completion/CamelEndpointUriCompletionTest.java +++ b/src/test/java/com/github/cameltooling/lsp/internal/completion/CamelEndpointUriCompletionTest.java @@ -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 data() { return Arrays.asList(new Object[][] { - // test the component schemes + // test the component schemes - FROM { "\n", 0, 11, "Empty component scheme", null, 300, ".xml"}, { "\n", 0, 12, "URI with component scheme f", "f", 8, ".xml"}, { "\n", 0, 13, "URI with component scheme fi", "fi", 1, ".xml"}, @@ -53,7 +53,7 @@ public static Collection data() { { "\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 { "\n", 0, 15, "Empty path param", "ahc:", 1, ".xml"}, { "\n", 0, 16, "URI with path param h", "ahc:h", 1, ".xml"}, { "\n", 0, 17, "URI with path param ht", "ahc:ht", 1, ".xml"}, @@ -62,9 +62,9 @@ public static Collection data() { { "\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 - { "\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"}, + { "\n", 0, 20, "Empty option", null, 70, ".xml"}, { "\n", 0, 21, "URI with option n", "n", 1, ".xml"}, { "\n", 0, 22, "URI with option no", "no", 1, ".xml"}, { "\n", 0, 23, "URI with option noo", "noo", 1, ".xml"}, @@ -76,8 +76,50 @@ public static Collection data() { { "\n", 0, 25, "URI with option noop", null, 2, ".xml"}, { "\n", 0, 21, "Param Key Completion", "n", 1, ".xml"}, { "\n", 0, 22, "Param Key Completion", "no", 1, ".xml"}, - { "\n", 0, 35, "Second option", null, 70, ".xml"} + { "\n", 0, 35, "Second option", null, 70, ".xml"}, + + // test the component schemes - TO + { "\n", 0, 9, "Empty component scheme", null, 300, ".xml"}, + { "\n", 0, 10, "URI with component scheme f", "f", 8, ".xml"}, + { "\n", 0, 11, "URI with component scheme fi", "fi", 1, ".xml"}, + { "\n", 0, 12, "URI with component scheme fil", "fil", 1, ".xml"}, + { "\n", 0, 13, "URI with component scheme file", "file", 1, ".xml"}, + { "\n", 0, 9, "URI with component scheme file", null, 300, ".xml"}, + { "\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 + { "\n", 0, 13, "Empty path param", "ahc:", 1, ".xml"}, + { "\n", 0, 14, "URI with path param h", "ahc:h", 1, ".xml"}, + { "\n", 0, 15, "URI with path param ht", "ahc:ht", 1, ".xml"}, + { "\n", 0, 16, "URI with path param htt", "ahc:htt", 1, ".xml"}, + { "\n", 0, 17, "URI with path param http", "ahc:http", 1, ".xml"}, + { "\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 + { "\n", 0, 15, "Empty component scheme", null, 300, ".xml"}, + { "\n", 0, 16, "URI with component scheme f", "f", 8, ".xml"}, + { "\n", 0, 17, "URI with component scheme fi", "fi", 1, ".xml"}, + { "\n", 0, 18, "URI with component scheme fil", "fil", 1, ".xml"}, + { "\n", 0, 19, "URI with component scheme file", "file", 1, ".xml"}, + { "\n", 0, 15, "URI with component scheme file", null, 300, ".xml"}, + { "\n", 0, 16, "URI with component scheme file", "f", 8, ".xml"}, + // test the endpoint path params + { "\n", 0, 19, "Empty path param", "ahc:", 1, ".xml"}, + { "\n", 0, 20, "URI with path param h", "ahc:h", 1, ".xml"}, + { "\n", 0, 21, "URI with path param ht", "ahc:ht", 1, ".xml"}, + { "\n", 0, 22, "URI with path param htt", "ahc:htt", 1, ".xml"}, + { "\n", 0, 23, "URI with path param http", "ahc:http", 1, ".xml"}, + { "\n", 0, 19, "URI with path param http", null, 1, ".xml"}, + // endpoint uri options + { "\n", 0, 24, "Empty option", null, 70, ".xml"}, + { "\n", 0, 25, "URI with option n", "n", 1, ".xml"}, + { "\n", 0, 26, "URI with option no", "no", 1, ".xml"}, + { "\n", 0, 27, "URI with option noo", "noo", 1, ".xml"}, + { "\n", 0, 28, "URI with option noop", "noop", 1, ".xml"}, + { "\n", 0, 24, "URI with option noop", null, 10, ".xml"}, + { "\n", 0, 30, "URI with option noop", "f", 1, ".xml"}, }); } @@ -99,7 +141,6 @@ public static Collection data() { @Test public void testProvideCompletionForCamelBlueprintNamespace() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer(textToTest, extension); - CompletableFuture, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(line, character)); List items = completions.get().getLeft(); assertThat(items.size()).isGreaterThanOrEqualTo(expectedMinResultSetSize);