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
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["crates/openpl-oracle", "crates/openpl-core", "app/src-tauri"]

[workspace.package]
version = "1.0.0-beta.12"
version = "1.0.0-beta.13"
edition = "2021"
license = "Apache-2.0 OR MIT"

Expand Down
4 changes: 2 additions & 2 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "openpl",
"private": true,
"version": "1.0.0-beta.12",
"version": "1.0.0-beta.13",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion app/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "OpenPL",
"version": "1.0.0-beta.12",
"version": "1.0.0-beta.13",
"identifier": "org.openpl.app",
"build": {
"beforeDevCommand": "npm run dev",
Expand Down
2 changes: 1 addition & 1 deletion app/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ test("compara el programa en su sesión aunque el explorador cambie de conexión
expect(
session.queryByRole("menuitem", { name: /Preparar compilación/ }),
).not.toBeInTheDocument();
expect(session.getByRole("menuitem", { name: /^Ejecutar(?! script)/ })).toBeEnabled();
expect(session.getByRole("menuitem", { name: /^Ejecutar(?! script| sentencia)/ })).toBeEnabled();
fireEvent.keyDown(document, { key: "Escape" });
fireEvent.keyDown(window, { key: "d", altKey: true, shiftKey: true });
expect(await screen.findByText("Sin diferencias de texto")).toBeInTheDocument();
Expand Down
7 changes: 5 additions & 2 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const SqlWindow = lazy(() =>
const quoteName = (name: string) => `"${name.replace(/"/g, '""')}"`;
const TAB_DRAG_TYPE = "application/x-openpl-tab";
const sqlTabActions = [
"executeStatement",
"execute",
"showSymbolCard",
"goToDefinition",
Expand Down Expand Up @@ -271,7 +272,7 @@ export default function App() {
(program.sql!.transaction && !program.sql!.busy),
)
.map((id) => [id, () => {
if (id === "execute" && states[program.sql!.sessionId] === "Disconnected") {
if ((id === "execute" || id === "executeStatement") && states[program.sql!.sessionId] === "Disconnected") {
reconnectSqlButton.current?.focus();
showNotice(reconnectErrors[program.sql!.sessionId] ?? "Sesión desconectada");
return;
Expand All @@ -298,6 +299,7 @@ export default function App() {
"compareProgram",
"test",
"execute",
"executeStatement",
"cancel",
"goToLine",
"find",
Expand All @@ -321,7 +323,7 @@ export default function App() {
if (id === "test") return !!program.object && !!editorConnection;
if (id === "compareProgram")
return !!program.object && !!editorConnection;
if (id === "execute" || id === "cancel")
if (id === "execute" || id === "executeStatement" || id === "cancel")
return !!program.object && !!editorConnection && !program.readOnly;
if (id === "spec" || id === "body" || id === "sideBySide")
return program.parts.length === 2;
Expand Down Expand Up @@ -1168,6 +1170,7 @@ export default function App() {
run("reconnect"),
"sep",
run("execute"),
run("executeStatement"),
run("executeScript"),
run("cancel"),
"sep",
Expand Down
46 changes: 46 additions & 0 deletions app/src/components/ProgramWindow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -980,3 +980,49 @@ test("Ctrl+clic sin contexto de símbolos igual ubica el cursor", async () => {
fireEvent.mouseDown(view.contentDOM, { ctrlKey: true, button: 0, clientX: 5, clientY: 5 });
await waitFor(() => expect(view.state.selection.main.head).toBe(position));
});

test("Ctrl+Enter compila igual que F8", async () => {
const ref = createRef<ProgramActions>();
const compile = compiler();
render(<ProgramWindow ref={ref} parts={[compiled]} readOnly={false} onDirty={vi.fn()}
readCurrentProgram={vi.fn().mockResolvedValue([compiled])} compilationTarget={hrTarget} compile={compile} />);
await act(async () => ref.current?.executeStatement?.());
expect(compile.run).toHaveBeenCalledWith(compiledStatement);
});

describe("menú de Estructura", () => {
const spec = "PACKAGE PKG_A AS\n PROCEDURE publico;\nEND;";
const body = "PACKAGE BODY PKG_A AS\n PROCEDURE privado IS\n BEGIN\n NULL;\n END;\n PROCEDURE publico IS BEGIN NULL; END;\nEND;";
const both = [{ ...parts[0], source: spec }, { ...parts[1], source: body }];
const openMenu = () => {
fireEvent.click(screen.getByRole("tab", { name: /^Body/ }));
const outline = within(screen.getByRole("complementary", { name: "Estructura" }));
fireEvent.contextMenu(outline.getByRole("button", { name: /privado.*Privado/ }));
};

test("Copiar código copia la rutina privada entera", async () => {
const { clipboard } = await import("../api");
const write = vi.spyOn(clipboard, "writeText").mockResolvedValue();
render(<ProgramWindow readOnly={false} onDirty={vi.fn()} parts={both} />);
openMenu();
fireEvent.click(screen.getByRole("menuitem", { name: "Copiar código" }));
expect(write).toHaveBeenCalledWith("PROCEDURE privado IS\n BEGIN\n NULL;\n END;");
});

test("Comentar comenta la rutina y un solo deshacer la restaura", () => {
render(<ProgramWindow readOnly={false} onDirty={vi.fn()} parts={both} />);
openMenu();
fireEvent.click(screen.getByRole("menuitem", { name: "Comentar" }));
const view = EditorView.findFromDOM(screen.getByRole("textbox", { name: "Body" }).closest<HTMLElement>(".cm-editor")!)!;
expect(view.state.doc.toString()).toContain(" -- PROCEDURE privado IS\n -- BEGIN\n -- NULL;\n -- END;");
act(() => { undo(view); });
expect(view.state.doc.toString()).toBe(body);
});

test("en solo lectura no se puede comentar", () => {
render(<ProgramWindow readOnly onDirty={vi.fn()} parts={both} />);
openMenu();
expect(screen.getByRole("menuitem", { name: "Copiar código" })).toBeInTheDocument();
expect(screen.queryByRole("menuitem", { name: "Comentar" })).not.toBeInTheDocument();
});
});
47 changes: 42 additions & 5 deletions app/src/components/ProgramWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { startCompletion } from "@codemirror/autocomplete";
import { gotoLine } from "@codemirror/search";
import { findNextMatch, findPrevMatch, openFind, openReplace } from "./EditorSearch";
import { copyLineDown, deleteLine, indentLess, indentMore, redo, toggleComment, undo } from "@codemirror/commands";
import { api } from "../api";
import { api, clipboard } from "../api";
import { programSymbols } from "../programSymbols";
import { toggleLineComments } from "../lineComments";
import { commands, formatKeys, type CommandId } from "../keymap";
import { describeError, type ObjectInfo, type ProgramPart } from "../types";
import { editorReference } from "../editorReference";
Expand All @@ -22,7 +24,7 @@ import { ProgramComparison, type ComparisonResult } from "./ProgramComparison";
import { compileStatement, type CompilationTarget } from "../programScript";
import { programStructure, type DeclarationKind, type ProgramDeclaration } from "../programStructure";
import { useCompletionCatalog } from "../useCompletionCatalog";
import { ContextMenu } from "./ContextMenu";
import { ContextMenu, type ContextItem } from "./ContextMenu";
import type { SourcePart, SymbolLookup } from "../symbolSources";
import { editorPart, showSymbolCard, type ContextFor } from "../symbolHover";

Expand Down Expand Up @@ -129,6 +131,8 @@ export function ProgramWindow({
const [objectMenu, setObjectMenu] = useState<(ObjectRequest & { id: number; part: number; position: number }) | null>(null);
const [declarationMenu, setDeclarationMenu] = useState<{ title: string; x: number; y: number; targets: NavigationTarget[] } | null>(null);
const [routineMenu, setRoutineMenu] = useState<{ name: string; x: number; y: number } | null>(null);
const [outlineMenu, setOutlineMenu] = useState<{ entry: ProgramDeclaration; index: number; x: number; y: number } | null>(null);
const closeOutlineMenu = useCallback(() => setOutlineMenu(null), []);
const closeRoutineMenu = useCallback(() => setRoutineMenu(null), []);
const [description, setDescription] = useState<{ object: ObjectInfo; sessionId: string; id: number } | null>(null);
const [outlineWidth, setOutlineWidthState] = useState(storedOutlineWidth);
Expand Down Expand Up @@ -270,6 +274,31 @@ export function ProgramWindow({
closeDeclarationMenu();
setRoutineMenu({ name: entry.name, x, y });
}
/** Probar, Copiar código y Comentar/Descomentar para una entrada de Estructura. */
function outlineItems(entry: ProgramDeclaration, index: number): ContextItem[] {
const view = views.current[index];
const text = view?.state.doc.toString() ?? parts[index].source;
const range = programSymbols(text).find((symbol) => symbol.from === entry.from && symbol.range)?.range;
const items: ContextItem[] = [];
if (onTestRoutine && canTest(entry, index)) {
items.push({ label: "Probar", keys: commands.test.keys, run: () => onTestRoutine(entry.name, outlineMenu?.x ?? 0, outlineMenu?.y ?? 0) });
}
if (!range) return items;
items.push({
label: "Copiar código",
run: () => void clipboard.writeText(text.slice(range.from, range.to)).catch((error) => setMessage(describeError(error).message)),
});
if (!readOnly && view) {
const { changes, commented } = toggleLineComments(text, range.from, range.to);
items.push({
label: commented ? "Descomentar" : "Comentar",
// Una sola transacción: un Ctrl+Z lo deshace.
run: () => view.dispatch({ changes, userEvent: "input" }),
});
}
return items;
}

function routineAt(index: number, position: number) {
const { texts, first, second, keys } = structureNow();
return (index === 0 ? first : second).find((entry) =>
Expand Down Expand Up @@ -524,6 +553,7 @@ export function ProgramWindow({
unfoldBlock: runInEditor(unfoldCode),
compareProgram: readCurrentProgram ? () => void compare() : undefined,
execute: canCompile ? () => void compileActive() : undefined,
executeStatement: canCompile ? () => void compileActive() : undefined,
cancel: canCompile ? stopCompilation : undefined,
test: onTestRoutine ? runInEditor((view) => {
const position = view.state.selection.main.head;
Expand Down Expand Up @@ -613,10 +643,13 @@ export function ProgramWindow({
return (
<button key={entry.from} type="button" title={`${KIND_BADGES[entry.kind].label} · ${entry.label}`}
aria-label={[KIND_BADGES[entry.kind].label, entry.label, visibility].filter(Boolean).join(" ")}
onContextMenu={canTest(entry, selected) ? (event) => {
onContextMenu={(event) => {
event.preventDefault();
openRoutineMenu(entry, event.clientX, event.clientY);
} : undefined}
closeObjectMenu();
closeDeclarationMenu();
closeRoutineMenu();
setOutlineMenu({ entry, index: selected, x: event.clientX, y: event.clientY });
}}
onClick={() => navigateAt(selected, entry.from)}>
<span className={`decl-badge decl-${entry.kind}`} aria-hidden>{KIND_BADGES[entry.kind].letter}</span>
<span className="program-outline-name">{entry.label}</span>
Expand Down Expand Up @@ -717,6 +750,10 @@ export function ProgramWindow({
onMessage={setMessage}
onDescribe={(object) => setDescription({ object, sessionId: catalog.sessionId, id: objectMenu.id })} />
)}
{active && outlineMenu && (
<ContextMenu x={outlineMenu.x} y={outlineMenu.y} label={outlineMenu.entry.label} onClose={closeOutlineMenu}
items={outlineItems(outlineMenu.entry, outlineMenu.index)} />
)}
{active && routineMenu && onTestRoutine && (
<ContextMenu x={routineMenu.x} y={routineMenu.y} label={routineMenu.name} onClose={closeRoutineMenu}
items={[...(readOnlyItem ? [readOnlyItem] : []), { label: "Probar", keys: commands.test.keys, run: () => onTestRoutine(routineMenu.name, routineMenu.x, routineMenu.y) }]} />
Expand Down
Loading
Loading