8000 Use async API of CodeLens. · angelozerr/typescript.java@e79f1ad · GitHub
[go: up one dir, main page]

Skip to content

Commit e79f1ad

Browse files
committed
Use async API of CodeLens.
1 parent 4da6b4f commit e79f1ad

File tree

4 files changed

+42
-63
lines changed

4 files changed

+42
-63
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@
616616
<codeLensProvider
617617
name="%TypeScriptReferencesCodeLensProvider.name"
618618
class="ts.eclipse.ide.internal.ui.codelens.TypeScriptReferencesCodeLensProvider"
619-
target="typeScript.codeLens">
619+
targetId="typeScript.codeLens">
620620
</codeLensProvider>
621621
</extension>
622622

@@ -626,7 +626,7 @@
626626
<codeLensProvider
627627
name="%TypeScriptImplementationsCodeLensProvider.name"
628628
class="ts.eclipse.ide.internal.ui.codelens.TypeScriptImplementationsCodeLensProvider"
629-
target="typeScript.codeLens">
629+
targetId="typeScript.codeLens">
630630
</codeLensProvider>
631631
</extension>
632632

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/internal/ui/codelens/TypeScriptImplementationsCodeLensProvider.java

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.text.MessageFormat;
44
import java.util.List;
5+
import java.util.concurrent.CompletableFuture;
56
import java.util.concurrent.TimeUnit;
67
import java.util.stream.Collectors;
78

@@ -20,7 +21,7 @@
2021
public class TypeScriptImplementationsCodeLensProvider extends TypeScriptBaseCodeLensProvider {
2122

2223
@Override
23-
public ICodeLens resolveCodeLens(ICodeLensContext context, ICodeLens cl, IProgressMonitor monitor) {
24+
public CompletableFuture<ICodeLens> resolveCodeLens(ICodeLensContext context, ICodeLens cl, IProgressMonitor monitor) {
2425
ImplementationsCodeLens codeLens = (ImplementationsCodeLens) cl;
2526
// const codeLens = inputCodeLens as ReferencesCodeLens;
2627
// const args: Proto.FileLocationRequestArgs = {
@@ -31,31 +32,20 @@ public ICodeLens resolveCodeLens(ICodeLensContext context, ICodeLens cl, IProgre
3132
IIDETypeScriptFile tsFile = codeLens.getTsFile();
3233
try {
3334
int position = tsFile.getPosition(codeLens.getRange().startLineNumber, codeLens.getRange().startColumn);
34-
List<FileSpan> refs = tsFile.implementation(position).get(1000, TimeUnit.MILLISECONDS);
35-
int refCount = refs.size();
36-
if (refCount == 1) {
37-
codeLens.setCommand(new Command("1 implementation", "implementation"));
38-
} else {
39-
codeLens.setCommand(
40-
new Command(MessageFormat.format("{0} implementations", refCount), "implementation"));
41-
}
42-
43-
// (response -> {
44-
// response.getRefs().stream().map(reference -> {
45-
// return null;
46-
// });
47-
// int refCount = response.getRefs().size() - 1;
48-
// if (refCount == 1) {
49-
// codeLens.setCommand(new Command("1 reference", null));
50-
// } else {
51-
// codeLens.setCommand(new Command(MessageFormat.format("{0}
52-
// references", refCount), null));
53-
// }
54-
// });
35+
return tsFile.implementation(position).thenApply(refs -> {
36+
int refCount = refs.size();
37+
if (refCount == 1) {
38+
codeLens.setCommand(new Command("1 implementation", "implementation"));
39+
} else {
40+
codeLens.setCommand(
41+
new Command(MessageFormat.format("{0} implementations", refCount), "implementation"));
42+
}
43+
return codeLens;
44+
});
5545
} catch (Exception e) {
5646
codeLens.setCommand(new Command("Could not determine implementations", null));
5747
}
58-
return codeLens;
48+
return null;
5949
}
6050

6151
@Override

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/internal/ui/codelens/TypeScriptReferencesCodeLensProvider.java

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.text.MessageFormat;
44
import java.util.List;
5-
import java.util.concurrent.TimeUnit;
5+
import java.util.concurrent.CompletableFuture;
66
import java.util.stream.Collectors;
77

88
import org.eclipse.core.runtime.IProgressMonitor;
@@ -13,14 +13,14 @@
1313

1414
import ts.ScriptElementKind;
1515
import ts.client.navbar.NavigationBarItem;
16-
import ts.client.references.ReferencesResponseItem;
1716
import ts.eclipse.ide.core.resources.IIDETypeScriptFile;
1817
import ts.eclipse.ide.ui.codelens.TypeScriptBaseCodeLensProvider;
1918

2019
public class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvider {
2120

2221
@Override
23-
public ICodeLens resolveCodeLens(ICodeLensContext context, ICodeLens cl, IProgressMonitor monitor) {
22+
public CompletableFuture<ICodeLens> resolveCodeLens(ICodeLensContext context, ICodeLens cl,
23+
IProgressMonitor monitor) {
2424
ReferencesCodeLens codeLens = (ReferencesCodeLens) cl;
2525
// const codeLens = inputCodeLens as ReferencesCodeLens;
2626
// const args: Proto.FileLocationRequestArgs = {
@@ -31,29 +31,19 @@ public ICodeLens resolveCodeLens(ICodeLensContext context, ICodeLens cl, IProgre
3131
IIDETypeScriptFile tsFile = codeLens.getTsFile();
3232
try {
3333
int position = tsFile.getPosition(codeLens.getRange().startLineNumber, codeLens.getRange().startColumn);
34-
List<ReferencesResponseItem> refs = tsFile.references(position).get(1000, TimeUnit.MILLISECONDS).getRefs();
35-
int refCount = refs.size() - 1;
36-
if (refCount == 1) {
37-
codeLens.setCommand(new Command("1 reference", "references"));
38-
} else {
39-
codeLens.setCommand(new Command(MessageFormat.format("{0} references", refCount), "references"));
40-
}
41-
// (response -> {
42-
// response.getRefs().stream().map(reference -> {
43-
// return null;
44-
// });
45-
// int refCount = response.getRefs().size() - 1;
46-
// if (refCount == 1) {
47-
// codeLens.setCommand(new Command("1 reference", null));
48-
// } else {
49-
// codeLens.setCommand(new Command(MessageFormat.format("{0}
50-
// references", refCount), null));
51-
// }
52-
// });
34+
return tsFile.references(position).thenApply(body -> {
35+
int refCount = body.getRefs().size() - 1;
36+
if (refCount == 1) {
37+
codeLens.setCommand(new Command("1 reference", "references"));
38+
} else {
39+
codeLens.setCommand(new Command(MessageFormat.format("{0} references", refCount), "references"));
40+
}
41+
return codeLens;
42+
});
5343
} catch (Exception e) {
5444
codeLens.setCommand(new Command("Could not determine references", null));
5545
}
56-
return codeLens;
46+
return null;
5747
// return this.client.execute('references', args, token).then(response
5848
// => {
5949
// if (!response || !response.body) {

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/ui/codelens/TypeScriptBaseCodeLensProvider.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.List;
5-
import java.util.concurrent.TimeUnit;
5+
import java.util.concurrent.CompletableFuture;
66
import java.util.regex.Matcher;
77
import java.util.regex.Pattern;
88

@@ -27,7 +27,7 @@
2727
public abstract class TypeScriptBaseCodeLensProvider implements ICodeLensProvider {
2828

2929
@Override
30-
public ICodeLens[] provideCodeLenses(ICodeLensContext context, IProgressMonitor monitor) {
30+
public CompletableFuture<ICodeLens[]> provideCodeLenses(ICodeLensContext context, IProgressMonitor monitor) {
3131
ITextViewer textViewer = context.getViewer();
3232
IResource resource = TypeScriptResourceUtil.getFile(textViewer.getDocument());
3333
if (resource == null) {
@@ -42,13 +42,13 @@ public ICodeLens[] provideCodeLenses(ICodeLensContext context, IProgressMonitor
4242
IIDETypeScriptProject tsProject = TypeScriptResourceUtil.getTypeScriptProject(project);
4343
IDocument document = textViewer.getDocument();
4444
IIDETypeScriptFile tsFile = tsProject.openFile(resource, document);
45-
NavigationBarItem tree = tsProject.getClient().navtree(tsFile.getName(), tsFile).get(1000,
46-
TimeUnit.MILLISECONDS);
47-
List<Range> referenceableSpans = new ArrayList<>();
48-
if (tree != null && tree.hasChildItems()) {
49-
tree.getChildItems().forEach(item -> this.walkNavTree(tsFile, item, null, referenceableSpans));
50-
}
51-
return toCodeLenses(referenceableSpans, tsFile);
45+
return tsProject.getClient().navtree(tsFile.getName(), tsFile).thenApply(tree -> {
46+
List<Range> referenceableSpans = new ArrayList<>();
47+
if (tree != null && tree.hasChildItems()) {
48+
tree.getChildItems().forEach(item -> this.walkNavTree(tsFile, item, null, referenceableSpans));
49+
}
50+
return toCodeLenses(referenceableSpans, tsFile);
51+
});
5252
} catch (Exception e) {
5353
TypeScriptUIPlugin.log("Error while TypeScript codelens", e);
5454
}
@@ -133,12 +133,11 @@ protected Range getSymbolRange(IIDETypeScriptFile tsFile, NavigationBarItem item
133133
* const text = document.getText(range);
134134
*
135135
* const identifierMatch = new RegExp(`^(.*?(\\b|\\W))${(item.text ||
136-
* '').replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')}(\\b|\\W)`, 'gm');
137-
* const match = identifierMatch.exec(text); const prefixLength = match
138-
* ? match.index + match[1].length : 0; const startOffset =
139-
* document.offsetAt(new Position(range.start.line,
140-
* range.start.characte 6ACF r)) + prefixLength; return new Range(
141-
* document.positionAt(startOffset), document.positionAt(startOffset +
136+
* '').replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')}(\\b|\\W)`, 'gm'); const
137+
* match = identifierMatch.exec(text); const prefixLength = match ? match.index
138+
* + match[1].length : 0; const startOffset = document.offsetAt(new
139+
* Position(range.start.line, range.start.character)) + prefixLength; return new
140+
* Range( document.positionAt(startOffset), document.positionAt(startOffset +
142141
* item.text.length));
143142
*/
144143
return range;

0 commit comments

Comments
 (0)
0