Skip to content
Merged
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
73 changes: 61 additions & 12 deletions src/cli/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import Gio from "gi://Gio";
import Gtk from "gi://Gtk";
import Adw from "gi://Adw";

import { createLSPClient, languages } from "../common.js";
import { createLSPClient, languages, getLanguage } from "../common.js";
import lint, { waitForDiagnostics } from "./lint.js";
import format from "./format.js";
import format, { formatting } from "./format.js";

Gtk.init();

Expand Down Expand Up @@ -90,6 +90,27 @@ function createLSPClients({ root_uri }) {
);
}

async function checkFile({ lspc, file, lang, uri }) {
const [contents] = await file.load_contents_async(null);
const text = new TextDecoder().decode(contents);
const buffer = new Gtk.TextBuffer({ text });

const buffer_tmp = new Gtk.TextBuffer({ text: buffer.text });
await formatting({ buffer: buffer_tmp, uri, lang, lspc });

if (buffer_tmp.text === buffer.text) {
print(` ✅ checks`);
return true;
} else {
printerr(
` ❌ formatting differs - open and run ${file
.get_parent()
.get_basename()} with Workbench to fix`,
);
return false;
}
}

async function ci({ filenames, current_dir }) {
for (const filename of filenames) {
const demo_dir = Gio.File.new_for_path(filename);
Expand Down Expand Up @@ -158,7 +179,6 @@ async function ci({ filenames, current_dir }) {
print(` ✅ compiles`);

try {
// const { blp } =
await lsp_clients.blueprint._request("x-blueprint/decompile", {
text: xml,
});
Expand All @@ -175,14 +195,22 @@ async function ci({ filenames, current_dir }) {
) {
throw err;
}

await lsp_clients.blueprint._notify("textDocument/didClose", {
textDocument: {
uri,
},
});
}

const checks = await checkFile({
lspc: lsp_clients.blueprint,
file: file_blueprint,
lang: getLanguage("blueprint"),
uri,
});
if (!checks) return false;

await lsp_clients.blueprint._notify("textDocument/didClose", {
textDocument: {
uri,
},
});

const tree = parse(xml);
const template_el = tree.getChild("template");

Expand Down Expand Up @@ -223,9 +251,16 @@ async function ci({ filenames, current_dir }) {
printerr(serializeDiagnostics({ diagnostics }));
return false;
}

print(` ✅ lints`);

const checks = await checkFile({
lspc: lsp_clients.css,
file: file_css,
lang: getLanguage("css"),
uri,
});
if (!checks) return false;

await lsp_clients.css._notify("textDocument/didClose", {
textDocument: {
uri,
Expand Down Expand Up @@ -261,9 +296,16 @@ async function ci({ filenames, current_dir }) {
printerr(serializeDiagnostics({ diagnostics }));
return false;
}

print(` ✅ lints`);

const checks = await checkFile({
lspc: lsp_clients.javascript,
file: file_javascript,
lang: getLanguage("javascript"),
uri,
});
if (!checks) return false;

const js_object_ids = getCodeObjectIds(text);
for (const object_id of js_object_ids) {
if (!blueprint_object_ids.includes(object_id)) {
Expand Down Expand Up @@ -341,9 +383,16 @@ async function ci({ filenames, current_dir }) {
printerr(serializeDiagnostics({ diagnostics }));
return false;
}

print(` ✅ lints`);

const checks = await checkFile({
lspc: lsp_clients.vala,
file: file_vala,
lang: getLanguage("vala"),
uri,
});
if (!checks) return false;

await lsp_clients.vala._notify("textDocument/didClose", {
textDocument: {
uri,
Expand Down
10 changes: 5 additions & 5 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ export const languages = [
index: 3,
},
];
if (!GLib.getenv("FLATPAK_ID")) {
languages.forEach((lang) => {
if (!lang.language_server) return;
lang.language_server = ["./build-aux/fun", ...lang.language_server];
});

export function getLanguage(id) {
return languages.find(
(language) => language.id.toLowerCase() === id.toLowerCase(),
);
}

export function createLSPClient({ lang, root_uri }) {
Expand Down
8 changes: 2 additions & 6 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import GLib from "gi://GLib";
import Gio from "gi://Gio";
import Xdp from "gi://Xdp";
import GObject from "gi://GObject";
import { languages } from "./common.js";
import { getLanguage } from "./common.js";

export const portal = new Xdp.Portal();

Expand Down Expand Up @@ -38,11 +38,7 @@ export function getFlatpakInfo() {
return keyFile;
}

export function getLanguage(id) {
return languages.find(
(language) => language.id.toLowerCase() === id.toLowerCase(),
);
}
export { getLanguage };

export function listenProperty(object, property, fn, { initial = false } = {}) {
if (initial) {
Expand Down