From 66af49f629b243251835f89443313575cc4726eb Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Wed, 13 Jul 2005 20:06:55 +0000 Subject: [PATCH] Bug 102913 - Check for null workingCopy during completions which happens when you open an external file. --- .../ui/text/contentassist/CCompletionProcessor2.java | 10 ++++++---- .../contentassist/SearchCompletionContributor.java | 10 +++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java index 389168863d5..0b9c314ef92 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java @@ -71,7 +71,8 @@ public class CCompletionProcessor2 implements IContentAssistProcessor { boolean fileScope = store.getBoolean(ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE); boolean projectScope = store.getBoolean(ContentAssistPreference.PROJECT_SEARCH_SCOPE); - if (fileScope) { // do a full parse + if (fileScope && workingCopy != null) { // do a full parse + IFile file = (IFile)workingCopy.getResource(); if (file != null) completionNode = CDOM.getInstance().getCompletionNode( @@ -90,11 +91,12 @@ public class CCompletionProcessor2 implements IContentAssistProcessor { if (completionNode != null) prefix = completionNode.getPrefix(); - - } else if (projectScope) { // find the prefix from the document - prefix = scanPrefix(viewer.getDocument(), offset); + } + if (prefix == null) + prefix = scanPrefix(viewer.getDocument(), offset); + errorMessage = CUIMessages.getString(noCompletions); List proposals = new ArrayList(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/SearchCompletionContributor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/SearchCompletionContributor.java index d427a36ac79..03603c17b07 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/SearchCompletionContributor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/SearchCompletionContributor.java @@ -42,14 +42,18 @@ public class SearchCompletionContributor implements ICompletionContributor { if (prefix == null || prefix.length() == 0) return; - + // Create search engine SearchEngine searchEngine = new SearchEngine(); searchEngine.setWaitingPolicy( ICSearchConstants.FORCE_IMMEDIATE_SEARCH ); // Create search scope - ICElement[] projects = new ICElement[] { workingCopy.getCProject() }; - ICSearchScope scope = SearchEngine.createCSearchScope(projects, true); + ICSearchScope scope; + if (workingCopy != null) { + ICElement[] projects = new ICElement[] { workingCopy.getCProject() }; + scope = SearchEngine.createCSearchScope(projects, true); + } else + scope = SearchEngine.createWorkspaceScope(); // Create the pattern ICSearchPattern pattern = SearchEngine.createSearchPattern(prefix + "*", ICSearchConstants.UNKNOWN_SEARCH_FOR, ICSearchConstants.ALL_OCCURRENCES, true); //$NON-NLS-1$