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

Support single quotes #124 #126

Merged
merged 3 commits into from
Aug 8, 2018
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@
*/
package com.github.cameltooling.lsp.internal.parser;

import java.util.Arrays;
import java.util.List;

import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.TextDocumentItem;

import com.github.cameltooling.lsp.internal.instancemodel.CamelURIInstance;

public abstract class ParserFileHelper {

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

public String getLine(TextDocumentItem textDocumentItem, Position position) {
int line = position.getLine();
return getLine(textDocumentItem, line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@
*/
package com.github.cameltooling.lsp.internal.parser;

import java.util.Arrays;
import java.util.List;

import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.TextDocumentItem;

import com.github.cameltooling.lsp.internal.instancemodel.CamelURIInstance;

public class ParserJavaFileHelper extends ParserFileHelper {


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

@Override
public String getCamelComponentUri(String line, int characterPosition) {
for (String methodName : CAMEL_POSSIBLE_TYPES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,29 @@
public class ParserXMLFileHelper extends ParserFileHelper {

private static final Logger LOGGER = LoggerFactory.getLogger(ParserXMLFileHelper.class);

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

private static final String ATTRIBUTE_ROUTE = "route";
private static final String ATTRIBUTE_CAMEL_CONTEXT = "camelContext";
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 = uriAttribute + URI_PARAM.length();
Character closure = line.charAt(firstQuote);
if (POSSIBLE_URI_CLOSURE_CHARS.contains(closure)) {
int nextQuote = line.indexOf(closure, firstQuote+1);
if (isBetween(characterPosition, firstQuote, nextQuote)) {
return line.substring(firstQuote+1, nextQuote);
}
} else {
LOGGER.warn("Encountered an unsupported URI closure char %s", closure);
}
}
return null;
Expand Down Expand Up @@ -147,5 +158,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,45 +39,87 @@
@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"},
{ "<from uri=\"fil\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 14, "URI with component scheme fil", "fil", 1, ".xml"},
{ "<from uri=\"file\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 15, "URI with component scheme file", "file", 1, ".xml"},
{ "<from uri='file' xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 15, "URI with component scheme file", "file", 1, ".xml"},
{ "<from uri=\"file\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 11, "URI with component scheme file", null, 300, ".xml"},
{ "<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: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"},
{ "<from uri=\"ahc:htt\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 18, "URI with path param htt", "ahc:htt", 1, ".xml"},
{ "<from uri=\"ahc:http\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 19, "URI with path param http", "ahc:http", 1, ".xml"},
{ "<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"},
{ "<from uri=\"file:bla?noop\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 24, "URI with option noop", "noop", 1, ".xml"},
{ "<from uri='file:bla?noop' xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 24, "URI with option noop", "noop", 1, ".xml"},
{ "<from uri=\"file:bla?noop\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 20, "URI with option noop", null, 10, ".xml"},
{ "<from uri=\"file:bla?noop=f\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 26, "URI with option noop", "f", 1, ".xml"},
{ "from(\"file:bla?noop=f\")//camel", 0, 21, "URI with option noop", "f", 1, ".java"},
{ "<from uri=\"file:bla?noop=t\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 26, "URI with option noop", "t", 1, ".xml"},
{ "<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