Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Rust demos with clippy #897

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
63 changes: 19 additions & 44 deletions src/cli/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions src/langs/rust/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
);
Expand Down
16 changes: 12 additions & 4 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
Loading