eclipse plugin: Implement the suggesting of parsed lua tags & keys :D
This commit is contained in:
parent
af7f958661
commit
62665dbc37
12 changed files with 74 additions and 42 deletions
|
@ -15,6 +15,8 @@ Eclipse plugin changelog
|
|||
* Improved the content assist for:
|
||||
- variables
|
||||
- events
|
||||
- tags & keys - now the lua defined tags and keys are recognized
|
||||
and suggested to the user
|
||||
|
||||
1.0.3
|
||||
* Fixed bug #18080
|
||||
|
|
|
@ -49,8 +49,6 @@ import com.google.inject.Provider;
|
|||
@SuppressWarnings("all")
|
||||
public class WMLUiModule extends org.wesnoth.ui.AbstractWMLUiModule
|
||||
{
|
||||
public final static boolean DEBUG = false;
|
||||
|
||||
public WMLUiModule(AbstractUIPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.wesnoth.projects.ProjectCache;
|
|||
import org.wesnoth.projects.ProjectUtils;
|
||||
import org.wesnoth.schema.SchemaParser;
|
||||
import org.wesnoth.templates.TemplateProvider;
|
||||
import org.wesnoth.ui.WMLUiModule;
|
||||
import org.wesnoth.ui.editor.WMLEditor;
|
||||
import org.wesnoth.ui.labeling.WMLLabelProvider;
|
||||
import org.wesnoth.utils.ResourceUtils;
|
||||
|
@ -93,7 +92,6 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
projectCache_ = ProjectUtils.getCacheForProject( file.getProject( ) );
|
||||
|
||||
// load the schema so we know what to suggest for autocomplete
|
||||
SchemaParser.reloadSchemas( false );
|
||||
schemaParser_ = SchemaParser.getInstance( WesnothInstallsUtils.getInstallNameForResource( file ) );
|
||||
|
||||
dependencyIndex_ = ResourceUtils.getDependencyIndex( file );
|
||||
|
@ -105,7 +103,7 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
{
|
||||
super.completeWMLKey_Name(model, assignment, context, acceptor);
|
||||
refresh( );
|
||||
dbg("completing wmlkeyname"); //$NON-NLS-1$
|
||||
|
||||
addKeyNameProposals(model, context, acceptor);
|
||||
}
|
||||
|
||||
|
@ -115,7 +113,7 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
{
|
||||
super.complete_WMLKeyValue(model, ruleCall, context, acceptor);
|
||||
refresh( );
|
||||
dbg("completing wmlkeyvalue - rule"); //$NON-NLS-1$
|
||||
|
||||
addKeyValueProposals(model, context, acceptor);
|
||||
}
|
||||
|
||||
|
@ -125,7 +123,7 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
{
|
||||
super.complete_WMLTag(model, ruleCall, context, acceptor);
|
||||
refresh( );
|
||||
dbg("completing wmltag - rule"); //$NON-NLS-1$
|
||||
|
||||
addTagProposals(model, true, context, acceptor);
|
||||
}
|
||||
|
||||
|
@ -135,7 +133,7 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
{
|
||||
super.completeWMLTag_Name(model, assignment, context, acceptor);
|
||||
refresh( );
|
||||
dbg("completing wmltagname"); //$NON-NLS-1$
|
||||
|
||||
addTagProposals(model, false, context, acceptor);
|
||||
}
|
||||
|
||||
|
@ -145,7 +143,7 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
{
|
||||
super.completeWMLMacroCall_Name(model, assignment, context, acceptor);
|
||||
refresh( );
|
||||
dbg("completing wmlmacrocallname"); //$NON-NLS-1$
|
||||
|
||||
addMacroCallProposals(model, false, context, acceptor);
|
||||
}
|
||||
|
||||
|
@ -155,7 +153,7 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
{
|
||||
super.complete_WMLMacroCall(model, ruleCall, context, acceptor);
|
||||
refresh( );
|
||||
dbg("completing wmlmacrocall - rule"); //$NON-NLS-1$
|
||||
|
||||
addMacroCallProposals(model, true, context, acceptor);
|
||||
}
|
||||
|
||||
|
@ -183,7 +181,6 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
{
|
||||
if ( model == null || !( model instanceof WMLKey ) )
|
||||
return;
|
||||
dbg(model);
|
||||
WMLKey key = (WMLKey)model;
|
||||
String keyName = key.getName( );
|
||||
|
||||
|
@ -273,7 +270,12 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
|
||||
if (tag != null)
|
||||
{
|
||||
WMLTag schemaTag = schemaParser_.getTags().get(tag.getName());
|
||||
WMLTag schemaTag = schemaParser_.getTags().get( tag.getName() );
|
||||
// try getting the custom ones
|
||||
if ( schemaTag == null ) {
|
||||
schemaTag = projectCache_.getWMLTags( ).get( tag.getName( ) );
|
||||
}
|
||||
|
||||
if ( schemaTag != null)
|
||||
{
|
||||
for( WMLKey key : schemaTag.getWMLKeys( ) )
|
||||
|
@ -343,18 +345,21 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
ruleProposal, context));
|
||||
}
|
||||
}
|
||||
else
|
||||
dbg("!!! no tag found with that name:" + parentTag.getName()); //$NON-NLS-1$
|
||||
}
|
||||
else // we are at the root
|
||||
{
|
||||
WMLTag rootTag = schemaParser_.getTags().get("root"); //$NON-NLS-1$
|
||||
dbg( "root node. adding tags: "+ rootTag.getExpressions( ).size() ); //$NON-NLS-1$
|
||||
for( WMLTag tag : rootTag.getWMLTags( ) )
|
||||
{
|
||||
acceptor.accept( createTagProposal( tag, "", ruleProposal, context ) ); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
// parsed custom tags
|
||||
for( WMLTag tag : projectCache_.getWMLTags( ).values( ) )
|
||||
{
|
||||
acceptor.accept( createTagProposal( tag, "", ruleProposal, context ) ); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -397,16 +402,4 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
return createCompletionProposal(proposal, new StyledString(displayString),
|
||||
image, priority, contentAssistContext.getPrefix(), contentAssistContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for debugging the auto completion
|
||||
* @param str
|
||||
*/
|
||||
@SuppressWarnings( "unused" )
|
||||
private void dbg(Object str)
|
||||
{
|
||||
if (!(WMLUiModule.DEBUG))
|
||||
return;
|
||||
System.out.println(str.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,12 +53,13 @@ import org.eclipse.xtext.ui.editor.utils.EditorUtils;
|
|||
import org.wesnoth.Logger;
|
||||
import org.wesnoth.WesnothPlugin;
|
||||
import org.wesnoth.ui.Messages;
|
||||
import org.wesnoth.ui.WMLUiModule;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class WMLEditor extends XtextEditor
|
||||
{
|
||||
private final static boolean DEBUG = false;
|
||||
|
||||
protected static final String AUTOLINK_PROJECT_NAME = "_AutoLinked_CFGExternalFiles_"; //$NON-NLS-1$
|
||||
protected static final String ENCODING_UTF8 = "utf-8"; //$NON-NLS-1$
|
||||
|
||||
|
@ -70,7 +71,7 @@ public class WMLEditor extends XtextEditor
|
|||
public WMLEditor()
|
||||
{
|
||||
super();
|
||||
if (WMLUiModule.DEBUG)
|
||||
if ( DEBUG )
|
||||
org.apache.log4j.Logger.getLogger(XtextEditor.class).setLevel(Level.DEBUG);
|
||||
// activate the wesnoth plugin
|
||||
WesnothPlugin.getDefault();
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<eClassifiers xsi:type="ecore:EClass" name="WMLTag" eSuperTypes="platform:/resource/org.wesnoth/src-gen/org/wesnoth/WML.ecore#//WMLRootExpression">
|
||||
<eOperations name="getWMLTags">
|
||||
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
|
||||
<details key="body" value="
 EList<WMLTag> result = new org.eclipse.emf.common.util.BasicEList<WMLTag>();
 for ( WMLExpression expression : getExpressions( ) ) {
 if ( expression.isWMLTag( ) )
 result.add( expression.asWMLTag( ) );
 }

 return result;"/>
|
||||
<details key="body" value="EList<WMLTag> result = new org.eclipse.emf.common.util.BasicEList<WMLTag>();
 for ( WMLExpression expression : getExpressions( ) ) {
 if ( expression.isWMLTag( ) )
 result.add( expression.asWMLTag( ) );
 }

 return result;"/>
|
||||
</eAnnotations>
|
||||
<eGenericType eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EEList">
|
||||
<eTypeArguments eClassifier="ecore:EClass platform:/resource/org.wesnoth/src-gen/org/wesnoth/WML.ecore#//WMLTag"/>
|
||||
|
|
|
@ -186,7 +186,7 @@ public interface WMLTag extends WMLRootExpression
|
|||
* <!-- begin-user-doc -->
|
||||
* <!-- end-user-doc -->
|
||||
* @model kind="operation" many="false"
|
||||
* annotation="http://www.eclipse.org/emf/2002/GenModel body='\n EList<WMLTag> result = new org.eclipse.emf.common.util.BasicEList<WMLTag>();\n for ( WMLExpression expression : getExpressions( ) ) {\n if ( expression.isWMLTag( ) )\n result.add( expression.asWMLTag( ) );\n }\n\n return result;'"
|
||||
* annotation="http://www.eclipse.org/emf/2002/GenModel body='EList<WMLTag> result = new org.eclipse.emf.common.util.BasicEList<WMLTag>();\n for ( WMLExpression expression : getExpressions( ) ) {\n if ( expression.isWMLTag( ) )\n result.add( expression.asWMLTag( ) );\n }\n\n return result;'"
|
||||
* @generated
|
||||
*/
|
||||
EList<WMLTag> getWMLTags();
|
||||
|
|
|
@ -313,8 +313,7 @@ public class WMLTagImpl extends WMLRootExpressionImpl implements WMLTag
|
|||
*/
|
||||
public EList<WMLTag> getWMLTags()
|
||||
{
|
||||
|
||||
EList<WMLTag> result = new org.eclipse.emf.common.util.BasicEList<WMLTag>();
|
||||
EList<WMLTag> result = new org.eclipse.emf.common.util.BasicEList<WMLTag>();
|
||||
for ( WMLExpression expression : getExpressions( ) ) {
|
||||
if ( expression.isWMLTag( ) )
|
||||
result.add( expression.asWMLTag( ) );
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.wesnoth.preprocessor.Define;
|
|||
import org.wesnoth.preprocessor.PreprocessorUtils;
|
||||
import org.wesnoth.utils.ResourceUtils;
|
||||
import org.wesnoth.wml.WMLConfig;
|
||||
import org.wesnoth.wml.WMLTag;
|
||||
import org.wesnoth.wml.WMLVariable;
|
||||
|
||||
/**
|
||||
|
@ -266,4 +267,18 @@ public class ProjectCache implements Serializable
|
|||
|
||||
saveCache( );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parsed WML Tags from all configs of this project
|
||||
* @return A list of Tags
|
||||
*/
|
||||
public Map<String, WMLTag> getWMLTags()
|
||||
{
|
||||
Map<String, WMLTag> res = new HashMap<String, WMLTag>();
|
||||
for ( WMLConfig config : configFiles_.values( ) ) {
|
||||
res.putAll( config.getWMLTags( ) );
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ package org.wesnoth.schema;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -330,7 +330,13 @@ public class SchemaParser
|
|||
*/
|
||||
private void sortChildren( WMLTag tag)
|
||||
{
|
||||
Collections.sort( tag.getExpressions( ), new CardinalityComparator( ) );
|
||||
WMLExpression[] expressions = ( WMLExpression[] ) tag.getExpressions( ).toArray( );
|
||||
Arrays.sort( expressions, new CardinalityComparator( ) );
|
||||
tag.getExpressions( ).clear( );
|
||||
|
||||
for ( WMLExpression expression : expressions ) {
|
||||
tag.getExpressions( ).add( expression );
|
||||
}
|
||||
|
||||
for ( WMLTag subTag : tag.getWMLTags( ) ) {
|
||||
sortChildren( subTag );
|
||||
|
|
|
@ -12,8 +12,9 @@ import java.io.BufferedReader;
|
|||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.wesnoth.Logger;
|
||||
import org.wesnoth.utils.StringUtils;
|
||||
|
@ -24,7 +25,7 @@ import org.wesnoth.utils.StringUtils;
|
|||
*/
|
||||
public class SimpleLuaParser
|
||||
{
|
||||
private List<WMLTag> tags_;
|
||||
private Map<String, WMLTag> tags_;
|
||||
private Reader reader_;
|
||||
|
||||
private final static String TAG_REGEX = "wml_actions\\..+\\( *cfg *\\)";
|
||||
|
@ -33,7 +34,7 @@ public class SimpleLuaParser
|
|||
|
||||
public SimpleLuaParser( String contents )
|
||||
{
|
||||
tags_ = new ArrayList<WMLTag> ( );
|
||||
tags_ = new HashMap<String, WMLTag>( );
|
||||
reader_ = new StringReader( contents == null ? "" : contents );
|
||||
}
|
||||
|
||||
|
@ -61,7 +62,7 @@ public class SimpleLuaParser
|
|||
token.lastIndexOf( '(' ) );
|
||||
|
||||
currentTag = WmlFactory2.eINSTANCE.createWMLTag( tagName );
|
||||
tags_.add( currentTag );
|
||||
tags_.put( tagName, currentTag );
|
||||
}
|
||||
|
||||
// parse the attributes
|
||||
|
@ -94,9 +95,9 @@ public class SimpleLuaParser
|
|||
|
||||
/**
|
||||
* Returns the parsed tags from the lua code
|
||||
* @return A list with Tags
|
||||
* @return A map with Tags
|
||||
*/
|
||||
public List< WMLTag > getTags()
|
||||
public Map<String, WMLTag > getTags()
|
||||
{
|
||||
return tags_;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,9 @@ public class SimpleWMLParser
|
|||
WMLTag currentTag = null;
|
||||
String currentTagName = "";
|
||||
|
||||
// clear tags
|
||||
config_.getWMLTags( ).clear( );
|
||||
|
||||
while ( itor.hasNext( ) ) {
|
||||
EObject object = itor.next( );
|
||||
|
||||
|
@ -119,7 +122,8 @@ public class SimpleWMLParser
|
|||
SimpleLuaParser luaParser = new SimpleLuaParser(
|
||||
( ( WMLLuaCode ) object ).getValue( ) );
|
||||
luaParser.parse( );
|
||||
tags_.addAll( luaParser.getTags( ) );
|
||||
|
||||
config_.getWMLTags( ).putAll( luaParser.getTags( ) );
|
||||
}
|
||||
}
|
||||
//TODO: parse custom events
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
package org.wesnoth.wml;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -35,10 +37,12 @@ public class WMLConfig implements Serializable
|
|||
public boolean IsCampaign;
|
||||
|
||||
private String filename_;
|
||||
private Map<String, WMLTag> tags_;
|
||||
|
||||
public WMLConfig(String filename)
|
||||
{
|
||||
filename_ = filename;
|
||||
tags_ = new HashMap<String, WMLTag>( );
|
||||
}
|
||||
|
||||
public String getFilename()
|
||||
|
@ -46,6 +50,15 @@ public class WMLConfig implements Serializable
|
|||
return filename_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parsed WML Tags from this config file
|
||||
* @return A list of Tags
|
||||
*/
|
||||
public Map<String, WMLTag> getWMLTags()
|
||||
{
|
||||
return tags_;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue