Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 462f4a5e1d fix(editor): indent Slint element blocks by their braces
Slint borrows the C mode for highlighting until slint-lsp's semantic tokens
arrive, and Enter used that mode's statement indentation: after a child
element's closing brace the next line went back to column 0, and nested
blocks below it opened one level short. Slint now uses the brace-based
fallback indentation even though a highlighting mode is loaded.

Fixes #6976
2026-11-30 18:21:56 +08:00
l0ng-ai 1cfbb24b31 fix(project-tree): add Select Opened File as a Project View action for the keymap (#7011)
The keymap listed "Select Opened File" only as the Database view action, so a shortcut assigned to it revealed the file in the Database view and did nothing in a project without data sources. Like IDEA's SelectOpenedFileInProjectView, the Project view now has its own Select Opened File action (the toolbar button runs it), and imported IDEA keymaps map SelectOpenedFileInProjectView and SelectInProjectView.

Fixes #6978
2026-11-30 18:18:33 +08:00
l0ng-ai a8a0cdb315 fix(plugins): load precompiled plugin components in the signed macOS app (#7010)
compile_cached loaded the cached .cwasm with Component::deserialize_file, which maps the file and makes its pages executable; the hardened runtime of the signed app refuses that, so every activation discarded the cache and compiled the plugin again. The file is now read into memory and deserialized from the bytes. A new test checks the cache is hit; signed with the app entitlements it fails with the old code.

Refs #6954
2026-11-30 18:16:20 +08:00
l0ng-ai 8ab776ada6 fix(keymap): import an Emacs-based IDEA keymap on top of $default, not macOS (#7008)
presetOf picked the macOS preset for any parent whose name contains "mac", including "Emacs", so a keymap derived from IDEA's Emacs keymap was imported as based on macOS. The match is now on the word (Mac OS X, macOS), and Emacs and its copies map to the $default preset they inherit in IDEA.

Refs #6896
2026-11-30 18:14:01 +08:00
11 змінених файлів з 123 додано та 9 видалено

No files matched your search

+25 -2
Переглянути файл
@@ -613,11 +613,14 @@ impl PluginEngine {
pub fn compile_cached(&self, wasm: &Path, cache_dir: &Path) -> Result<Component, String> {
let bytes = std::fs::read(wasm).map_err(|e| format!("{}: {e}", wasm.display()))?;
let file = cache_dir.join(format!("{}.cwasm", self.cache_key(&bytes)));
if file.is_file() {
// Read into memory rather than `deserialize_file`: that maps the file and makes its pages
// executable, which the hardened runtime of the signed macOS app refuses ("failed to make
// memory executable"), so the cache never hit and every activation compiled again.
if let Ok(precompiled) = std::fs::read(&file) {
// SAFETY: the cache directory belongs to the IDE (inside its plugins
// directory) and is written only by `store_precompiled` below from
// components this engine compiled; a corrupt file fails validation.
match unsafe { Component::deserialize_file(&self.engine, &file) } {
match unsafe { Component::deserialize(&self.engine, &precompiled) } {
Ok(component) => return Ok(component),
Err(e) => {
tracing::info!("discarding precompiled {}: {e}", file.display());
@@ -3035,6 +3038,26 @@ impl Runtime {
mod tests {
use super::*;
/// The second compile of the same component loads the cached one instead of compiling and
/// writing it again (a failed load deletes and rewrites the file).
#[test]
fn a_precompiled_component_is_loaded_from_the_cache() {
let engine = PluginEngine::new().unwrap();
let wasm = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/hello/dist/plugin.wasm");
let cache = tempfile::tempdir().unwrap();
engine.compile_cached(&wasm, cache.path()).unwrap();
let cached = || {
let entries: Vec<_> = std::fs::read_dir(cache.path()).unwrap().flatten().map(|e| e.path()).collect();
assert_eq!(entries.len(), 1, "{entries:?}");
let file = entries[0].clone();
(std::fs::metadata(&file).unwrap().modified().unwrap(), file)
};
let before = cached();
std::thread::sleep(std::time::Duration::from_millis(20));
engine.compile_cached(&wasm, cache.path()).unwrap();
assert_eq!(cached(), before, "loaded, not compiled and stored again");
}
#[test]
fn readonly_field_extensions_are_parsed_and_unknown_or_malformed_fields_are_skipped() {
let fields = [
+42 -2
Переглянути файл
@@ -1,12 +1,12 @@
import { EditorSelection, EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { insertNewlineAndIndent } from "@codemirror/commands";
import { LanguageDescription, type Language } from "@codemirror/language";
import { LanguageDescription, indentUnit, type Language } from "@codemirror/language";
import { describe, expect, it } from "vitest";
import { getIndentation } from "@codemirror/language";
import { highlightTree, tagHighlighter, tags as t } from "@lezer/highlight";
import { logWarning } from "./highlight";
import { fencedCodeMode, findLanguageDescription, loadSupport } from "./languages";
import { commentTokens, fencedCodeMode, findLanguageDescription, loadSupport } from "./languages";
describe("language modes", () => {
it("highlights Julia declarations, calls, types, macros and literals without semantic tokens", async () => {
@@ -765,3 +765,43 @@ describe("language modes", () => {
expect(found).not.toContain("yes:keyword");
});
});
describe("Slint indentation", () => {
it("indents element blocks by their braces under the C highlighting mode", async () => {
const support = await loadSupport(findLanguageDescription("C", "/p/app.slint")!);
const slint = commentTokens({
id: "slint",
name: "Slint",
extensions: ["slint"],
uiMode: "C",
lineComment: "//",
blockComment: ["/*", "*/"],
indent: { tabSize: 4, insertSpaces: true },
});
const enter = (doc: string, at = doc.length) => {
const view = new EditorView({
state: EditorState.create({
doc,
selection: EditorSelection.cursor(at),
extensions: [support!, slint, indentUnit.of(" ")],
}),
parent: document.body,
});
insertNewlineAndIndent(view);
const out = view.state.doc.toString();
view.destroy();
return out;
};
const app = "export component App inherits Window {";
expect(enter(app)).toBe(`${app}\n `);
expect(enter(`${app}}`, app.length)).toBe(`${app}\n \n}`);
expect(enter(`${app}\n width: 100px;`)).toBe(`${app}\n width: 100px;\n `);
// After a child element closes, the next line stays at the child's level.
expect(enter(`${app}\n Text {\n text: "hi";\n }`)).toBe(
`${app}\n Text {\n text: "hi";\n }\n `,
);
expect(enter(`${app}\n Text {\n }\n Rectangle {`)).toBe(
`${app}\n Text {\n }\n Rectangle {\n `,
);
});
});
+8 -1
Переглянути файл
@@ -740,6 +740,13 @@ const NO_INDENT_LANGS = new Set([
"gitattributes",
]);
/**
* Languages highlighted by a borrowed mode whose own indentation doesn't fit them: Slint's
* element blocks (`Text { … }` without a `;`) read as unfinished C statements, so Enter after
* one lands at the wrong column. These use the brace-based fallback indentation instead.
*/
const BRACE_INDENT_OVER_MODE = new Set(["slint"]);
function opensBlock(code: string, language: string | undefined): boolean {
if (!code) return false;
if (/[{([]$/.test(code)) return true;
@@ -779,7 +786,7 @@ function indentationCode(text: string, lineComment: string | undefined): string
*/
export function fallbackIndent(language?: string): Extension {
return indentService.of((cx, pos) => {
if (cx.state.facet(languageFacet)) return undefined;
if (cx.state.facet(languageFacet) && !BRACE_INDENT_OVER_MODE.has(language ?? "")) return undefined;
const lineComment = cx.state.languageDataAt<{ line?: string }>("commentTokens", pos)[0]?.line;
const stripComment = (text: string) => indentationCode(text, lineComment);
+2 -2
Переглянути файл
@@ -100,9 +100,9 @@ export function ProjectHeaderActions() {
{!alwaysSelect && (
<IconButton
icon="locate"
action="navigate.selectInProjectView"
action="project.selectOpenedFile"
title="Select Opened File"
shortcut={shortcutLabel("navigate.selectInProjectView")}
shortcut={shortcutLabel("project.selectOpenedFile")}
size="small"
/>
)}
+10
Переглянути файл
@@ -254,6 +254,16 @@ export function registerProjectActions(): () => void {
keywords: ["locate", "reveal", "scroll from source", "select opened file"],
run: ({ arg }) => void selectInProjectView(typeof arg === "string" ? arg : null),
},
{
// IDEA's SelectOpenedFileInProjectView: the Project view toolbar's locate button.
id: "project.selectOpenedFile",
title: "Select Opened File",
category: "Project View",
icon: "locate",
when: OPEN,
keywords: ["locate", "reveal", "scroll from source", "select in project view"],
run: () => void selectInProjectView(null),
},
{
id: "project.reveal",
title: "Reveal in Project View",
+12
Переглянути файл
@@ -152,6 +152,18 @@ describe("Select In (⌥F1)", () => {
expect(useContextMenuStore.getState().menu).toBeNull();
});
it("Select Opened File is a Project View action of its own, as in IDEA's keymap", async () => {
const { IDEA_ACTIONS } = await import("@/platform/ideaActions");
disposers.push(registerProjectActions(), () => setContext("projectOpen", false));
setContext("projectOpen", true);
expect(getAction("project.selectOpenedFile")).toMatchObject({
title: "Select Opened File",
category: "Project View",
});
expect(IDEA_ACTIONS.SelectOpenedFileInProjectView).toBe("project.selectOpenedFile");
expect(IDEA_ACTIONS.SelectInProjectView).toBe("navigate.selectInProjectView");
});
it("expands an in-project folder when expand is true and reveals out-of-project folders in the file manager", async () => {
const { useProjectTree } = await import("./store");
const prev = useProjectTree.getState();
+2
Переглянути файл
@@ -6,6 +6,8 @@ export const IDEA_ACTIONS: Readonly<Record<string, string>> = {
GotoDeclaration: "navigate.declaration",
GotoImplementation: "navigate.implementation",
GotoTypeDeclaration: "navigate.typeDeclaration",
SelectInProjectView: "navigate.selectInProjectView",
SelectOpenedFileInProjectView: "project.selectOpenedFile",
GotoSuperMethod: "navigate.superMethod",
GotoTest: "navigate.gotoTest",
GotoRelated: "navigate.relatedSymbol",
+16
Переглянути файл
@@ -49,6 +49,22 @@ describe("IntelliJ IDEA keymap import", () => {
expect(k.overrides).toEqual({});
});
it("bases a keymap derived from Emacs on $default, not macOS", () => {
for (const parent of ["Emacs", "Emacs copy"]) {
const k = parseIdeaKeymap(`<keymap name="E" parent="${parent}"></keymap>`);
expect(k.parent).toBe("intellij-windows");
}
for (const [parent, preset] of [
["Mac OS X", "intellij-macos"],
["macOS System Shortcuts", "intellij-macos"],
["Eclipse (Mac OS X)", "eclipse-macos"],
["VSCode (macOS)", "vscode-macos"],
["Default for KDE", "intellij-windows"],
]) {
expect(parseIdeaKeymap(`<keymap name="K" parent="${parent}"></keymap>`).parent).toBe(preset);
}
});
it("maps Duplicate Entire Lines, which has no shortcut in the presets", () => {
const k = parseIdeaKeymap(
`<keymap name="M" parent="Mac OS X 10.5+"><action id="EditorDuplicateLines"><keyboard-shortcut first-keystroke="shift meta D"/></action></keymap>`,
+4 -2
Переглянути файл
@@ -31,11 +31,13 @@ export interface ImportedIdeaKeymap {
/** IDEA's bundled keymap names (`<keymap name=…>`) → our presets. */
function presetOf(parent: string | null): string {
const p = parent ?? "";
const mac = /mac/i.test(p);
// "Mac OS X 10.5+", "Eclipse (Mac OS X)", "VSCode (macOS)"; not the "mac" inside "Emacs".
const mac = /\bmac(?: ?os)?\b/i.test(p);
if (/^eclipse/i.test(p)) return mac ? "eclipse-macos" : "eclipse-windows";
if (/^vs ?code/i.test(p)) return mac ? "vscode-macos" : "vscode-windows";
if (mac) return "intellij-macos";
if (p === "$default" || /^default for/i.test(p)) return "intellij-windows";
// IDEA's Emacs keymap (and copies of it) inherits $default.
if (p === "$default" || /^default for/i.test(p) || /^emacs\b/i.test(p)) return "intellij-windows";
return defaultPreset();
}
+1
Переглянути файл
@@ -531,6 +531,7 @@ export const intellijMacos: Record<string, string[]> = {
"db.showDiagram": ["Meta+Alt+Shift+U"],
"db.showDiagramPopup": ["Meta+Alt+U"],
"db.selectOpened": [],
"project.selectOpenedFile": [],
"db.expandAll": [],
"db.collapseAll": [],
// Terminal (keyWhen: terminalFocus); after VCS Update / Go to Test so it wins there.
+1
Переглянути файл
@@ -529,6 +529,7 @@ export const intellijWindows: Record<string, string[]> = {
"db.showDiagram": ["Ctrl+Alt+Shift+U"],
"db.showDiagramPopup": ["Ctrl+Alt+U"],
"db.selectOpened": [],
"project.selectOpenedFile": [],
"db.expandAll": [],
"db.collapseAll": [],
// Terminal (keyWhen: terminalFocus); after VCS Update / Go to Test so it wins there.