дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 01:57:13 +02:00
Порівняти коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
2ab0d55c80 | ||
|
|
34f2e18ff1 | ||
|
|
83a949ffe9 | ||
|
|
af8bd1afcd | ||
|
|
ce12f68613 |
No files matched your search
@@ -180,29 +180,6 @@ unsafe extern "C-unwind" fn should_terminate(_this: *mut AnyObject, _selector: S
|
||||
|
||||
static APP: std::sync::OnceLock<AppHandle> = std::sync::OnceLock::new();
|
||||
|
||||
/// Escape the page leaves unhandled reaches the window as `cancelOperation:`, on which NSWindow
|
||||
/// leaves full screen, so pressing Escape once more after closing a popup left full screen. The
|
||||
/// IDE's windows answer it with nothing; View › Appearance › Toggle Full Screen (⌃⌘F) leaves it.
|
||||
pub fn keep_full_screen_on_escape() {
|
||||
static ONCE: std::sync::Once = std::sync::Once::new();
|
||||
ONCE.call_once(|| unsafe {
|
||||
let Some(class) = AnyClass::get(c"TaoWindow") else {
|
||||
tracing::warn!("no TaoWindow class: Escape leaves full screen");
|
||||
return;
|
||||
};
|
||||
let imp: Imp = std::mem::transmute(ignore_cancel_operation as CancelOperation);
|
||||
let class = class as *const AnyClass as *mut AnyClass;
|
||||
let added = objc2::ffi::class_addMethod(class, objc2::sel!(cancelOperation:), imp, c"v@:@".as_ptr());
|
||||
if !added.as_bool() {
|
||||
tracing::warn!("could not handle cancelOperation:");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
type CancelOperation = unsafe extern "C-unwind" fn(*mut AnyObject, Sel, *mut AnyObject);
|
||||
|
||||
unsafe extern "C-unwind" fn ignore_cancel_operation(_this: *mut AnyObject, _selector: Sel, _sender: *mut AnyObject) {}
|
||||
|
||||
/// Whether AppKit is handling a key press right now. A menu item performed at this point
|
||||
/// was chosen by its key equivalent: a click, arrow keys plus Return and accessibility
|
||||
/// presses all run with a non-key current event.
|
||||
|
||||
@@ -730,8 +730,6 @@ fn build_project_window(app: &AppHandle, mut config: WindowConfig) -> IdeResult<
|
||||
decorate_csd(&window);
|
||||
#[cfg(target_os = "macos")]
|
||||
crate::page_swipe::install(&window);
|
||||
#[cfg(target_os = "macos")]
|
||||
crate::macos::keep_full_screen_on_escape();
|
||||
apply_zoom(app, &window);
|
||||
#[cfg(target_os = "macos")]
|
||||
align_titlebar(app, &window, app.try_state::<WindowsState>().is_some_and(|w| w.opens_project(window.label())));
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getIndentation } from "@codemirror/language";
|
||||
import { EditorState } from "@codemirror/state";
|
||||
import { findLanguageDescription, loadSupport } from "./languages";
|
||||
|
||||
describe("vue language mode", () => {
|
||||
@@ -23,4 +25,31 @@ describe("vue language mode", () => {
|
||||
expect(tree).toContain("Declaration");
|
||||
expect(tree).not.toContain("SassVariableName");
|
||||
});
|
||||
|
||||
it("indents the top-level <template>'s children only, not <script setup> or <style> code", async () => {
|
||||
const support = await loadSupport(findLanguageDescription("Vue", "/p/a.vue")!);
|
||||
const doc = [
|
||||
"<template>",
|
||||
"<div>",
|
||||
"</div>",
|
||||
"</template>",
|
||||
'<script setup lang="ts">',
|
||||
"const a = 1",
|
||||
"function f() {",
|
||||
"return a",
|
||||
"}",
|
||||
"</script>",
|
||||
"<style>",
|
||||
".a { color: red; }",
|
||||
"</style>",
|
||||
].join("\n");
|
||||
const state = EditorState.create({ doc, extensions: [support!, EditorState.tabSize.of(2)] });
|
||||
const indent = (line: number) => getIndentation(state, state.doc.line(line).from);
|
||||
expect(indent(2)).toBe(2);
|
||||
expect(indent(6)).toBe(0);
|
||||
expect(indent(7)).toBe(0);
|
||||
expect(indent(8)).toBe(2);
|
||||
expect(indent(10)).toBe(0);
|
||||
expect(indent(12)).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -4,24 +4,38 @@
|
||||
* stock `vue()` parses every `<style>` as plain CSS, which loses the SCSS
|
||||
* colours.
|
||||
*/
|
||||
import { LanguageSupport } from "@codemirror/language";
|
||||
import { indentNodeProp, LanguageSupport, type LRLanguage, type TreeIndentContext } from "@codemirror/language";
|
||||
import { html } from "@codemirror/lang-html";
|
||||
import { sassLanguage } from "@codemirror/lang-sass";
|
||||
import { vue } from "@codemirror/lang-vue";
|
||||
|
||||
/**
|
||||
* WebStorm's Vue code style indents the children of the top-level `<template>` only: code in
|
||||
* `<script setup>` or `<style>` starts at the margin, as `npm create vue` writes it.
|
||||
*/
|
||||
function elementIndent(context: TreeIndentContext): number | null {
|
||||
const after = /^(\s*)(<\/)?/.exec(context.textAfter)!;
|
||||
const node = context.node;
|
||||
if (node.to <= context.pos + after[0].length) return context.continue();
|
||||
const tag = node.firstChild?.getChild("TagName");
|
||||
const flat =
|
||||
node.parent?.name === "Document" && !!tag && context.state.sliceDoc(tag.from, tag.to).toLowerCase() !== "template";
|
||||
return context.lineIndent(node.from) + (after[2] || flat ? 0 : context.unit);
|
||||
}
|
||||
|
||||
export function vueLanguage(): LanguageSupport {
|
||||
return vue({
|
||||
base: html({
|
||||
selfClosingTags: true,
|
||||
// `<style>` without `lang` (or with `lang="css"`) keeps HTML's own CSS
|
||||
// nesting; only an explicit SCSS/Sass dialect re-parses it.
|
||||
nestedLanguages: [
|
||||
{
|
||||
tag: "style",
|
||||
attrs: (a) => a.lang === "scss" || a.lang === "sass",
|
||||
parser: sassLanguage.parser,
|
||||
},
|
||||
],
|
||||
}),
|
||||
const base = html({
|
||||
selfClosingTags: true,
|
||||
// `<style>` without `lang` (or with `lang="css"`) keeps HTML's own CSS
|
||||
// nesting; only an explicit SCSS/Sass dialect re-parses it.
|
||||
nestedLanguages: [
|
||||
{
|
||||
tag: "style",
|
||||
attrs: (a) => a.lang === "scss" || a.lang === "sass",
|
||||
parser: sassLanguage.parser,
|
||||
},
|
||||
],
|
||||
});
|
||||
const language = (base.language as LRLanguage).configure({ props: [indentNodeProp.add({ Element: elementIndent })] });
|
||||
return vue({ base: new LanguageSupport(language, base.support) });
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const opened = vi.hoisted(() => [] as string[]);
|
||||
|
||||
vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
const ipc = await importOriginal<typeof import("@/platform/ipc")>();
|
||||
const doc = (path: string) => Promise.resolve({ status: "ok", data: { id: 3, path } });
|
||||
return {
|
||||
...ipc,
|
||||
isTauri: () => true,
|
||||
commands: {
|
||||
...ipc.commands,
|
||||
docOpen: (path: string) => (opened.push(`file ${path}`), doc(path)),
|
||||
docOpenVirtual: (uri: string) => (opened.push(`virtual ${uri}`), doc(uri)),
|
||||
docClose: () => Promise.resolve(),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const { withDocument } = await import("./ipc");
|
||||
|
||||
describe("withDocument", () => {
|
||||
it("opens a library type through its language server, a project file from disk", async () => {
|
||||
const uri = "jdt://contents/java.base/java.util/UUID.class?=demo/%5C/jdk%5C/lib%5C/jrt-fs.jar%60java.base";
|
||||
await withDocument(uri, async (doc) => doc);
|
||||
await withDocument("/p/src/App.java", async (doc) => doc);
|
||||
expect(opened).toEqual([`virtual ${uri}`, "file /p/src/App.java"]);
|
||||
});
|
||||
});
|
||||
@@ -134,7 +134,8 @@ export async function readManyFileLines(
|
||||
export async function withDocument<T>(path: string, fn: (doc: number) => Promise<T>): Promise<T> {
|
||||
const open = editorsFor(path)[0];
|
||||
if (open) return fn(open.ctx.doc);
|
||||
const info = await lspRequest(() => commands.docOpen(path));
|
||||
// Library types (`jdt://…`) are documents the language server provides, not files on disk.
|
||||
const info = await lspRequest(() => (isVirtualUri(path) ? commands.docOpenVirtual(path) : commands.docOpen(path)));
|
||||
try {
|
||||
return await fn(info.id);
|
||||
} finally {
|
||||
|
||||
@@ -176,6 +176,24 @@ describe("run config → launch config", () => {
|
||||
expect(extra(uv)).toMatchObject({ python: ["uv", "run", "python"], debugLauncherPython: "python" });
|
||||
});
|
||||
|
||||
it("debugpy: a Windows venv interpreter or tool path debugs with that interpreter", () => {
|
||||
usePlatform.setState({ os: "windows" });
|
||||
const venv = "C:\\work\\app\\.venv\\Scripts\\";
|
||||
const script = launchConfigFor(
|
||||
rc({ kind: "python", command: `${venv}python.exe`, args: ["main.py"], debugAdapter: "debugpy" }),
|
||||
"C:/work/app",
|
||||
)!;
|
||||
expect(extra(script).python).toBe(`${venv}python.exe`);
|
||||
expect(extra(script).module).toBeUndefined();
|
||||
expect(script.program).toBe("C:/work/app/main.py");
|
||||
|
||||
const pytest = launchConfigFor(
|
||||
rc({ kind: "pytest", command: `${venv}pytest.exe`, args: ["-x"], debugAdapter: "debugpy" }),
|
||||
"C:/work/app",
|
||||
)!;
|
||||
expect(extra(pytest)).toMatchObject({ module: "pytest", python: `${venv}python.exe` });
|
||||
});
|
||||
|
||||
it("js-debug: npm scripts run through the package manager, node scripts directly", () => {
|
||||
const npm = launchConfigFor(
|
||||
rc({ kind: "npm", command: "pnpm", args: ["run", "dev"], cwd: "web", debugAdapter: "js-debug" }),
|
||||
|
||||
@@ -76,7 +76,7 @@ function cargoLaunch(rc: RunConfig, cwd: string, adapter: string): LaunchConfig
|
||||
};
|
||||
}
|
||||
|
||||
const PYTHON_NAME = /^python[\d.]*(\.exe)?$/;
|
||||
const PYTHON_NAME = /^python[\d.]*(\.exe)?$/i;
|
||||
|
||||
/** `python` on Windows (`python3` is at most a Store alias there, and venvs have no `python3.exe`), `python3` elsewhere. */
|
||||
function systemPython(): string {
|
||||
@@ -85,10 +85,10 @@ function systemPython(): string {
|
||||
|
||||
function pythonFor(rc: RunConfig, cwd: string): string {
|
||||
const cmd = rc.command;
|
||||
const name = cmd.split("/").pop() ?? cmd;
|
||||
if (PYTHON_NAME.test(name)) return resolveCommand(cmd, cwd);
|
||||
// A venv tool such as `.venv/bin/pytest`: use the interpreter next to it.
|
||||
if (cmd.includes("/")) return resolveCommand(cmd.slice(0, cmd.lastIndexOf("/") + 1) + "python", cwd);
|
||||
if (PYTHON_NAME.test(commandName(cmd))) return resolveCommand(cmd, cwd);
|
||||
// A venv tool such as `.venv/bin/pytest` or `.venv\Scripts\pytest.exe`: use the interpreter next to it.
|
||||
const dir = cmd.slice(0, Math.max(cmd.lastIndexOf("/"), cmd.lastIndexOf("\\")) + 1);
|
||||
if (dir) return resolveCommand(dir + (hostOs() === "windows" ? "python.exe" : "python"), cwd);
|
||||
return systemPython();
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ function debugpyLaunch(rc: RunConfig, cwd: string): LaunchConfig {
|
||||
subProcess: dbg.python.attachSubprocess,
|
||||
};
|
||||
if (dbg.python.gevent) extra.gevent = true;
|
||||
const name = (rc.command.split("/").pop() ?? rc.command).replace(/\.exe$/, "");
|
||||
const name = commandName(rc.command);
|
||||
let args = rc.args;
|
||||
let tool: string | null = PYTHON_NAME.test(name) ? null : name;
|
||||
if (PYTHON_RUNNERS.has(name) && args[0] === "run" && args[1]) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import { call, commands, isTauri } from "./platform/ipc";
|
||||
import { hideSplash } from "./platform/splash";
|
||||
import { prefetchLazyComponents } from "./ui";
|
||||
import { installWindowDrag } from "./workbench/window-drag";
|
||||
import { installFullscreenEscapeGuard } from "./workbench/fullscreenEscape";
|
||||
|
||||
if (import.meta.env.DEV && isTauri()) {
|
||||
// The Tauri MCP bridge returns eval results via `window.__TAURI__` on Windows/Linux
|
||||
@@ -71,6 +72,8 @@ if (aux?.kind === "settings") {
|
||||
activateSecondaryWindow();
|
||||
activateDeploymentWindowFeatures(aux.parent);
|
||||
} else {
|
||||
// Before the features' and the dispatcher's key handlers: it wraps the Escape they see.
|
||||
installFullscreenEscapeGuard();
|
||||
activateWorkbench();
|
||||
// `vite build --mode perf` is a production bundle for the performance harness (`perf/`).
|
||||
const perfBuild = import.meta.env.MODE === "perf";
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { usePlatform } from "@/platform/platformInfo";
|
||||
import { installFullscreenEscapeGuard } from "./fullscreenEscape";
|
||||
|
||||
let fullscreen = true;
|
||||
let dispose = () => {};
|
||||
const escape = (target: EventTarget) => {
|
||||
const e = new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true });
|
||||
target.dispatchEvent(e);
|
||||
return e;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
fullscreen = true;
|
||||
usePlatform.setState({ os: "macos" });
|
||||
dispose = installFullscreenEscapeGuard(window, () => fullscreen);
|
||||
});
|
||||
afterEach(() => {
|
||||
dispose();
|
||||
document.body.replaceChildren();
|
||||
});
|
||||
|
||||
describe("Escape in full screen", () => {
|
||||
it("is marked handled when nothing handles it, so the window stays in full screen", () => {
|
||||
expect(escape(document.body).defaultPrevented).toBe(true);
|
||||
});
|
||||
|
||||
it("is marked handled when a handler stops it", () => {
|
||||
const popup = document.body.appendChild(document.createElement("div"));
|
||||
popup.addEventListener("keydown", (e) => e.stopPropagation());
|
||||
expect(escape(popup).defaultPrevented).toBe(true);
|
||||
// The next key press is not affected by a listener left behind.
|
||||
fullscreen = false;
|
||||
expect(escape(document.body).defaultPrevented).toBe(false);
|
||||
});
|
||||
|
||||
it("reaches other handlers not yet default-prevented", () => {
|
||||
let seen: boolean | null = null;
|
||||
const onKey = (e: KeyboardEvent) => (seen = e.defaultPrevented);
|
||||
window.addEventListener("keydown", onKey);
|
||||
escape(document.body);
|
||||
window.removeEventListener("keydown", onKey);
|
||||
expect(seen).toBe(false);
|
||||
});
|
||||
|
||||
it("is left alone outside full screen and on other systems", () => {
|
||||
fullscreen = false;
|
||||
expect(escape(document.body).defaultPrevented).toBe(false);
|
||||
fullscreen = true;
|
||||
usePlatform.setState({ os: "windows" });
|
||||
expect(escape(document.body).defaultPrevented).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* macOS: an Escape key press the page leaves unhandled (not default-prevented) goes back from
|
||||
* WebKit to AppKit as the web view's `cancelOperation:`, and AppKit answers it in a full-screen
|
||||
* window by leaving full screen, so pressing Escape once more after closing a popup dropped the
|
||||
* IDE out of full screen. While this window is in full screen, Escape is marked handled after
|
||||
* everything else has seen it; View › Appearance › Toggle Full Screen (⌃⌘F) leaves full screen.
|
||||
*/
|
||||
import { commands, isTauri, onIdeEvent } from "@/platform/ipc";
|
||||
import { usePlatform } from "@/platform/platformInfo";
|
||||
|
||||
/** Installs the guard on `target`; `isFullscreen` is this window's state (tests pass their own). */
|
||||
export function installFullscreenEscapeGuard(
|
||||
target: Window = window,
|
||||
isFullscreen: () => boolean = trackFullscreen(),
|
||||
): () => void {
|
||||
const onCapture = (e: KeyboardEvent) => {
|
||||
if (e.key !== "Escape" || e.isComposing || usePlatform.getState().os !== "macos" || !isFullscreen()) return;
|
||||
// Runs last in the bubble phase: handlers that check `defaultPrevented` see the event as it was.
|
||||
const handled = () => e.preventDefault();
|
||||
target.addEventListener("keydown", handled, { once: true });
|
||||
// A handler that stops the event has handled it; the bubble listener above won't run then.
|
||||
for (const name of ["stopPropagation", "stopImmediatePropagation"] as const) {
|
||||
const stop = e[name].bind(e);
|
||||
e[name] = () => {
|
||||
target.removeEventListener("keydown", handled);
|
||||
e.preventDefault();
|
||||
stop();
|
||||
};
|
||||
}
|
||||
};
|
||||
// Capture on the window before anything else is installed: it runs first.
|
||||
target.addEventListener("keydown", onCapture, true);
|
||||
return () => target.removeEventListener("keydown", onCapture, true);
|
||||
}
|
||||
|
||||
function trackFullscreen(): () => boolean {
|
||||
let fullscreen = false;
|
||||
if (!isTauri()) return () => fullscreen;
|
||||
const sync = () =>
|
||||
void commands
|
||||
.windowIsFullscreen()
|
||||
.then((on) => (fullscreen = on))
|
||||
.catch(() => {});
|
||||
sync();
|
||||
onIdeEvent("windowFullscreenChanged", sync);
|
||||
return () => fullscreen;
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача