дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-30 14:22:34 +02:00
Порівняти коміти
4
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
462f4a5e1d | ||
|
|
1cfbb24b31 | ||
|
|
a8a0cdb315 | ||
|
|
8ab776ada6 |
No files matched your search
@@ -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 = [
|
||||
|
||||
@@ -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 `,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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"
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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>`,
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Заблокувати користувача