Skip to content

Commit c9fe0f6

Browse files
v1.2.1 (#21)
* [[explicit-variables]] Adds command to toggle explicit variable checks (#17) This patch adds a setting to allow the user to toggle variable checking for the linter to alert the user if variables have not been declared. * [[indentation]] Adds support for custom indentaton (#15) This patch adds support for custom indentation that allows you to choose between tabs or spaces, with custom indentation size for spaces. Tabs are locked at 1 indentation size. Co-authored-by: William <[email protected]> * [[live-server]] Edited code in vscode is displayed in livecode scripts (#16) This patch adds the connection between vscode and livecode using TCP sockets to send code changes from vscode to the LiveCode script editor. Co-authored-by: William <[email protected]> * Version updated * [[live-server]] Adds toast notifications for users (#19) This patch adds toast notifications to indicate to the user what is happening in the connection between vscode and LiveCode. Also tidied up some functions. * [[indentation]] Changed indentation to be same format as current code (#20) This patch adds the indentation checks to be within the switch statement of the already existing code. * Version updated Co-authored-by: Ruaridh Bell <[email protected]>
1 parent ce85984 commit c9fe0f6

File tree

5 files changed

+99
-78
lines changed

5 files changed

+99
-78
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,29 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
8+
# [1.2.1] - 2022-10-05
9+
10+
### Changed
11+
- Indentation changed to be consistent with current code
12+
13+
### Added
14+
- Use toasts to notify about the status of the connection with LC
15+
16+
17+
18+
19+
720
# [1.2.0] - 2022-10-05
821

922
### Added
1023
- Setting to toggle explicit variable checks
1124
- Edited code in vscode is displayed in livecode scripts
1225
- Support for custom indentation
1326

27+
28+
29+
1430
## [1.1.7] - 2022-03-22
1531

1632
### Fixed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "livecodescript",
33
"description": "This extension adds several features to handle livecodescript files",
44
"displayName": "Livecode Language Support",
5-
"version": "1.2.0",
5+
"version": "1.2.1"
66
"author": "FerrusLogic",
77
"publisher": "Ferruslogic",
88
"license": "SEE LICENSE IN LICENSE.md",

src/features/livecodescript/LCSformat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export class LivecodescriptFormattingProvider implements vscode.DocumentRangeFor
4242
.resolve(__dirname, "../../../tools/Formatter.lc")
4343
.replace(/[\\]+/g, "/"),
4444
"-scope=.source.livecodescript",
45-
indentation,
46-
indentationSize,
45+
`-indentation=${indentation}`,
46+
`-indentationSize=${indentationSize}`,
4747
];
4848

4949
/* let container = config.get("perltidyContainer", "");

src/features/livecodescript/LCSserverProvider.ts

100755100644
Lines changed: 74 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,25 @@ import * as vscode from "vscode";
22
import { TextDecoder } from "text-encoding";
33
import { PromiseSocket } from "promise-socket";
44

5-
const enum Setting {
6-
Enable = "livecodescript.server.enable",
7-
Host = "livecodescript.server.host",
8-
Port = "livecodescript.server.port",
9-
}
105

116
export default class LivecodescriptServerProvider {
127
private enabled: boolean;
138
private host: string;
149
private port: number;
1510

16-
constructor() {}
11+
12+
constructor() {
13+
this.loadConfiguration();
14+
}
15+
1716

1817
public activate(subscriptions: vscode.Disposable[]) {
1918
subscriptions.push(this);
2019
subscriptions.push(
2120
vscode.workspace.onDidSaveTextDocument(
2221
async ({ fileName, languageId, lineAt }) => {
23-
if (this.enabled === undefined) {
24-
await this.loadConfiguration();
25-
}
22+
23+
console.log("DOCUMENT SAVED");
2624

2725
if (this.enabled && languageId === "livecodescript") {
2826
const regex = '"([-.:a-zA-Z0-9_s?!]+)"';
@@ -32,78 +30,82 @@ export default class LivecodescriptServerProvider {
3230
stack: scriptName,
3331
filename: fileName,
3432
};
35-
36-
let prms = new URLSearchParams(query);
37-
38-
const socket = new PromiseSocket();
39-
socket.setTimeout(300);
40-
41-
try {
42-
await socket.connect(this.port, this.host);
43-
await socket.write(`${prms.toString()}\n`);
44-
45-
const data = await socket.read();
46-
let result = new TextDecoder().decode(data);
47-
48-
if (result !== "success") {
49-
if (result.includes("error: 360")) {
50-
console.log(
51-
"error: script is being executed within Livecode"
52-
);
53-
} else {
54-
console.log(
55-
`error running command in LiveCode: ${result}`
56-
);
57-
}
58-
} else {
59-
console.log(
60-
"command successfully sent to LiveCode"
61-
);
62-
}
63-
socket.destroy();
64-
} catch (err) {
65-
console.log(err);
66-
socket.destroy();
67-
}
33+
34+
this.sendToLiveCode(query);
6835
}
6936
}
7037
)
7138
);
72-
}
39+
40+
subscriptions.push(
41+
vscode.workspace.onDidChangeConfiguration(() =>
42+
this.loadConfiguration()
43+
)
44+
);
45+
7346

7447
public dispose(): void {}
7548

76-
private async loadConfiguration(): Promise<void> {
77-
const section = vscode.workspace.getConfiguration();
78-
this.enabled = this.getSettingValue<boolean>(
79-
section,
80-
Setting.Enable,
81-
false
82-
);
83-
this.host = this.getSettingValue<string>(
84-
section,
85-
Setting.Host,
86-
"localhost"
87-
);
88-
this.port = this.getSettingValue<number>(section, Setting.Port, 61373);
49+
50+
private loadConfiguration() {
51+
console.log("CONFIG CHANGED");
52+
const section = vscode.workspace.getConfiguration("livecodescript");
53+
this.enabled = section.get("server.enable", false);
54+
this.host = section.get("server.host", "localhost");
55+
this.port = section.get("server.port", 61373);
8956
}
9057

91-
private getSettingValue<T>(
92-
section: vscode.WorkspaceConfiguration,
93-
setting: Setting,
94-
def: T
95-
): T {
96-
const value = section.inspect<T>(setting);
97-
if (value === undefined) {
98-
return def;
99-
} else if (value.workspaceValue !== undefined) {
100-
return value.workspaceValue;
101-
} else if (value.globalValue !== undefined) {
102-
return value.globalValue;
103-
} else if (value.defaultValue !== undefined) {
104-
return value.defaultValue;
105-
} else {
106-
return def;
58+
private async sendToLiveCode(query) {
59+
let prms = new URLSearchParams(query);
60+
const socket = new PromiseSocket();
61+
socket.setTimeout(300);
62+
63+
try {
64+
await socket.connect(this.port, this.host);
65+
await socket.write(`${prms.toString()}\n`);
66+
67+
const data = await socket.read();
68+
socket.destroy();
69+
let result = new TextDecoder().decode(data);
70+
71+
if (result !== "success") {
72+
if (result.includes("error: 360")) {
73+
vscode.window.showInformationMessage(
74+
"error: script is being executed within Livecode"
75+
);
76+
} else {
77+
vscode.window
78+
.showErrorMessage(
79+
`error running command in LiveCode: ${result}`,
80+
...["Retry"]
81+
)
82+
.then((selection) => {
83+
console.log(selection);
84+
if (selection === "Retry") {
85+
this.sendToLiveCode(query);
86+
}
87+
});
88+
}
89+
} else {
90+
vscode.window.showInformationMessage(
91+
"command successfully sent to LiveCode"
92+
);
93+
}
94+
} catch (err) {
95+
socket.destroy();
96+
console.log(err);
97+
vscode.window
98+
.showErrorMessage(
99+
"An error occurred while updating LiveCode.",
100+
...["Retry"]
101+
)
102+
.then((selection) => {
103+
console.log(selection);
104+
if (selection === "Retry") {
105+
this.sendToLiveCode(query);
106+
}
107+
});
108+
107109
}
108110
}
109111
}

tools/Formatter.lc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ command FormatScript
1313
local tIndentation, tIndentSize, tArgs
1414

1515
put the commandArguments into tArgs
16-
put tArgs[3] into tIndentation
17-
put tArgs[4] into tIndentSize
18-
1916
repeat for each element theArgument in tArgs
2017
split theArgument with "="
2118
switch theArgument[1]
2219
case "-scope"
2320
put theArgument[2] into tScope
2421
break
22+
case "-indentation"
23+
put theArgument[2] into tIndentation
24+
break
25+
case "-indentationSize"
26+
put theArgument[2] into tIndentSize
27+
break
2528
end switch
2629
end repeat
2730

0 commit comments

Comments
 (0)