Skip to content

Commit 6d83d1d

Browse files
committed
Open Implementation popup when click on "implementations" CodeLens. See
#181
1 parent 5b5dca0 commit 6d83d1d

File tree

3 files changed

+54
-22
lines changed

3 files changed

+54
-22
lines changed

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

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
package ts.eclipse.ide.jsdt.internal.ui.editor.codelens;
22

3+
import org.eclipse.jface.text.ITextSelection;
4+
import org.eclipse.jface.text.ITextViewer;
5+
import org.eclipse.jface.text.TextSelection;
36
import org.eclipse.jface.text.provisional.codelens.CodeLens;
47
import org.eclipse.jface.text.provisional.codelens.Range;
8+
import org.eclipse.swt.SWT;
9+
import org.eclipse.swt.widgets.Display;
10+
import org.eclipse.swt.widgets.Shell;
511
import org.eclipse.wst.jsdt.internal.ui.search.SearchUtil;
612

713
import ts.TypeScriptException;
814
import ts.eclipse.ide.core.resources.IIDETypeScriptFile;
15+
import ts.eclipse.ide.ui.implementation.TypeScriptImplementationDialog;
916
import ts.eclipse.ide.ui.search.TypeScriptSearchQuery;
1017

1118
public class ReferencesCodeLens extends CodeLens {
12-
1319
private final IIDETypeScriptFile tsFile;
1420

1521
public ReferencesCodeLens(IIDETypeScriptFile tsFile, Range range) {
@@ -23,7 +29,9 @@ public IIDETypeScriptFile getTsFile() {
2329

2430
@Override
2531
public void open() {
26-
if (getCommand().getCommand().equals("references")) {
32+
String command = getCommand().getCommand();
33+
if (command.equals("references")) {
34+
// Execute Search
2735
try {
2836
int offset = tsFile.getPosition(getRange().startLineNumber, getRange().startColumn);
2937
TypeScriptSearchQuery query = new TypeScriptSearchQuery(tsFile.getResource(), offset);
@@ -32,6 +40,21 @@ public void open() {
3240
e.printStackTrace();
3341
}
3442
} else {
43+
// Open Implementation dialog
44+
Display.getDefault().asyncExec(() -> {
45+
try {
46+
Shell parent = Display.getDefault().getActiveShell();
47+
TypeScriptImplementationDialog dialog = new TypeScriptImplementationDialog(parent, SWT.RESIZE,
48+
tsFile);
49+
int offset = tsFile.getPosition(getRange().startLineNumber, getRange().startColumn);
50+
ITextSelection selection = new TextSelection(offset, 1);
51+
dialog.setSize(450, 500);
52+
dialog.setInput(selection);
53+
dialog.open();
54+
} catch (TypeScriptException e) {
55+
e.printStackTrace();
56+
}
57+
});
3558

3659
}
3760
}

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

+25-20
Original file line numberDiff line numberDiff line change
@@ -83,46 +83,51 @@ protected Range getSymbolRange(IIDETypeScriptFile tsFile, NavigationBarItem item
8383

8484
Range range = new Range(span.getStart().getLine(), span.getStart().getOffset());
8585

86-
8786
// Range range = new Range(
8887
// span.getStart().getLine() - 1, span.getStart().getOffset() - 1,
8988
// span.getEnd().getLine() - 1, span.getEnd().getOffset()- 1);
9089

91-
9290
try {
9391
IDocument document = tsFile.getDocument();
9492
int offset = tsFile.getPosition(span.getStart());
9593
int endOffset = tsFile.getPosition(span.getEnd());
9694
String text = document.get(offset, span.getLength());
97-
98-
String regex = "^(.*?(\\b|\\W))" + (item.getText() != null ? item.getText() : "").replaceAll("[-[\\\\]{}()*+?.,\\\\^$|#\\s]", "\\\\$&") + "(\\b|\\W)";
95+
96+
String regex = "^(.*?(\\b|\\W))" + (item.getText() != null ? item.getText() : "")
97+
.replaceAll("[-[\\\\]{}()*+?.,\\\\^$|#\\s]", "\\\\$&") + "(\\b|\\W)";
9998
Matcher identifierMatch = Pattern.compile(regex, Pattern.MULTILINE).matcher(text);
10099
int prefixLength = identifierMatch.find() ? identifierMatch.start() + identifierMatch.end() : 0;
101-
100+
102101
int position = offset + prefixLength;
103-
102+
104103
Location location = tsFile.getLocation(position);
105104
int newLine = location.getLine();
106105
int newOffset = location.getOffset();
107-
106+
108107
return new Range(newLine, newOffset);
109-
// return new Range(
110-
// document.positionAt(startOffset),
111-
// document.positionAt(startOffset + item.text.length));
112-
113-
// new RegExp(`^(.*?(\\b|\\W))${(item.text || '').replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')}(\\b|\\W)`, 'gm');
114-
//
115-
// const identifierMatch = Pattern.compile(".*?(\\b|\\W))${(item.text || '').replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')}(\\b|\\W)`, 'gm');
116-
// const match = identifierMatch.exec(text);
117-
// const prefixLength = match ? match.index + match[1].length : 0;
118-
119-
//const identifierMatch = new RegExp(`^(.*?(\\b|\\W))${(item.text || * '').replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')}(\\b|\\W)`, 'gm');
108+
// return new Range(
109+
// document.positionAt(startOffset),
110+
// document.positionAt(startOffset + item.text.length));
111+
112+
// new RegExp(`^(.*?(\\b|\\W))${(item.text ||
113+
// '').replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')}(\\b|\\W)`,
114+
// 'gm');
115+
//
116+
// const identifierMatch =
117+
// Pattern.compile(".*?(\\b|\\W))${(item.text ||
118+
// '').replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')}(\\b|\\W)`,
119+
// 'gm');
120+
// const match = identifierMatch.exec(text);
121+
// const prefixLength = match ? match.index + match[1].length : 0;
122+
123+
// const identifierMatch = new RegExp(`^(.*?(\\b|\\W))${(item.text
124+
// || * '').replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')}(\\b|\\W)`,
125+
// 'gm');
120126
} catch (Exception e) {
121127
// TODO Auto-generated catch block
122128
e.printStackTrace();
123129
}
124-
125-
130+
126131
/*
127132
* const text = document.getText(range);
128133
*

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/ui/implementation/TypeScriptImplementationDialog.java

+4
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,8 @@ protected ILabelProvider getLabelProvider() {
7272
return new TypeScriptImplementationLabelProvider();
7373
}
7474

75+
@Override
76+
public void setSize(int width, int height) {
77+
super.setSize(width, height);
78+
}
7579
}

0 commit comments

Comments
 (0)