Skip to content

Commit d7e2324

Browse files
authored
Merge pull request #894 from urbanfly/feature/docs-without-ext
Add support for extensionless documents to the parametric language server
2 parents 64479bd + 339f669 commit d7e2324

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"files.exclude": {
3+
"rascal-lsp": true,
4+
"rascal-vscode-extension": true
5+
}
6+
}

rascal-language-servers.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
},
66
{
77
"path": "rascal-vscode-extension"
8+
},
9+
{
10+
"name": "root",
11+
"path": "."
812
}
913
],
1014
"extensions": {

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,17 @@ private static <T> T last(List<T> l) {
644644
}
645645

646646
private Optional<String> safeLanguage(ISourceLocation loc) {
647-
return Optional.ofNullable(registeredExtensions.get(extension(loc)));
647+
var ext = extension(loc);
648+
if ("".equals(ext)) {
649+
if (contributions.size() == 1) {
650+
logger.trace("file was opened without an extension; falling back to the single registered language for: {}", loc);
651+
return contributions.keySet().stream().findFirst();
652+
} else {
653+
logger.error("file was opened without an extension and there are multiple languages registered, so we cannot pick a fallback for: {}", loc);
654+
return Optional.empty();
655+
}
656+
}
657+
return Optional.ofNullable(registeredExtensions.get(ext));
648658
}
649659

650660
private String language(ISourceLocation loc) {

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

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* POSSIBILITY OF SUCH DAMAGE.
2626
*/
2727

28-
import { SideBarView, VSBrowser, WebDriver, Workbench } from 'vscode-extension-tester';
28+
import { InputBox, TextEditor, SideBarView, VSBrowser, WebDriver, Workbench } from 'vscode-extension-tester';
2929
import { Delays, IDEOperations, ignoreFails, printRascalOutputOnFailure, RascalREPL, sleep, TestWorkspace } from './utils';
3030

3131
import { expect } from 'chai';
@@ -75,7 +75,6 @@ parameterizedDescribe(function (errorRecovery: boolean) {
7575
await repl.terminate();
7676
}
7777

78-
7978
before(async () => {
8079
browser = VSBrowser.instance;
8180
driver = browser.driver;
@@ -103,7 +102,7 @@ parameterizedDescribe(function (errorRecovery: boolean) {
103102
await fs.writeFile(TestWorkspace.picoFile, picoFileBackup);
104103
});
105104

106-
it("have highlighting and parse errors", async function () {
105+
it("has highlighting and parse errors", async function () {
107106
await ignoreFails(new Workbench().getEditorView().closeAllEditors());
108107
const editor = await ide.openModule(TestWorkspace.picoFile);
109108
const isPicoLoading = ide.statusContains("Pico");
@@ -126,7 +125,7 @@ parameterizedDescribe(function (errorRecovery: boolean) {
126125
}
127126
}).retries(2);
128127

129-
it("have highlighting and parse errors for second extension", async function () {
128+
it("has highlighting and parse errors for second extension", async function () {
130129
const editor = await ide.openModule(TestWorkspace.picoNewFile);
131130
await ide.hasSyntaxHighlighting(editor);
132131
try {
@@ -137,6 +136,40 @@ parameterizedDescribe(function (errorRecovery: boolean) {
137136
}
138137
});
139138

139+
it("has syntax highlighting in documents without extension", async function () {
140+
await bench.executeCommand("workbench.action.files.newUntitledFile");
141+
await bench.executeCommand("workbench.action.editor.changeLanguageMode");
142+
143+
const inputBox = new InputBox();
144+
await inputBox.setText("parametric-rascalmpl");
145+
await inputBox.confirm();
146+
147+
const file = "Untitled-1";
148+
const editor = await driver.wait(async () => {
149+
const result = await ignoreFails(new Workbench().getEditorView().openEditor(file)) as TextEditor;
150+
if (result && await ignoreFails(result.getTitle()) === file) {
151+
return result;
152+
}
153+
return undefined! as TextEditor;
154+
}, Delays.normal, "Could not open file");
155+
expect(editor).to.not.be.undefined;
156+
157+
await editor.setText(`begin
158+
declare
159+
a : natural;
160+
a := 2
161+
end
162+
`);
163+
await ide.hasSyntaxHighlighting(editor, Delays.slow);
164+
165+
try {
166+
await editor.setTextAtLine(4, " a := ");
167+
await ide.hasErrorSquiggly(editor, Delays.slow);
168+
} finally {
169+
await ide.revertOpenChanges();
170+
}
171+
}).retries(2);
172+
140173
it("error recovery works", async function () {
141174
if (!errorRecovery) { this.skip(); }
142175
const editor = await ide.openModule(TestWorkspace.picoNewFile);

0 commit comments

Comments
 (0)