Implement code folding [message #506417] |
Thu, 07 January 2010 08:28  |
Eclipse User |
|
|
|
Hi,
I have been searching the forum for a while but I wasn't able to find a satifying answer. How to enable code folding in a DLTK based editor. I've got both DLTK parser and editor, I just would like to fold function in the editor. Does anyone know where I should look?
Regards
[Updated on: Thu, 07 January 2010 08:32] by Moderator
|
|
|
|
Re: Implement code folding [message #506608 is a reply to message #506519] |
Fri, 08 January 2010 05:23   |
Eclipse User |
|
|
|
Thanks for your quick answer.
I've implemented the minimal folding, just to have a quick look. Functions don't fold yet. I think that's pretty normal as functions aren't partitionned yet.
Anyway, comments are partitionned and they don't fold either. Am I forgetting something? The comments and strings are in color, that mean that ther are parsed and the editor is aware of their existence.
Here my partitions:
public interface ILuaPartitions {
public static final String LUA_PARTITIONING = LuaConstants.LUA_PARTITIONING;
public static final String LUA_COMMENT = "__lua_comment"; //$NON-NLS-1$
public static final String LUA_MULTI_LINE_COMMENT = "__lua_multi_line_comment"; //$NON-NLS-1$
public static final String LUA_STRING = "__lua_string"; //$NON-NLS-1$
public static final String LUA_SINGLE_QUOTE_STRING = "__lua_single_quote_string"; //$NON-NLS-1$
public final static String[] LUA_PARTITION_TYPES = new String[] {
IDocument.DEFAULT_CONTENT_TYPE, ILuaPartitions.LUA_COMMENT,
ILuaPartitions.LUA_STRING, ILuaPartitions.LUA_SINGLE_QUOTE_STRING,
ILuaPartitions.LUA_MULTI_LINE_COMMENT };
}
And the associated rules:public class LuaPartitionScanner extends RuleBasedPartitionScanner {
public LuaPartitionScanner() {
super();
List<PatternRule> rules = new ArrayList<PatternRule>();
/*
* Deal with single and double quote multi lines strings
*/
IToken string = new Token(ILuaPartitions.LUA_STRING);
IToken singleQuoteString = new Token(
ILuaPartitions.LUA_SINGLE_QUOTE_STRING);
rules
.add(new MultiLineRule(
"\'", "\'", singleQuoteString, '\\', false)); //$NON-NLS-1$ //$NON-NLS-2$
rules.add(new MultiLineRule("\"", "\"", string, '\\', false)); //$NON-NLS-1$ //$NON-NLS-2$
/*
* Deal with comments
*/
// Multi-line
IToken multiLineComment = new Token(
ILuaPartitions.LUA_MULTI_LINE_COMMENT);
rules.add(new MultiLineRule("--[[", "]]", multiLineComment));//$NON-NLS-1$
// Single line
IToken comment = new Token(ILuaPartitions.LUA_COMMENT);
rules.add(new EndOfLineRule("--", comment)); //$NON-NLS-1$
// Apply rules
IPredicateRule[] result = new IPredicateRule[rules.size()];
rules.toArray(result);
setPredicateRules(result);
}
}
|
|
|
|
|
|
|
|
Re: Implement code folding [message #515271 is a reply to message #510808] |
Thu, 18 February 2010 05:29  |
Eclipse User |
|
|
|
I've manages to fold comments. In your class inherited from AbstractPreferenceInitializerpublic class YourPreferenceInitializer extends AbstractPreferenceInitializer {
@Override
public void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
// ...
store.setDefault( PreferenceConstants.EDITOR_DOCS_FOLDING_ENABLED, true);
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.04316 seconds