Skip to content

Commit

Permalink
Add support for js.erb files (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB committed Feb 12, 2022
1 parent 00d7295 commit c2c8fcb
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 12 deletions.
156 changes: 156 additions & 0 deletions eclipse-solargraph-plugin/grammar/js_erb.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"version": "https://github.com/textmate/ruby-on-rails-tmbundle/commit/4efef9bfea373a26044f5dd69069cb68d6232baf",
"name": "JS (Ruby - ERB)",
"scopeName": "source.js.erb.rails",
"fileTypes": [
"js.erb"
],
"injections": {
"L:source.js.erb.rails - (meta.embedded.block.erb | meta.embedded.line.erb | comment)": {
"patterns": [
{
"begin": "(^\\s*)(?=<%+#(?![^%]*%>))",
"beginCaptures": {
"0": {
"name": "punctuation.whitespace.comment.leading.erb"
}
},
"end": "(?!\\G)(\\s*$\\n)?",
"endCaptures": {
"0": {
"name": "punctuation.whitespace.comment.trailing.erb"
}
},
"patterns": [
{
"include": "#comment"
}
]
},
{
"begin": "(^\\s*)(?=<%(?![^%]*%>))",
"beginCaptures": {
"0": {
"name": "punctuation.whitespace.embedded.leading.erb"
}
},
"end": "(?!\\G)(\\s*$\\n)?",
"endCaptures": {
"0": {
"name": "punctuation.whitespace.embedded.trailing.erb"
}
},
"patterns": [
{
"include": "#tags"
}
]
},
{
"include": "#comment"
},
{
"include": "#tags"
}
]
}
},
"keyEquivalent": "^~J",
"name": "JavaScript (Rails)",
"patterns": [
{
"include": "source.js"
}
],
"repository": {
"comment": {
"patterns": [
{
"begin": "<%+#",
"beginCaptures": {
"0": {
"name": "punctuation.definition.comment.begin.erb"
}
},
"end": "%>",
"endCaptures": {
"0": {
"name": "punctuation.definition.comment.end.erb"
}
},
"name": "comment.block.erb"
}
]
},
"tags": {
"patterns": [
{
"begin": "<%+(?!>)[-=]?(?![^%]*%>)",
"beginCaptures": {
"0": {
"name": "punctuation.section.embedded.begin.erb"
}
},
"contentName": "source.ruby",
"end": "(-?%)>",
"endCaptures": {
"0": {
"name": "punctuation.section.embedded.end.erb"
},
"1": {
"name": "source.ruby.rails"
}
},
"name": "meta.embedded.block.erb",
"patterns": [
{
"captures": {
"1": {
"name": "punctuation.definition.comment.erb"
}
},
"match": "(#).*?(?=-?%>)",
"name": "comment.line.number-sign.erb"
},
{
"include": "source.ruby.rails"
}
]
},
{
"begin": "<%+(?!>)[-=]?",
"beginCaptures": {
"0": {
"name": "punctuation.section.embedded.begin.erb"
}
},
"contentName": "source.ruby",
"end": "(-?%)>",
"endCaptures": {
"0": {
"name": "punctuation.section.embedded.end.erb"
},
"1": {
"name": "source.ruby.rails.ruby"
}
},
"name": "meta.embedded.line.erb",
"patterns": [
{
"captures": {
"1": {
"name": "punctuation.definition.comment.erb"
}
},
"match": "(#).*?(?=-?%>)",
"name": "comment.line.number-sign.erb"
},
{
"include": "source.ruby.rails"
}
]
}
]
}
}
}
65 changes: 53 additions & 12 deletions eclipse-solargraph-plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@
</content-type>
<content-type
base-type="org.eclipse.core.runtime.text"
file-extensions="erb,rhtml,rhtm"
id="io.github.pyvesb.eclipse_solargraph.erb"
name="Embedded Ruby"
file-extensions="rhtml,rhtm"
file-patterns="*.erb"
id="io.github.pyvesb.eclipse_solargraph.html_erb"
name="HTML Embedded Ruby"
priority="high">
</content-type>
<content-type
base-type="org.eclipse.core.runtime.text"
file-patterns="*.js.erb"
id="io.github.pyvesb.eclipse_solargraph.js_erb"
name="JS Embedded Ruby"
priority="high">
</content-type>
</extension>
Expand All @@ -50,7 +58,11 @@
editorId="org.eclipse.ui.genericeditor.GenericEditor">
</editorContentTypeBinding>
<editorContentTypeBinding
contentTypeId="io.github.pyvesb.eclipse_solargraph.erb"
contentTypeId="io.github.pyvesb.eclipse_solargraph.html_erb"
editorId="org.eclipse.ui.genericeditor.GenericEditor">
</editorContentTypeBinding>
<editorContentTypeBinding
contentTypeId="io.github.pyvesb.eclipse_solargraph.js_erb"
editorId="org.eclipse.ui.genericeditor.GenericEditor">
</editorContentTypeBinding>
</extension>
Expand All @@ -70,7 +82,11 @@
id="io.github.pyvesb.eclipse_solargraph">
</contentTypeMapping>
<contentTypeMapping
contentType="io.github.pyvesb.eclipse_solargraph.erb"
contentType="io.github.pyvesb.eclipse_solargraph.html_erb"
id="io.github.pyvesb.eclipse_solargraph">
</contentTypeMapping>
<contentTypeMapping
contentType="io.github.pyvesb.eclipse_solargraph.js_erb"
id="io.github.pyvesb.eclipse_solargraph">
</contentTypeMapping>
</extension>
Expand All @@ -85,9 +101,13 @@
scopeName="source.ruby.gemfile">
</grammar>
<grammar
path="grammar/erb.tmLanguage.json"
path="grammar/html_erb.tmLanguage.json"
scopeName="text.html.erb">
</grammar>
<grammar
path="grammar/js_erb.tmLanguage.json"
scopeName="source.js.erb.rails">
</grammar>
<scopeNameContentTypeBinding
contentTypeId="io.github.pyvesb.eclipse_solargraph"
scopeName="source.ruby">
Expand All @@ -97,9 +117,13 @@
scopeName="source.ruby.gemfile">
</scopeNameContentTypeBinding>
<scopeNameContentTypeBinding
contentTypeId="io.github.pyvesb.eclipse_solargraph.erb"
contentTypeId="io.github.pyvesb.eclipse_solargraph.html_erb"
scopeName="text.html.erb">
</scopeNameContentTypeBinding>
<scopeNameContentTypeBinding
contentTypeId="io.github.pyvesb.eclipse_solargraph.js_erb"
scopeName="source.js.erb.rails">
</scopeNameContentTypeBinding>
</extension>
<extension
point="org.eclipse.ui.genericeditor.presentationReconcilers">
Expand All @@ -113,7 +137,11 @@
</presentationReconciler>
<presentationReconciler
class="org.eclipse.tm4e.ui.text.TMPresentationReconciler"
contentType="io.github.pyvesb.eclipse_solargraph.erb">
contentType="io.github.pyvesb.eclipse_solargraph.html_erb">
</presentationReconciler>
<presentationReconciler
class="org.eclipse.tm4e.ui.text.TMPresentationReconciler"
contentType="io.github.pyvesb.eclipse_solargraph.js_erb">
</presentationReconciler>
</extension>
<extension
Expand All @@ -128,7 +156,11 @@
</icon>
<icon
icon="icon/erb-editor.png"
contentType="io.github.pyvesb.eclipse_solargraph.erb">
contentType="io.github.pyvesb.eclipse_solargraph.html_erb">
</icon>
<icon
icon="icon/erb-editor.png"
contentType="io.github.pyvesb.eclipse_solargraph.js_erb">
</icon>
</extension>
<extension
Expand All @@ -142,7 +174,11 @@
path="language-configuration/ruby-configuration.json">
</languageConfiguration>
<languageConfiguration
contentTypeId="io.github.pyvesb.eclipse_solargraph.erb"
contentTypeId="io.github.pyvesb.eclipse_solargraph.html_erb"
path="language-configuration/erb-configuration.json">
</languageConfiguration>
<languageConfiguration
contentTypeId="io.github.pyvesb.eclipse_solargraph.js_erb"
path="language-configuration/erb-configuration.json">
</languageConfiguration>
</extension>
Expand All @@ -159,10 +195,15 @@
scopeName="source.ruby.gemfile">
</snippet>
<snippet
name="Embedded Ruby sample"
path="snippet/sample.erb"
name="HTML Embedded Ruby sample"
path="snippet/sample.html.erb"
scopeName="text.html.erb">
</snippet>
<snippet
name="JS Embedded Ruby sample"
path="snippet/sample.js.erb"
scopeName="source.js.erb.rails">
</snippet>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
Expand Down
33 changes: 33 additions & 0 deletions eclipse-solargraph-plugin/snippet/sample.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* 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;
}

0 comments on commit c2c8fcb

Please sign in to comment.