Skip to content

Commit c687f92

Browse files
committed
chore: lint
1 parent 2b629e0 commit c687f92

25 files changed

+373
-349
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
1010
"typescript.tsc.autoDetect": "off",
1111
"typescript.tsdk": "node_modules/typescript/lib",
12-
"python.languageServer": "None",
12+
"python.languageServer": "None"
1313
}

CHANGELOG.md

+105-124
Large diffs are not rendered by default.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Run your editor with the `RUST_LOG` environment variable like below, e.g. for VS
141141
RUST_LOG=odoo_lsp=debug code ..
142142
```
143143

144-
This will enable debug logs for the *LSP server* itself, which can be seen via your editor's logging mechanism.
144+
This will enable debug logs for the _LSP server_ itself, which can be seen via your editor's logging mechanism.
145145
Please include these logs when opening an issue.
146146

147147
## Development

biome.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
}
1515
}
1616
]
17-
}
17+
}

client/src/extension.ts

+97-75
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { mkdir, rm } from "node:fs/promises";
77
import { type Stats, existsSync } from "node:fs";
88
import { spawn } from "node:child_process";
99
import { get } from "node:https";
10-
import { LanguageClient, LanguageClientOptions, RevealOutputChannelOn, ServerOptions } from "vscode-languageclient/node";
10+
import {
11+
LanguageClient,
12+
LanguageClientOptions,
13+
RevealOutputChannelOn,
14+
ServerOptions,
15+
} from "vscode-languageclient/node";
1116
import { registerXmlFileAssociations, registerXPathSemanticTokensProvider } from "./xml";
1217
import {
1318
$,
@@ -175,71 +180,77 @@ async function downloadLspBinary(context: vscode.ExtensionContext) {
175180
}
176181

177182
async function latestReleaseInfo(includeStable: boolean, fallback?: string) {
178-
return (await new Promise<string | undefined>(resolve =>
179-
get(
180-
"https://api.github.com/repos/Desdaemon/odoo-lsp/releases?per_page=5",
181-
{
182-
headers: {
183-
accept: "application/vnd.github+json",
184-
"user-agent": "vscode-odoo-lsp",
183+
return (
184+
(await new Promise<string | undefined>((resolve) =>
185+
get(
186+
"https://api.github.com/repos/Desdaemon/odoo-lsp/releases?per_page=5",
187+
{
188+
headers: {
189+
accept: "application/vnd.github+json",
190+
"user-agent": "vscode-odoo-lsp",
191+
},
185192
},
186-
},
187-
(resp) => {
188-
const chunks: Buffer[] = [];
189-
resp.on("data", chunks.push.bind(chunks)).on("end", () => {
190-
try {
191-
const releases: { tag_name: string; name: string, published_at: string }[] = JSON.parse(Buffer.concat(chunks).toString());
192-
const today = new Date();
193-
releases.sort((a, z) => z.published_at.localeCompare(a.published_at));
194-
const latest = releases.find((r) => (includeStable || r.name === "nightly") && compareDate(today, new Date(r.published_at)) >= 0);
195-
resolve(latest?.tag_name || fallback);
196-
} catch (err) {
197-
vscode.window.showErrorMessage(`Unable to fetch nightly release: ${err}`);
198-
resolve(fallback);
199-
}
200-
});
201-
},
202-
),
203-
)) || fallback;
193+
(resp) => {
194+
const chunks: Buffer[] = [];
195+
resp.on("data", chunks.push.bind(chunks)).on("end", () => {
196+
try {
197+
const releases: { tag_name: string; name: string; published_at: string }[] = JSON.parse(
198+
Buffer.concat(chunks).toString(),
199+
);
200+
const today = new Date();
201+
releases.sort((a, z) => z.published_at.localeCompare(a.published_at));
202+
const latest = releases.find(
203+
(r) => (includeStable || r.name === "nightly") && compareDate(today, new Date(r.published_at)) >= 0,
204+
);
205+
resolve(latest?.tag_name || fallback);
206+
} catch (err) {
207+
vscode.window.showErrorMessage(`Unable to fetch nightly release: ${err}`);
208+
resolve(fallback);
209+
}
210+
});
211+
},
212+
),
213+
)) || fallback
214+
);
204215
}
205216

206217
function updateExtension(context: vscode.ExtensionContext, release: string) {
207218
const runtimeDir = context.globalStorageUri.fsPath;
208219
const vsixLink = `${repo}/releases/download/${release}/odoo-lsp-${context.extension.packageJSON.version}.vsix`;
209220
const vsixOutput = `${runtimeDir}/odoo-lsp.vsix`;
210-
downloadFile(vsixLink, vsixOutput).then(async () => {
211-
const resp =
212-
extensionState.nightlyExtensionUpdates === "always"
213-
? "Yes"
214-
: await vscode.window.showInformationMessage(
215-
"A new nightly update for the extension is available. Install?",
216-
"Yes",
217-
"No",
218-
"Always",
219-
"Never show again",
220-
);
221-
if (resp === "Always") extensionState.nightlyExtensionUpdates = "always";
222-
else if (resp === "Never show again") extensionState.nightlyExtensionUpdates = "never";
223-
224-
if (resp === "Yes" || resp === "Always") {
225-
try{
226-
await vscode.commands.executeCommand(
227-
"workbench.extensions.installExtension",
228-
vscode.Uri.file(vsixOutput),
229-
);
230-
} catch (err) {
231-
vscode.window.showErrorMessage(`Failed to update extension: ${err}`);
232-
return;
221+
downloadFile(vsixLink, vsixOutput).then(
222+
async () => {
223+
const resp =
224+
extensionState.nightlyExtensionUpdates === "always"
225+
? "Yes"
226+
: await vscode.window.showInformationMessage(
227+
"A new nightly update for the extension is available. Install?",
228+
"Yes",
229+
"No",
230+
"Always",
231+
"Never show again",
232+
);
233+
if (resp === "Always") extensionState.nightlyExtensionUpdates = "always";
234+
else if (resp === "Never show again") extensionState.nightlyExtensionUpdates = "never";
235+
236+
if (resp === "Yes" || resp === "Always") {
237+
try {
238+
await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(vsixOutput));
239+
} catch (err) {
240+
vscode.window.showErrorMessage(`Failed to update extension: ${err}`);
241+
return;
242+
}
243+
vscode.window
244+
.showInformationMessage(`Extension updated to ${release}. Reload to apply changes.`, "Reload now", "Later")
245+
.then((resp) => {
246+
if (resp === "Reload now") vscode.commands.executeCommand("workbench.action.reloadWindow");
247+
});
233248
}
234-
vscode.window
235-
.showInformationMessage(`Extension updated to ${release}. Reload to apply changes.`, "Reload now", "Later")
236-
.then((resp) => {
237-
if (resp === "Reload now") vscode.commands.executeCommand("workbench.action.reloadWindow");
238-
});
239-
}
240-
}, reason => {
241-
vscode.window.showErrorMessage(`Failed to download extension update: ${reason}`);
242-
})
249+
},
250+
(reason) => {
251+
vscode.window.showErrorMessage(`Failed to download extension update: ${reason}`);
252+
},
253+
);
243254
}
244255

245256
const makeExtensionState = (context: vscode.ExtensionContext) =>
@@ -274,17 +285,19 @@ export async function activate(context: vscode.ExtensionContext) {
274285
const runtimeDir = context.globalStorageUri.fsPath;
275286
let latestRelease: string | undefined;
276287
let vsixStat: Stats | null;
277-
if (preferNightly
278-
&& command === "odoo-lsp"
279-
&& (latestRelease = await latestReleaseInfo(false))
280-
&& latestRelease.startsWith('nightly-')
281-
&& (!(vsixStat = tryStatSync(`${runtimeDir}/odoo-lsp.vsix`))
282-
|| compareDate(vsixStat.ctime, parseNightly(latestRelease)) < 0)) {
288+
if (
289+
preferNightly &&
290+
command === "odoo-lsp" &&
291+
(latestRelease = await latestReleaseInfo(false)) &&
292+
latestRelease.startsWith("nightly-") &&
293+
(!(vsixStat = tryStatSync(`${runtimeDir}/odoo-lsp.vsix`)) ||
294+
compareDate(vsixStat.ctime, parseNightly(latestRelease)) < 0)
295+
) {
283296
updateExtension(context, latestRelease);
284297
}
285298

286299
const logLevel = vscode.workspace.getConfiguration("odoo-lsp.trace").get("binary");
287-
const RUST_LOG_STYLE = 'never'
300+
const RUST_LOG_STYLE = "never";
288301
const serverOptions: ServerOptions = {
289302
run: {
290303
command,
@@ -305,27 +318,36 @@ export async function activate(context: vscode.ExtensionContext) {
305318
const splitPattern = /^\[/gm;
306319

307320
const oldAppend = binaryOutputChannel.append.bind(binaryOutputChannel);
308-
binaryOutputChannel.append = (function(this: vscode.LogOutputChannel, lines: string) {
321+
binaryOutputChannel.append = function (this: vscode.LogOutputChannel, lines: string) {
309322
if (!lines) return;
310-
323+
311324
for (const line of lines.split(splitPattern)) {
312325
const match = logPattern.exec(line);
313326
if (match) {
314327
const rest = line.substring(match[0].length).trimEnd();
315328
const target = match[2]!.trimStart();
316-
switch (match[1]) {
317-
case 'INFO': this.info(`[${target}]${rest}`); break;
318-
case 'WARN': this.warn(`[${target}]${rest}`); break;
319-
case 'ERROR': this.error(`[${target}]${rest}`); break;
320-
case 'DEBUG': this.debug(`[${target}]${rest}`); break;
321-
case 'TRACE': this.trace(`[${target}]${rest}`); break;
329+
switch (match[1]) {
330+
case "INFO":
331+
this.info(`[${target}]${rest}`);
332+
break;
333+
case "WARN":
334+
this.warn(`[${target}]${rest}`);
335+
break;
336+
case "ERROR":
337+
this.error(`[${target}]${rest}`);
338+
break;
339+
case "DEBUG":
340+
this.debug(`[${target}]${rest}`);
341+
break;
342+
case "TRACE":
343+
this.trace(`[${target}]${rest}`);
344+
break;
322345
}
323346
continue;
324347
}
325348
if (line.trim()) oldAppend(line);
326349
}
327-
328-
}).bind(binaryOutputChannel);
350+
}.bind(binaryOutputChannel);
329351

330352
const clientOptions = {
331353
documentSelector: [

client/src/utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ export async function openLink(url: string) {
9393
}
9494

9595
export function parseNightly(releaseName: string) {
96-
if (!releaseName.startsWith('nightly-')) {
96+
if (!releaseName.startsWith("nightly-")) {
9797
throw new Error(`bug: releaseName=${releaseName} is not a nightly release`);
9898
}
9999
// nightly-YYYYMMDD
100-
const dateString = releaseName.slice('nightly-'.length);
100+
const dateString = releaseName.slice("nightly-".length);
101101
const yearString = dateString.slice(0, 4);
102102
const monthString = dateString.slice(4, 6);
103103
const dayString = dateString.slice(6, 8);
104-
return new Date(Date.UTC(+yearString, (+monthString)-1, (+dayString)+1))
104+
return new Date(Date.UTC(+yearString, +monthString - 1, +dayString + 1));
105105
}

crates/ts-indent/.vscode/launch.json

+20-23
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
{
2-
// Use IntelliSense to learn about possible attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5-
"version": "0.2.0",
6-
"configurations": [
7-
{
8-
"type": "lldb",
9-
"request": "launch",
10-
"name": "Debug",
11-
"program": "${workspaceFolder}/../../target/debug/ts-indent",
12-
"cwd": "${workspaceFolder}",
13-
"cargo": {
14-
"args": [
15-
"build",
16-
"-p", "ts-indent"
17-
],
18-
"filter": {
19-
"kind": "bin"
20-
}
21-
}
22-
}
23-
]
24-
}
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "Debug",
11+
"program": "${workspaceFolder}/../../target/debug/ts-indent",
12+
"cwd": "${workspaceFolder}",
13+
"cargo": {
14+
"args": ["build", "-p", "ts-indent"],
15+
"filter": {
16+
"kind": "bin"
17+
}
18+
}
19+
}
20+
]
21+
}

0 commit comments

Comments
 (0)