From 82fde43267f2a7ea8534cbf29dfcd672bb833a2d Mon Sep 17 00:00:00 2001 From: Julian Hofer Date: Sun, 25 Feb 2024 10:54:12 +0100 Subject: [PATCH] Test Rust demos with clippy --- Makefile | 4 +-- package.json | 4 +-- src/cli/main.js | 63 ++++++++++++-------------------------- src/langs/rust/Compiler.js | 5 +-- src/util.js | 16 +++++++--- 5 files changed, 37 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index d3649e47f..a09533927 100644 --- a/Makefile +++ b/Makefile @@ -51,8 +51,8 @@ unit: test: unit lint ./build-aux/fun workbench-cli ci demos/demos/Welcome -ci: setup test - ./build-aux/fun workbench-cli ci demos/demos/** +ci: setup + ./build-aux/fun workbench-cli ci demos/demos/* # Note that if you have Sdk extensions installed they will be used # make sure to test without the sdk extensions installed diff --git a/package.json b/package.json index a6eec53e9..d0fd6ce6b 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,7 @@ "rollup-plugin-node-polyfills": "^0.2.1" }, "type": "module", - "scripts": { - "prepare": "husky install" - }, + "scripts": {}, "lint-staged": { "*.{json,md,yaml,yml}": "prettier --write", "*.{js,cjs,mjs}": "eslint --fix", diff --git a/src/cli/main.js b/src/cli/main.js index 565ea02ab..216af0f8d 100644 --- a/src/cli/main.js +++ b/src/cli/main.js @@ -12,6 +12,9 @@ import { createLSPClient, languages, getLanguage } from "../common.js"; import lint, { waitForDiagnostics } from "./lint.js"; import format, { formatting } from "./format.js"; +import { setupRustProject, installRustLibraries } from "../langs/rust/rust.js"; +import { targetPath } from "../langs/rust/Compiler.js"; + Gtk.init(); export async function main([action, ...args]) { @@ -399,51 +402,23 @@ async function ci({ filenames, current_dir }) { const file_rust = demo_dir.get_child("code.rs"); if (file_rust.query_exists(null)) { - print(` ${file_rust.get_path()}`); - - const uri = file_rust.get_uri(); - const languageId = "rust"; - let version = 0; - - const [contents] = await file_rust.load_contents_async(null); - const text = new TextDecoder().decode(contents); - - await lsp_clients.rust._notify("textDocument/didOpen", { - textDocument: { - uri, - languageId, - version: version++, - text, - }, - }); - - // FIXME: rust analyzer doesn't publish diagnostics if there are none - // probably we should switch to pulling diagnostics but unknown if supported - // https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_pullDiagnostics - - // const diagnostics = await waitForDiagnostics({ - // uri, - // lspc: lsp_clients.rust, - // }); - // if (diagnostics.length > 0) { - // printerr(serializeDiagnostics({ diagnostics })); - // return false; - // } - // print(` ✅ lints`); - - const checks = await checkFile({ - lspc: lsp_clients.rust, - file: file_rust, - lang: getLanguage("rust"), - uri, - }); + await setupRustProject(demo_dir); + await installRustLibraries(demo_dir); + const cargo_launcher = new Gio.SubprocessLauncher(); + cargo_launcher.set_cwd(demo_dir.get_path()); + const cargo = cargo_launcher.spawnv([ + "cargo", + "clippy", + "--locked", + "--verbose", + "--target-dir", + targetPath, + ]); + await cargo.wait_async(null); + + const checks = cargo.get_successful(); + cargo_launcher.close(); if (!checks) return false; - - await lsp_clients.rust._notify("textDocument/didClose", { - textDocument: { - uri, - }, - }); } await Promise.all( diff --git a/src/langs/rust/Compiler.js b/src/langs/rust/Compiler.js index 1daf8ca27..fa51aa15c 100644 --- a/src/langs/rust/Compiler.js +++ b/src/langs/rust/Compiler.js @@ -4,10 +4,11 @@ import dbus_previewer from "../../Previewer/DBusPreviewer.js"; import { decode, encode } from "../../util.js"; import { installRustLibraries } from "./rust.js"; +const cacheDir = GLib.get_user_cache_dir(); +export const targetPath = `${cacheDir}/rust_build_cache`; + export default function Compiler({ session }) { const { file } = session; - const cacheDir = GLib.get_user_cache_dir(); - const targetPath = `${cacheDir}/rust_build_cache`; const rustcVersionFile = Gio.File.new_for_path( `${targetPath}/rustc_version.txt`, ); diff --git a/src/util.js b/src/util.js index 6cb61bfe4..dd3944410 100644 --- a/src/util.js +++ b/src/util.js @@ -6,10 +6,18 @@ import { getLanguage } from "./common.js"; export const portal = new Xdp.Portal(); -export const settings = new Gio.Settings({ - schema_id: pkg.name, - path: "/re/sonny/Workbench/", -}); +export let settings; + +try { + settings = new Gio.Settings({ + schema_id: pkg.name, + path: "/re/sonny/Workbench/", + }); +} catch (error) { + console.error("An error occurred while creating Gio.Settings: ", error); + // Handle the error or set a default value to settings + settings = null; +} export const data_dir = Gio.File.new_for_path( GLib.build_filenamev([GLib.get_user_data_dir(), pkg.name]),