mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Added support for completion in external files. Also cleaned up the service provider.
This commit is contained in:
parent
4dfe0944bc
commit
229dce01a0
4 changed files with 77 additions and 49 deletions
|
@ -139,9 +139,6 @@ public class CDOM implements IASTServiceProvider {
|
||||||
return defaultService.getTranslationUnit(fileToParse, fileCreator, configuration );
|
return defaultService.getTranslationUnit(fileToParse, fileCreator, configuration );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getCompletionNode(org.eclipse.core.resources.IFile, int, org.eclipse.cdt.core.dom.ICodeReaderFactory)
|
|
||||||
*/
|
|
||||||
public ASTCompletionNode getCompletionNode(IFile fileToParse, int offset,
|
public ASTCompletionNode getCompletionNode(IFile fileToParse, int offset,
|
||||||
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
|
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
|
||||||
//TODO - At this time, we purely delegate blindly
|
//TODO - At this time, we purely delegate blindly
|
||||||
|
@ -149,6 +146,13 @@ public class CDOM implements IASTServiceProvider {
|
||||||
return defaultService.getCompletionNode(fileToParse, offset, fileCreator);
|
return defaultService.getCompletionNode(fileToParse, offset, fileCreator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ASTCompletionNode getCompletionNode(IStorage fileToParse, IProject project, int offset,
|
||||||
|
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
|
||||||
|
//TODO - At this time, we purely delegate blindly
|
||||||
|
//In the future, we may need to delegate based upon context provided
|
||||||
|
return defaultService.getCompletionNode(fileToParse, project, offset, fileCreator);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method allows a UI component to register its IWorkingCopyProvider to the CDOM.
|
* This method allows a UI component to register its IWorkingCopyProvider to the CDOM.
|
||||||
*
|
*
|
||||||
|
|
|
@ -97,4 +97,16 @@ public interface IASTServiceProvider {
|
||||||
*/
|
*/
|
||||||
public ASTCompletionNode getCompletionNode( IFile fileToParse, int offset, ICodeReaderFactory fileCreator) throws UnsupportedDialectException;
|
public ASTCompletionNode getCompletionNode( IFile fileToParse, int offset, ICodeReaderFactory fileCreator) throws UnsupportedDialectException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a parse tree that represents the content provided as parameters.
|
||||||
|
*
|
||||||
|
* @param fileToParse the file in question
|
||||||
|
* @param project the project containing the scanner info
|
||||||
|
* @param offset the offset at which you require completion at
|
||||||
|
* @param fileCreator @see CDOM#getCodeReaderFactory(int)
|
||||||
|
* @return syntactical parse tree
|
||||||
|
* @throws UnsupportedDialectException
|
||||||
|
*/
|
||||||
|
public ASTCompletionNode getCompletionNode( IStorage fileToParse, IProject project, int offset, ICodeReaderFactory fileCreator) throws UnsupportedDialectException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@ import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IStorage;
|
import org.eclipse.core.resources.IStorage;
|
||||||
import org.eclipse.core.runtime.IPath;
|
|
||||||
import org.eclipse.core.runtime.content.IContentType;
|
import org.eclipse.core.runtime.content.IContentType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,14 +68,14 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit()
|
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit()
|
||||||
*/
|
*/
|
||||||
public IASTTranslationUnit getTranslationUnit(IFile fileToParse) throws UnsupportedDialectException {
|
public IASTTranslationUnit getTranslationUnit(IFile fileToParse) throws UnsupportedDialectException {
|
||||||
return getTranslationUnit( fileToParse, fileToParse.getLocation().toOSString(), fileToParse.getProject(), SavedCodeReaderFactory.getInstance(), null );
|
return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, SavedCodeReaderFactory.getInstance(), null );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.cdt.core.dom.ICodeReaderFactory)
|
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.cdt.core.dom.ICodeReaderFactory)
|
||||||
*/
|
*/
|
||||||
public IASTTranslationUnit getTranslationUnit(IFile fileToParse, ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
|
public IASTTranslationUnit getTranslationUnit(IFile fileToParse, ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
|
||||||
return getTranslationUnit( fileToParse, fileToParse.getLocation().toOSString(), fileToParse.getProject(), fileCreator, null );
|
return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, fileCreator, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -84,27 +83,23 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
*/
|
*/
|
||||||
public IASTTranslationUnit getTranslationUnit(
|
public IASTTranslationUnit getTranslationUnit(
|
||||||
IFile fileToParse, ICodeReaderFactory fileCreator, IParserConfiguration configuration) throws UnsupportedDialectException {
|
IFile fileToParse, ICodeReaderFactory fileCreator, IParserConfiguration configuration) throws UnsupportedDialectException {
|
||||||
return getTranslationUnit( fileToParse, fileToParse.getLocation().toOSString(), fileToParse.getProject(), fileCreator, configuration );
|
return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, fileCreator, configuration );
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTTranslationUnit getTranslationUnit(
|
public IASTTranslationUnit getTranslationUnit(
|
||||||
IStorage fileToParse, String os_path, IProject project, ICodeReaderFactory fileCreator, IParserConfiguration configuration ) throws UnsupportedDialectException
|
String filename, IResource infoProvider, ICodeReaderFactory fileCreator, IParserConfiguration configuration ) throws UnsupportedDialectException
|
||||||
{
|
{
|
||||||
|
IProject project = infoProvider.getProject();
|
||||||
IScannerInfo scanInfo = null;
|
IScannerInfo scanInfo = null;
|
||||||
|
|
||||||
if( configuration == null )
|
if( configuration == null )
|
||||||
{
|
{
|
||||||
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
|
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
|
||||||
if (provider != null){
|
if (provider != null){
|
||||||
IScannerInfo buildScanInfo = null;
|
IScannerInfo buildScanInfo = provider.getScannerInformation(infoProvider);
|
||||||
if( fileToParse instanceof IResource )
|
|
||||||
buildScanInfo = provider.getScannerInformation( (IResource) fileToParse );
|
|
||||||
else
|
|
||||||
buildScanInfo = provider.getScannerInformation( project);
|
|
||||||
|
|
||||||
if (buildScanInfo != null){
|
if (buildScanInfo != null)
|
||||||
scanInfo = buildScanInfo;
|
scanInfo = buildScanInfo;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
scanInfo = new ScannerInfo();
|
scanInfo = new ScannerInfo();
|
||||||
}
|
}
|
||||||
|
@ -112,8 +107,7 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
else
|
else
|
||||||
scanInfo = configuration.getScannerInfo();
|
scanInfo = configuration.getScannerInfo();
|
||||||
|
|
||||||
|
CodeReader reader = fileCreator.createCodeReaderForTranslationUnit(filename);
|
||||||
CodeReader reader = fileCreator.createCodeReaderForTranslationUnit( os_path );
|
|
||||||
if( reader == null )
|
if( reader == null )
|
||||||
return null;
|
return null;
|
||||||
IScanner scanner = null;
|
IScanner scanner = null;
|
||||||
|
@ -121,7 +115,7 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
|
|
||||||
if( configuration == null )
|
if( configuration == null )
|
||||||
{
|
{
|
||||||
ParserLanguage l = getLanguage(fileToParse.getFullPath(), project);
|
ParserLanguage l = getLanguage(filename, project);
|
||||||
IScannerExtensionConfiguration scannerExtensionConfiguration = null;
|
IScannerExtensionConfiguration scannerExtensionConfiguration = null;
|
||||||
if( l == ParserLanguage.CPP )
|
if( l == ParserLanguage.CPP )
|
||||||
scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION;
|
scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION;
|
||||||
|
@ -175,31 +169,34 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
return tu;
|
return tu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
public ASTCompletionNode getCompletionNode(IStorage fileToParse, IProject project, int offset,
|
||||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getCompletionNode(org.eclipse.core.resources.IFile, int, org.eclipse.cdt.core.dom.ICodeReaderFactory)
|
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
|
||||||
*/
|
return getCompletionNode(fileToParse.getFullPath().toOSString(), project, offset, fileCreator);
|
||||||
|
}
|
||||||
|
|
||||||
public ASTCompletionNode getCompletionNode(IFile fileToParse, int offset,
|
public ASTCompletionNode getCompletionNode(IFile fileToParse, int offset,
|
||||||
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
|
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
|
||||||
// Get the scanner info
|
return getCompletionNode(fileToParse.getLocation().toOSString(), fileToParse, offset, fileCreator);
|
||||||
IProject currentProject = fileToParse.getProject();
|
}
|
||||||
IScannerInfo scanInfo = null;
|
|
||||||
|
|
||||||
IScannerInfoProvider provider = CCorePlugin.getDefault()
|
public ASTCompletionNode getCompletionNode(String filename, IResource infoProvider, int offset,
|
||||||
.getScannerInfoProvider(currentProject);
|
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
|
||||||
|
// Get the scanner info
|
||||||
|
IScannerInfo scanInfo = null;
|
||||||
|
IProject project = infoProvider.getProject();
|
||||||
|
|
||||||
|
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
|
||||||
if (provider != null) {
|
if (provider != null) {
|
||||||
IScannerInfo buildScanInfo = provider
|
IScannerInfo buildScanInfo = provider.getScannerInformation(infoProvider);
|
||||||
.getScannerInformation(fileToParse);
|
|
||||||
if (buildScanInfo != null)
|
if (buildScanInfo != null)
|
||||||
scanInfo = buildScanInfo;
|
scanInfo = buildScanInfo;
|
||||||
else
|
else
|
||||||
scanInfo = new ScannerInfo();
|
scanInfo = new ScannerInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeReader reader = fileCreator
|
CodeReader reader = fileCreator.createCodeReaderForTranslationUnit(filename);
|
||||||
.createCodeReaderForTranslationUnit(fileToParse.getLocation()
|
|
||||||
.toOSString());
|
|
||||||
|
|
||||||
ParserLanguage l = getLanguage(fileToParse.getLocation(), currentProject);
|
ParserLanguage l = getLanguage(filename, project);
|
||||||
IScannerExtensionConfiguration scannerExtensionConfiguration = null;
|
IScannerExtensionConfiguration scannerExtensionConfiguration = null;
|
||||||
if (l == ParserLanguage.CPP)
|
if (l == ParserLanguage.CPP)
|
||||||
scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION;
|
scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION;
|
||||||
|
@ -239,12 +236,12 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
return dialects;
|
return dialects;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ParserLanguage getLanguage( IPath path, IProject project )
|
private ParserLanguage getLanguage( String filename, IProject project )
|
||||||
{
|
{
|
||||||
//FIXME: ALAIN, for headers should we assume CPP ??
|
//FIXME: ALAIN, for headers should we assume CPP ??
|
||||||
// The problem is that it really depends on how the header was included.
|
// The problem is that it really depends on how the header was included.
|
||||||
String id = null;
|
String id = null;
|
||||||
IContentType contentType = CCorePlugin.getContentType(project, path.lastSegment());
|
IContentType contentType = CCorePlugin.getContentType(project, filename);
|
||||||
if (contentType != null) {
|
if (contentType != null) {
|
||||||
id = contentType.getId();
|
id = contentType.getId();
|
||||||
}
|
}
|
||||||
|
@ -266,10 +263,10 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTTranslationUnit getTranslationUnit(IStorage fileToParse, IProject project, ICodeReaderFactory fileCreator) throws UnsupportedDialectException{
|
public IASTTranslationUnit getTranslationUnit(IStorage fileToParse, IProject project, ICodeReaderFactory fileCreator) throws UnsupportedDialectException{
|
||||||
return getTranslationUnit( fileToParse, fileToParse.getFullPath().toOSString(), project, fileCreator, null );
|
return getTranslationUnit( fileToParse.getFullPath().toOSString(), project, fileCreator, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTTranslationUnit getTranslationUnit(IStorage fileToParse, IProject project) throws UnsupportedDialectException {
|
public IASTTranslationUnit getTranslationUnit(IStorage fileToParse, IProject project) throws UnsupportedDialectException {
|
||||||
return getTranslationUnit( fileToParse, fileToParse.getFullPath().toOSString(), project, SavedCodeReaderFactory.getInstance(), null );
|
return getTranslationUnit( fileToParse.getFullPath().toOSString(), project, SavedCodeReaderFactory.getInstance(), null );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,12 @@ import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.internal.ui.CUIMessages;
|
import org.eclipse.cdt.internal.ui.CUIMessages;
|
||||||
import org.eclipse.cdt.internal.ui.text.CParameterListValidator;
|
import org.eclipse.cdt.internal.ui.text.CParameterListValidator;
|
||||||
|
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
|
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IStorage;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtension;
|
import org.eclipse.core.runtime.IExtension;
|
||||||
import org.eclipse.core.runtime.IExtensionPoint;
|
import org.eclipse.core.runtime.IExtensionPoint;
|
||||||
|
@ -59,10 +62,22 @@ public class CCompletionProcessor2 implements IContentAssistProcessor {
|
||||||
int offset) {
|
int offset) {
|
||||||
try {
|
try {
|
||||||
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
|
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
|
||||||
ASTCompletionNode completionNode = CDOM.getInstance().getCompletionNode(
|
ASTCompletionNode completionNode = null;
|
||||||
(IFile)workingCopy.getResource(),
|
IFile file = (IFile)workingCopy.getResource();
|
||||||
|
if (file != null)
|
||||||
|
completionNode = CDOM.getInstance().getCompletionNode(
|
||||||
|
file,
|
||||||
offset,
|
offset,
|
||||||
CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
|
CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
|
||||||
|
else if (editor.getEditorInput() instanceof ExternalEditorInput) {
|
||||||
|
IStorage storage = ((ExternalEditorInput)(editor.getEditorInput())).getStorage();
|
||||||
|
IProject project = workingCopy.getCProject().getProject();
|
||||||
|
completionNode = CDOM.getInstance().getCompletionNode(
|
||||||
|
storage,
|
||||||
|
project,
|
||||||
|
offset,
|
||||||
|
CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
|
||||||
|
}
|
||||||
|
|
||||||
errorMessage = CUIMessages.getString(noCompletions);
|
errorMessage = CUIMessages.getString(noCompletions);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue