Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » No LSP suggestions when keywords are separate parser rules
No LSP suggestions when keywords are separate parser rules [message #1809205] Thu, 11 July 2019 13:46 Go to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
I'm sure this has been asked and answered before so I apologize in advance.

I created a DSL which has a repeating pattern like With Class, Expect Property. Thus, initially I defined those rules simply something like:

ClassBlock:
   'With' 'Class' // ...
;

PropertyBlock:
   modifier=('With' | 'Expect') 'Class' // ...
;


This works fine but multiple parser rules will contain the Expect and With keywords, so I thought it was sane to put them in their own rules:

WithModifier: 'With';
ExpectModifier: 'Expect';

ClassBlock:
   WithModifier 'Class' // ...
;

PropertyBlock:
   modifier=(WithModifier | ExpectModifier) 'Class' // ...
;


Unfortunately, as soon as I did that, they stop being suggested by Language Server. Why is that?

Bonus question: Why do they additionally stop being keywords when the modifier rules are changed into terminals?

Thanks,
Tom
Re: No LSP suggestions when keywords are separate parser rules [message #1809262 is a reply to message #1809205] Fri, 12 July 2019 15:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi, you have to implement content assist for datatype rules yourself.
WithModifier: 'With'; is a datype rule
WithModifier: xxx='With'; is a normal parser rule

the bonus question i did not understand


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: No LSP suggestions when keywords are separate parser rules [message #1809264 is a reply to message #1809262] Fri, 12 July 2019 15:16 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
Thanks, I will look into content assist. It is supported by LSP, right? Not just Eclipse?

For the bonus question, I mean what I noticed in the generated mode-extension file. When I write terminal WITH_MODIFIER: 'With'; instead, then 'With' gets removed for the keywords and thus stops being highlighted (not sure what other side effects that produces).
Re: No LSP suggestions when keywords are separate parser rules [message #1809268 is a reply to message #1809264] Fri, 12 July 2019 15:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes. you have to customize IdeContentProposalProvider.

lsp highlighting in which client?
the current impl might not highlight arbitray terminal as keyword.
extension point is
org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 12 July 2019 15:30]

Report message to a moderator

Re: No LSP suggestions when keywords are separate parser rules [message #1809281 is a reply to message #1809268] Fri, 12 July 2019 17:17 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
I meant LSP in the generated example web client.

Interestingly though, neither of the types you mention are generated. In fact I only have IdeModule and IdeSetup in the side project. Something to configure in the mwe2 workflow?
Re: No LSP suggestions when keywords are separate parser rules [message #1809282 is a reply to message #1809281] Fri, 12 July 2019 17:21 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
I generated using Maven layout, without the Eclipse support with only IDE support
Re: No LSP suggestions when keywords are separate parser rules [message #1809283 is a reply to message #1809282] Fri, 12 July 2019 17:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you can always create subclasses of default types and add bindings to the module manually :(

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 12 July 2019 17:24]

Report message to a moderator

Re: No LSP suggestions when keywords are separate parser rules [message #1809588 is a reply to message #1809283] Thu, 18 July 2019 15:02 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
This has finally got on my nerves and I'm trying to implement that proposals provider. Looking at the statemachine provider, I find this particular switch statement

switch ruleCall.rule {
			
			case BOOLEANRule: {


When I try to write it like that it compiles fine but none of my cases get actually hit at runtime.

Is there something different in more recent Xtend?
Re: No LSP suggestions when keywords are separate parser rules [message #1809589 is a reply to message #1809588] Thu, 18 July 2019 15:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
You know you can debug / write a unit test (see Xtext core in github for example)
Can you provide a minimal grammar , impl and test


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: No LSP suggestions when keywords are separate parser rules [message #1809596 is a reply to message #1809589] Thu, 18 July 2019 16:06 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
I'm new to Java, let alone Xtext, and all of this giving me a lot of pain.

I did manage to debug but for content assist the only way I figured out is to attach to Tomcat. Kind of annoying.

As for testing, I'm currently stuck on some generated stuff missing in my setup. Apparently the tests need an InjectorProvider like the example PartialContentAssistTestLanguageInjectorProvider

I really wouldn't like to copy/paste something similar into my repository. Any suggestions on what I need to to to get this generated in my .ide project?

[Updated on: Thu, 18 July 2019 16:07]

Report message to a moderator

Re: No LSP suggestions when keywords are separate parser rules [message #1809597 is a reply to message #1809596] Thu, 18 July 2019 16:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
I don't know how you created your project
By default it is is the tests project
How does your project setup look like
(The wizard has too many options for guessing

In doubt you can create the class manually


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: No LSP suggestions when keywords are separate parser rules [message #1809598 is a reply to message #1809597] Thu, 18 July 2019 16:18 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
I created setting up as shown on the attached image.

It generates test in dsl project but no tests in either web or ide
  • Attachment: maven.png
    (Size: 145.60KB, Downloaded 64 times)
Re: No LSP suggestions when keywords are separate parser rules [message #1809599 is a reply to message #1809598] Thu, 18 July 2019 16:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Please use source layout default / plain
(Not maven /Gradle)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: No LSP suggestions when keywords are separate parser rules [message #1809600 is a reply to message #1809599] Thu, 18 July 2019 16:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
But it might be that you have to customize / manually create the injector provider anyway so that your use mifule and binding is used

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: No LSP suggestions when keywords are separate parser rules [message #1809606 is a reply to message #1809600] Thu, 18 July 2019 17:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
pps:

i was thinking of https://github.com/eclipse/xtext-core/blob/master/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/CompletionTest.xtend
which does not need an injector provider (just add mydsl.ide to deps of mydsl.tests)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 18 July 2019 17:16]

Report message to a moderator

Re: No LSP suggestions when keywords are separate parser rules [message #1809617 is a reply to message #1809606] Thu, 18 July 2019 20:53 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
Christian Dietrich wrote on Thu, 18 July 2019 17:04
pps:

which does not need an injector provider (just add mydsl.ide to deps of mydsl.tests)


This one is promising. I managed to get it "running" in both maven and plain setup.

Unfortunately it's giving me a NullPointerException trying to get ANTLR name of the to rule (see attachment). It fails soon after in the getFollowElements method.
Re: No LSP suggestions when keywords are separate parser rules [message #1809618 is a reply to message #1809617] Thu, 18 July 2019 20:53 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
Oh, and I tried to run the linked xtext-core project but that simply fails to even compile
Re: No LSP suggestions when keywords are separate parser rules [message #1809620 is a reply to message #1809618] Thu, 18 July 2019 21:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Can you please provide a minimal reproducing example (hello world dsl). Maybe there is something wrong with the grammar or impl

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: No LSP suggestions when keywords are separate parser rules [message #1809628 is a reply to message #1809620] Fri, 19 July 2019 06:30 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
Got it!

The problem occurs as soon as I add a second language, subgrammar of the the other.

Here's a repro: https://github.com/tpluscode/xtext-completion-nullpointer

Thanks for helping me Christian!
Re: No LSP suggestions when keywords are separate parser rules [message #1809630 is a reply to message #1809628] Fri, 19 July 2019 07:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
looks like
https://github.com/eclipse/xtext-core/issues/993


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: No LSP suggestions when keywords are separate parser rules [message #1809632 is a reply to message #1809630] Fri, 19 July 2019 07:25 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
Maybe. The only difference from the reported issue is that the exception is also thrown when the grammars are completely unrelated. One depending on the other is in fact not a factor.
Re: No LSP suggestions when keywords are separate parser rules [message #1809633 is a reply to message #1809632] Fri, 19 July 2019 07:26 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
No Message Body
Re: No LSP suggestions when keywords are separate parser rules [message #1809634 is a reply to message #1809633] Fri, 19 July 2019 07:27 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
And also, the content assist does work in the Ace editor. I only have problem with junit tests.
Re: No LSP suggestions when keywords are separate parser rules [message #1809635 is a reply to message #1809634] Fri, 19 July 2019 07:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
ähmm no

when i change hydra to

grammar org.xtext.example.mydsl.Hydra with org.eclipse.xtext.common.Terminals
    
generate hydra "http://testing.hypermedia.app/dsl/hydra"
 
Model:
    "model" name=ID;


and rerun the workflow
then i get

org.junit.ComparisonFailure: expected:<[package -> package [[0, 0] .. [0, 0]]
type -> type [[0, 0] .. [0, 0]]
Sample Snippet -> type ${1|A,B,C|} {
                
            }] [[0, 0] .. [0, 0]]
> but was:<[With Class -> With Class] [[0, 0] .. [0, 0]]
>
	at org.junit.Assert.assertEquals(Assert.java:115)
	at org.junit.Assert.assertEquals(Assert.java:144)
	at org.eclipse.xtext.testing.AbstractLanguageServerTest.assertEquals(AbstractLanguageServerTest.java:1304)
	at org.eclipse.xtext.testing.AbstractLanguageServerTest.testCompletion(AbstractLanguageServerTest.java:1047)
	at org.xtext.example.mydsl.tests.CompletionTest.testCompletion_01(CompletionTest.java:29)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:628)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:117)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:184)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:180)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:127)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:137)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)




and not a npe


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: No LSP suggestions when keywords are separate parser rules [message #1809636 is a reply to message #1809635] Fri, 19 July 2019 07:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
=> how does your proposal provider customization look like?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: No LSP suggestions when keywords are separate parser rules [message #1809637 is a reply to message #1809635] Fri, 19 July 2019 08:04 Go to previous messageGo to next message
Tomasz Pluskiewicz is currently offline Tomasz PluskiewiczFriend
Messages: 14
Registered: July 2019
Junior Member
Christian Dietrich wrote on Fri, 19 July 2019 07:31
ähmm no

when i change hydra to


ok, sorry. must have forgotten to run the workflow.

Quote:
=> how does your proposal provider customization look like?


Not too fancy until I figure out how to work with the grammar model:

https://github.com/hypermedia-app/hypertest/blob/keyword-code-assist/app.hypermedia.testing.dsl.ide/src/main/java/app/hypermedia/testing/dsl/ide/editor/contentassist/CoreContentAssist.xtend

I experiment some more and indeed, a test for the sub grammar passes. Only the base grammar throws NPE.

Again, weirdly enough, code assists work fine for both languages in ace editor.
Re: No LSP suggestions when keywords are separate parser rules [message #1809639 is a reply to message #1809637] Fri, 19 July 2019 08:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes the grammars beeing singleton does not work for subgrammars.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: No LSP suggestions when keywords are separate parser rules [message #1809640 is a reply to message #1809639] Fri, 19 July 2019 08:32 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
inverting the order in *ide/src/main/xtext-gen/META-INF/services/org.eclipse.xtext.ISetup
seems to help as well


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:osgi logging fragment configuration not working
Next Topic:Configuring Log4J
Goto Forum:
  


Current Time: Thu Apr 18 13:52:46 GMT 2024

Powered by FUDForum. Page generated in 0.03956 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top