diff --git a/csl.api/apichanges.xml b/csl.api/apichanges.xml --- a/csl.api/apichanges.xml +++ b/csl.api/apichanges.xml @@ -49,6 +49,22 @@ Common Scripting Language API + + + Provide information that the calling task was canceled. + + + + + +

+ Extend CodeCompletionHandler2.documentElement method to provide information + that the calling task was cancelled. +

+
+ + +
Provide a way to configure external documentation URL diff --git a/csl.api/nbproject/project.properties b/csl.api/nbproject/project.properties --- a/csl.api/nbproject/project.properties +++ b/csl.api/nbproject/project.properties @@ -40,7 +40,7 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. -spec.version.base=2.45.0 +spec.version.base=2.46.0 is.autoload=true javac.source=1.6 diff --git a/csl.api/src/org/netbeans/modules/csl/api/CodeCompletionHandler2.java b/csl.api/src/org/netbeans/modules/csl/api/CodeCompletionHandler2.java --- a/csl.api/src/org/netbeans/modules/csl/api/CodeCompletionHandler2.java +++ b/csl.api/src/org/netbeans/modules/csl/api/CodeCompletionHandler2.java @@ -41,6 +41,7 @@ */ package org.netbeans.modules.csl.api; +import java.util.concurrent.Callable; import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.modules.csl.spi.ParserResult; @@ -61,8 +62,11 @@ * * @param info the parsing information * @param element the element for which the documentation is requested + * @param cancel a {@link Callable} to signal the cancel request * @return the documentation for the element + * @since 2.46 */ @CheckForNull - Documentation documentElement(@NonNull ParserResult info, @NonNull ElementHandle element); + Documentation documentElement(@NonNull ParserResult info, @NonNull ElementHandle element, @NonNull Callable cancel); + } diff --git a/csl.api/src/org/netbeans/modules/csl/editor/completion/GsfCompletionDoc.java b/csl.api/src/org/netbeans/modules/csl/editor/completion/GsfCompletionDoc.java --- a/csl.api/src/org/netbeans/modules/csl/editor/completion/GsfCompletionDoc.java +++ b/csl.api/src/org/netbeans/modules/csl/editor/completion/GsfCompletionDoc.java @@ -47,6 +47,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; +import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractAction; @@ -78,10 +79,12 @@ private ElementHandle elementHandle; private Language language; private ParserResult controller; + private Callable cancel; - private GsfCompletionDoc(final ParserResult controller, final ElementHandle elementHandle, URL url) { + private GsfCompletionDoc(final ParserResult controller, final ElementHandle elementHandle, URL url, Callable cancel) { this.controller = controller; this.language = LanguageRegistry.getInstance().getLanguageByMimeType(controller.getSnapshot().getMimeType()); + this.cancel = cancel; if (elementHandle != null && elementHandle.getMimeType() != null) { Language embeddedLanguage = LanguageRegistry.getInstance().getLanguageByMimeType(elementHandle.getMimeType()); if (embeddedLanguage != null && embeddedLanguage.getParser(Collections.singleton(controller.getSnapshot())) != null) { @@ -110,7 +113,7 @@ if (completer != null) { if (completer instanceof CodeCompletionHandler2) { - Documentation doc = ((CodeCompletionHandler2) completer).documentElement(controller, elementHandle); + Documentation doc = ((CodeCompletionHandler2) completer).documentElement(controller, elementHandle, cancel); if (doc != null) { this.content = doc.getContent(); if (docURL == null) { @@ -130,8 +133,8 @@ } public static final GsfCompletionDoc create(ParserResult controller, - ElementHandle elementHandle) { - return new GsfCompletionDoc(controller, elementHandle, null); + ElementHandle elementHandle, Callable cancel) { + return new GsfCompletionDoc(controller, elementHandle, null, cancel); } public String getText() { @@ -169,7 +172,7 @@ } } - return new GsfCompletionDoc(controller, handle, url); + return new GsfCompletionDoc(controller, handle, url, cancel); } return null; } diff --git a/csl.api/src/org/netbeans/modules/csl/editor/completion/GsfCompletionProvider.java b/csl.api/src/org/netbeans/modules/csl/editor/completion/GsfCompletionProvider.java --- a/csl.api/src/org/netbeans/modules/csl/editor/completion/GsfCompletionProvider.java +++ b/csl.api/src/org/netbeans/modules/csl/editor/completion/GsfCompletionProvider.java @@ -49,6 +49,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.prefs.PreferenceChangeEvent; import java.util.prefs.PreferenceChangeListener; @@ -538,7 +539,12 @@ private void resolveDocumentation(ParserResult controller) throws IOException { if (element != null) { - documentation = GsfCompletionDoc.create(controller, element); + documentation = GsfCompletionDoc.create(controller, element, new Callable(){ + @Override + public Boolean call() throws Exception { + return isTaskCancelled(); + } + }); } else { Env env = getCompletionEnvironment(controller, false); int offset = env.getOffset(); @@ -562,7 +568,12 @@ for (CompletionProposal proposal : result.getItems()) { ElementHandle el = proposal.getElement(); if (el != null) { - documentation = GsfCompletionDoc.create(controller, el); + documentation = GsfCompletionDoc.create(controller, el, new Callable(){ + @Override + public Boolean call() throws Exception { + return isTaskCancelled(); + } + }); // TODO - find some way to show the multiple overloaded methods? if (documentation.getText() != null && documentation.getText().length() > 0) { // Make sure we at least pick an alternative that has documentation diff --git a/csl.api/src/org/netbeans/modules/csl/editor/hyperlink/GoToSupport.java b/csl.api/src/org/netbeans/modules/csl/editor/hyperlink/GoToSupport.java --- a/csl.api/src/org/netbeans/modules/csl/editor/hyperlink/GoToSupport.java +++ b/csl.api/src/org/netbeans/modules/csl/editor/hyperlink/GoToSupport.java @@ -50,6 +50,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; @@ -180,7 +181,12 @@ if (element != null) { String documentationContent; if (completer instanceof CodeCompletionHandler2) { - Documentation documentation = ((CodeCompletionHandler2) completer).documentElement(info, element); + Documentation documentation = ((CodeCompletionHandler2) completer).documentElement(info, element, new Callable(){ + @Override + public Boolean call() throws Exception { + return cancel.get(); + } + }); if (documentation != null) { documentationContent = documentation.getContent(); } else { diff --git a/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java b/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java --- a/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java +++ b/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java @@ -3009,7 +3009,12 @@ String documentation; if (cc instanceof CodeCompletionHandler2) { CodeCompletionHandler2 cc2 = (CodeCompletionHandler2) cc; - Documentation docu = cc2.documentElement(pr, match.getElement()); + Documentation docu = cc2.documentElement(pr, match.getElement(), new Callable() { + @Override + public Boolean call() throws Exception { + return false; + } + }); documentation = docu == null ? cc2.document(pr, match.getElement()) : docu.getContent(); } else { documentation = cc.document(pr, match.getElement());