8000 Move TypeScript CodeLens to UI plugin. · rubensa/typescript.java@39e56ba · GitHub
[go: up one dir, main page]

Skip to content

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 39e56ba

Browse files
committed
Move TypeScript CodeLens to UI plugin.
1 parent 2982ba9 commit 39e56ba

File tree

14 files changed

+152
-111
lines changed

14 files changed

+152
-111
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ private CompletableFuture<Collection<CodeLensData>> getCodeLensData(ITextViewer
7373
if (providers != null) {
7474
for (ICodeLensProvider provider : providers) {
7575
ICodeLens[] lenses = provider.provideCodeLenses(textViewer);
76-
for (int i = 0; i < lenses.length; i++) {
77-
symbols.add(new CodeLensData(lenses[i], provider));
76+
if (lenses != null) {
77+
for (int i = 0; i < lenses.length; i++) {
78+
symbols.add(new CodeLensData(lenses[i], provider));
79+
}
7880
}
7981
}
8082
Collections.sort(symbols, (a, b) -> {

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/plugin.properties

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ providerName=Angelo ZERR
1313

1414
TypeScriptCompletionProposalCategory.name=TypeScript Proposals
1515
TypeScriptHyperLinkDetector=TypeScript Element
16+
HTMLTypeScriptHyperLinkDetector=TypeScript Element inside HTML
1617

1718
# Editor
1819
JavaScriptEditor.name=JavaScript (Salsa) Editor
@@ -123,8 +124,4 @@ templates.jsdoc.contextType.name=JSDoc
123124
templates.react.contextType.name=ReactJS
124125

125126
# textMate snippets
126-
textmate.snippet.jsx=JSX Snippet
127-
128-
# CodeLens Providers
129-
TypeScriptReferencesCodeLensProvider.name=TypeScript References
130-
TypeScriptImplementationsCodeLensProvider.name=TypeScript Implementations
127+
textmate.snippet.jsx=JSX Snippet

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/plugin.xml

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,12 @@
142142
targetId="org.eclipse.wst.jsdt.ui.javaCode">
143143
</hyperlinkDetector>
144144
<hyperlinkDetector
145-
class="ts.eclipse.ide.ui.hyperlink.TypeScriptHyperLinkDetector"
146-
id="ts.eclipse.ide.ui.hyperlink.htTypeScriptHyperLml.inkDetector"
147-
name="%HTMLAngularHyperLinkDetector.name"
148-
targetId="org.eclipse.wst.html.core.htmlsource">
149-
</hyperlinkDetector>
145+
class="ts.eclipse.ide.ui.hyperlink.TypeScriptHyperLinkDetector"
146+
id="ts.eclipse.ide.ui.hyperlink.HTMLTypeScriptHyperLinkDetector"
147+
name="%HTMLTypeScriptHyperLinkDetector"
148+
activate="true"
149+
targetId="org.eclipse.wst.html.core.htmlsource">
150+
</hyperlinkDetector>
150151
</extension>
151152

152153
<!-- Text Hover for JavaScript (inside JavaScript file) -->
@@ -764,27 +765,5 @@
764765
scopeName="source.js">
765766
</snippet>
766767
</extension>
767-
768-
<!-- TypeScript CodeLens providers -->
769-
770-
<!-- TypeScript "references" CodeLens -->
771-
<extension
772-
point="org.eclipse.codelens.codeLensProviders">
773-
<codeLensProvider
774-
name="%TypeScriptReferencesCodeLensProvider.name"
775-
class="ts.eclipse.ide.jsdt.internal.ui.editor.codelens.TypeScriptReferencesCodeLensProvider"
776-
target="typeScript.codeLens">
777-
</codeLensProvider>
778-
</extension>
779-
780-
<!-- TypeScript "implementations" CodeLens -->
781-
<extension
782-
point="org.eclipse.codelens.codeLensProviders">
783-
<codeLensProvider
784-
name="%TypeScriptImplementationsCodeLensProvider.name"
785-
class="ts.eclipse.ide.jsdt.internal.ui.editor.codelens.TypeScriptImplementationsCodeLensProvider"
786-
target="typeScript.codeLens">
787-
</codeLensProvider>
788-
</extension>
789768

790769
</plugin>

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/editor/codelens/ReferencesCodeLens.java

Lines changed: 0 additions & 62 deletions
This file was deleted.

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/validation/TypeScriptDocumentRegionProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import ts.eclipse.ide.core.utils.TypeScriptResourceUtil;
2828
import ts.eclipse.ide.jsdt.core.JSDTTypeScriptCorePlugin;
2929
import ts.eclipse.ide.jsdt.internal.ui.editor.TypeScriptFoldingStrategy;
30-
import ts.eclipse.ide.jsdt.internal.ui.editor.codelens.TypeScriptCodeLensStrategy;
3130
import ts.eclipse.ide.ui.TypeScriptUIPlugin;
31+
import ts.eclipse.ide.ui.codelens.TypeScriptCodeLensStrategy;
3232
import ts.eclipse.ide.ui.folding.IndentFoldingStrategy;
3333
import ts.eclipse.ide.ui.preferences.TypeScriptUIPreferenceConstants;
3434
import ts.utils.FileUtils;

eclipse/ts.eclipse.ide.ui/META-INF/MANIFEST.MF

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ Require-Bundle: org.eclipse.ui,
3232
com.google.gson,
3333
ts.eclipse.ide.terminal.interpreter,
3434
org.eclipse.tm.terminal.view.core,
35-
org.eclipse.tm.terminal.view.ui
35+
org.eclipse.tm.terminal.view.ui,
36+
org.eclipse.codelens
3637
Bundle-ActivationPolicy: lazy
3738
Bundle-Activator: ts.eclipse.ide.ui.TypeScriptUIPlugin
3839
Import-Package: com.eclipsesource.json;version="[0.9.4,0.9.5)"
3940
Export-Package: ts.eclipse.ide.ui,
41+
ts.eclipse.ide.ui.codelens,
4042
ts.eclipse.ide.ui.console,
4143
ts.eclipse.ide.ui.folding,
4244
ts.eclipse.ide.ui.hover,

eclipse/ts.eclipse.ide.ui/plugin.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ typeScriptHoverDescription= TypeScript Hover
2020
TypeScriptOutlineView.name=TypeScript
2121
testNavigatorContent_name=TypeScript content
2222

23+
# TypeScript CodeLens Providers
24+
TypeScriptReferencesCodeLensProvider.name=TypeScript References
25+
TypeScriptImplementationsCodeLensProvider.name=TypeScript Implementations
26+
2327
# Preferences
2428
TypeScriptMainPreferencePage.name=TypeScript
2529
TypeScriptMainPropertyPage.name=TypeScript

eclipse/ts.eclipse.ide.ui/plugin.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,4 +607,27 @@
607607
<description>%NewClassWizard.desc</description>
608608
</wizard>
609609
</extension>
610+
611+
<!-- TypeScript CodeLens providers -->
612+
613+
<!-- TypeScript "references" CodeLens -->
614+
<extension
615+
point="org.eclipse.codelens.codeLensProviders">
616+
<codeLensProvider
617+
name="%TypeScriptReferencesCodeLensProvider.name"
618+
class="ts.eclipse.ide.internal.ui.codelens.TypeScriptReferencesCodeLensProvider"
619+
target="typeScript.codeLens">
620+
</codeLensProvider>
621+
</extension>
622+
623+
<!-- TypeScript "implementations" CodeLens -->
624+
<extension
625+
point="org.eclipse.codelens.codeLensProviders">
626+
<codeLensProvider
627+
name="%TypeScriptImplementationsCodeLensProvider.name"
628+
class="ts.eclipse.ide.internal.ui.codelens.TypeScriptImplementationsCodeLensProvider"
629+
target="typeScript.codeLens">
630+
</codeLensProvider>
631+
</extension>
632+
610633
</plugin>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package ts.eclipse.ide.internal.ui.codelens;
2+
3+
import org.eclipse.jface.text.ITextSelection;
4+
import org.eclipse.jface.text.TextSelection;
5+
import org.eclipse.jface.text.provisional.codelens.CodeLens;
6+
import org.eclipse.jface.text.provisional.codelens.Range;
7+
import org.eclipse.swt.SWT;
8+
import org.eclipse.swt.widgets.Display;
9+
import org.eclipse.swt.widgets.Shell;
10+
11+
import ts.TypeScriptException;
12+
import ts.eclipse.ide.core.resources.IIDETypeScriptFile;
13+
import ts.eclipse.ide.ui.implementation.TypeScriptImplementationDialog;
14+
15+
public class ImplementationsCodeLens extends CodeLens {
16+
private final IIDETypeScriptFile tsFile;
17+
18+
public ImplementationsCodeLens(IIDETypeScriptFile tsFile, Range range) {
19+
super(range);
20+
this.tsFile = tsFile;
21+
}
22+
23+
public IIDETypeScriptFile getTsFile() {
24+
return tsFile;
25+
}
26+
27+
@Override
28+
public void open() {
29+
// Open Implementation dialog
30+
Display.getDefault().asyncExec(() -> {
31+
try {
32+
Shell parent = Display.getDefault().getActiveShell();
33+
TypeScriptImplementationDialog dialog = new TypeScriptImplementationDialog(parent, SWT.RESIZE, tsFile);
34+
int offset = tsFile.getPosition(getRange().startLineNumber, getRange().startColumn);
35+
ITextSelection selection = new TextSelection(offset, 1);
36+
dialog.setSize(450, 500);
37+
dialog.setInput(selection);
38+
dialog.open();
39+
} catch (TypeScriptException e) {
40+
e.printStackTrace();
41+
}
42+
});
43+
}
44+
45+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package ts.eclipse.ide.internal.ui.codelens;
2+
3+
import org.eclipse.jface.text.provisional.codelens.CodeLens;
4+
import org.eclipse.jface.text.provisional.codelens.Range;
5+
import org.eclipse.search.ui.NewSearchUI;
6+
7+
import ts.TypeScriptException;
8+
import ts.eclipse.ide.core.resources.IIDETypeScriptFile;
9+
import ts.eclipse.ide.ui.search.TypeScriptSearchQuery;
10+
11+
public class ReferencesCodeLens extends CodeLens {
12+
private final IIDETypeScriptFile tsFile;
13+
14+
public ReferencesCodeLens(IIDETypeScriptFile tsFile, Range range) {
15+
super(range);
16+
this.tsFile = tsFile;
17+
}
18+
19+
public IIDETypeScriptFile getTsFile() {
20+
return tsFile;
21+
}
22+
23+
@Override
24+
public void open() {
25+
// Execute Search
26+
try {
27+
int offset = tsFile.getPosition(getRange().startLineNumber, getRange().startColumn);
28+
TypeScriptSearchQuery query = new TypeScriptSearchQuery(tsFile.getResource(), offset);
29+
NewSearchUI.runQueryInBackground(query);
30+
} catch (TypeScriptException e) {
31+
e.printStackTrace();
32+
}
33+
}
34+
35+
}
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package ts.eclipse.ide.jsdt.internal.ui.editor.codelens;
1+
package ts.eclipse.ide.internal.ui.codelens;
22

33
import java.text.MessageFormat;
44
import java.util.List;
55
import java.util.concurrent.TimeUnit;
6+
import java.util.stream.Collectors;
67

78
import org.eclipse.jface.text.ITextViewer;
89
import org.eclipse.jface.text.provisional.codelens.Command;
@@ -13,12 +14,13 @@
1314
import ts.client.FileSpan;
1415
import ts.client.navbar.NavigationBarItem;
1516
import ts.eclipse.ide.core.resources.IIDETypeScriptFile;
17+
import ts.eclipse.ide.ui.codelens.TypeScriptBaseCodeLensProvider;
1618

1719
public class TypeScriptImplementationsCodeLensProvider extends TypeScriptBaseCodeLensProvider {
1820

1921
@Override
2022
public ICodeLens resolveCodeLens(ITextViewer textViewer, ICodeLens cl) {
21-
ReferencesCodeLens codeLens = (ReferencesCodeLens) cl;
23+
ImplementationsCodeLens codeLens = (ImplementationsCodeLens) cl;
2224
// const codeLens = inputCodeLens as ReferencesCodeLens;
2325
// const args: Proto.FileLocationRequestArgs = {
2426
// file: codeLens.file,
@@ -33,9 +35,10 @@ public ICodeLens resolveCodeLens(ITextViewer textViewer, ICodeLens cl) {
3335
if (refCount == 1) {
3436
codeLens.setCommand(new Command("1 implementation", "implementation"));
3537
} else {
36-
codeLens.setCommand(new Command(MessageFormat.format("{0} implementations", refCount), "implementation"));
38+
codeLens.setCommand(
39+
new Command(MessageFormat.format("{0} implementations", refCount), "implementation"));
3740
}
38-
41+
3942
// (response -> {
4043
// response.getRefs().stream().map(reference -> {
4144
// return null;
@@ -49,7 +52,7 @@ public ICodeLens resolveCodeLens(ITextViewer textViewer, ICodeLens cl) {
4952
// }
5053
// });
5154
} catch (Exception e) {
52-
codeLens.setCommand(new Command("Could not determine references", null));
55+
codeLens.setCommand(new Command("Could not determine implementations", null));
5356
}
5457
return codeLens;
5558
}
@@ -74,7 +77,12 @@ protected Range extractSymbol(IIDETypeScriptFile document, NavigationBarItem ite
7477
}
7578
}
7679
return null;
80+
}
7781

82+
@Override
83+
protected ICodeLens[] toCodeLenses(List<Range> referenceableSpans, IIDETypeScriptFile tsFile) {
84+
return referenceableSpans.stream().map(span -> new ImplementationsCodeLens(tsFile, span))
85+
.collect(Collectors.toList()).toArray(new ICodeLens[0]);
7886
}
7987

8088
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package ts.eclipse.ide.jsdt.internal.ui.editor.codelens;
1+
package ts.eclipse.ide.internal.ui.codelens;
22

33
import java.text.MessageFormat;
44
import java.util.List;
55
import java.util.concurrent.TimeUnit;
6+
import java.util.stream.Collectors;
67

78
import org.eclipse.jface.text.ITextViewer;
89
import org.eclipse.jface.text.provisional.codelens.Command;
@@ -13,6 +14,7 @@
1314
import ts.client.navbar.NavigationBarItem;
1415
import ts.client.references.ReferencesResponseItem;
1516
import ts.eclipse.ide.core.resources.IIDETypeScriptFile;
17+
import ts.eclipse.ide.ui.codelens.TypeScriptBaseCodeLensProvider;
1618

1719
public class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvider {
1820

@@ -128,4 +130,10 @@ protected Range extractSymbol(IIDETypeScriptFile document, NavigationBarItem ite
128130

129131
}
130132

133+
@Override
134+
protected ICodeLens[] toCodeLenses(List<Range> referenceableSpans, IIDETypeScriptFile tsFile) {
135+
return referenceableSpans.stream().map(span -> new ReferencesCodeLens(tsFile, span))
136+
.collect(Collectors.toList()).toArray(new ICodeLens[0]);
137+
}
138+
131139
}

0 commit comments

Comments
 (0)
0