eclipse plugin: Add the parsed variables to the variables proposal list
This commit is contained in:
parent
7420f6b659
commit
8cf5d7eb7c
4 changed files with 51 additions and 12 deletions
|
@ -8,6 +8,8 @@
|
|||
*******************************************************************************/
|
||||
package org.wesnoth.ui.contentassist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
@ -33,16 +35,23 @@ 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;
|
||||
import org.wesnoth.utils.StringUtils;
|
||||
import org.wesnoth.utils.WMLUtils;
|
||||
import org.wesnoth.wml.WMLKey;
|
||||
import org.wesnoth.wml.WMLTag;
|
||||
import org.wesnoth.wml.core.WMLConfig;
|
||||
import org.wesnoth.wml.core.WMLVariable;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
|
||||
public class WMLProposalProvider extends AbstractWMLProposalProvider
|
||||
{
|
||||
protected SchemaParser schemaParser_;
|
||||
protected ProjectCache projectCache_;
|
||||
protected int dependencyIndex_;
|
||||
|
||||
protected static final int KEY_VALUE_PRIORITY = 1700;
|
||||
protected static final int KEY_NAME_PRIORITY = 1500;
|
||||
|
@ -86,6 +95,8 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
// load the schema so we know what to suggest for autocomplete
|
||||
SchemaParser.reloadSchemas( false );
|
||||
schemaParser_ = SchemaParser.getInstance( WesnothInstallsUtils.getInstallNameForResource( file ) );
|
||||
|
||||
dependencyIndex_ = ResourceUtils.getDependencyIndex( file );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -217,7 +228,26 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
}
|
||||
} else {
|
||||
// add variables
|
||||
List<String> variables = TemplateProvider.getInstance( ).getCAC( "variables" );
|
||||
List<String> variables = new ArrayList<String>();
|
||||
variables.addAll( TemplateProvider.getInstance( ).getCAC( "variables" ) );
|
||||
|
||||
// filter variables by index
|
||||
Collection<String> projectVariables = Collections2.transform(
|
||||
projectCache_.getVariables( ).values( ),
|
||||
new Function<WMLVariable, String> () {
|
||||
|
||||
@Override
|
||||
public String apply( WMLVariable from )
|
||||
{
|
||||
if ( from.getScopeStartIndex( ) <= dependencyIndex_ &&
|
||||
dependencyIndex_ <= from.getScopeEndIndex( ) )
|
||||
return from.getName( );
|
||||
return null;
|
||||
}
|
||||
} );
|
||||
|
||||
variables.addAll( Collections2.filter( projectVariables,
|
||||
Predicates.notNull( ) ) );
|
||||
|
||||
for ( String variable : variables ) {
|
||||
acceptor.accept( createCompletionProposal( "$" + variable, context ) );
|
||||
|
@ -282,7 +312,7 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
|
||||
String parentIndent = ""; //$NON-NLS-1$
|
||||
if (context.getCurrentNode().getOffset() > 0)
|
||||
parentIndent = NodeModelUtils.findLeafNodeAtOffset(node.getParent(),
|
||||
parentIndent = NodeModelUtils.findLeafNodeAtOffset(node,
|
||||
context.getCurrentNode().getOffset() -
|
||||
// if we have a non-rule proposal, subtract 1
|
||||
(ruleProposal ? 0 : 1) ).getText();
|
||||
|
@ -347,14 +377,14 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
if (ruleProposal)
|
||||
proposal.append("["); //$NON-NLS-1$
|
||||
proposal.append(tag.getName());
|
||||
proposal.append("]\n"); //$NON-NLS-1$
|
||||
proposal.append("\n"); //$NON-NLS-1$
|
||||
for(TagKey key : tag.getKeyChildren())
|
||||
{
|
||||
if (key.isRequired())
|
||||
proposal.append(String.format("\t%s%s=\n", //$NON-NLS-1$
|
||||
indent, key.getName()));
|
||||
}
|
||||
proposal.append(String.format("%s[/%s]",indent, tag.getName())); //$NON-NLS-1$
|
||||
proposal.append(String.format("%s[/%s",indent, tag.getName())); //$NON-NLS-1$
|
||||
return createCompletionProposal(proposal.toString(), tag.getName(),
|
||||
WML_TAG_IMAGE, context, TAG_PRIORITY);
|
||||
}
|
||||
|
|
|
@ -194,14 +194,14 @@ public class TemplateProvider
|
|||
/**
|
||||
* Gets the Content Assist Config list for the specified type
|
||||
* @param type The type of the CAC
|
||||
* @return A list of String values
|
||||
* @return A list of String values. The returned list is read-only
|
||||
*/
|
||||
public List<String> getCAC( String type )
|
||||
{
|
||||
List<String> result = cacs_.get( type );
|
||||
|
||||
if ( result == null )
|
||||
return new ArrayList<String>( 0 );
|
||||
return new ArrayList<String>( );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.eclipse.emf.ecore.EObject;
|
|||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.wesnoth.projects.ProjectCache;
|
||||
import org.wesnoth.projects.ProjectUtils;
|
||||
import org.wesnoth.utils.ResourceUtils;
|
||||
import org.wesnoth.utils.WMLUtils;
|
||||
import org.wesnoth.wml.WMLKey;
|
||||
|
@ -37,8 +38,7 @@ public class SimpleWMLParser
|
|||
*/
|
||||
public SimpleWMLParser( IFile file )
|
||||
{
|
||||
file_ = file;
|
||||
config_ = new WMLConfig( file.getProjectRelativePath( ).toString( ) );
|
||||
this( file, new WMLConfig( file.getProjectRelativePath( ).toString( ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,6 +48,7 @@ public class SimpleWMLParser
|
|||
{
|
||||
config_ = Preconditions.checkNotNull( config );
|
||||
file_ = file;
|
||||
projectCache_ = ProjectUtils.getCacheForProject( file.getProject( ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,7 +65,6 @@ public class SimpleWMLParser
|
|||
|
||||
while ( itor.hasNext( ) ) {
|
||||
EObject object = itor.next( );
|
||||
System.out.println( object );
|
||||
|
||||
if ( object instanceof WMLTag ) {
|
||||
currentTag = ( WMLTag ) object;
|
||||
|
@ -95,8 +95,7 @@ public class SimpleWMLParser
|
|||
}
|
||||
else if ( object instanceof WMLMacroCall ) {
|
||||
WMLMacroCall macroCall = ( WMLMacroCall ) object;
|
||||
String macroCallName = macroCall.getName( );
|
||||
if ( macroCallName.equals( "VARIABLE" ) ) {
|
||||
if ( macroCall.getName( ).equals( "VARIABLE" ) ) {
|
||||
handleSetVariable( object );
|
||||
}
|
||||
}
|
||||
|
@ -125,6 +124,7 @@ public class SimpleWMLParser
|
|||
|
||||
if ( ! variable.getName( ).isEmpty( ) ) {
|
||||
projectCache_.getVariables( ).put( variable.getName( ), variable );
|
||||
System.out.println( "added variable: " + variable );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public class WMLVariable
|
|||
|
||||
public WMLVariable( String name, String location, int offset )
|
||||
{
|
||||
this( name, location, offset, Integer.MAX_VALUE, Integer.MAX_VALUE );
|
||||
this( name, location, offset, Integer.MIN_VALUE, Integer.MAX_VALUE );
|
||||
}
|
||||
|
||||
public WMLVariable( String name, String location, int offset,
|
||||
|
@ -90,4 +90,13 @@ public class WMLVariable
|
|||
{
|
||||
scopeStartIndex_ = scopeStartIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Variable - Name: " + name_ +
|
||||
"; Location:" + location_ +
|
||||
"; Offset:" + offset_ +
|
||||
"; Scope: " + scopeStartIndex_ + " -> " + scopeEndIndex_;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue