8000 Consume codeLensProviders extension point. · rubensa/typescript.java@951d4c3 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 951d4c3

Browse files
committed
Consume codeLensProviders extension point.
1 parent c68454e commit 951d4c3

File tree

7 files changed

+243
-51
lines changed

7 files changed

+243
-51
lines changed

eclipse/codelens/org.eclipse.codelens/META-INF/MANIFEST.MF

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ Export-Package: org.eclipse.jface.text.provisional.codelens,
3535
org.eclipse.jface.text.source.patch,
3636
org.eclipse.swt.custom.patch,
3737
org.eclipse.swt.custom.provisional
38+
Bundle-Name: %pluginName
39+
Bundle-ActivationPolicy: lazy
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright (c) 2015-2016 Angelo ZERR.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
10+
* Lorenzo Dalla Vecchia <lorenzo.dallavecchia@webratio.com> - getter for ProblemManager
11+
*/
12+
package org.eclipse.codelens.internal;
13+
14+
import org.eclipse.core.runtime.CoreException;
15+
import org.eclipse.core.runtime.IStatus;
16+
import org.eclipse.core.runtime.Plugin;
17+
import org.eclipse.core.runtime.Status;
18+
import org.eclipse.jface.text.provisional.codelens.CodeLensProviderRegistry;
19+
import org.osgi.framework.BundleContext;
20+
21+
/**
22+
* The activator class controls the plug-in life cycle
23+
*/
24+
public class CodeLensPlugin extends Plugin {
25+
26+
public static final String PLUGIN_ID = "org.eclipse.codelens"; //$NON-NLS-1$
27+
28+
// The shared instance.
29+
private static CodeLensPlugin plugin;
30+
31+
/**
32+
* The constructor.
33+
*/
34+
public CodeLensPlugin() {
35+
super();
36+
plugin = this;
37+
}
38+
39+
@Override
40+
public void start(BundleContext context) throws Exception {
41+
super.start(context);
42+
CodeLensProviderRegistry.getInstance().initialize();
43+
}
44+
45+
@Override
46+
public void stop(BundleContext context) throws Exception {
47+
CodeLensProviderRegistry.getInstance().initialize();
48+
plugin = null;
49+
super.stop(context);
50+
}
51+
52+
/**
53+
* Returns the shared instance
54+
*
55+
* @return the shared instance
56+
*/
57+
public static CodeLensPlugin getDefault() {
58+
return plugin;
59+
}
60+
61+
public static void log(IStatus status) {
62+
CodeLensPlugin plugin = getDefault();
63+
if (plugin != null) {
64+
plugin.getLog().log(status);
65+
} else {
66+
System.err.println(status.getPlugin() + ": " + status.getMessage()); //$NON-NLS-1$
67+
}
68+
}
69+
70+
public static void log(Throwable e) {
71+
if (e instanceof CoreException) {
72+
log(new Status(IStatus.ERROR, PLUGIN_ID, ((CoreException) e).getStatus().getSeverity(), e.getMessage(),
73+
e.getCause()));
74+
} else {
75+
log(new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e));
76+
}
77+
}
78+
}

eclipse/codelens/org.eclipse.codelens/src/org/eclipse/jface/text/provisional/codelens/CodeLensProviderRegistry.java

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,29 @@
55
import java.util.List;
66
import java.util.Map;
77

8-
public class CodeLensProviderRegistry {
8+
import org.eclipse.codelens.internal.CodeLensPlugin;
9+
import org.eclipse.core.runtime.IConfigurationElement;
10+
import org.eclipse.core.runtime.IExtensionDelta;
11+
import org.eclipse.core.runtime.IExtensionRegistry;
12+
import org.eclipse.core.runtime.IRegistryChangeEvent;
13+
import org.eclipse.core.runtime.IRegistryChangeListener;
14+
import org.eclipse.core.runtime.Platform;
15+
16+
public class CodeLensProviderRegistry implements IRegistryChangeListener {
917

1018
private static final CodeLensProviderRegistry INSTANCE = new CodeLensProviderRegistry();
19+
private static final String EXTENSION_CODELENS_PROVIDERS = "codeLensProviders";
1120

1221
public static CodeLensProviderRegistry getInstance() {
1322
return INSTANCE;
1423
}
1524

25+
private boolean codeLensProviderLoaded;
1626
private final Map<String, List<ICodeLensProvider>> providersMap;
1727

1828
public CodeLensProviderRegistry() {
1929
this.providersMap = new HashMap<>();
30+
this.codeLensProviderLoaded = false;
2031
}
2132

2233
public void register(String target, ICodeLensProvider provider) {
@@ -29,7 +40,96 @@ public void register(String target, ICodeLensProvider provider) {
2940
}
3041

3142
public List<ICodeLensProvider> all(String target) {
43+
loadCodeLensProvidersIfNeeded();
3244
return providersMap.get(target);
3345
}
3446

47+
@Override
48+
public void registryChanged(IRegistryChangeEvent event) {
49+
IExtensionDelta[] deltas = event.getExtensionDeltas(CodeLensPlugin.PLUGIN_ID, EXTENSION_CODELENS_PROVIDERS);
50+
if (deltas != null) {
51+
for (IExtensionDelta delta : deltas)
52+
handleCodeLensProvidersDelta(delta);
53+
}
54+
}
55+
56+
private void loadCodeLensProvidersIfNeeded() {
57+
if (codeLensProviderLoaded) {
58+
return;
59+
}
60+
loadCodeLensProviders();
61+
}
62+
63+
/**
64+
* Load the SourceMap language supports.
65+
*/
66+
private synchronized void loadCodeLensProviders() {
67+
if (codeLensProviderLoaded) {
68+
return;
69+
}
70+
71+
try {
72+
IExtensionRegistry registry = Platform.getExtensionRegistry();
73+
if (registry == null) {
74+
return;
75+
}
76+
IConfigurationElement[] cf = registry.getConfigurationElementsFor(CodeLensPlugin.PLUGIN_ID,
77+
EXTENSION_CODELENS_PROVIDERS);
78+
loadCodeLensProvidersFromExtension(cf);
79+
} finally {
80+
codeLensProviderLoaded = true;
81+
}
82+
}
83+
84+
/**
85+
* Add the SourceMap language supports.
86+
*/
87+
private synchronized void loadCodeLensProvidersFromExtension(IConfigurationElement[] cf) {
88+
for (IConfigurationElement ce : cf) {
89+
try {
90+
String target = ce.getAttribute("target");
91+
ICodeLensProvider provider = (ICodeLensProvider) ce.createExecutableExtension("class");
92+
register(target, provider);
93+
} catch (Throwable e) {
94+
CodeLensPlugin.log(e);
95+
}
96+
}
97+
}
98+
99+
protected void handleCodeLensProvidersDelta(IExtensionDelta delta) {
100+
if (!codeLensProviderLoaded) // not loaded yet
101+
return;
102+
103+
IConfigurationElement[] cf = delta.getExtension().getConfigurationElements();
104+
105+
// List<CodeLensProviderType> list = new
106+
// ArrayList<CodeLensProviderType>(
107+
// codeLensProviders);
108+
// if (delta.getKind() == IExtensionDelta.ADDED) {
109+
// loadCodeLensProvidersFromExtension(cf, list);
110+
// } else {
111+
// int size = list.size();
112+
// CodeLensProviderType[] st = new CodeLensProviderType[size];
113+
// list.toArray(st);
114+
// int size2 = cf.length;
115+
//
116+
// for (int i = 0; i < size; i++) {
117+
// for (int j = 0; j < size2; j++) {
118+
// if (st[i].getId().equals(cf[j].getAttribute("id"))) {
119+
// list.remove(st[i]);
120+
// }
121+
// }
122+
// }
123+
// }
124+
// codeLensProviders = list;
125+
}
126+
127+
public void initialize() {
128+
IExtensionRegistry registry = Platform.getExtensionRegistry();
129+
registry.addRegistryChangeListener(this, CodeLensPlugin.PLUGIN_ID);
130+
}
131+
132+
public void destroy() {
133+
Platform.getExtensionRegistry().removeRegistryChangeListener(this);
134+
}
35135
}

eclipse/codelens/org.eclipse.codelens/src/org/eclipse/jface/text/provisional/viewzones/ViewZoneChangeAccessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private class ViewZoneMouseListener implements MouseListener, MouseTrackListener
3939

4040
@Override
4141
public void mouseUp(MouseEvent arg0) {
42-
System.err.println("mouseUp");
42+
//System.err.println("mouseUp");
4343
if (hoveredZone != null) {
4444

4545
}
@@ -54,7 +54,7 @@ public void mouseDown(MouseEvent event) {
5454

5555
@Override
5656
public void mouseDoubleClick(MouseEvent arg0) {
57-
System.err.println("mouseDoubleClick");
57+
// System.err.println("mouseDoubleClick");
5858

5959
}
6060

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/editor/TypeScriptEditor.java

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
import org.eclipse.jface.text.TabsToSpacesConverter;
5050
import org.eclipse.jface.text.contentassist.IContentAssistant;
5151
import org.eclipse.jface.text.link.LinkedModeModel;
52-
import org.eclipse.jface.text.provisional.codelens.CodeLensStrategy;
53-
import org.eclipse.jface.text.provisional.codelens.CodeLensProviderRegistry;
5452
import org.eclipse.jface.text.source.Annotation;
5553
import org.eclipse.jface.text.source.IAnnotationModel;
5654
import org.eclipse.jface.text.source.IAnnotationModelExtension;
@@ -102,14 +100,11 @@
102100
import ts.eclipse.ide.jsdt.internal.ui.actions.IndentAction;
103101
import ts.eclipse.ide.jsdt.internal.ui.actions.RefactorActionGroup;
104102
import ts.eclipse.ide.jsdt.internal.ui.actions.TypeScriptSearchActionGroup;
105-
import ts.eclipse.ide.jsdt.internal.ui.editor.codelens.TypeScriptImplementationsCodeLensProvider;
106-
import ts.eclipse.ide.jsdt.internal.ui.editor.codelens.TypeScriptReferencesCodeLensProvider;
107103
import ts.eclipse.ide.jsdt.ui.IContextMenuConstants;
108104
import ts.eclipse.ide.jsdt.ui.actions.ITypeScriptEditorActionDefinitionIds;
109105
import ts.eclipse.ide.ui.TypeScriptUIPlugin;
110106
import ts.eclipse.ide.ui.outline.IEditorOutlineFeatures;
111107
import ts.eclipse.ide.ui.outline.TypeScriptContentOutlinePage;
112-
import ts.eclipse.ide.ui.preferences.TypeScriptUIPreferenceConstants;
113108
import ts.eclipse.ide.ui.utils.EditorUtils;
114109
import ts.resources.ITypeScriptFile;
115110

@@ -119,14 +114,6 @@
119114
*/
120115
public class TypeScriptEditor extends JavaScriptLightWeightEditor implements IEditorOutlineFeatures {
121116

122-
public static String CODELENS_TARGET = "typeScript.codeLens";
123-
124-
static {
125-
CodeLensProviderRegistry registry = CodeLensProviderRegistry.getInstance();
126-
registry.register(CODELENS_TARGET, new TypeScriptReferencesCodeLensProvider());
127-
registry.register(CODELENS_TARGET, new TypeScriptImplementationsCodeLensProvider());
128-
}
129-
130117
private static final boolean CODE_ASSIST_DEBUG = "true" //$NON-NLS-1$
131118
.equalsIgnoreCase(Platform.getDebugOption("ts.eclipse.ide.jsdt.ui/debug/ResultCollector")); //$NON-NLS-1$
132119

@@ -298,7 +285,7 @@ public void selectionChanged(SelectionChangedEvent event) {
298285
private TypeScriptContentOutlinePage contentOutlinePage;
299286

300287
private final ProblemTickUpdater problemTickUpdater;
301-
//private CodeLensContribution contribution;
288+
// private CodeLensContribution contribution;
302289

303290
public TypeScriptEditor() {
304291
super();
@@ -432,9 +419,9 @@ public void dispose() {
432419
fActivationListener = null;
433420
}
434421

435-
// if (contribution != null) {
436-
// contribution.dispose();
437-
// }
422+
// if (contribution != null) {
423+
// contribution.dispose();
424+
// }
438425
}
439426

440427
void updateTitleImage(Image titleImage) {
@@ -459,30 +446,31 @@ public void createPartControl(Composite parent) {
459446
editorSelectionChangedListener = new EditorSelectionChangedListener();
460447
editorSelectionChangedListener.install(getSelectionProvider());
461448

462-
// if (isActivateCodeLenses()) {
463-
// installCodeLenses();
464-
// }
449+
// if (isActivateCodeLenses()) {
450+
// installCodeLenses();
451+
// }
465452
}
466453

467-
// protected boolean isActivateCodeLenses() {
468-
// IPreferenceStore store = getPreferenceStore();
469-
// return store != null && store.getBoolean(TypeScriptUIPreferenceConstants.EDITOR_ACTIVATE_CODELENS);
470-
// }
471-
472-
// private void installCodeLenses() {
473-
// try {
474-
// ITextViewer textViewer = getSourceViewer();
475-
// contribution = new CodeLensContribution(textViewer);
476-
// contribution.addTarget(CODELENS_TARGET);
477-
// //contribution.start();
478-
// } catch (Exception e) {
479-
// e.printStackTrace();
480-
// }
481-
// }
482-
//
483-
// public CodeLensContribution getCodeLensContribution() {
484-
// return contribution;
485-
// };
454+
// protected boolean isActivateCodeLenses() {
455+
// IPreferenceStore store = getPreferenceStore();
456+
// return store != null &&
457+
// store.getBoolean(TypeScriptUIPreferenceConstants.EDITOR_ACTIVATE_CODELENS);
458+
// }
459+
460+
// private void installCodeLenses() {
461+
// try {
462+
// ITextViewer textViewer = getSourceViewer();
463+
// contribution = new CodeLensContribution(textViewer);
464+
// contribution.addTarget(CODELENS_TARGET);
465+
// //contribution.start();
466+
// } catch (Exception e) {
467+
// e.printStackTrace();
468+
// }
469+
// }
470+
//
471+
// public CodeLensContribution getCodeLensContribution() {
472+
// return contribution;
473+
// };
486474

487475
/*
488476
* @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) 2015-2016 Angelo ZERR.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
10+
*/
11+
package ts.eclipse.ide.jsdt.internal.ui.editor.codelens;
12+
13+
import org.eclipse.jface.text.ITextViewer;
14+
import org.eclipse.jface.text.provisional.codelens.CodeLensStrategy;
15+
16+
/**
17+
* TypeScript CodeLens strategy.
18+
*
19+
*/
20+
public class TypeScriptCodeLensStrategy extends CodeLensStrategy {
21+
22+
private static String CODELENS_TARGET = "typeScript.codeLens";
23+
24+
public TypeScriptCodeLensStrategy(ITextViewer textViewer) {
25+
super(textViewer);
26+
super.addTarget(CODELENS_TARGET);
27+
}
28+
29+
}

0 commit comments

Comments
 (0)
0