Skip to content

Commit bc2d1a0

Browse files
authored
Fix summaries/go-to-def for modules inside JAR (#668)
* Only resolve project URIs. * Don't stat TPL in UI test.
1 parent ec6c9c2 commit bc2d1a0

File tree

7 files changed

+34
-51
lines changed

7 files changed

+34
-51
lines changed

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/LSPIDEServices.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,15 @@ public void browse(URI uri, String title, int viewColumn) {
9191

9292
@Override
9393
public void edit(ISourceLocation path) {
94-
try {
95-
ISourceLocation physical = Locations.toClientLocation(path);
96-
ShowDocumentParams params = new ShowDocumentParams(physical.getURI().toASCIIString());
97-
params.setTakeFocus(true);
98-
99-
if (physical.hasOffsetLength()) {
100-
params.setSelection(Locations.toRange(physical, docService.getColumnMap(physical)));
101-
}
94+
ISourceLocation physical = Locations.toClientLocation(path);
95+
ShowDocumentParams params = new ShowDocumentParams(physical.getURI().toASCIIString());
96+
params.setTakeFocus(true);
10297

103-
languageClient.showDocument(params);
104-
} catch (IOException e) {
105-
logger.info("ignored edit of {}, because {}", path, e);
98+
if (physical.hasOffsetLength()) {
99+
params.setSelection(Locations.toRange(physical, docService.getColumnMap(physical)));
106100
}
101+
102+
languageClient.showDocument(params);
107103
}
108104

109105
@Override

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,7 @@ IFunction makePathConfigGetter(Evaluator e) {
174174

175175
IFunction makeParseTreeGetter(Evaluator e) {
176176
return e.getFunctionValueFactory().function(getParseTreeType, (t, u) -> {
177-
ISourceLocation resolvedLocation;
178-
try {
179-
resolvedLocation = Locations.toClientLocation((ISourceLocation) t[0]);
180-
} catch (IOException e1) {
181-
throw RuntimeExceptionFactory.io("Error resolving " + t[0]);
182-
}
183-
// First, check whether the file is open and a parse tree is available
177+
ISourceLocation resolvedLocation = Locations.toClientLocation((ISourceLocation) t[0]);
184178
try {
185179
var tree = rascalTextDocumentService.getFile(resolvedLocation).getLastTreeWithoutErrors();
186180
if (tree != null) {

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/model/FileFacts.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,8 @@ public void reportParseErrors(ISourceLocation file, List<Diagnostic> msgs) {
8787

8888
private FileFact getFile(ISourceLocation l) {
8989
l = l.top();
90-
ISourceLocation resolved = null;
91-
try {
92-
resolved = Locations.toClientLocation(l);
93-
if (resolved == null) {
94-
resolved = l;
95-
}
96-
} catch (IOException e) {
90+
ISourceLocation resolved = Locations.toClientLocation(l);
91+
if (resolved == null) {
9792
resolved = l;
9893
}
9994
return files.computeIfAbsent(resolved, l1 -> new FileFact(l1, exec));

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/terminal/TerminalIDEClient.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,15 @@ public void browse(URI uri, String title, int viewColumn) {
101101

102102
@Override
103103
public void edit(ISourceLocation path) {
104-
try {
105-
ISourceLocation physical = Locations.toClientLocation(path);
106-
ShowDocumentParams params = new ShowDocumentParams(physical.getURI().toASCIIString());
107-
params.setTakeFocus(true);
108-
109-
if (physical.hasOffsetLength()) {
110-
params.setSelection(Locations.toRange(physical, columns));
111-
}
104+
ISourceLocation physical = Locations.toClientLocation(path);
105+
ShowDocumentParams params = new ShowDocumentParams(physical.getURI().toASCIIString());
106+
params.setTakeFocus(true);
112107

113-
server.edit(params);
114-
} catch (IOException e) {
115-
logger.info("ignored edit of {} because {}", path, e);
108+
if (physical.hasOffsetLength()) {
109+
params.setSelection(Locations.toRange(physical, columns));
116110
}
111+
112+
server.edit(params);
117113
}
118114

119115
private String getContents(ISourceLocation file) {

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/Diagnostics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public static Map<ISourceLocation, List<Diagnostic>> translateMessages(IList mes
245245
}
246246

247247
private static ISourceLocation getMessageLocation(IConstructor message) {
248-
return Locations.toClientLocationIfPossible(((ISourceLocation) message.get("at")));
248+
return Locations.toClientLocation(((ISourceLocation) message.get("at")));
249249
}
250250

251251
private static boolean hasValidLocation(IConstructor d, ISourceLocation file) {

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/locations/Locations.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,14 @@
4848
* strip source locations of their "lsp+" prefix.
4949
*/
5050
public class Locations {
51-
public static ISourceLocation toClientLocation(ISourceLocation loc) throws IOException {
52-
return LSPOpenFileResolver.stripLspPrefix(URIResolverRegistry.getInstance().logicalToPhysical(loc));
53-
}
54-
55-
public static ISourceLocation toClientLocationIfPossible(ISourceLocation loc) {
56-
var result = toPhysicalIfPossible(loc);
57-
if (result.getScheme().startsWith("lsp+")) {
58-
try {
59-
return URIUtil.changeScheme(result, result.getScheme().substring("lsp+".length()));
60-
} catch (URISyntaxException e) {
61-
// fall through
62-
}
51+
public static ISourceLocation toClientLocation(ISourceLocation loc) {
52+
loc = LSPOpenFileResolver.stripLspPrefix(loc);
53+
if (loc.getScheme().equals("project")) {
54+
return toPhysicalIfPossible(loc);
6355
}
64-
return result;
56+
return loc;
6557
}
58+
6659
public static ISourceLocation toPhysicalIfPossible(ISourceLocation loc) {
6760
ISourceLocation physical;
6861
try {

rascal-vscode-extension/src/test/vscode-suite/ide.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,21 @@ describe('IDE', function () {
146146
await editor.selectText("println");
147147
await bench.executeCommand("Go to Definition");
148148
await waitForActiveEditor("IO.rsc", Delays.extremelySlow, "IO.rsc should be opened for println");
149+
150+
await editor.selectText("&T", 0);
151+
const defLoc = await editor.getCoordinates();
152+
153+
await editor.selectText("&T", 1);
154+
await bench.executeCommand("Go to Definition");
155+
const jumpLoc = await editor.getCoordinates();
156+
157+
expect(jumpLoc).to.deep.equal(defLoc);
149158
});
150159

151160
it("go to definition works across projects", async () => {
152161
// due to a current bug, we have to make sure that the lib in the other project is correctly resolved
153162
const libEditor = await ide.openModule(TestWorkspace.libFile);
154-
await triggerTypeChecker(libEditor, TestWorkspace.libFileTpl, true);
163+
await triggerTypeChecker(libEditor, "", true);
155164
await bench.getEditorView().closeAllEditors();
156165

157166
const editor = await ide.openModule(TestWorkspace.libCallFile);

0 commit comments

Comments
 (0)