mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 12:25:35 +02:00
84019, 103196 - Folding support for comments and preprocessor branches (work in progress)
This commit is contained in:
parent
594a9298a0
commit
a9f3514fa0
9 changed files with 1390 additions and 349 deletions
|
@ -8,3 +8,6 @@ org.eclipse.cdt.ui/debug/ASTProvider=false
|
|||
|
||||
# Enables all semantic highlighting types
|
||||
org.eclipse.cdt.ui/debug/SemanticHighlighting=false
|
||||
|
||||
# Enables debug information related to folding
|
||||
org.eclipse.cdt.ui/debug/folding=false
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.eclipse.ui.IWorkbenchPartReference;
|
|||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
import org.eclipse.cdt.core.IPositionConverter;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
@ -93,12 +94,10 @@ public final class ASTProvider {
|
|||
*/
|
||||
public static final WAIT_FLAG WAIT_NO= new WAIT_FLAG("don't wait"); //$NON-NLS-1$
|
||||
|
||||
public static int PARSE_MODE_FULL= ILanguage.AST_SKIP_IF_NO_BUILD_INFO;
|
||||
public static int PARSE_MODE_FAST= ILanguage.AST_SKIP_IF_NO_BUILD_INFO | ILanguage.AST_SKIP_INDEXED_HEADERS;
|
||||
public static int PARSE_MODE_FAST_INDEX= ILanguage.AST_SKIP_IF_NO_BUILD_INFO | ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_USE_INDEX;
|
||||
public static int PARSE_MODE_INDEX= ILanguage.AST_SKIP_IF_NO_BUILD_INFO | ILanguage.AST_USE_INDEX;
|
||||
|
||||
public static int PARSE_MODE= PARSE_MODE_FULL;
|
||||
/** Full parse mode (no PDOM) */
|
||||
public static int PARSE_MODE_FULL= 0;
|
||||
/** Fast parse mode (use PDOM) */
|
||||
public static int PARSE_MODE_FAST= ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_USE_INDEX;
|
||||
|
||||
/**
|
||||
* Tells whether this class is in debug mode.
|
||||
|
@ -232,6 +231,7 @@ public final class ASTProvider {
|
|||
|
||||
private ICElement fReconcilingCElement;
|
||||
private ICElement fActiveCElement;
|
||||
private IPositionConverter fActivePositionConverter;
|
||||
private IASTTranslationUnit fAST;
|
||||
private ActivationListener fActivationListener;
|
||||
private Object fReconcileLock= new Object();
|
||||
|
@ -239,7 +239,8 @@ public final class ASTProvider {
|
|||
private boolean fIsReconciling;
|
||||
private IWorkbenchPart fActiveEditor;
|
||||
|
||||
|
||||
protected int fParseMode= PARSE_MODE_FAST;
|
||||
|
||||
/**
|
||||
* Returns the C plug-in's AST provider.
|
||||
*
|
||||
|
@ -280,7 +281,7 @@ public final class ASTProvider {
|
|||
synchronized (this) {
|
||||
fActiveEditor= editor;
|
||||
fActiveCElement= cElement;
|
||||
cache(null, cElement);
|
||||
cache(null, null, cElement);
|
||||
}
|
||||
|
||||
if (DEBUG)
|
||||
|
@ -337,7 +338,7 @@ public final class ASTProvider {
|
|||
fIsReconciling= true;
|
||||
fReconcilingCElement= cElement;
|
||||
}
|
||||
cache(null, cElement);
|
||||
cache(null, null, cElement);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -353,7 +354,7 @@ public final class ASTProvider {
|
|||
|
||||
fAST= null;
|
||||
|
||||
cache(null, null);
|
||||
cache(null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -393,7 +394,7 @@ public final class ASTProvider {
|
|||
* @param ast
|
||||
* @param cElement
|
||||
*/
|
||||
private synchronized void cache(IASTTranslationUnit ast, ICElement cElement) {
|
||||
private synchronized void cache(IASTTranslationUnit ast, IPositionConverter converter, ICElement cElement) {
|
||||
|
||||
if (fActiveCElement != null && !fActiveCElement.equals(cElement)) {
|
||||
if (DEBUG && cElement != null) // don't report call from disposeAST()
|
||||
|
@ -408,6 +409,7 @@ public final class ASTProvider {
|
|||
disposeAST();
|
||||
|
||||
fAST= ast;
|
||||
fActivePositionConverter= converter;
|
||||
|
||||
// Signal AST change
|
||||
synchronized (fWaitLock) {
|
||||
|
@ -502,9 +504,9 @@ public final class ASTProvider {
|
|||
if (fAST != null) {
|
||||
if (DEBUG)
|
||||
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "Ignore created AST for " + cElement.getElementName() + "- AST from reconciler is newer"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
reconciled(fAST, cElement, null);
|
||||
reconciled(fAST, fActivePositionConverter, cElement, null);
|
||||
} else
|
||||
reconciled(ast, cElement, null);
|
||||
reconciled(ast, null, cElement, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -550,7 +552,7 @@ public final class ASTProvider {
|
|||
if (progressMonitor != null && progressMonitor.isCanceled()) {
|
||||
root[0]= null;
|
||||
} else {
|
||||
root[0]= tu.getLanguage().getASTTranslationUnit(tu, PARSE_MODE);
|
||||
root[0]= tu.getLanguage().getASTTranslationUnit(tu, fParseMode);
|
||||
}
|
||||
} catch (OperationCanceledException ex) {
|
||||
root[0]= null;
|
||||
|
@ -601,9 +603,9 @@ public final class ASTProvider {
|
|||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.ICReconcilingListener#reconciled(org.eclipse.cdt.core.dom.IASTTranslationUnit)
|
||||
* @see org.eclipse.cdt.internal.ui.text.ICReconcilingListener#reconciled()
|
||||
*/
|
||||
void reconciled(IASTTranslationUnit ast, ICElement cElement, IProgressMonitor progressMonitor) {
|
||||
void reconciled(IASTTranslationUnit ast, IPositionConverter converter, ICElement cElement, IProgressMonitor progressMonitor) {
|
||||
|
||||
if (DEBUG)
|
||||
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "reconciled: " + toString(cElement) + ", AST: " + toString(ast)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
@ -624,7 +626,7 @@ public final class ASTProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
cache(ast, cElement);
|
||||
cache(ast, converter, cElement);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -635,6 +637,17 @@ public final class ASTProvider {
|
|||
else
|
||||
return Thread.currentThread().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @return the position converter for the AST of the active element or <code>null</code>
|
||||
*/
|
||||
public IPositionConverter getActivePositionConverter(ICElement element) {
|
||||
if (fActiveCElement == element) {
|
||||
return fActivePositionConverter;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2183,7 +2183,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
|||
return;
|
||||
|
||||
// Always notify AST provider
|
||||
cuiPlugin.getASTProvider().reconciled(ast, getInputCElement(), progressMonitor);
|
||||
cuiPlugin.getASTProvider().reconciled(ast, positionTracker, getInputCElement(), progressMonitor);
|
||||
|
||||
// Notify listeners
|
||||
Object[] listeners = fReconcilingListeners.getListeners();
|
||||
|
@ -2200,10 +2200,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
|||
* @param listener The reconcile listener to be added
|
||||
* @since 4.0
|
||||
*/
|
||||
final void addReconcileListener(ICReconcilingListener listener) {
|
||||
synchronized (fReconcilingListeners) {
|
||||
fReconcilingListeners.add(listener);
|
||||
}
|
||||
final public void addReconcileListener(ICReconcilingListener listener) {
|
||||
fReconcilingListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2213,10 +2211,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
|||
* @param listener the reconcile listener to be removed
|
||||
* @since 4.0
|
||||
*/
|
||||
final void removeReconcileListener(ICReconcilingListener listener) {
|
||||
synchronized (fReconcilingListeners) {
|
||||
fReconcilingListeners.remove(listener);
|
||||
}
|
||||
final public void removeReconcileListener(ICReconcilingListener listener) {
|
||||
fReconcilingListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2005 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -84,7 +84,10 @@ public class WorkInProgressPreferencePage extends PreferencePage implements IWor
|
|||
result.setLayout(layout);
|
||||
|
||||
// Add your controls here
|
||||
addCheckBox(result, "Semantic Highlighting", PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED); //$NON-NLS-1$
|
||||
addCheckBox(result, "Enable semantic highlighting", PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED); //$NON-NLS-1$
|
||||
addCheckBox(result, "Enable folding of preprocessor branches (#if/#endif)", PreferenceConstants.EDITOR_FOLDING_PREPROCESSOR_BRANCHES_ENABLED); //$NON-NLS-1$
|
||||
addCheckBox(result, "Enable comment folding", PreferenceConstants.EDITOR_FOLDING_COMMENTS_ENABLED); //$NON-NLS-1$
|
||||
|
||||
applyDialogFont(result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.text.folding;
|
||||
|
@ -64,6 +65,9 @@ public class DefaultCFoldingPreferenceBlock implements ICFoldingPreferenceBlock
|
|||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_FUNCTIONS));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_METHODS));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_STRUCTURES));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_COMMENTS));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_HEADERS));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_INACTIVE_CODE));
|
||||
|
||||
return (OverlayKey[]) overlayKeys.toArray(new OverlayKey[overlayKeys.size()]);
|
||||
}
|
||||
|
@ -88,6 +92,9 @@ public class DefaultCFoldingPreferenceBlock implements ICFoldingPreferenceBlock
|
|||
addCheckBox(inner, FoldingMessages.getString("DefaultCFoldingPreferenceBlock.functions"), PreferenceConstants.EDITOR_FOLDING_FUNCTIONS, 0); //$NON-NLS-1$
|
||||
addCheckBox(inner, FoldingMessages.getString("DefaultCFoldingPreferenceBlock.methods"), PreferenceConstants.EDITOR_FOLDING_METHODS, 0); //$NON-NLS-1$
|
||||
addCheckBox(inner, FoldingMessages.getString("DefaultCFoldingPreferenceBlock.structures"), PreferenceConstants.EDITOR_FOLDING_STRUCTURES, 0); //$NON-NLS-1$
|
||||
addCheckBox(inner, FoldingMessages.getString("DefaultCFoldingPreferenceBlock.comments"), PreferenceConstants.EDITOR_FOLDING_COMMENTS, 0); //$NON-NLS-1$
|
||||
addCheckBox(inner, FoldingMessages.getString("DefaultCFoldingPreferenceBlock.headers"), PreferenceConstants.EDITOR_FOLDING_HEADERS, 0); //$NON-NLS-1$
|
||||
addCheckBox(inner, FoldingMessages.getString("DefaultCFoldingPreferenceBlock.inactive_code"), PreferenceConstants.EDITOR_FOLDING_INACTIVE_CODE, 0); //$NON-NLS-1$
|
||||
|
||||
return inner;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -7,6 +7,7 @@
|
|||
#
|
||||
# Contributors:
|
||||
# IBM Corporation - initial API and implementation
|
||||
# Anton Leherbauer (Wind River Systems)
|
||||
###############################################################################
|
||||
|
||||
|
||||
|
@ -15,5 +16,8 @@ DefaultCFoldingPreferenceBlock.macros= &Macros
|
|||
DefaultCFoldingPreferenceBlock.functions= &Functions
|
||||
DefaultCFoldingPreferenceBlock.methods= &Methods
|
||||
DefaultCFoldingPreferenceBlock.structures= &Structures
|
||||
DefaultCFoldingPreferenceBlock.comments= &Comments
|
||||
DefaultCFoldingPreferenceBlock.headers= &Header Comments
|
||||
DefaultCFoldingPreferenceBlock.inactive_code= &Inactive Preprocessor Branches
|
||||
|
||||
EmptyCFoldingPreferenceBlock.emptyCaption=
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* QNX Software Systems - Initial API and implementation
|
||||
* IBM Corp. - Rational Software
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui;
|
||||
|
||||
|
@ -435,6 +436,9 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
}
|
||||
};
|
||||
CCorePlugin.getDefault().getDOM().setWorkingCopyProvider(workingCopyProvider);
|
||||
|
||||
// init ast provider
|
||||
getASTProvider();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui;
|
||||
|
||||
|
@ -399,6 +400,56 @@ public class PreferenceConstants {
|
|||
*/
|
||||
public static final String EDITOR_FOLDING_MACROS= "editor_folding_default_macros"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that stores the value for comment folding for the default folding provider.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>.
|
||||
* </p>
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public static final String EDITOR_FOLDING_COMMENTS= "editor_folding_default_comments"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that stores the value for header comment folding for the default folding provider.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>.
|
||||
* </p>
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public static final String EDITOR_FOLDING_HEADERS= "editor_folding_default_headers"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that stores the value for inactive code folding for the default folding provider.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>.
|
||||
* </p>
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public static final String EDITOR_FOLDING_INACTIVE_CODE= "editor_folding_default_inactive"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that controls whether folding of preprocessor branches is enabled.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>.
|
||||
* </p>
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public static final String EDITOR_FOLDING_PREPROCESSOR_BRANCHES_ENABLED= "editor_folding_preprocessor_enabled"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that controls whether folding of comments is enabled.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>.
|
||||
* </p>
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public static final String EDITOR_FOLDING_COMMENTS_ENABLED= "editor_folding_comments_enabled"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that controls if templates are formatted when applied.
|
||||
* <p>
|
||||
|
@ -545,6 +596,11 @@ public class PreferenceConstants {
|
|||
store.setDefault(PreferenceConstants.EDITOR_FOLDING_STRUCTURES, true);
|
||||
store.setDefault(PreferenceConstants.EDITOR_FOLDING_METHODS, false);
|
||||
store.setDefault(PreferenceConstants.EDITOR_FOLDING_MACROS, true);
|
||||
store.setDefault(PreferenceConstants.EDITOR_FOLDING_COMMENTS, false);
|
||||
store.setDefault(PreferenceConstants.EDITOR_FOLDING_HEADERS, true);
|
||||
store.setDefault(PreferenceConstants.EDITOR_FOLDING_INACTIVE_CODE, true);
|
||||
store.setDefault(PreferenceConstants.EDITOR_FOLDING_COMMENTS_ENABLED, false);
|
||||
store.setDefault(PreferenceConstants.EDITOR_FOLDING_PREPROCESSOR_BRANCHES_ENABLED, false);
|
||||
|
||||
store.setDefault(PreferenceConstants.EDITOR_CLOSE_STRINGS, true);
|
||||
store.setDefault(PreferenceConstants.EDITOR_CLOSE_BRACKETS, true);
|
||||
|
|
Loading…
Add table
Reference in a new issue