PyvesB / eclipse-solargraph

:gem: Ruby development tools for Eclipse.
https://marketplace.eclipse.org/content/ruby-solargraph
Eclipse Public License 2.0
30 stars 6 forks source link

[feature request] js.erb gramar #19

Closed pldavid2 closed 2 years ago

pldavid2 commented 2 years ago

Any chance of adding a js.erb gramar to this fantastic ruby plugin for eclipse? Currently those files are opening with the html.erb gramar, so styling is pretty limited for dynamic js files.

PyvesB commented 2 years ago

Hello @pldavid2! :wave:

Yes, I can add support for that. To save me a little bit of effort, could you please share a small js.erb sample file, similar to the HTML example?

pldavid2 commented 2 years ago

Awesome! Something link this would be fine? It's the js snippet from wildwebdeveloper, with a minor erb addition.



/**
 * This is about <code>Example.js</code>.
 * {@link com.yourCompany.aPackage.aFile}
 * @author author
 * @deprecated use <code>BetterExample.js</code>
 */
var index = 0;
var arr = [];
var rbs = "<%= rbstring %>";

function foo() {
    /* This comment may span multiple lines. */
    var var1 = new Object();
    var obj = { carMake: 'Amet', carModel: 'Porro', carYear: 2012 };
    var s = "abc123";
    clear(var1);    
    var template = `This is a template literal value,
      it may span multiple lines.`;
}

function pop() {
    return arr[index--];
}

function push(elem) {
    // This comment may span only this line
    arr[index++] = elem;
}

function isEmpty() {
    // TASK: refactor
    return index == 0;
}
PyvesB commented 2 years ago

The only readily available grammar I found was the following: sample.js.erb. I converted it to JSON and added a couple of missing bits, hopefully it will do the job. Here's the kind of syntax highlighting I get with your sample (light theme): Screenshot 2022-02-12 145756

I tried the same sample in VSCode, but I couldn't get syntax highlighting to work properly for js.erb files, even after trying half a dozen plugins. Maybe I'm missing something, but seems like Eclipse may have a small edge on some competitors here. 😄 Cc @akurtakov for awareness.

I'll go and prepare the release so that you can give it a spin yourself. Feel free to star the repository or the marketplace listing, it always helps these kind of projects to get a bit more visibility. 😉

pldavid2 commented 2 years ago

Working perfectly, thanks! Amazing support.

Already rate both the project and marketplace :smiley:

PS: Some off topic question, is it possible to get some kind of syntax checking with the plugin? I mean for example not ended blocks or something like that (code completion working perfectly by the way :+1:

PyvesB commented 2 years ago

You're welcome, glad to have helped!

PS: Some off topic question, is it possible to get some kind of syntax checking with the plugin? I mean for example not ended blocks or something like that (code completion working perfectly by the way 👍

These are called diagnostics in the language server protocol world. You raise a very good question, I guess I never really worried about those as the little Ruby I do generally doesn't go beyond small scripting.

Looking at the Solargraph gem code, I noticed that diagnostics are disabled by default: https://github.com/castwide/solargraph/blob/2ea80efdb5f02744b74f5af98c67174a55ab7c41/lib/solargraph/language_server/host.rb#L632

I'm not sure why that would be, it seems to me that these should be enabled without users having to worry about turning them on explicitly. I'll add a config override in the plugin, if someone really wants to disable them, they can always create a Solargraph configuration file in their workspace and specify reporters: [].

Will ship a new update next weekend.

pldavid2 commented 2 years ago

Great! I found out after posting that rubocop offer that feature, but my knowledge of solargraph is highly limited so I thought that was some kind of API not implemented. And sorry I made the offtopic here :sweat: I created a new issue to keep things clean https://github.com/PyvesB/eclipse-solargraph/issues/20.