Permalink
Browse files

APSTUD-4861: Cache for ast with editor contents and doing single requ…

…est for ast for folding/outline.
  • Loading branch information...
1 parent baa10e7 commit affd88d41538a89d564fd7b8bc14feec3e464812 @fabioz fabioz committed Jun 19, 2012
@@ -61,7 +61,7 @@ public String getContentType()
@Override
public ITreeContentProvider getOutlineContentProvider()
{
- return new RHTMLOutlineContentProvider();
+ return new RHTMLOutlineContentProvider(this);
}
@Override
@@ -7,14 +7,16 @@
*/
package com.aptana.editor.erb.html.outline;
+import com.aptana.editor.common.AbstractThemeableEditor;
import com.aptana.editor.html.outline.HTMLOutlineContentProvider;
import com.aptana.editor.ruby.outline.RubyOutlineContentProvider;
import com.aptana.ruby.core.IRubyConstants;
public class RHTMLOutlineContentProvider extends HTMLOutlineContentProvider
{
- public RHTMLOutlineContentProvider()
+ public RHTMLOutlineContentProvider(AbstractThemeableEditor editor)
{
+ super(editor);
addSubLanguage(IRubyConstants.CONTENT_TYPE_RUBY, new RubyOutlineContentProvider());
}
}
@@ -20,7 +20,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.debug.ui,
com.aptana.ruby.debug.ui,
org.eclipse.core.filesystem,
- org.eclipse.compare
+ org.eclipse.compare,
+ com.aptana.parsing
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Eclipse-ExtensibleAPI: true
@@ -23,6 +23,7 @@
import com.aptana.editor.common.AbstractThemeableEditor;
import com.aptana.editor.common.text.reconciler.IFoldingComputer;
import com.aptana.editor.common.text.reconciler.Messages;
+import com.aptana.parsing.ast.IParseRootNode;
public class HAMLFoldingComputer implements IFoldingComputer
{
@@ -41,8 +42,8 @@ public HAMLFoldingComputer(AbstractThemeableEditor editor, IDocument document)
* @see com.aptana.editor.common.text.reconciler.IFoldingComputer#emitFoldingRegions(org.eclipse.core.runtime.
* IProgressMonitor)
*/
- public Map<ProjectionAnnotation, Position> emitFoldingRegions(boolean initialReconcile, IProgressMonitor monitor)
- throws BadLocationException
+ public Map<ProjectionAnnotation, Position> emitFoldingRegions(boolean initialReconcile, IProgressMonitor monitor,
+ IParseRootNode ast) throws BadLocationException
{
int lineCount = fDocument.getNumberOfLines();
SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.CommonReconcilingStrategy_FoldingTaskName,
@@ -19,7 +19,8 @@ Require-Bundle: org.eclipse.core.runtime,
com.aptana.theme,
com.aptana.editor.common,
com.aptana.editor.css,
- org.eclipse.compare
+ org.eclipse.compare,
+ com.aptana.parsing
Export-Package: com.aptana.editor.sass,
com.aptana.editor.sass.merge
Bundle-Localization: plugin
@@ -25,6 +25,7 @@
import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
import com.aptana.editor.common.text.reconciler.IFoldingComputer;
+import com.aptana.parsing.ast.IParseRootNode;
public class SassFoldingComputer implements IFoldingComputer
{
@@ -41,7 +42,8 @@ public SassFoldingComputer(IDocument document)
* @see com.aptana.editor.common.text.reconciler.IFoldingComputer#emitFoldingRegions(boolean,
* org.eclipse.core.runtime.IProgressMonitor)
*/
- public Map<ProjectionAnnotation, Position> emitFoldingRegions(boolean initialReconcile, IProgressMonitor monitor)
+ public Map<ProjectionAnnotation, Position> emitFoldingRegions(boolean initialReconcile, IProgressMonitor monitor,
+ IParseRootNode ast)
{
int lineCount = getDocument().getNumberOfLines();
if (lineCount <= 1)
@@ -27,7 +27,7 @@
@Override
protected void setUp() throws Exception
{
- fContentProvider = new RHTMLOutlineContentProvider();
+ fContentProvider = new RHTMLOutlineContentProvider(null);
}
@Override
@@ -7,4 +7,5 @@ Bundle-Vendor: Aptana
Fragment-Host: com.aptana.editor.haml
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: com.aptana.editor.haml.tests
-Require-Bundle: org.junit
+Require-Bundle: org.junit,
+ com.aptana.parsing
@@ -37,6 +37,8 @@ protected int getTabSize()
};
return folder;
}
+
+
public void testFoldingByIndent() throws Exception
{
@@ -52,7 +54,7 @@ public void testFoldingByIndent() throws Exception
" #footer \n" + // fold_start 5
" %span.author John Q. Caker"; //
folder = createFolder(src);
- Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(false, new NullProgressMonitor());
+ Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(false, new NullProgressMonitor(), null);
Collection<Position> positions = annotations.values();
assertEquals(5, positions.size());
assertTrue(positions.contains(new Position(11, 249)));
@@ -74,7 +76,7 @@ public void testFoldingWithLargeIndentShift() throws Exception
" #footer \n" + // fold_start 5
" %span.author John Q. Caker"; //
folder = createFolder(src);
- Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(false, new NullProgressMonitor());
+ Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(false, new NullProgressMonitor(), null);
Collection<Position> positions = annotations.values();
assertEquals(5, positions.size());
assertTrue(positions.contains(new Position(11, 139)));
@@ -95,7 +97,7 @@ public void testAPSTUD3038DoesntOfferFoldingForBlankLinesThatChangeIndentLevel()
" \n" + //
" %div{'http-equiv' => 'Content-Type', :content => 'text/html'}"; //
folder = createFolder(src);
- Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(false, new NullProgressMonitor());
+ Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(false, new NullProgressMonitor(), null);
Collection<Position> positions = annotations.values();
assertEquals(2, positions.size());
assertTrue(positions.contains(new Position(0, 154)));
@@ -113,7 +115,7 @@ public void testEmptyLineWithChangedIndentDoesntAffectFolding() throws Exception
" \n" + // empty line with indent level changed, should be ignored
" %title= $title_for_layout"; //
folder = createFolder(src);
- Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(false, new NullProgressMonitor());
+ Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(false, new NullProgressMonitor(), null);
Collection<Position> positions = annotations.values();
assertEquals(2, positions.size());
assertTrue(positions.contains(new Position(11, src.length() - 11)));
@@ -6,6 +6,7 @@
import junit.framework.TestCase;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
@@ -15,7 +16,6 @@
import com.aptana.editor.ruby.preferences.IPreferenceConstants;
import com.aptana.parsing.IParseState;
import com.aptana.parsing.ParseState;
-import com.aptana.parsing.ast.IParseNode;
import com.aptana.parsing.ast.IParseRootNode;
import com.aptana.ruby.core.RubyParser;
@@ -33,22 +33,7 @@ protected void tearDown() throws Exception
protected void createFolder(String src)
{
- folder = new RubyFoldingComputer(null, new Document(src))
- {
- protected IParseNode getAST()
- {
- IParseState parseState = new ParseState(getDocument().get(), 0);
- try
- {
- return parse(parseState);
- }
- catch (Exception e)
- {
- fail(e.getMessage());
- }
- return null;
- };
- };
+ folder = new RubyFoldingComputer(null, new Document(src));
}
public void testMultilineCommentFolding() throws Exception
@@ -60,12 +45,29 @@ public void testMultilineCommentFolding() throws Exception
"=end\n";
// @formatter:on
createFolder(src);
- Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(false, new NullProgressMonitor());
+ Map<ProjectionAnnotation, Position> annotations = emitFoldingRegions(false, src);
Collection<Position> positions = annotations.values();
assertEquals("Incorrect number of folding points", 1, positions.size());
assertTrue(positions.contains(new Position(0, src.length()))); // eats whole line at end
}
+ protected Map<ProjectionAnnotation, Position> emitFoldingRegions(boolean initialReconcile, String src)
+ throws BadLocationException
+ {
+ IParseState parseState = new ParseState(src, 0);
+ IParseRootNode ast;
+ try
+ {
+ ast = parse(parseState);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ return folder.emitFoldingRegions(initialReconcile, new NullProgressMonitor(), ast);
+ }
+
// public void testContiguousSinglelineCommentFolding() throws Exception
// {
// // @formatter:off
@@ -90,7 +92,7 @@ public void testModuleFolding() throws Exception
"end\n";
// @formatter:on
createFolder(src);
- Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(false, new NullProgressMonitor());
+ Map<ProjectionAnnotation, Position> annotations = emitFoldingRegions(false, src);
Collection<Position> positions = annotations.values();
assertEquals("Incorrect number of folding points", 1, positions.size());
assertTrue(positions.contains(new Position(0, src.length()))); // eats whole line at end
@@ -105,7 +107,7 @@ public void testClassFolding() throws Exception
"end\n";
// @formatter:on
createFolder(src);
- Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(false, new NullProgressMonitor());
+ Map<ProjectionAnnotation, Position> annotations = emitFoldingRegions(false, src);
Collection<Position> positions = annotations.values();
assertEquals("Incorrect number of folding points", 1, positions.size());
assertTrue(positions.contains(new Position(0, src.length()))); // eats whole line at end
@@ -120,7 +122,7 @@ public void testMethodFolding() throws Exception
"end\n";
// @formatter:on
createFolder(src);
- Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(false, new NullProgressMonitor());
+ Map<ProjectionAnnotation, Position> annotations = emitFoldingRegions(false, src);
Collection<Position> positions = annotations.values();
assertEquals("Incorrect number of folding points", 1, positions.size());
assertTrue(positions.contains(new Position(0, src.length()))); // eats whole line at end
@@ -141,12 +143,12 @@ public void testCommentInitiallyFolded() throws Exception
EclipseUtil.instanceScope().getNode(RubyEditorPlugin.PLUGIN_ID)
.putBoolean(IPreferenceConstants.INITIALLY_FOLD_COMMENTS, true);
- Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(true, new NullProgressMonitor());
+ Map<ProjectionAnnotation, Position> annotations = emitFoldingRegions(true, src);
assertEquals("Wrong number of folding annotations", 1, annotations.size());
assertTrue(annotations.keySet().iterator().next().isCollapsed());
// After initial reconcile, don't mark any collapsed
- annotations = folder.emitFoldingRegions(false, new NullProgressMonitor());
+ annotations = emitFoldingRegions(false, src);
assertFalse(annotations.keySet().iterator().next().isCollapsed());
}
@@ -163,11 +165,11 @@ public void testMethodInitiallyFolded() throws Exception
EclipseUtil.instanceScope().getNode(RubyEditorPlugin.PLUGIN_ID)
.putBoolean(IPreferenceConstants.INITIALLY_FOLD_METHODS, true);
- Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(true, new NullProgressMonitor());
+ Map<ProjectionAnnotation, Position> annotations = emitFoldingRegions(true, src);
assertTrue(annotations.keySet().iterator().next().isCollapsed());
// After initial reconcile, don't mark any collapsed
- annotations = folder.emitFoldingRegions(false, new NullProgressMonitor());
+ annotations = emitFoldingRegions(false, src);
assertFalse(annotations.keySet().iterator().next().isCollapsed());
}
@@ -186,14 +188,14 @@ public void testInnerTypeInitiallyFolded() throws Exception
EclipseUtil.instanceScope().getNode(RubyEditorPlugin.PLUGIN_ID)
.putBoolean(IPreferenceConstants.INITIALLY_FOLD_INNER_TYPES, true);
- Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(true, new NullProgressMonitor());
+ Map<ProjectionAnnotation, Position> annotations = emitFoldingRegions(true, src);
assertEquals("Wrong number of folding annotations", 2, annotations.size());
// Grab the inner type folding...
ProjectionAnnotation annotation = getByPosition(annotations, new Position(19, 18));
assertTrue(annotation.isCollapsed());
// After initial reconcile, don't mark any collapsed
- annotations = folder.emitFoldingRegions(false, new NullProgressMonitor());
+ annotations = emitFoldingRegions(false, src);
annotation = getByPosition(annotations, new Position(19, 18));
assertFalse(annotation.isCollapsed());
}
@@ -212,11 +214,11 @@ public void testBlockInitiallyFolded() throws Exception
EclipseUtil.instanceScope().getNode(RubyEditorPlugin.PLUGIN_ID)
.putBoolean(IPreferenceConstants.INITIALLY_FOLD_BLOCKS, true);
- Map<ProjectionAnnotation, Position> annotations = folder.emitFoldingRegions(true, new NullProgressMonitor());
+ Map<ProjectionAnnotation, Position> annotations = emitFoldingRegions(true, src);
assertTrue(annotations.keySet().iterator().next().isCollapsed());
// After initial reconcile, don't mark any collapsed
- annotations = folder.emitFoldingRegions(false, new NullProgressMonitor());
+ annotations = emitFoldingRegions(false, src);
assertFalse(annotations.keySet().iterator().next().isCollapsed());
}
@@ -27,7 +27,7 @@ public void testFolding() throws Exception
" margin: $margin / 2\n" +
" border-color: $blue");
SassFoldingComputer sfc = new SassFoldingComputer(document);
- Map<ProjectionAnnotation, Position> annotations = sfc.emitFoldingRegions(false, null);
+ Map<ProjectionAnnotation, Position> annotations = sfc.emitFoldingRegions(false, null, null);
assertNotNull(annotations);
Collection<Position> positions = annotations.values();

0 comments on commit affd88d

Please sign in to comment.