Skip to content

Commit d6f7923

Browse files
committed
massive temp
1 parent 6d59071 commit d6f7923

File tree

5 files changed

+117
-8
lines changed

5 files changed

+117
-8
lines changed

scripts/build.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ async function build() {
3535
const url = `https://github.com/mug1wara26/source-lsp/releases/latest/download/${lspFilename}`;
3636
const outputPath = path.join(outputFolder, lspFilename); // Save in the same directory
3737
// Function below handles the 302 Found redirection from GitHub
38-
await downloadFile(url, outputPath);
39-
console.log(`LSP server downloaded from ${url}`);
38+
// await downloadFile(url, outputPath);
39+
// console.log(`LSP server downloaded from ${url}`);
4040
}
4141

4242
/**
@@ -52,25 +52,31 @@ function downloadFile(url, outputPath) {
5252
});
5353
}
5454
function onError(err) {
55+
console.log(`Error: ${err.message}`);
5556
fs.unlink(outputPath, () => {
5657
reject(err);
5758
});
5859
}
5960

6061
https
6162
.get(url, (res) => {
63+
console.log(`Response status code: ${res.statusCode}`);
6264
if (res.statusCode >= 200 && res.statusCode < 300) {
6365
if (res.statusCode !== 200) {
6466
console.log("Warn: Status code is not 200");
6567
}
6668
onSuccess(res);
67-
}
68-
if (res.statusCode === 301 || res.statusCode === 302) {
69+
} else if (res.statusCode === 301 || res.statusCode === 302) {
70+
console.log(`Redirecting to ${res.headers.location}`);
6971
https
7072
.get(res.headers.location, (res) => {
73+
// TODO: There needs to be second check here
74+
console.log(`Response status code: ${res.statusCode}`);
7175
onSuccess(res);
7276
})
7377
.on("error", onError);
78+
} else {
79+
console.log(`Error: ${res.statusCode}`);
7480
}
7581
})
7682
.on("error", onError);

src/lsp/client.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { /* commands, */ window } from "vscode";
1212

1313
let client: LanguageClient;
14-
// const SECTION = "\u00A7";
14+
const SECTION = "\u00A7";
1515

1616
export function activateLspClient(context: ExtensionContext) {
1717
// The server is implemented in node
@@ -51,6 +51,19 @@ export function activateLspClient(context: ExtensionContext) {
5151
// Start the client. This will also launch the server
5252
client.start();
5353

54+
const version = `Source ${SECTION}4`;
55+
56+
(async function () {
57+
try {
58+
const response = await client.sendRequest("setLanguageVersion", {
59+
version,
60+
});
61+
window.showInformationMessage(`Language version set to ${version}`);
62+
} catch (error) {
63+
window.showErrorMessage(`Failed to set language version: ${error}`);
64+
}
65+
})();
66+
5467
// TODO: Combine this functionality with existing language selector
5568
// context.subscriptions.push(
5669
// commands.registerCommand("sourcejs.setLanguageVersion", async () => {

src/utils/messages.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const Messages = createMessages({
3434
code,
3535
}),
3636
EvalEditor: (workspaceLocation: VscWorkspaceLocation) => ({
37-
workspaceLocation: workspaceLocation,
37+
workspaceLocation,
3838
}),
3939
});
4040

@@ -96,6 +96,7 @@ export const MessageTypeNames = (() =>
9696
// Wrapper functions
9797
// ================================================================================
9898

99+
// TODO: Rename this as sendToExtension
99100
/**
100101
* API to send a Message to the VSC extension.
101102
* To only be used within source-academy/frontend.

syntaxes/source.tmLanguage.json

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
{
109109
"include": "#arrow-function"
110110
},
111+
{
112+
"include": "#function-call"
113+
},
111114
{
112115
"include": "#literal"
113116
},
@@ -180,10 +183,20 @@
180183
"patterns": [
181184
{
182185
"name": "meta.function",
183-
"begin": "(function)\\s?\\w+\\(\\w*\\)\\s?\\{",
186+
"begin": "(function)\\s?(\\w+)\\((\\w*)\\)\\s?\\{",
184187
"beginCaptures": {
185188
"1": {
186189
"name": "storage.type.function"
190+
},
191+
"2": {
192+
"name": "entity.name.function.js"
193+
},
194+
"3": {
195+
"patterns": [
196+
{
197+
"include": "#identifier"
198+
}
199+
]
187200
}
188201
},
189202
"end": "}",
@@ -402,6 +415,49 @@
402415
}
403416
]
404417
},
418+
"function-call": {
419+
"patterns": [
420+
{
421+
"name": "meta.function-call.js",
422+
"match": "(\\w+)\\((.+)\\)",
423+
"captures": {
424+
"1": {
425+
"name": "entity.name.function.js"
426+
},
427+
"2": {
428+
"patterns": [
429+
{
430+
"include": "#expression"
431+
}
432+
]
433+
}
434+
}
435+
},
436+
{
437+
"name": "meta.function-call.js",
438+
"begin": "(\\w+)(\\()",
439+
"beginCaptures": {
440+
"0": {
441+
"name": "entity.name.function.js"
442+
},
443+
"1": {
444+
"name": "meta.brace.round.ts"
445+
}
446+
},
447+
"end": "\\)",
448+
"endCaptures": {
449+
"0": {
450+
"name": "meta.brace.round.ts"
451+
}
452+
},
453+
"patterns": [
454+
{
455+
"include": "#expression"
456+
}
457+
]
458+
}
459+
]
460+
},
405461
"paren-expression": {
406462
"begin": "\\(",
407463
"beginCaptures": {

syntaxes/source.tmLanguage.yaml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ repository:
5757
expression:
5858
patterns:
5959
- include: "#arrow-function"
60+
- include: "#function-call"
6061
- include: "#literal"
6162
- include: "#identifier"
6263
- include: "#string"
@@ -100,9 +101,11 @@ repository:
100101
function-declaration:
101102
patterns:
102103
- name: meta.function
103-
begin: (function)\s?\w+\(\w*\)\s?\{
104+
begin: (function)\s?(\w+)\((\w*)\)\s?\{
104105
beginCaptures:
105106
"1": { name: storage.type.function }
107+
"2": { name: entity.name.function.js }
108+
"3": { patterns: [{ include: "#identifier" }] }
106109
end: "}"
107110
patterns:
108111
- include: "#statement"
@@ -203,6 +206,36 @@ repository:
203206
- include: "#block"
204207
- name: meta.arrow
205208

209+
# function-declaration:
210+
# patterns:
211+
# - name: meta.function
212+
# begin: (function)\s?(\w+)\((\w*)\)\s?\{
213+
# beginCaptures:
214+
# "1": { name: storage.type.function }
215+
# "2": { name: entity.name.function.js }
216+
# "3": { patterns: [{ include: "#identifier" }] }
217+
# end: "}"
218+
# patterns:
219+
# - include: "#statement"
220+
221+
function-call:
222+
patterns:
223+
- name: meta.function-call.js
224+
match: (\w+)\((.+)\)
225+
captures:
226+
"1": { name: entity.name.function.js }
227+
"2": { patterns: [{ include: "#expression" }] }
228+
- name: meta.function-call.js
229+
begin: (\w+)(\()
230+
beginCaptures:
231+
"0": { name: entity.name.function.js }
232+
"1": { name: meta.brace.round.ts }
233+
end: \)
234+
endCaptures:
235+
"0": { name: meta.brace.round.ts }
236+
patterns:
237+
- include: "#expression"
238+
206239
paren-expression:
207240
begin: \(
208241
beginCaptures:

0 commit comments

Comments
 (0)