Re: Implement additional Hints for existing Language
Alex Muthmann <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <[email protected]> |
First of all thanks for your time, I really appreciate this!
I already found some of the links (espacially the ones in context with
FreeMarker). But as far as I can understand, this is the otherway round:
You implement a new Language FreeMarker with a new MimeType (text/x-ftl)
and then inject the Language registered for text/html ?
This would be a cool solution if I want to have a new MimeType. But as
the file-extension is given, I can't simply replace text/html with e.g.
text/sly and then use this mimeType.
I'll try to explain the use case once again:
If I open a HTML File in Netbeans, I want the Editor to:
* display the Hints provided by HtmlLanguage
* additional Hints provided by my plugin
I don't care, how this should be implemented (Extension Points, custom
Language etc) as long as it works.
Am 2016-10-09 14:24, schrieb geertjan wielenga:
> I'm still trying to understand what it is you're trying to do. How
> different is what you want to what the HTML editor already has?
>
> On 9-10-2016 14:20, Alex Muthmann wrote:
>>> But that's my question. Do you really need your own Language at all?
>> No, I'd be happy to skip the complete "implement a Language foobar"
>> step.
>>
>>> ...and even embed one
>>> Language into another.
>> No I can't cause I have no clue, how this would be possible and
>> neither the Netbeans Sources nor Google provides any concrete example
>> here :(
>
> http://bits.netbeans.org/8.0/javadoc/org-netbeans-modules-lexer/org/netbeans/spi/lexer/LanguageEmbedding.html
>
> http://www.programcreek.com/java-api-examples/index.php?api=org.netbeans.spi.lexer.LanguageEmbedding
>
> https://blogs.oracle.com/geertjan/entry/html_embedding_for_freemarker
>
> Plus, many more.
>
> Again, don't know what you need, so don't know if this helps, but I
> think you could investigate that approach.
>
> Gj
>
>>
>> Am 2016-10-09 14:11, schrieb geertjan wielenga:
>>> On 9-10-2016 14:08, Alex Muthmann wrote:
>>>>> Really look in the source code, see the
>>>>> 'html.editor\src\org\netbeans\modules\html\editor\hints' package
>>>>> for
>>>>> example, i.e., in the 'html.editor' module.
>>>> Sorry, no offense but this does not help me :( I already had a
>>>> deeper look into the source code, otherwise I'd not ask here.
>>>>
>>>> All Rules/Hints in
>>>> html.editor\src\org\netbeans\modules\html\editor\hints are used in
>>>> the HTMLLanguage and NOT in an extension of it. I really can't see
>>>> any option to implement a Rule without a matching Language providing
>>>> it.
>>>
>>> But that's my question. Do you really need your own Language at all?
>>>
>>> Or do you have additional elements etc to add to the existing HTML
>>> Editor in NetBeans? I.e., you can add elements etc and even embed one
>>> Language into another.
>>>
>>> Gj
>>>
>>>
>>>
>>>>
>>>> Am 2016-10-09 13:51, schrieb geertjan wielenga:
>>>>> On 9-10-2016 13:49, Alex Muthmann wrote:
>>>>>> Can you give me an example for this approach? I already had a look
>>>>>> into this, but I was only able to find the possiblity to implement
>>>>>> a "Java Hint".
>>>>>
>>>>> Really look in the source code, see the
>>>>> 'html.editor\src\org\netbeans\modules\html\editor\hints' package
>>>>> for
>>>>> example, i.e., in the 'html.editor' module.
>>>>>
>>>>>> Also the Wizard for Module Development does not provide anything
>>>>>> that looks even vaguely correct.
>>>>>
>>>>> There are hundreds of things that can be done with NetBeans APIs
>>>>> that
>>>>> are not supported by the wizards...
>>>>>
>>>>> Gj
>>>>>
>>>>>>
>>>>>> Am 2016-10-09 13:38, schrieb geertjan wielenga:
>>>>>>> Why not extend the existing HTML editor instead of creating a
>>>>>>> Sightly
>>>>>>> editor? I.e., maybe don't create SightlyLanguage at all and use
>>>>>>> the
>>>>>>> HTML extension points in NetBeans? You can embed one language in
>>>>>>> another, if needed.
>>>>>>>
>>>>>>> Gj
>>>>>>>
>>>>>>> On 9-10-2016 13:27, Alex Muthmann wrote:
>>>>>>>> Ok :)
>>>>>>>>
>>>>>>>> Some time ago, Adobe published a new Templating Language
>>>>>>>> (Sightly) which is afaik currently only used in Adobe's
>>>>>>>> Experience Manager (AEM). Most of the work is done in html files
>>>>>>>> which may contain special tags evaluated by the Sightly-Compiler
>>>>>>>> (e.g. <div data-sly-test='${foobar}>)
>>>>>>>>
>>>>>>>> To simplify work, I implemented a Plugin for Netbeans that
>>>>>>>> provides Autocompletion for those tags
>>>>>>>> (http://wcm.io/tooling/netbeans/sightly/). But as I've got some
>>>>>>>> spare time now, I'd like to extend the plugin to provide
>>>>>>>> additional Hints for wrong tags, invalid code etc.
>>>>>>>>
>>>>>>>> Netbeans uses a combination of the interface GsfLanguage and
>>>>>>>> HintProvider to supply hints. The Language has to be annotated
>>>>>>>> with LanguageRegistration and a matching mimeType:
>>>>>>>>
>>>>>>>> @LanguageRegistration(mimeType="text/html", useMultiview = true)
>>>>>>>>
>>>>>>>> As Sightly is a mere extension of the featureset of the
>>>>>>>> Html-Language (implemented in
>>>>>>>> org.netbeans.modules.html.editor.gsf.HtmlLanguage), I need to
>>>>>>>> register my Language "SightlyLanguage" on the mimeType
>>>>>>>> "text/html". At this point I'd expect Netbeans to use both
>>>>>>>> HintProviders provided by HtmlLanguage AND SightlyLanguage but
>>>>>>>> somehow only the later one is used.
>>>>>>>> I did some research here and found the "getLanguageByMimeType"
>>>>>>>> method in org.netbeans.modules.csl.core.LanguageRegistry which
>>>>>>>> only returns a single Language for a given mimetype. Based on
>>>>>>>> this finding, my assumption is, that Netbeans does not allow
>>>>>>>> multiple Language registered on the same mimetype.
>>>>>>>>
>>>>>>>> So now I'm looking for a way to either bypass this limitation or
>>>>>>>> get Netbeans to use my Hints in another way.
>>>>>>>>
>>>>>>>> I hope this is a better description of my problem?
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Am 2016-10-09 12:30, schrieb geertjan wielenga:
>>>>>>>>> On 9-10-2016 12:28, Alex Muthmann wrote:
>>>>>>>>>> I'm sorry to repeat myself but my problem is not, that I'm
>>>>>>>>>> unable to implement and register a hint but that it does seem
>>>>>>>>>> to be impossible, to add hints to an existing Language.
>>>>>>>>>
>>>>>>>>> I don't understand. JavaScript is an existing language. If you
>>>>>>>>> want to
>>>>>>>>> add hints to an existing language, e.g., JavaScript, then you
>>>>>>>>> create
>>>>>>>>> rules and register them in the layer.
>>>>>>>>>
>>>>>>>>>> If I would like to implement a new language with a new
>>>>>>>>>> mimetype etc, I would not have to ask those questions.
>>>>>>>>>>
>>>>>>>>>> All I need is an advice, how multiple Languages can be
>>>>>>>>>> registered on the same mimetype OR if there is another way to
>>>>>>>>>> add hints.
>>>>>>>>>
>>>>>>>>> No, I don't understand at all.
>>>>>>>>>
>>>>>>>>> This is the first I'm hearing in this thread about multiple
>>>>>>>>> languages.
>>>>>>>>>
>>>>>>>>> Can you explain in a lot more detail the context of what you're
>>>>>>>>> trying to do.
>>>>>>>>>
>>>>>>>>> Gj
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Am 2016-10-09 12:24, schrieb geertjan wielenga:
>>>>>>>>>>> Now that you have a HintsProvider, you need to implement
>>>>>>>>>>> Rules (pic-1)
>>>>>>>>>>> and register them in the layer (pic-2).
>>>>>>>>>>>
>>>>>>>>>>> Gj
>>>>>>>>>>>
>>>>>>>>>>> On 9-10-2016 12:18, Alex Muthmann wrote:
>>>>>>>>>>>> Please have a look at the github links I provided, you'll
>>>>>>>>>>>> see, that I already have both Language and HintsProvider
>>>>>>>>>>>> implemented.
>>>>>>>>>>>>
>>>>>>>>>>>> Also both classes you mention do NOT cover my use case as
>>>>>>>>>>>> they are mere Hints used in JsHintsProvider, which is used
>>>>>>>>>>>> in JsLanguage (registered on text/javascript). So this does
>>>>>>>>>>>> not add a new HTML hint in a module but implements a
>>>>>>>>>>>> completely new Language :(
>>>>>>>>>>>>
>>>>>>>>>>>> Am 2016-10-09 12:10, schrieb geertjan wielenga:
>>>>>>>>>>>>> Look at
>>>>>>>>>>>>> org.netbeans.modules.javascript2.editor.hints.JsAstRule or
>>>>>>>>>>>>> JsConventionHint. Also you have to implement HintsProvider.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Gj
>>>>>>>>>>>>>
>>>>>>>>>>>>> On 9-10-2016 11:50, Alex Muthmann wrote:
>>>>>>>>>>>>>> yes, exactly, that would be awesome!
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Am 2016-10-09 11:42, schrieb geertjan wielenga:
>>>>>>>>>>>>>>> So, to be clear, if I show an example of how to create a
>>>>>>>>>>>>>>> new plugin
>>>>>>>>>>>>>>> that adds a new HTML hint in NetBeans IDE, that's what
>>>>>>>>>>>>>>> you're looking
>>>>>>>>>>>>>>> for?
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Gj
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On 9-10-2016 11:39, Alex Muthmann wrote:
>>>>>>>>>>>>>>>> Yes, this is what I (of course) did first, I also had a
>>>>>>>>>>>>>>>> deeper look into the Netbeans sources but there was no
>>>>>>>>>>>>>>>> implementation covering my requirement (extend an
>>>>>>>>>>>>>>>> existing language). It looks easy to implement a new
>>>>>>>>>>>>>>>> one, but if you need to use an already registered
>>>>>>>>>>>>>>>> mimeType it gets fuzzy :(
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Am 2016-10-09 01:13, schrieb geertjan wielenga:
>>>>>>>>>>>>>>>>> I'll try to take a look but if I were you I'd go to
>>>>>>>>>>>>>>>>> Google and search
>>>>>>>>>>>>>>>>> for 'getHintsProvider' to see how others have
>>>>>>>>>>>>>>>>> implemented that -- I
>>>>>>>>>>>>>>>>> can see many implementations when I do that.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Gj
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> On 8-10-2016 20:57, Alex Muthmann wrote:
>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> thanks for your reply.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> You can find the code here:
>>>>>>>>>>>>>>>>>> https://github.com/wcm-io/wcm-io-tooling/tree/netbeans-sightly-hints
>>>>>>>>>>>>>>>>>> SightlyLanguage.java:
>>>>>>>>>>>>>>>>>> https://github.com/wcm-io/wcm-io-tooling/blob/netbeans-sightly-hints/netbeans/sightly/src/main/java/io/wcm/tooling/netbeans/sightly/editor/SightlyLanguage.java
>>>>>>>>>>>>>>>>>> SightylHintsProvider:
>>>>>>>>>>>>>>>>>> https://github.com/wcm-io/wcm-io-tooling/blob/netbeans-sightly-hints/netbeans/sightly/src/main/java/io/wcm/tooling/netbeans/sightly/editor/hints/SightlyHintsProvider.java
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> I added some exceptions, so I would expect to see
>>>>>>>>>>>>>>>>>> those as soon, as the language is called successfully.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Am 2016-10-08 12:21, schrieb geertjan wielenga:
>>>>>>>>>>>>>>>>>>> On 7-10-2016 0:26, Alex Muthmann wrote:
>>>>>>>>>>>>>>>>>>>> Hi there,
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> there has already be a discussion with Geertjan and
>>>>>>>>>>>>>>>>>>>> Petr regarding the options to implement additional
>>>>>>>>>>>>>>>>>>>> Hints for an existing language. I need to add
>>>>>>>>>>>>>>>>>>>> additional Hints for HTML files and the consensus
>>>>>>>>>>>>>>>>>>>> was, that I should use the CSL API to implement a
>>>>>>>>>>>>>>>>>>>> Language and add a HintProvider.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> I did some basic tests
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Put your code on GitHub and send a link to it here so
>>>>>>>>>>>>>>>>>>> we can all see
>>>>>>>>>>>>>>>>>>> the code rather than text.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Gj
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> but ran into the following situation:
>>>>>>>>>>>>>>>>>>>> As soon as I register a new Language XYZ which uses
>>>>>>>>>>>>>>>>>>>> the mimeType text/html, the build-in HTML Language
>>>>>>>>>>>>>>>>>>>> does not work anymore (no hints, no code-completion
>>>>>>>>>>>>>>>>>>>> etc). I'd expect that all languages registered on a
>>>>>>>>>>>>>>>>>>>> mimeType are used and not only one of those.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> I was not able to find this use-case in the netbeans
>>>>>>>>>>>>>>>>>>>> source-code and I'm currently lost :(
>>>>>>>>>>>>>>>>>>>> Could somebody probably provide an example of a
>>>>>>>>>>>>>>>>>>>> working extension of an existing language or an
>>>>>>>>>>>>>>>>>>>> alternative to the implementation of a complete new
>>>>>>>>>>>>>>>>>>>> language?
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Thank you very much,
>>>>>>>>>>>>>>>>>>>> Alex Muthmann