Skip to content

Commit 8e630f8

Browse files
committed
Use Rome language server for JavaScript
Rome is a linter and formatter. It is very young but it supports TypeScript, CSS support is planned and it will be a compiler too. Hopefully it will reduce the amount of tooling necessary in Workbench. https://rome.tools/
1 parent 4c1f9fe commit 8e630f8

File tree

8 files changed

+359
-124
lines changed

8 files changed

+359
-124
lines changed

re.sonny.Workbench.Devel.json

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
{
3636
"name": "libportal",
3737
"buildsystem": "meson",
38-
"config-opts": ["-Ddocs=false", "-Dvapi=false", "-Dbackends=gtk4"],
38+
"config-opts": [
39+
"-Ddocs=false",
40+
"-Dvapi=false",
41+
"-Dbackends=gtk4"
42+
],
3943
"sources": [
4044
{
4145
"type": "archive",
@@ -62,7 +66,6 @@
6266
{
6367
"type": "git",
6468
"url": "https://github.com/vala-lang/vala-language-server/",
65-
"branch": "master",
6669
"commit": "bf978c0cda97cff946f355477ec8da08b1cb4e5e"
6770
}
6871
],
@@ -112,11 +115,39 @@
112115
}
113116
]
114117
},
118+
{
119+
"name": "rome",
120+
"buildsystem": "simple",
121+
"build-commands": [
122+
"chmod +x rome",
123+
"cp rome /app/bin/rome"
124+
],
125+
"sources": [
126+
{
127+
"type": "archive",
128+
"only-arches": [
129+
"aarch64"
130+
],
131+
"url": "https://registry.npmjs.org/@rometools/cli-linux-arm64/-/cli-linux-arm64-10.0.1.tgz",
132+
"sha512": "2658d9b27b9dd4a09f7b7e9536c561fcbad8740ce06ca6dcb024f37828d6f513a4332363f29990fe021417167e3f284c160a301c80c68a1a0d7f89bea60a7190"
133+
},
134+
{
135+
"type": "archive",
136+
"only-arches": [
137+
"x86_64"
138+
],
139+
"url": "https://registry.npmjs.org/@rometools/cli-linux-x64/-/cli-linux-x64-10.0.1.tgz",
140+
"sha512": "8d722a77d883c9951ec64eb70917c05c3038ccd0d41e912b52609e8e319a6f77610edd4a038d1f0ea29bfa4c59a40858ded42858d48d432a3be74cd7e4d6b02f"
141+
}
142+
]
143+
},
115144
{
116145
"name": "Workbench",
117146
"buildsystem": "meson",
118147
"builddir": true,
119-
"config-opts": ["-Dprofile=development"],
148+
"config-opts": [
149+
"-Dprofile=development"
150+
],
120151
"sources": [
121152
{
122153
"type": "dir",

re.sonny.Workbench.json

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
{
3636
"name": "libportal",
3737
"buildsystem": "meson",
38-
"config-opts": ["-Ddocs=false", "-Dvapi=false", "-Dbackends=gtk4"],
38+
"config-opts": [
39+
"-Ddocs=false",
40+
"-Dvapi=false",
41+
"-Dbackends=gtk4"
42+
],
3943
"sources": [
4044
{
4145
"type": "archive",
@@ -63,7 +67,6 @@
6367
{
6468
"type": "git",
6569
"url": "https://github.com/vala-lang/vala-language-server/",
66-
"branch": "master",
6770
"commit": "bf978c0cda97cff946f355477ec8da08b1cb4e5e"
6871
}
6972
],
@@ -113,11 +116,39 @@
113116
}
114117
]
115118
},
119+
{
120+
"name": "rome",
121+
"buildsystem": "simple",
122+
"build-commands": [
123+
"chmod +x rome",
124+
"cp rome /app/bin/rome"
125+
],
126+
"sources": [
127+
{
128+
"type": "archive",
129+
"only-arches": [
130+
"aarch64"
131+
],
132+
"url": "https://registry.npmjs.org/@rometools/cli-linux-arm64/-/cli-linux-arm64-10.0.1.tgz",
133+
"sha512": "2658d9b27b9dd4a09f7b7e9536c561fcbad8740ce06ca6dcb024f37828d6f513a4332363f29990fe021417167e3f284c160a301c80c68a1a0d7f89bea60a7190"
134+
},
135+
{
136+
"type": "archive",
137+
"only-arches": [
138+
"x86_64"
139+
],
140+
"url": "https://registry.npmjs.org/@rometools/cli-linux-x64/-/cli-linux-x64-10.0.1.tgz",
141+
"sha512": "8d722a77d883c9951ec64eb70917c05c3038ccd0d41e912b52609e8e319a6f77610edd4a038d1f0ea29bfa4c59a40858ded42858d48d432a3be74cd7e4d6b02f"
142+
}
143+
]
144+
},
116145
{
117146
"name": "Workbench",
118147
"buildsystem": "meson",
119148
"builddir": true,
120-
"config-opts": ["-Dprofile=default"],
149+
"config-opts": [
150+
"-Dprofile=default"
151+
],
121152
"sources": [
122153
{
123154
"type": "dir",

rome.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
{
22
"formatter": {
33
"enabled": true,
4-
"ignore": ["icon-development-kit-www", ".flatpak", "src/lib", "troll"],
4+
"ignore": [
5+
"icon-development-kit-www",
6+
".flatpak",
7+
"src/lib",
8+
"troll"
9+
],
510
"indentStyle": "space",
611
"indentSize": 2
712
},
813
"linter": {
914
"enabled": true,
10-
"ignore": ["icon-development-kit-www", ".flatpak", "src/lib", "troll"],
15+
"ignore": [
16+
"icon-development-kit-www",
17+
".flatpak",
18+
"src/lib",
19+
"troll"
20+
],
1121
"rules": {
1222
"recommended": true,
1323
"correctness": {

src/PanelCode.js

Lines changed: 4 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
import Gio from "gi://Gio";
2-
import GLib from "gi://GLib";
32
import GObject from "gi://GObject";
43

5-
import LSPClient from "./lsp/LSPClient.js";
4+
import { settings } from "./util.js";
65

7-
import {
8-
getLanguage,
9-
settings,
10-
prepareSourceView,
11-
handleDiagnostics,
12-
} from "./util.js";
13-
import WorkbenchHoverProvider from "./WorkbenchHoverProvider.js";
14-
import { getPid } from "../troll/src/util.js";
6+
import { setup as setupVala } from "./langs/vala.js";
7+
import { setup as setupJavaScript } from "./langs/javascript.js";
158

169
export default function PanelCode({ builder, previewer, data_dir }) {
1710
const panel_code = builder.get_object("panel_code");
@@ -49,6 +42,7 @@ export default function PanelCode({ builder, previewer, data_dir }) {
4942
};
5043

5144
setupVala({ data_dir });
45+
setupJavaScript({ data_dir });
5246

5347
function switchLanguage() {
5448
panel.language = dropdown_code_lang.selected_item.string;
@@ -60,102 +54,3 @@ export default function PanelCode({ builder, previewer, data_dir }) {
6054

6155
return panel;
6256
}
63-
64-
function setupVala({ data_dir }) {
65-
const buffer_vala = getLanguage("vala").document.buffer;
66-
const state_file = getLanguage("vala").document.file;
67-
const provider = new WorkbenchHoverProvider();
68-
69-
const api_file = Gio.File.new_for_path(
70-
GLib.build_filenamev([pkg.pkgdatadir, "workbench-api.vala"]),
71-
);
72-
73-
let document_version = 0;
74-
prepareSourceView({
75-
source_view: getLanguage("vala").document.source_view,
76-
provider,
77-
});
78-
79-
const vls = createVLSClient({
80-
buffer: buffer_vala,
81-
provider,
82-
});
83-
84-
async function setupLSP() {
85-
if (vls.proc) return;
86-
vls.start();
87-
88-
api_file.copy(
89-
Gio.File.new_for_path(data_dir).get_child("workbench.vala"),
90-
Gio.FileCopyFlags.OVERWRITE,
91-
null,
92-
null,
93-
);
94-
95-
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize
96-
await vls.request("initialize", {
97-
processId: getPid(),
98-
clientInfo: {
99-
name: "re.sonny.Workbench",
100-
version: pkg.name,
101-
},
102-
rootPath: data_dir,
103-
rootUri: Gio.File.new_for_path(data_dir).get_uri(),
104-
});
105-
106-
await vls.notify("textDocument/didOpen", {
107-
textDocument: {
108-
uri: state_file.get_uri(),
109-
languageId: "vala",
110-
version: ++document_version,
111-
text: buffer_vala.text,
112-
},
113-
});
114-
}
115-
setupLSP().catch(logError);
116-
117-
function createVLSClient({ buffer, provider }) {
118-
const vls = new LSPClient([
119-
// "/usr/lib/sdk/vala/bin/vala-language-server",
120-
"vala-language-server",
121-
]);
122-
vls.connect("exit", () => {
123-
console.debug("vls exit");
124-
});
125-
vls.connect("output", (_self, message) => {
126-
console.debug(`vls OUT:\n${JSON.stringify(message)}`);
127-
});
128-
vls.connect("input", (_self, message) => {
129-
console.debug(`vls IN:\n${JSON.stringify(message)}`);
130-
});
131-
132-
vls.connect(
133-
"notification::textDocument/publishDiagnostics",
134-
(_self, { diagnostics, uri }) => {
135-
if (!state_file.equal(Gio.File.new_for_uri(uri))) {
136-
return;
137-
}
138-
handleDiagnostics({ language: "Vala", diagnostics, buffer, provider });
139-
},
140-
);
141-
142-
buffer.connect("modified-changed", () => {
143-
if (!buffer.get_modified()) return;
144-
updateVLS().catch(logError);
145-
});
146-
147-
return vls;
148-
}
149-
150-
async function updateVLS() {
151-
await setupLSP();
152-
153-
await vls.notify("textDocument/didChange", {
154-
textDocument: {
155-
uri: state_file.get_uri(),
156-
version: ++document_version,
157-
},
158-
contentChanges: [{ text: buffer_vala.text }],
159-
});
160-
}
161-
}

0 commit comments

Comments
 (0)