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
9 changes: 8 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
* @sonnyp

/src/langs/vala/ @lw64
*.vala @lw64

/src/langs/rust/ @lw64
*.rs @Hofer-Julian
Cargo.toml @Hofer-Julian
Cargo.lock @Hofer-Julian

/src/langs/python/ @theCapypara
*.py @theCapypara

*.c @andyholmes
*.h @andyholmes
*.py @theCapypara
5 changes: 1 addition & 4 deletions src/PanelStyle.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 { setup as setupCSS } from "./langs/css/css.js";

export default function PanelStyle({ builder, document_css, settings }) {
export default function PanelStyle({ builder, settings }) {
const button_style = builder.get_object("button_style");
const panel_style = builder.get_object("panel_style");
settings.bind(
Expand All @@ -18,5 +16,4 @@ export default function PanelStyle({ builder, document_css, settings }) {
"visible",
GObject.BindingFlags.SYNC_CREATE,
);
setupCSS({ document: document_css });
}
33 changes: 26 additions & 7 deletions src/langs/css/CssDocument.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
import { format as prettier } from "../../lib/prettier.js";
import prettier_postcss from "../../lib/prettier-postcss.js";

import Document from "../../Document.js";
import { applyTextEdits } from "../../lsp/sourceview.js";
import { setup } from "./css.js";

export class CssDocument extends Document {
constructor(...args) {
super(...args);

this.lspc = setup({ document: this });
}

async format() {
const code = await prettier(this.buffer.text, {
parser: "css",
plugins: [prettier_postcss],
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_formatting
const text_edits = await this.lspc.request("textDocument/formatting", {
textDocument: {
uri: this.file.get_uri(),
},
options: {
tabSize: 2,
insertSpaces: true,
trimTrailingWhitespace: true,
insertFinalNewline: true,
trimFinalNewlines: true,
},
});
this.code_view.replaceText(code, true);

// 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);
}
}
2 changes: 2 additions & 0 deletions src/langs/css/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export function setup({ document }) {
if (!code_view.buffer.get_modified()) return;
lspc.didChange().catch(console.error);
});

return lspc;
}

function createLSPClient({ code_view, file }) {
Expand Down
15 changes: 15 additions & 0 deletions src/langs/css/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
gjspack = find_program(meson.project_source_root() / 'troll/gjspack/bin/gjspack')
custom_target('prettier',
input: ['prettier.js'],
output: ['prettier', 'prettier.src.gresource'],
command: [
gjspack,
'--resource-root', meson.project_source_root() / 'src',
'@INPUT0@',
'@OUTDIR@',
],
install: true,
install_dir: get_option('bindir'),
build_always_stale: true,
)

29 changes: 29 additions & 0 deletions src/langs/css/prettier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env -S gjs -m

// Shim to Node.js prettier CLI for GTKCssLanguageServer
// ./src/langs/css/prettier.js --stdin-filepath src/style.css
// or
// ./troll/gjspack/bin/gjspack src/langs/css/prettier.js src/langs/css && ./src/langs/css/prettier --stdin-filepath src/style.css

import { exit } from "system";
import Gio from "gi://Gio";

import { format } from "../../lib/prettier.js";
import prettier_postcss from "../../lib/prettier-postcss.js";

const idx = ARGV.indexOf("--stdin-filepath");
if (idx < 0) exit(1);
const filename = ARGV[idx + 1];
if (!filename) exit(1);

const file = Gio.File.new_for_path(filename);
const [, contents] = file.load_contents(null);
const text = new TextDecoder().decode(contents);

const formatted = await format(text, {
parser: "css",
plugins: [prettier_postcss],
});

// eslint-disable-next-line no-restricted-globals
print(formatted);
18 changes: 0 additions & 18 deletions src/lib/prettier-babel.js

This file was deleted.

37 changes: 0 additions & 37 deletions src/lib/prettier-estree.js

This file was deleted.

Loading