Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

197 lines (185 sloc) 9.503 kB
From 77ce677aa977413a9b138409358cf91a0f51bfb5 Thu, 26 May 2011 23:44:44 +0200
From: Laurent Petit <laurent.petit@gmail.com>
Date: Tue, 13 Jul 2010 15:31:11 +0200
Subject: [PATCH] WIP
diff --git a/ccw.core/src/ccw/debug/serverrepl.clj b/ccw.core/src/ccw/debug/serverrepl.clj
index d2ce121..af09db9 100644
--- a/ccw.core/src/ccw/debug/serverrepl.clj
+++ b/ccw.core/src/ccw/debug/serverrepl.clj
@@ -94,11 +94,26 @@
[prefix]
(filter #(splitted-match prefix (str %) ["\\."]) (all-ns)))
-(defn code-complete [ns-str prefix only-publics]
- (when-let [nss (matching-ns ns-str)]
+(def man nil)
+(defn- matching-aliased-ns
+ "seq of aliased namespaces which match the prefix
+ clojure.co matches clojure.core, ...
+ c.c also matches clojure.core, ..."
+ [cur-ns-str prefix]
+ (let [al-map (ns-aliases (the-ns (symbol cur-ns-str)))]
+ (map
+ (fn [[al-name al-ns]] al-ns)
+ (filter
+ (fn [[al-name al-ns]] (splitted-match prefix (str al-name) ["\\."]))
+ al-map))))
+
+(defn code-complete [cur-ns-str ns-str prefix only-publics]
+ (when-let [nss (clojure.set/union
+ (set (matching-ns ns-str))
+ (when (seq ns-str)
+ (set (matching-aliased-ns cur-ns-str prefix))))]
(let [search-fn (if only-publics ns-publics ns-map)
- ns-symbols (fn [ns] (search-fn ns))
- symbols (mapcat ns-symbols nss)]
+ symbols (mapcat search-fn nss)]
(into [] (map (fn [[k v]] [k (str v) (if (var? v) (var-info v) nil)])
(filter #(or (.startsWith (first %) prefix)
(splitted-match prefix (first %) ["-"]))
@@ -126,4 +141,4 @@
(= "null" qualified-ns) ((symbol s) (ns-map (the-ns (symbol current-ns))))
a (ns-resolve a (symbol s))
:else (resolve (symbol qualified-ns s))))
- [:ns :name :line :file]))))
\ No newline at end of file
+ [:ns :name :line :file]))))
diff --git a/ccw.core/src/ccw/editors/antlrbased/ClojureProposalProcessor.java b/ccw.core/src/ccw/editors/antlrbased/ClojureProposalProcessor.java
index 37e6cb2..c36018d 100644
--- a/ccw.core/src/ccw/editors/antlrbased/ClojureProposalProcessor.java
+++ b/ccw.core/src/ccw/editors/antlrbased/ClojureProposalProcessor.java
@@ -73,6 +73,8 @@
public final boolean fullyQualified;
public final String nsPart;
public final String symbolPrefix;
+ public final String currentNamespace;
+
public PrefixInfo(final IClojureEditor editor, final String prefix, final int prefixOffset) {
this.prefix = prefix;
this.prefixOffset = prefixOffset;
@@ -86,6 +88,7 @@
symbolPrefix = prefix;
fullyQualified = false;
}
+ currentNamespace = editor.findDeclaringNamespace();
}
}
@@ -191,7 +194,7 @@
private List<ICompletionProposal> computeClojureFullyQualifiedSymbolsProposals(PrefixInfo prefixInfo) {
final List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
- final List<List> dynamicSymbols = dynamicComplete(prefixInfo.nsPart,
+ final List<List> dynamicSymbols = dynamicComplete(prefixInfo.currentNamespace, prefixInfo.nsPart,
prefixInfo.symbolPrefix, editor, prefixInfo.fullyQualified); //parse(doc.get());
// Add dynamic completion proposals
for (List l: dynamicSymbols) {
@@ -222,7 +225,7 @@
private List<ICompletionProposal> computeClojureSymbolsProposals(PrefixInfo prefixInfo) {
final List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
- final List<List> dynamicSymbols = dynamicComplete(prefixInfo.nsPart,
+ final List<List> dynamicSymbols = dynamicComplete(prefixInfo.currentNamespace, prefixInfo.nsPart,
prefixInfo.symbolPrefix, editor, prefixInfo.fullyQualified); //parse(doc.get());
// Add dynamic completion proposals
for (List l: dynamicSymbols) {
@@ -319,6 +322,7 @@
}
proposals.add(new MethodLazyCompletionProposal(
(IMethod) match.getElement(),
+ null,
methodPrefix,
prefixInfo.prefixOffset + 1, null,
editor));
@@ -362,6 +366,7 @@
public AbstractLazyCompletionProposal lazyCompletionProposal(PrefixInfo prefixInfo, IClojureEditor editor, SearchMatch match) {
return new MethodLazyCompletionProposal(
(IMethod) match.getElement(),
+ null,
prefixInfo.nsPart + "/" + prefixInfo.symbolPrefix,
prefixInfo.prefixOffset, editor.findDeclaringNamespace(),
editor);
@@ -377,6 +382,7 @@
public AbstractLazyCompletionProposal lazyCompletionProposal(PrefixInfo prefixInfo, IClojureEditor editor, SearchMatch match) {
return new ClassLazyCompletionProposal(
(IType) match.getElement(),
+ null,
prefixInfo.prefix,
prefixInfo.prefixOffset, editor.findDeclaringNamespace(),
editor);
@@ -392,6 +398,7 @@
public AbstractLazyCompletionProposal lazyCompletionProposal(PrefixInfo prefixInfo, IClojureEditor editor, SearchMatch match) {
return new PackageLazyCompletionProposal(
(IPackageFragment) match.getElement(),
+ null,
prefixInfo.prefix,
prefixInfo.prefixOffset, editor.findDeclaringNamespace(),
editor);
@@ -480,6 +487,7 @@
private final String prefix;
private final int prefixOffset;
private final String ns;
+ private final String currentNamespace;
private final IClojureEditor editor;
private String displayString;
private CompletionProposal completionProposal;
@@ -510,7 +518,7 @@
} else {
List<List> dynamicSymbols =
(ns!= null)
- ? dynamicComplete(ns, methodTypeName, editor, false)
+ ? dynamicComplete(currentNamespace, ns, methodTypeName, editor, false)
: null;
if (dynamicSymbols != null) {
@@ -555,7 +563,8 @@
return completionProposal;
}
- public AbstractLazyCompletionProposal(IMethod method, String methodPrefix, int methodPrefixOffset, String ns, IClojureEditor editor) {
+ public AbstractLazyCompletionProposal(IMethod method, String currentNamespace, String methodPrefix, int methodPrefixOffset, String ns, IClojureEditor editor) {
+ this.currentNamespace = currentNamespace;
this.method = method;
this.prefix = methodPrefix;
this.prefixOffset = methodPrefixOffset;
@@ -595,8 +604,8 @@
}
private static class MethodLazyCompletionProposal extends AbstractLazyCompletionProposal {
- public MethodLazyCompletionProposal(IMethod method, String methodPrefix, int methodPrefixOffset, String ns, IClojureEditor editor) {
- super(method, methodPrefix, methodPrefixOffset, ns, editor);
+ public MethodLazyCompletionProposal(IMethod method, String currentNamespace, String methodPrefix, int methodPrefixOffset, String ns, IClojureEditor editor) {
+ super(method, currentNamespace, methodPrefix, methodPrefixOffset, ns, editor);
}
public Image getImage() {
return CCWPlugin.getDefault().getImageRegistry().get(CCWPlugin.PUBLIC_FUNCTION);
@@ -649,8 +658,8 @@
return completionProposal;
}
- public ClassLazyCompletionProposal(IType method, String methodPrefix, int methodPrefixOffset, String ns, IClojureEditor editor) {
- super(null, methodPrefix, methodPrefixOffset, ns, editor); // TODO vraiment nulle comme technique !
+ public ClassLazyCompletionProposal(IType method, String currentNamespace, String methodPrefix, int methodPrefixOffset, String ns, IClojureEditor editor) {
+ super(null, currentNamespace, methodPrefix, methodPrefixOffset, ns, editor); // TODO vraiment nulle comme technique !
this.method = method;
this.prefix = methodPrefix;
this.prefixOffset = methodPrefixOffset;
@@ -698,8 +707,8 @@
return completionProposal;
}
- public PackageLazyCompletionProposal(IPackageFragment method, String methodPrefix, int methodPrefixOffset, String ns, IClojureEditor editor) {
- super(null, methodPrefix, methodPrefixOffset, ns, editor); // TODO vraiment nulle comme technique !
+ public PackageLazyCompletionProposal(IPackageFragment method, String currentNamespace, String methodPrefix, int methodPrefixOffset, String ns, IClojureEditor editor) {
+ super(null, currentNamespace, methodPrefix, methodPrefixOffset, ns, editor); // TODO vraiment nulle comme technique !
this.method = method;
this.prefix = methodPrefix;
this.prefixOffset = methodPrefixOffset;
@@ -725,7 +734,7 @@
}
return false;
}
- private static List<List> dynamicComplete(String namespace, String prefix, IClojureEditor editor, boolean findOnlyPublic) {
+ private static List<List> dynamicComplete(String currentNamespace, String namespace, String prefix, IClojureEditor editor, boolean findOnlyPublic) {
if (namespace == null) {
return Collections.emptyList();
}
@@ -737,7 +746,7 @@
if (repl == null) return Collections.emptyList();
Connection connection = repl.getToolingConnection();
- Response response = connection.send("(ccw.debug.serverrepl/code-complete \"" + namespace + "\" \"" + prefix + "\" " + (findOnlyPublic ? "true" : "false") + ")");
+ Response response = connection.send("(ccw.debug.serverrepl/code-complete \"" + currentNamespace + "\" \"" + namespace + "\" \"" + prefix + "\" " + (findOnlyPublic ? "true" : "false") + ")");
return (List<List>) extractSingleValue(response, Collections.emptyList());
}
private List<List> dynamicNamespaceComplete(String prefix) {
Jump to Line
Something went wrong with that request. Please try again.