diff --git a/.gitmodules b/.gitmodules index 0f4a5ee60..02339e69e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,6 +8,6 @@ path = blueprint-compiler url = https://gitlab.gnome.org/jwestman/blueprint-compiler.git [submodule "src/langs/typescript/template/gi-types"] - path = src/langs/typescript/gi-types + path = gi-types url = https://gitlab.gnome.org/BrainBlasted/gi-typescript-definitions.git branch = nightly diff --git a/Makefile b/Makefile index 1def6fedc..6822a86ff 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,9 @@ SHELL:=/bin/bash -O globstar setup: flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo - flatpak install --or-update --user --noninteractive flathub org.gnome.Sdk//46 org.flatpak.Builder org.freedesktop.Sdk.Extension.rust-stable//23.08 org.freedesktop.Sdk.Extension.vala//23.08 org.freedesktop.Sdk.Extension.llvm18//23.08 org.freedesktop.Sdk.Extension.node20//23.08 org.freedesktop.Sdk.Extension.typescript//23.08 + flatpak install --or-update --user --noninteractive flathub org.gnome.Sdk//46 org.flatpak.Builder org.freedesktop.Sdk.Extension.rust-stable//23.08 org.freedesktop.Sdk.Extension.vala//23.08 org.freedesktop.Sdk.Extension.llvm18//23.08 org.freedesktop.Sdk.Extension.node18//23.08 org.freedesktop.Sdk.Extension.typescript//23.08 # flatpak remote-add --user --if-not-exists flathub-beta https://flathub.org/beta-repo/flathub-beta.flatpakrepo -# flatpak install --or-update --user --noninteractive flathub-beta org.freedesktop.Sdk.Extension.rust-stable//24.08beta org.freedesktop.Sdk.Extension.vala//24.08beta org.freedesktop.Sdk.Extension.llvm18//24.08beta org.freedesktop.Sdk.Extension.node20//24.08beta org.freedesktop.Sdk.Extension.typescript//24.08beta +# flatpak install --or-update --user --noninteractive flathub-beta org.freedesktop.Sdk.Extension.rust-stable//24.08beta org.freedesktop.Sdk.Extension.vala//24.08beta org.freedesktop.Sdk.Extension.llvm18//24.08beta org.freedesktop.Sdk.Extension.node18//24.08beta org.freedesktop.Sdk.Extension.typescript//24.08beta # flatpak remote-add --user --if-not-exists gnome-nightly https://nightly.gnome.org/gnome-nightly.flatpakrepo # flatpak install --or-update --user --noninteractive gnome-nightly org.gnome.Sdk//master git submodule update --init diff --git a/build-aux/modules/biome.json b/build-aux/modules/biome.json deleted file mode 100644 index 6de6f5f89..000000000 --- a/build-aux/modules/biome.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "biome", - "buildsystem": "simple", - "build-commands": ["chmod +x biome", "cp biome /app/bin/biome"], - "sources": [ - { - "type": "file", - "dest-filename": "biome", - "only-arches": ["aarch64"], - "url": "https://github.com/biomejs/biome/releases/download/cli%2Fv1.8.3/biome-linux-arm64", - "sha256": "d134e89f6f4fc29d32c8101efb074969ac263ebdb0303e07039e3735002c6a2d" - }, - { - "type": "file", - "dest-filename": "biome", - "only-arches": ["x86_64"], - "url": "https://github.com/biomejs/biome/releases/download/cli%2Fv1.8.3/biome-linux-x64", - "sha256": "5495f2f69edd94e9f26ed1adb9ed8023d7c143c3cc6f275f90abdded612217e4" - } - ] -} diff --git a/build-aux/re.sonny.Workbench.Devel.json b/build-aux/re.sonny.Workbench.Devel.json index 05b779299..3f731a2fd 100644 --- a/build-aux/re.sonny.Workbench.Devel.json +++ b/build-aux/re.sonny.Workbench.Devel.json @@ -8,11 +8,11 @@ "org.freedesktop.Sdk.Extension.vala", "org.freedesktop.Sdk.Extension.rust-stable", "org.freedesktop.Sdk.Extension.llvm18", - "org.freedesktop.Sdk.Extension.node20", + "org.freedesktop.Sdk.Extension.node18", "org.freedesktop.Sdk.Extension.typescript" ], "build-options": { - "append-path": "/usr/lib/sdk/vala/bin:/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/node20/bin:/usr/lib/sdk/typescript/bin", + "append-path": "/usr/lib/sdk/vala/bin:/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/node18/bin:/usr/lib/sdk/typescript/bin", "append-ld-library-path": "/usr/lib/sdk/vala/lib" }, "command": "workbench", @@ -39,7 +39,6 @@ ], "modules": [ "modules/blueprint-compiler.json", - "modules/biome.json", "modules/gst-plugin-gtk4.json", "modules/vte.json", "modules/libshumate.json", diff --git a/build-aux/re.sonny.Workbench.json b/build-aux/re.sonny.Workbench.json index 4f6e3ab48..29718089e 100644 --- a/build-aux/re.sonny.Workbench.json +++ b/build-aux/re.sonny.Workbench.json @@ -8,11 +8,11 @@ "org.freedesktop.Sdk.Extension.vala", "org.freedesktop.Sdk.Extension.rust-stable", "org.freedesktop.Sdk.Extension.llvm18", - "org.freedesktop.Sdk.Extension.node20", + "org.freedesktop.Sdk.Extension.node18", "org.freedesktop.Sdk.Extension.typescript" ], "build-options": { - "append-path": "/usr/lib/sdk/vala/bin:/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/node20/bin:/usr/lib/sdk/typescript/bin", + "append-path": "/usr/lib/sdk/vala/bin:/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/node18/bin:/usr/lib/sdk/typescript/bin", "append-ld-library-path": "/usr/lib/sdk/vala/lib" }, "command": "workbench", @@ -39,7 +39,6 @@ ], "modules": [ "modules/blueprint-compiler.json", - "modules/biome.json", "modules/gst-plugin-gtk4.json", "modules/vte.json", "modules/libshumate.json", diff --git a/data/app.metainfo.xml b/data/app.metainfo.xml index 54d0744a7..cb68dc228 100644 --- a/data/app.metainfo.xml +++ b/data/app.metainfo.xml @@ -55,7 +55,7 @@ diff --git a/src/langs/typescript/gi-types b/gi-types similarity index 100% rename from src/langs/typescript/gi-types rename to gi-types diff --git a/src/Extensions/Extensions.js b/src/Extensions/Extensions.js index 570bcab24..c64ba3dce 100644 --- a/src/Extensions/Extensions.js +++ b/src/Extensions/Extensions.js @@ -53,7 +53,7 @@ export function Extensions({ window }) { window.add_action(action_extensions); } -let rust_enabled = false; +let rust_enabled = null; export function isRustEnabled() { rust_enabled ??= Gio.File.new_for_path("/usr/lib/sdk/rust-stable").query_exists(null) && @@ -61,14 +61,14 @@ export function isRustEnabled() { return rust_enabled; } -let vala_enabled = false; +let vala_enabled = null; export function isValaEnabled() { vala_enabled ??= Gio.File.new_for_path("/usr/lib/sdk/vala").query_exists(null); return vala_enabled; } -let typescript_enabled = false; +let typescript_enabled = null; export function isTypeScriptEnabled() { typescript_enabled ??= Gio.File.new_for_path("/usr/lib/sdk/typescript").query_exists(null) && @@ -77,6 +77,6 @@ export function isTypeScriptEnabled() { } const llvm = "llvm18"; -const node = "node20"; +const node = "node18"; const runtime = getFlatpakInfo().get_string("Application", "runtime"); const freedesktop_version = runtime.endsWith("master") ? "24.08beta" : "23.08"; diff --git a/src/PanelCode.js b/src/PanelCode.js index 5c07fe3a2..fb95b424a 100644 --- a/src/PanelCode.js +++ b/src/PanelCode.js @@ -4,6 +4,7 @@ import GObject from "gi://GObject"; import { makeDropdownFlat, settings as global_settings } from "./util.js"; import { setupRustProject } from "./langs/rust/rust.js"; import { setupTypeScriptProject } from "./langs/typescript/typescript.js"; +import { setupJavascriptProject } from "./langs/javascript/javascript.js"; export default function PanelCode({ builder, @@ -55,6 +56,12 @@ export default function PanelCode({ stack_code.visible_child_name = panel.language; previewer.useInternal().catch(console.error); + if (panel.language.toLowerCase() === "javascript") { + setupJavascriptProject(file, langs.javascript.document).catch( + console.error, + ); + } + if (panel.language.toLowerCase() === "rust") { setupRustProject(file).catch(console.error); } diff --git a/src/application.js b/src/application.js index 25acd8d74..a7c31b487 100644 --- a/src/application.js +++ b/src/application.js @@ -64,23 +64,7 @@ application.connect("open", (_self, files, hint) => { load().catch(console.error); }); -let proc_biome; - application.connect("startup", () => { - // biome lsp-proxy starts a background server - // it does not get stopped and leaves a process hanging - // so manage it manually instead - // See https://github.com/workbenchdev/Workbench/issues/828 - const subprocess_launcher = Gio.SubprocessLauncher.new( - Gio.SubprocessFlags.STDERR_SILENCE, - ); - proc_biome = subprocess_launcher.spawnv([ - "biome", - "__run_server", - "--config-path", - pkg.pkgdatadir, - ]); - Library({ application, }); @@ -90,10 +74,6 @@ application.connect("startup", () => { restoreSessions().catch(console.error); }); -application.connect("shutdown", () => { - proc_biome?.force_exit(); -}); - application.connect("activate", () => { if (application.is_remote) { bootstrap().catch(console.error); diff --git a/src/common.js b/src/common.js index a3f3679c5..3fd3b3656 100644 --- a/src/common.js +++ b/src/common.js @@ -1,5 +1,3 @@ -import GLib from "gi://GLib"; - import LSPClient from "./lsp/LSPClient.js"; const formatting_options = { @@ -47,14 +45,7 @@ export const languages = [ document: null, default_file: "main.js", index: 0, - language_server: [ - "biome", - "lsp-proxy", - // src/meson.build installs biome.json there - GLib.getenv("FLATPAK_ID") - ? `--config-path=${pkg.pkgdatadir}` - : `--config-path=src/langs/javascript`, - ], + language_server: ["typescript-language-server", "--stdio"], formatting_options: { ...formatting_options, tabSize: 2, diff --git a/src/langs/css/CssDocument.js b/src/langs/css/CssDocument.js index cced3fce0..733d0cd77 100644 --- a/src/langs/css/CssDocument.js +++ b/src/langs/css/CssDocument.js @@ -25,7 +25,7 @@ export class CssDocument extends Document { }, }); - // Biome doesn't support diff - it just returns one edit + // GTKCssLanguageServer doesn't support diff - it just returns one edit // we don't want to loose the cursor position so we use this const state = this.code_view.saveState(); applyTextEdits(text_edits, this.buffer); diff --git a/src/langs/javascript/JavaScriptDocument.js b/src/langs/javascript/JavaScriptDocument.js index 7bc14f468..a3bc46e3f 100644 --- a/src/langs/javascript/JavaScriptDocument.js +++ b/src/langs/javascript/JavaScriptDocument.js @@ -26,10 +26,6 @@ export class JavaScriptDocument extends Document { }, }); - // Biome doesn't support diff - it just returns one edit - // we don't want to loose the cursor position so we use this - const state = this.code_view.saveState(); applyTextEdits(text_edits, this.buffer); - await this.code_view.restoreState(state); } } diff --git a/src/langs/javascript/biome.json b/src/langs/javascript/biome.json deleted file mode 100644 index 4786af4fb..000000000 --- a/src/langs/javascript/biome.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "$schema": "https://biomejs.dev/schemas/1.3.3/schema.json", - "javascript": { - "globals": ["workbench"] - }, - "formatter": { - "indentStyle": "space", - "indentWidth": 2 - }, - "linter": { - "rules": { - "recommended": false, - "correctness": { - "noUndeclaredVariables": "error", - "noUnusedVariables": "warn" - } - } - } -} diff --git a/src/langs/javascript/javascript.js b/src/langs/javascript/javascript.js index 817d81451..972c33b5b 100644 --- a/src/langs/javascript/javascript.js +++ b/src/langs/javascript/javascript.js @@ -1,5 +1,7 @@ +import Gio from "gi://Gio"; + import { createLSPClient } from "../../common.js"; -import { getLanguage } from "../../util.js"; +import { getLanguage, copy } from "../../util.js"; export function setup({ document }) { const { file, buffer, code_view } = document; @@ -30,3 +32,22 @@ export function setup({ document }) { return lspc; } + +const javascript_template_dir = Gio.File.new_for_path( + pkg.pkgdatadir, +).resolve_relative_path("langs/javascript/template"); + +export async function setupJavascriptProject(destination, document) { + const destination_file = await copy( + "jsconfig.json", + javascript_template_dir, + destination, + Gio.FileCopyFlags.NONE, + ); + + // Notify the language server that the jsconfig file was created + // to initialize diagnostics and type checkings + await document.lspc.notify("workspace/didCreateFile", { + files: [{ uri: destination_file.get_uri() }], + }); +} diff --git a/src/langs/javascript/meson.build b/src/langs/javascript/meson.build new file mode 100644 index 000000000..a248fff88 --- /dev/null +++ b/src/langs/javascript/meson.build @@ -0,0 +1,6 @@ +configure_file( + input: 'template/jsconfig.json', + output: 'jsconfig.json', + install_dir: join_paths(pkgdatadir, 'langs/javascript/template/'), + configuration: bin_conf, +) diff --git a/src/langs/javascript/template/jsconfig.json b/src/langs/javascript/template/jsconfig.json new file mode 100644 index 000000000..835b0797c --- /dev/null +++ b/src/langs/javascript/template/jsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "checkJs": true, + "module": "ESNext", + "moduleResolution": "Bundler", + // TODO: should probably be fixed to ES2023, or whatever standard is + // currently supported by the latest GJS + "target": "ESNext", + "outDir": "compiled_javascript", + "baseUrl": ".", + "paths": { + "*": ["*", "@pkgdatadir@/langs/typescript/gi-types/*"] + }, + "skipLibCheck": true + }, + "include": [ + "main.js", + "@pkgdatadir@/langs/typescript/types/ambient.d.ts", + "@pkgdatadir@/langs/typescript/gi-types/gi.d.ts" + ] +} diff --git a/src/langs/typescript/meson.build b/src/langs/typescript/meson.build index 103d365b9..5b6ff274c 100644 --- a/src/langs/typescript/meson.build +++ b/src/langs/typescript/meson.build @@ -11,4 +11,7 @@ install_data( preserve_path: true, ) -install_subdir('gi-types', install_dir: join_paths(pkgdatadir, 'langs/typescript')) \ No newline at end of file +install_subdir( + meson.project_source_root() / 'gi-types', + install_dir: join_paths(pkgdatadir, 'langs/typescript'), +) diff --git a/src/meson.build b/src/meson.build index 289f86467..2a4bef688 100644 --- a/src/meson.build +++ b/src/meson.build @@ -15,6 +15,7 @@ blueprint_compiler = find_program( meson.add_install_script('../build-aux/library.js', pkgdatadir) +subdir('langs/javascript') subdir('langs/rust/template') subdir('langs/typescript') @@ -46,7 +47,6 @@ configure_file( ) install_data('langs/vala/workbench.vala', install_dir: pkgdatadir) -install_data('langs/javascript/biome.json', install_dir: pkgdatadir) install_data('project-readme.md', install_dir: pkgdatadir) subdir('libworkbench') subdir('Previewer') diff --git a/src/widgets/CodeView.js b/src/widgets/CodeView.js index 3859952f3..7d9f452b9 100644 --- a/src/widgets/CodeView.js +++ b/src/widgets/CodeView.js @@ -73,7 +73,6 @@ class CodeView extends Gtk.Widget { } #onUpdate = () => { - this.clearDiagnostics(); this.emit("changed"); }; diff --git a/src/workbench b/src/workbench index e8af5657a..49ec4edde 100755 --- a/src/workbench +++ b/src/workbench @@ -8,7 +8,7 @@ export PKG_CONFIG_PATH=/app/lib/pkgconfig/:$PKG_CONFIG_PATH source /usr/lib/sdk/rust-stable/enable.sh 2> /dev/null source /usr/lib/sdk/vala/enable.sh 2> /dev/null source /usr/lib/sdk/llvm18/enable.sh 2> /dev/null -source /usr/lib/sdk/node20/enable.sh 2> /dev/null +source /usr/lib/sdk/node18/enable.sh 2> /dev/null ## enabling the typescript extension export PATH=$PATH:/usr/lib/sdk/typescript/bin