-
Notifications
You must be signed in to change notification settings - Fork 25
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
[FUSETOOLS2-1673] Choice EIP implementation #861
base: main
Are you sure you want to change the base?
Conversation
@@ -36,5 +36,27 @@ public String getLine(String text, int line) { | |||
} | |||
return null; | |||
} | |||
|
|||
public String getTextUntilPosition(TextDocumentItem document, Position position) { | |||
String newLine = System.getProperty("line.separator"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually Client implementation of the LSP has their own policy for end of lines. Users are defining the type of end of line in either, thier IDE settings, thei rproject config, their git config. There is no need to take of care of the line separator from the system.
private static final String JAVA_CLASS_BLUEPRINT_CAMEL_ROUTEBUILDER_IMPORT | ||
= "import org.apache.camel.builder.RouteBuilder;"; | ||
|
||
private static final String JAVA_CLASS_BLUEPRINT_CLASS_DECLARATION = "public class TestRoute"; | ||
|
||
private static final String JAVA_CLASS_BLUEPRINT_CAMEL_ROUTEBUILDER_EXTEMD = "extends RouteBuilder"; | ||
|
||
private static final String JAVA_CLASS_BLUEPRINT_CONFIGURE_METHOD_DECLARATION = "public void configure()"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the terminology Bluerpint
should not be used here.
it will collides with the "Camel XML blueprint namespace" which is related to the Apache Aries Blueprint implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Blueprint can be associated with this kind of stye but I didn't know it had domain meaning. I'll change it.
.map(future -> future.join()) | ||
.flatMap(x -> x.stream()) | ||
.collect(Collectors.toList()) | ||
).thenApply(Either::forLeft); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed because we want to be able to add different completions that have different triggers
} | ||
|
||
public boolean canPutEIP(Position position) { | ||
Pattern CHOICE_EIP_PATTERN = Pattern.compile("\\)\\s*[.[c[h[o[i[c[e]?]?]?]?]?]?]?\\(?$", Pattern.MULTILINE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ugly :D, but I didn't feel like doing a Trie based implementation was justified with just one EIP, which was my original goal
I'll be refactoring this when I add more EIPs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CHOICE_EIP_PATTERN can be put as a static attribute. (if not, better to rename to follow convention of naming witout capital letter)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you precise what is working exactly and what is left for another iteration?
From my observations:
Content Based Router
template is provided when there is:- It doesn't appear when there are more letters. like
.ch
. That's fine, can be done later but in this case we can simplify the regex. But there is a test which seems to tell that it shoudl be workingcom.github.cameltooling.lsp.internal.completion.eip.EIPChoiceCompletionTest.testProvideInsertionMidWritingChoice()
, in this case I suspect that the fact that the Range is missing is causing VS Code to filter out the completion.:
- The insertion when there is
.c
is adding an extra dot:
Content Based Router
template is provided almost at the end of the completion list. I think this can be improved in another iteration by giving Range and priority- For another iteration: After calling the completion, setting the cursor for next edition inside the parenthesis of the first
when
would be great. having all places to edit would be even better
} | ||
|
||
public boolean canPutEIP(Position position) { | ||
Pattern CHOICE_EIP_PATTERN = Pattern.compile("\\)\\s*[.[c[h[o[i[c[e]?]?]?]?]?]?]?\\(?$", Pattern.MULTILINE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CHOICE_EIP_PATTERN can be put as a static attribute. (if not, better to rename to follow convention of naming witout capital letter)
String newLine = System.getProperty("line.separator"); | ||
CompletionItem completion = new CompletionItem("Content Based Router"); | ||
completion.setDocumentation( | ||
"Read more: https://camel.apache.org/components/3.11.x/eips/content-based-router-eip.html" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too old link, already a 404.
Better to link to the latest LTS, maybe https://camel.apache.org/components/3.20.x/eips/choice-eip.html
} | ||
|
||
private CompletionItem choiceEIPcompletion() { | ||
String newLine = System.getProperty("line.separator"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we can use \n and delegate to editor which end of line is configured.
it is even better in case of remote Camel Languaeg Server (we are not providing some right ow but ihe architecture allows it I provided proof of concept). It would mean that the client can be on a different OS than the server
} | ||
|
||
public boolean canPutEIP(Position position) { | ||
Pattern CHOICE_EIP_PATTERN = Pattern.compile("\\)\\s*[.[c[h[o[i[c[e]?]?]?]?]?]?]?\\(?$", Pattern.MULTILINE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sonar is complaining of duplicates in the regexp. I guess there should be a simpler way to write it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaving it out of the iteration for now as RegExr is not complaining nor I can find what would be the alternative right now. Mmm
String textUntilPosition = ""; | ||
|
||
for(int i = 0; i<position.getLine(); i++) { | ||
textUntilPosition += lines[i] + newLine; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sonar is recommending to use a StringBuilder
completionItem -> completionItem.getLabel().startsWith("Content Based Router") | ||
).collect(Collectors.toList()); | ||
|
||
assertThat(completionItems).hasSize(0); //Removing camel-k modeline insertion. Refactor later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssertJ is providing an isEmpty()
method. Itwill provide a better error message, simplifying the debugging process.
).collect(Collectors.toList()); | ||
|
||
|
||
assertThat(completionItems).hasSize(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssertJ is providing an isEmpty()
method. Itwill provide a better error message, simplifying the debugging process.
completionItem -> completionItem.getLabel().startsWith("Content Based Router") | ||
).collect(Collectors.toList()); | ||
|
||
assertThat(completionItems).hasSize(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssertJ is providing an isEmpty()
method. It will provide a better error message, simplifying the debugging process.
List<CompletionItem> completionItems = getCompletionsFor(contents, position); | ||
completionItems = completionItems.stream().filter( | ||
completionItem -> completionItem.getLabel().startsWith("Content Based Router") | ||
).collect(Collectors.toList()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code can be factorized.
it will be really useful in case the label of the completion is modified for instance
RouteTextBuilder.DocumentContentWithPosition document = | ||
RouteTextBuilder.createJavaDocumentClass(""); | ||
|
||
List<CompletionItem> completionItems = getCompletionsFor(document.content, document.position); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Java, we usually avoid to expose attributes and use getters and setters
Just saw this. I'm on with the improvements. |
Ok checking the range and priority things on top of all the comments. It should work for anything between I'll get first with the comments then on the top comment priorities. Expect an update today |
… it works fine...? Leaving it as is because I would have to use capturing group which have a higher load to fix it
…ere written to just have "\n" independently on the system so they broke. It didn't make sense to leave the carriage return as it would be treated as another whitespace character so I decided to simplify it
Implementation of the Content Based Router on the Camel language server.
Draft to set a working build although I'll be iterating on it to add/refactor stuff for better extendability.