Skip to content

Commit 4039611

Browse files
committed
learn super
1 parent 3b83c54 commit 4039611

File tree

1 file changed

+78
-52
lines changed

1 file changed

+78
-52
lines changed

client/src/languageserver.ts

Lines changed: 78 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ export const createClient = (context: ExtensionContext) => {
9090
defaultClient.start();
9191
}
9292

93-
class LuaClient {
94-
93+
class LuaClient extends Disposable {
9594
public client: LanguageClient;
9695
private disposables = new Array<Disposable>();
97-
constructor(private context: ExtensionContext,
98-
private documentSelector: DocumentSelector) {
96+
constructor(
97+
private context: ExtensionContext,
98+
private documentSelector: DocumentSelector
99+
) {
100+
super(() => this.dispose());
99101
}
100102

101103
async start() {
@@ -110,29 +112,35 @@ class LuaClient {
110112
},
111113
initializationOptions: {
112114
changeConfiguration: true,
113-
}
115+
},
114116
};
115117

116-
const config = Workspace.getConfiguration(undefined, vscode.workspace.workspaceFolders?.[0]);
118+
const config = Workspace.getConfiguration(
119+
undefined,
120+
vscode.workspace.workspaceFolders?.[0]
121+
);
117122
const commandParam = config.get("Lua.misc.parameters");
118123
const command = await this.getCommand(config);
119124

120-
if (!Array.isArray(commandParam)) throw new Error("Lua.misc.parameters must be an Array!");
125+
if (!Array.isArray(commandParam))
126+
throw new Error("Lua.misc.parameters must be an Array!");
121127

122128
const port = this.getPort(commandParam);
123129

124130
const serverOptions: ServerOptions = {
125131
command: command,
126-
transport: port ? {
127-
kind: TransportKind.socket,
128-
port: port,
129-
} : undefined,
130-
args: commandParam,
132+
transport: port
133+
? {
134+
kind: TransportKind.socket,
135+
port: port,
136+
}
137+
: undefined,
138+
args: commandParam,
131139
};
132140

133141
this.client = new LanguageClient(
134-
'Lua',
135-
'Lua',
142+
"Lua",
143+
"Lua",
136144
serverOptions,
137145
clientOptions
138146
);
@@ -146,7 +154,8 @@ class LuaClient {
146154
private async getCommand(config: vscode.WorkspaceConfiguration) {
147155
const executablePath = config.get("Lua.misc.executablePath");
148156

149-
if (typeof executablePath !== "string") throw new Error("Lua.misc.executablePath must be a string!");
157+
if (typeof executablePath !== "string")
158+
throw new Error("Lua.misc.executablePath must be a string!");
150159

151160
if (executablePath && executablePath !== "") {
152161
return executablePath;
@@ -156,39 +165,45 @@ class LuaClient {
156165
let command: string;
157166
let binDir: string | undefined;
158167

159-
if ((await fs.promises.stat(this.context.asAbsolutePath('server/bin'))).isDirectory()) {
160-
binDir = 'bin';
168+
if (
169+
(
170+
await fs.promises.stat(
171+
this.context.asAbsolutePath("server/bin")
172+
)
173+
).isDirectory()
174+
) {
175+
binDir = "bin";
161176
}
162177

163178
switch (platform) {
164179
case "win32":
165180
command = this.context.asAbsolutePath(
166181
path.join(
167-
'server',
168-
binDir ? binDir : 'bin-Windows',
169-
'lua-language-server.exe'
182+
"server",
183+
binDir ? binDir : "bin-Windows",
184+
"lua-language-server.exe"
170185
)
171186
);
172187
break;
173188
case "linux":
174189
command = this.context.asAbsolutePath(
175190
path.join(
176-
'server',
177-
binDir ? binDir : 'bin-Linux',
178-
'lua-language-server'
191+
"server",
192+
binDir ? binDir : "bin-Linux",
193+
"lua-language-server"
179194
)
180195
);
181-
await fs.promises.chmod(command, '777');
196+
await fs.promises.chmod(command, "777");
182197
break;
183198
case "darwin":
184199
command = this.context.asAbsolutePath(
185200
path.join(
186-
'server',
187-
binDir ? binDir : 'bin-macOS',
188-
'lua-language-server'
201+
"server",
202+
binDir ? binDir : "bin-macOS",
203+
"lua-language-server"
189204
)
190205
);
191-
await fs.promises.chmod(command, '777');
206+
await fs.promises.chmod(command, "777");
192207
break;
193208
default:
194209
throw new Error(`Unsupported operating system "${platform}"!`);
@@ -204,13 +219,14 @@ class LuaClient {
204219
});
205220
if (portIndex === -1) {
206221
return undefined;
207-
};
208-
const port = commandParam[portIndex].split("=")[1]
209-
|| commandParam[portIndex].split(" ")[1]
210-
|| commandParam[portIndex + 1];
222+
}
223+
const port =
224+
commandParam[portIndex].split("=")[1] ||
225+
commandParam[portIndex].split(" ")[1] ||
226+
commandParam[portIndex + 1];
211227
if (!port) {
212228
return undefined;
213-
};
229+
}
214230
return Number(port);
215231
}
216232

@@ -224,29 +240,39 @@ class LuaClient {
224240
statusBar() {
225241
const client = this.client;
226242
const bar = window.createStatusBarItem(vscode.StatusBarAlignment.Right);
227-
bar.text = 'Lua';
228-
bar.command = 'Lua.statusBar';
229-
this.disposables.push(Commands.registerCommand(bar.command, () => {
230-
client.sendNotification('$/status/click');
231-
}));
232-
this.disposables.push(client.onNotification('$/status/show', () => {
233-
bar.show();
234-
}));
235-
this.disposables.push(client.onNotification('$/status/hide', () => {
236-
bar.hide();
237-
}));
238-
this.disposables.push(client.onNotification('$/status/report', (params) => {
239-
bar.text = params.text;
240-
bar.tooltip = params.tooltip;
241-
}));
242-
client.sendNotification('$/status/refresh');
243+
bar.text = "Lua";
244+
bar.command = "Lua.statusBar";
245+
this.disposables.push(
246+
Commands.registerCommand(bar.command, () => {
247+
client.sendNotification("$/status/click");
248+
})
249+
);
250+
this.disposables.push(
251+
client.onNotification("$/status/show", () => {
252+
bar.show();
253+
})
254+
);
255+
this.disposables.push(
256+
client.onNotification("$/status/hide", () => {
257+
bar.hide();
258+
})
259+
);
260+
this.disposables.push(
261+
client.onNotification("$/status/report", (params) => {
262+
bar.text = params.text;
263+
bar.tooltip = params.tooltip;
264+
})
265+
);
266+
client.sendNotification("$/status/refresh");
243267
this.disposables.push(bar);
244268
}
245269

246270
onCommand() {
247-
this.disposables.push(this.client.onNotification('$/command', (params) => {
248-
Commands.executeCommand(params.command, params.data);
249-
}));
271+
this.disposables.push(
272+
this.client.onNotification("$/command", (params) => {
273+
Commands.executeCommand(params.command, params.data);
274+
})
275+
);
250276
}
251277
}
252278

0 commit comments

Comments
 (0)