Skip to content

Commit 02f8b05

Browse files
committed
Test Rust demos with clippy
1 parent c4da728 commit 02f8b05

File tree

6 files changed

+38
-56
lines changed

6 files changed

+38
-56
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ unit:
5151
test: unit lint
5252
./build-aux/fun workbench-cli ci demos/demos/Welcome
5353

54-
ci: setup test
55-
./build-aux/fun workbench-cli ci demos/demos/**
54+
ci: setup
55+
./build-aux/fun workbench-cli ci demos/demos/*
5656

5757
# Note that if you have Sdk extensions installed they will be used
5858
# make sure to test without the sdk extensions installed

demos

Submodule demos updated 149 files

package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
"rollup-plugin-node-polyfills": "^0.2.1"
2121
},
2222
"type": "module",
23-
"scripts": {
24-
"prepare": "husky install"
25-
},
23+
"scripts": {},
2624
"lint-staged": {
2725
"*.{json,md,yaml,yml}": "prettier --write",
2826
"*.{js,cjs,mjs}": "eslint --fix",

src/cli/main.js

+19-44
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import { createLSPClient, languages, getLanguage } from "../common.js";
1212
import lint, { waitForDiagnostics } from "./lint.js";
1313
import format, { formatting } from "./format.js";
1414

15+
import { setupRustProject, installRustLibraries } from "../langs/rust/rust.js";
16+
import { targetPath } from "../langs/rust/Compiler.js";
17+
1518
Gtk.init();
1619

1720
export async function main([action, ...args]) {
@@ -399,51 +402,23 @@ async function ci({ filenames, current_dir }) {
399402

400403
const file_rust = demo_dir.get_child("code.rs");
401404
if (file_rust.query_exists(null)) {
402-
print(` ${file_rust.get_path()}`);
403-
404-
const uri = file_rust.get_uri();
405-
const languageId = "rust";
406-
let version = 0;
407-
408-
const [contents] = await file_rust.load_contents_async(null);
409-
const text = new TextDecoder().decode(contents);
410-
411-
await lsp_clients.rust._notify("textDocument/didOpen", {
412-
textDocument: {
413-
uri,
414-
languageId,
415-
version: version++,
416-
text,
417-
},
418-
});
419-
420-
// FIXME: rust analyzer doesn't publish diagnostics if there are none
421-
// probably we should switch to pulling diagnostics but unknown if supported
422-
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_pullDiagnostics
423-
424-
// const diagnostics = await waitForDiagnostics({
425-
// uri,
426-
// lspc: lsp_clients.rust,
427-
// });
428-
// if (diagnostics.length > 0) {
429-
// printerr(serializeDiagnostics({ diagnostics }));
430-
// return false;
431-
// }
432-
// print(` ✅ lints`);
433-
434-
const checks = await checkFile({
435-
lspc: lsp_clients.rust,
436-
file: file_rust,
437-
lang: getLanguage("rust"),
438-
uri,
439-
});
405+
await setupRustProject(demo_dir);
406+
await installRustLibraries(demo_dir);
407+
const cargo_launcher = new Gio.SubprocessLauncher();
408+
cargo_launcher.set_cwd(demo_dir.get_path());
409+
const cargo = cargo_launcher.spawnv([
410+
"cargo",
411+
"clippy",
412+
"--locked",
413+
"--verbose",
414+
"--target-dir",
415+
targetPath,
416+
]);
417+
await cargo.wait_async(null);
418+
419+
const checks = cargo.get_successful();
420+
cargo_launcher.close();
440421
if (!checks) return false;
441-
442-
await lsp_clients.rust._notify("textDocument/didClose", {
443-
textDocument: {
444-
uri,
445-
},
446-
});
447422
}
448423

449424
await Promise.all(

src/langs/rust/Compiler.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import dbus_previewer from "../../Previewer/DBusPreviewer.js";
44
import { decode, encode } from "../../util.js";
55
import { installRustLibraries } from "./rust.js";
66

7+
const cacheDir = GLib.get_user_cache_dir();
8+
export const targetPath = `${cacheDir}/rust_build_cache`;
9+
710
export default function Compiler({ session }) {
811
const { file } = session;
9-
const cacheDir = GLib.get_user_cache_dir();
10-
const targetPath = `${cacheDir}/rust_build_cache`;
1112
const rustcVersionFile = Gio.File.new_for_path(
1213
`${targetPath}/rustc_version.txt`,
1314
);

src/util.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ import { getLanguage } from "./common.js";
66

77
export const portal = new Xdp.Portal();
88

9-
export const settings = new Gio.Settings({
10-
schema_id: pkg.name,
11-
path: "/re/sonny/Workbench/",
12-
});
9+
export let settings;
10+
11+
try {
12+
settings = new Gio.Settings({
13+
schema_id: pkg.name,
14+
path: "/re/sonny/Workbench/",
15+
});
16+
} catch (error) {
17+
console.error("An error occurred while creating Gio.Settings: ", error);
18+
// Handle the error or set a default value to settings
19+
settings = null;
20+
}
1321

1422
export const data_dir = Gio.File.new_for_path(
1523
GLib.build_filenamev([GLib.get_user_data_dir(), pkg.name]),

0 commit comments

Comments
 (0)