forked from ccw-ide/ccw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWIP-code-completion.patch
More file actions
196 lines (185 loc) · 9.28 KB
/
Copy pathWIP-code-completion.patch
File metadata and controls
196 lines (185 loc) · 9.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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) {