Skip to content

Commit 1f80777

Browse files
committed
Move lang specific code to src/langs
1 parent 8e630f8 commit 1f80777

File tree

18 files changed

+275
-202
lines changed

18 files changed

+275
-202
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"editor.defaultFormatter": "rome.rome"
1919
},
2020
"vala.languageServerPath": "/home/sonny/Projects/Workbench/.flatpak/vala-language-server.sh",
21+
"[json]": {
22+
"editor.defaultFormatter": "vscode.json-language-features"
23+
},
2124
"mesonbuild.configureOnOpen": false,
2225
"mesonbuild.buildFolder": "_build",
2326
"mesonbuild.mesonPath": "/home/sonny/Projects/Workbench/.flatpak/meson.sh"

data/app.metainfo.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
</screenshots>
4747
<content_rating type="oars-1.1" />
4848
<releases>
49+
<release version="43.2" date="2022-12-xx">
50+
<description>
51+
<ul>
52+
<li>Add support for JavaScript diagnostics</li>
53+
</ul>
54+
</description>
55+
</release>
4956
<release version="43.2" date="2022-11-20">
5057
<description>
5158
<ul>

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import nodePolyfills from "rollup-plugin-node-polyfills";
55

66
export default [
77
{
8-
input: "src/ltx.js",
8+
input: "src/langs/xml/ltx.js",
99
output: {
1010
file: "src/lib/ltx.js",
1111
},

src/PanelCode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import GObject from "gi://GObject";
33

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

6-
import { setup as setupVala } from "./langs/vala.js";
7-
import { setup as setupJavaScript } from "./langs/javascript.js";
6+
import { setup as setupVala } from "./langs/vala/vala.js";
7+
import { setup as setupJavaScript } from "./langs/javascript/javascript.js";
88

99
export default function PanelCode({ builder, previewer, data_dir }) {
1010
const panel_code = builder.get_object("panel_code");

src/PanelUI.js

Lines changed: 9 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import Gio from "gi://Gio";
22
import GObject from "gi://GObject";
3-
import GLib from "gi://GLib";
43
import Gtk from "gi://Gtk";
54

6-
import LSPClient from "./lsp/LSPClient.js";
75
import { LSPError } from "./lsp/LSP.js";
86
import {
97
getLanguage,
@@ -12,17 +10,15 @@ import {
1210
disconnect_signals,
1311
replaceBufferText,
1412
unstack,
15-
handleDiagnostics,
16-
prepareSourceView,
1713
} from "./util.js";
1814

19-
import { getPid, once } from "../troll/src/util.js";
20-
import WorkbenchHoverProvider from "./WorkbenchHoverProvider.js";
15+
import {
16+
setup as setupBlueprint,
17+
logBlueprintError,
18+
} from "./langs/blueprint/blueprint.js";
2119

2220
const { addSignalMethods } = imports.signals;
2321

24-
const SYSLOG_IDENTIFIER = pkg.name;
25-
2622
export default function PanelUI({
2723
application,
2824
builder,
@@ -38,19 +34,6 @@ export default function PanelUI({
3834

3935
const buffer_blueprint = getLanguage("blueprint").document.buffer;
4036
const buffer_xml = getLanguage("xml").document.buffer;
41-
const provider = new WorkbenchHoverProvider();
42-
43-
const blueprint = createBlueprintClient({
44-
data_dir,
45-
buffer: buffer_blueprint,
46-
provider,
47-
});
48-
49-
let document_version = 0;
50-
prepareSourceView({
51-
source_view: getLanguage("blueprint").document.source_view,
52-
provider,
53-
});
5437

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

55+
const { compile, decompile } = setupBlueprint({ data_dir });
56+
7257
async function convertToXML() {
7358
term_console.clear();
7459
settings.set_boolean("show-console", true);
7560

76-
const xml = await compileBlueprint(buffer_blueprint.text);
61+
const xml = await compile();
7762
replaceBufferText(buffer_xml, xml);
7863
settings.set_int("ui-language", 0);
7964
}
@@ -89,7 +74,7 @@ export default function PanelUI({
8974
let blp;
9075

9176
try {
92-
blp = await decompileXML(buffer_xml.text);
77+
blp = await decompile(buffer_xml.text);
9378
} catch (err) {
9479
if (err instanceof LSPError) {
9580
logBlueprintError(err);
@@ -150,7 +135,7 @@ export default function PanelUI({
150135
if (lang.id === "xml") {
151136
xml = lang.document.buffer.text;
152137
} else {
153-
xml = await compileBlueprint(lang.document.buffer.text);
138+
xml = await compile();
154139
}
155140
panel.xml = xml || "";
156141
panel.emit("updated");
@@ -181,129 +166,10 @@ export default function PanelUI({
181166

182167
start();
183168

184-
const uri = "workbench://state.blp";
185-
186-
async function setupLSP() {
187-
if (blueprint.proc) return;
188-
blueprint.start();
189-
190-
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize
191-
await blueprint.request("initialize", {
192-
processId: getPid(),
193-
clientInfo: {
194-
name: pkg.name,
195-
version: pkg.version,
196-
},
197-
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#clientCapabilities
198-
capabilities: {
199-
textDocument: {
200-
publishDiagnostics: {},
201-
"x-blueprintcompiler/publishCompiled": {},
202-
},
203-
},
204-
locale: "en",
205-
});
206-
207-
await blueprint.notify("textDocument/didOpen", {
208-
textDocument: {
209-
uri,
210-
languageId: "blueprint",
211-
version: ++document_version,
212-
text: buffer_blueprint.text,
213-
},
214-
});
215-
}
216-
217-
async function compileBlueprint() {
218-
await setupLSP();
219-
220-
await blueprint.notify("textDocument/didChange", {
221-
textDocument: {
222-
uri,
223-
version: ++document_version,
224-
},
225-
contentChanges: [buffer_blueprint.text],
226-
});
227-
228-
const [{ xml }] = await once(
229-
blueprint,
230-
"notification::textDocument/x-blueprintcompiler/publishCompiled",
231-
);
232-
233-
return xml;
234-
}
235-
236-
async function decompileXML(text) {
237-
await setupLSP();
238-
239-
const { blp } = await blueprint.request("x-blueprintcompiler/decompile", {
240-
text,
241-
});
242-
return blp;
243-
}
244-
245169
panel.start = start;
246170
panel.stop = stop;
247171
panel.update = update;
248172
panel.panel = panel_ui;
249173

250174
return panel;
251175
}
252-
253-
function logBlueprintError(err) {
254-
GLib.log_structured("Blueprint", GLib.LogLevelFlags.LEVEL_CRITICAL, {
255-
MESSAGE: `${err.message}`,
256-
SYSLOG_IDENTIFIER,
257-
});
258-
}
259-
260-
// function logBlueprintInfo(info) {
261-
// GLib.log_structured("Blueprint", GLib.LogLevelFlags.LEVEL_WARNING, {
262-
// MESSAGE: `${info.line + 1}:${info.col} ${info.message}`,
263-
// SYSLOG_IDENTIFIER,
264-
// });
265-
// }
266-
267-
function createBlueprintClient({ data_dir, buffer, provider }) {
268-
const file_blueprint_logs = Gio.File.new_for_path(
269-
GLib.build_filenamev([data_dir, "blueprint-logs"]),
270-
);
271-
file_blueprint_logs.replace_contents(
272-
" ",
273-
null,
274-
false,
275-
Gio.FileCreateFlags.REPLACE_DESTINATION,
276-
null,
277-
);
278-
const blueprint = new LSPClient([
279-
// "/home/sonny/Projects/Workbench/blueprint-compiler/blueprint-compiler.py",
280-
// "/app/bin/blueprint-compiler",
281-
"blueprint-compiler",
282-
"lsp",
283-
"--logfile",
284-
file_blueprint_logs.get_path(),
285-
]);
286-
blueprint.connect("exit", () => {
287-
console.debug("blueprint exit");
288-
});
289-
blueprint.connect("output", (_self, message) => {
290-
console.debug(`blueprint OUT:\n${JSON.stringify(message)}`);
291-
});
292-
blueprint.connect("input", (_self, message) => {
293-
console.debug(`blueprint IN:\n${JSON.stringify(message)}`);
294-
});
295-
296-
blueprint.connect(
297-
"notification::textDocument/publishDiagnostics",
298-
(_self, { diagnostics }) => {
299-
handleDiagnostics({
300-
language: "Blueprint",
301-
diagnostics,
302-
buffer,
303-
provider,
304-
});
305-
},
306-
);
307-
308-
return blueprint;
309-
}

src/Previewer/Previewer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import GObject from "gi://GObject";
33
import GLib from "gi://GLib";
44
import Gio from "gi://Gio";
55

6-
import * as xml from "../xml.js";
6+
import * as xml from "../langs/xml/xml.js";
77
import * as postcss from "../lib/postcss.js";
88

99
import {

src/about.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ function getValaVersion() {
7171

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

0 commit comments

Comments
 (0)