Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [Dltk-dev] How to integrate code generator into DLTK framework?

Hi Gerald,
> Editor is running well on the new DLTK 1.0M3 codebase.
>
> Having trouble understanding how to do a few things the "DLTK" way:
>
> 1) Formatters: I have implemented
> SourceViewerConfigurations#getContentFormatter(), but do not see what
> more needs to be done to make the formatters available/functional in
> the editor.  A quick list of the essential steps needed to integrate a
> custom content formatter into the DLTK framework would be appreciated.
At DLTK we aren't provide any formatting support yet.
To add it please start reading topic from eclipse wiki
(http://wiki.eclipse.org/FAQ_How_do_I_support_formatting_in_my_editor%3F).

After it please try to perform following steps:

1) Add formatting strategy to source viewer configuration. (Described in
topic ).
You need to implement method getContentFormatter of your
SourceViewerConfiguration implementation.

2) Add action, command and key declarations to your UI project plugin.xml.
As reference you could look at org.eclipse.jdt.ui/plugin.xml file and
search for "text.java.format"

Code you need to add to your plugin.xml.
First you need to add action.
---
<extension
         point="org.eclipse.ui.actionSets">
      <actionSet
            label="My Editor Action set"
            description="Action set description"
            visible="false"
            id="MY_PLUGIN.myActionSet">
         <action
               definitionId="*MY_PLUGIN.MY_ACTION_DEFINITION_NAME*"
               label="Format"
               retarget="true"
               menubarPath="org.eclipse.dltk.ui.source.menu/editGroup"
               id="MY_PLUGIN.MY_ACTION_FORMAT_ID">
         </action>
       </actionSet>
</extension>
---
Then command.
---
<extension
         point="org.eclipse.ui.commands">
      <command
            name="My Format"
            description="Format description"
            categoryId="org.eclipse.dltk.ui.category.source"
            id="*MY_PLUGIN.MY_ACTION_DEFINITION_NAME*">
      </command>
</extension>
---
And key binding.
---
<extension
         point="org.eclipse.ui.bindings">
    <key
            sequence="M1+M2+F"
            contextId="*MY_EDITOR_SCOPE*"
            commandId="*MY_PLUGIN.MY_ACTION_DEFINITION_NAME*"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
</extension>
---
Your editor context parent should be
"org.eclipse.dltk.ui.scriptEditorScope".

3) In your ScriptEditor implementation override method createActions() like:
----
protected void createActions() {
        super.createActions();
       
        action= new TextOperationAction(DLTKEditorMessages
                .getBundleForConstructedKeys(), "Format.", this,
ISourceViewer.FORMAT);
       
action.setActionDefinitionId("*MY_PLUGIN.MY_ACTION_DEFINITION_NAME*");
        setAction("Format", action);
        markAsStateDependentAction("Format", true);
        markAsSelectionDependentAction("Format", true);
}
---
Also please be careful to specify definition id, it should be equals to
one in plugin.xml.

>
> 2) Builders:  my editor is setup to edit a grammar specification that
> needs to be fed to an existing code generator.  I have tried creating
> an implementation of ScriptBuilder, but it is not being called in
> response to any editor actions/operations.  Again, a quick list of
> essential steps needed to enable an incremental builder would be
> appreciated.
Where is two ways to add builders support:

1) Create extension of "org.eclipse.dltk.core.*builder*" extension
point, and provide class implementing "*IScriptBuilder*" interface.

Our ScriptBuilder class implements IncrementalProjectBuilder, so
building are incremental.
Incremental build called then resource are saved.

Also it support dependencies, so then you build some module all needed
dependencies could be also builded.

In DLTK we use IScriptBuilde for several tasks, building or runtime
model(Mixin), and to execute external validators.

If you need to call it on every resource change, you should look to
reconciling mechanism. In DLTK We provide generic reconcile mechanism,
witch calls rebuilding of model, so for example outline are updated then
you change module.

You could extend reconciler from
ScriptSourceViewerConfiguration.getReconciler() method, but also you
should call our reconciler.

Nature which you contribute should add
"org.eclipse.dltk.core.scriptbuilder" to project builders.
Also you could extend your nature class from our "ScriptNature"
implementation, which configures our builder by default.

2) You could write your own builder, and register it from your nature.
It will work separately from our builder.

You could obtain information on how to write builder from Eclipse Wiki.
(http://wiki.eclipse.org/FAQ_How_do_I_implement_an_Eclipse_builder%3F)

Best regards,
Andrei.
>
> I have gone through the Ruby, Lua, and Perlipse code bases, but
> evidently missing how they do these two thing.
>
> Thanks,
> Gerald
>
>
> ----
> Gerald B. Rosenberg
> Certiv Analytics
>
> www.certiv.net
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> dltk-dev mailing list
> dltk-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/dltk-dev
>   



Back to the top