Skip to content

Commit

Permalink
Move lang specific code to src/langs
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Dec 4, 2022
1 parent 8e630f8 commit 1f80777
Show file tree
Hide file tree
Showing 18 changed files with 275 additions and 202 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"editor.defaultFormatter": "rome.rome"
},
"vala.languageServerPath": "/home/sonny/Projects/Workbench/.flatpak/vala-language-server.sh",
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"mesonbuild.configureOnOpen": false,
"mesonbuild.buildFolder": "_build",
"mesonbuild.mesonPath": "/home/sonny/Projects/Workbench/.flatpak/meson.sh"
Expand Down
7 changes: 7 additions & 0 deletions data/app.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
</screenshots>
<content_rating type="oars-1.1" />
<releases>
<release version="43.2" date="2022-12-xx">
<description>
<ul>
<li>Add support for JavaScript diagnostics</li>
</ul>
</description>
</release>
<release version="43.2" date="2022-11-20">
<description>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import nodePolyfills from "rollup-plugin-node-polyfills";

export default [
{
input: "src/ltx.js",
input: "src/langs/xml/ltx.js",
output: {
file: "src/lib/ltx.js",
},
Expand Down
4 changes: 2 additions & 2 deletions src/PanelCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import GObject from "gi://GObject";

import { settings } from "./util.js";

import { setup as setupVala } from "./langs/vala.js";
import { setup as setupJavaScript } from "./langs/javascript.js";
import { setup as setupVala } from "./langs/vala/vala.js";
import { setup as setupJavaScript } from "./langs/javascript/javascript.js";

export default function PanelCode({ builder, previewer, data_dir }) {
const panel_code = builder.get_object("panel_code");
Expand Down
152 changes: 9 additions & 143 deletions src/PanelUI.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Gio from "gi://Gio";
import GObject from "gi://GObject";
import GLib from "gi://GLib";
import Gtk from "gi://Gtk";

import LSPClient from "./lsp/LSPClient.js";
import { LSPError } from "./lsp/LSP.js";
import {
getLanguage,
Expand All @@ -12,17 +10,15 @@ import {
disconnect_signals,
replaceBufferText,
unstack,
handleDiagnostics,
prepareSourceView,
} from "./util.js";

import { getPid, once } from "../troll/src/util.js";
import WorkbenchHoverProvider from "./WorkbenchHoverProvider.js";
import {
setup as setupBlueprint,
logBlueprintError,
} from "./langs/blueprint/blueprint.js";

const { addSignalMethods } = imports.signals;

const SYSLOG_IDENTIFIER = pkg.name;

export default function PanelUI({
application,
builder,
Expand All @@ -38,19 +34,6 @@ export default function PanelUI({

const buffer_blueprint = getLanguage("blueprint").document.buffer;
const buffer_xml = getLanguage("xml").document.buffer;
const provider = new WorkbenchHoverProvider();

const blueprint = createBlueprintClient({
data_dir,
buffer: buffer_blueprint,
provider,
});

let document_version = 0;
prepareSourceView({
source_view: getLanguage("blueprint").document.source_view,
provider,
});

const button_ui = builder.get_object("button_ui");
const panel_ui = builder.get_object("panel_ui");
Expand All @@ -69,11 +52,13 @@ export default function PanelUI({
// flat does nothing on GtkDropdown or GtkComboBox or GtkComboBoxText
dropdown_ui_lang.get_first_child().get_style_context().add_class("flat");

const { compile, decompile } = setupBlueprint({ data_dir });

async function convertToXML() {
term_console.clear();
settings.set_boolean("show-console", true);

const xml = await compileBlueprint(buffer_blueprint.text);
const xml = await compile();
replaceBufferText(buffer_xml, xml);
settings.set_int("ui-language", 0);
}
Expand All @@ -89,7 +74,7 @@ export default function PanelUI({
let blp;

try {
blp = await decompileXML(buffer_xml.text);
blp = await decompile(buffer_xml.text);
} catch (err) {
if (err instanceof LSPError) {
logBlueprintError(err);
Expand Down Expand Up @@ -150,7 +135,7 @@ export default function PanelUI({
if (lang.id === "xml") {
xml = lang.document.buffer.text;
} else {
xml = await compileBlueprint(lang.document.buffer.text);
xml = await compile();
}
panel.xml = xml || "";
panel.emit("updated");
Expand Down Expand Up @@ -181,129 +166,10 @@ export default function PanelUI({

start();

const uri = "workbench://state.blp";

async function setupLSP() {
if (blueprint.proc) return;
blueprint.start();

// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize
await blueprint.request("initialize", {
processId: getPid(),
clientInfo: {
name: pkg.name,
version: pkg.version,
},
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#clientCapabilities
capabilities: {
textDocument: {
publishDiagnostics: {},
"x-blueprintcompiler/publishCompiled": {},
},
},
locale: "en",
});

await blueprint.notify("textDocument/didOpen", {
textDocument: {
uri,
languageId: "blueprint",
version: ++document_version,
text: buffer_blueprint.text,
},
});
}

async function compileBlueprint() {
await setupLSP();

await blueprint.notify("textDocument/didChange", {
textDocument: {
uri,
version: ++document_version,
},
contentChanges: [buffer_blueprint.text],
});

const [{ xml }] = await once(
blueprint,
"notification::textDocument/x-blueprintcompiler/publishCompiled",
);

return xml;
}

async function decompileXML(text) {
await setupLSP();

const { blp } = await blueprint.request("x-blueprintcompiler/decompile", {
text,
});
return blp;
}

panel.start = start;
panel.stop = stop;
panel.update = update;
panel.panel = panel_ui;

return panel;
}

function logBlueprintError(err) {
GLib.log_structured("Blueprint", GLib.LogLevelFlags.LEVEL_CRITICAL, {
MESSAGE: `${err.message}`,
SYSLOG_IDENTIFIER,
});
}

// function logBlueprintInfo(info) {
// GLib.log_structured("Blueprint", GLib.LogLevelFlags.LEVEL_WARNING, {
// MESSAGE: `${info.line + 1}:${info.col} ${info.message}`,
// SYSLOG_IDENTIFIER,
// });
// }

function createBlueprintClient({ data_dir, buffer, provider }) {
const file_blueprint_logs = Gio.File.new_for_path(
GLib.build_filenamev([data_dir, "blueprint-logs"]),
);
file_blueprint_logs.replace_contents(
" ",
null,
false,
Gio.FileCreateFlags.REPLACE_DESTINATION,
null,
);
const blueprint = new LSPClient([
// "/home/sonny/Projects/Workbench/blueprint-compiler/blueprint-compiler.py",
// "/app/bin/blueprint-compiler",
"blueprint-compiler",
"lsp",
"--logfile",
file_blueprint_logs.get_path(),
]);
blueprint.connect("exit", () => {
console.debug("blueprint exit");
});
blueprint.connect("output", (_self, message) => {
console.debug(`blueprint OUT:\n${JSON.stringify(message)}`);
});
blueprint.connect("input", (_self, message) => {
console.debug(`blueprint IN:\n${JSON.stringify(message)}`);
});

blueprint.connect(
"notification::textDocument/publishDiagnostics",
(_self, { diagnostics }) => {
handleDiagnostics({
language: "Blueprint",
diagnostics,
buffer,
provider,
});
},
);

return blueprint;
}
2 changes: 1 addition & 1 deletion src/Previewer/Previewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import GObject from "gi://GObject";
import GLib from "gi://GLib";
import Gio from "gi://Gio";

import * as xml from "../xml.js";
import * as xml from "../langs/xml/xml.js";
import * as postcss from "../lib/postcss.js";

import {
Expand Down
2 changes: 1 addition & 1 deletion src/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ function getValaVersion() {

function getBlueprintVersion() {
// https://gitlab.gnome.org/jwestman/blueprint-compiler/-/issues/61
return "Blueprint 0.4.0-Workbench";
return "Blueprint 0.6.0-Workbench";
}
Loading

0 comments on commit 1f80777

Please sign in to comment.