Compare commits

...
Author SHA1 Message Date
l0ng-ai fd0c8a9f05 fix(github): recognise remotes cloned through ssh.github.com
A repository cloned over GitHub's SSH-over-HTTPS host (ssh://[email protected]:443/o/r.git) wasn't recognised as a GitHub repository, so pull requests and issues weren't offered for it. The host is accepted for SSH remotes; https://ssh.github.com is still not a GitHub web URL.
2026-11-14 22:57:23 +08:00
akshathayadav378-boopandakshathayadav378-boop 13e18af777 fix(vcs): open Bitbucket SSH clones on bitbucket.org (#3379)
For a Bitbucket Cloud repository cloned over SSH ([email protected]:team/repo.git), Open In used ssh.bitbucket.org as the web host and GitLab routes. remoteWebUrl now maps the services' SSH front hosts (ssh.bitbucket.org, ssh.github.com, altssh.gitlab.com) to their web hosts before building the URL.

Co-authored-by: akshathayadav378-boop <[email protected]>
2026-11-14 22:54:44 +08:00
charlie-morrisonandcharlie-morrison 488e819b46 fix(vcs): keep the merge editor responsive on long files (#3381)
Opening a conflicted package-lock.json in the merge editor froze the app. The Your/Their panes diffed each side against the base with @codemirror/merge's default config, which gives up past ~16 KB of changed span and returns one chunk from the first change to the last, so each pane rendered the whole base as one deletion widget; syncMergeScroll ran an unbounded character diff on first scroll. Both now use the IDEA line comparison the diff viewer uses (ideaDiffConfig).

Co-authored-by: charlie-morrison <[email protected]>
2026-11-14 22:53:04 +08:00
l0ng-ai ad8df8fe00 feat(database): open several query consoles per data source (#3386)
New › Query Console always reopened the single console of a data source. It now creates another console each time (console, console_1, console_2…, as in DataGrip); Jump to Query Console opens the only console directly or lists them with New Query Console; Tools › Query Console keeps opening the default one. Backend: db_consoles(id, create).
2026-11-14 22:50:51 +08:00
20 changed files with 206 additions and 13 deletions

No files matched your search

+45 -6
View File
@@ -12,6 +12,7 @@ use ide_db::{
};
use serde::{Deserialize, Serialize};
use specta::Type;
use std::path::PathBuf;
/// One statement of a console run.
#[derive(Clone, Serialize, Deserialize, Type)]
@@ -179,6 +180,7 @@ pub(crate) fn register(d: &mut Dispatcher) {
apply_edits(&c.host, &c.window, &id, &schema, &table, edits).await
});
d.add("db_console_path", |c| async move { console_path(&c.host, &c.arg::<String>("id")?) });
d.add("db_consoles", |c| async move { consoles(&c.host, &c.arg::<String>("id")?, c.arg("create")?) });
}
/// The data sources configured for the project (the tree's roots).
@@ -472,11 +474,52 @@ pub async fn apply_edits(
/// created on first use. Consoles are files of the project, so a remote
/// window resolves it on the host the project runs on.
pub fn console_path(host: &Host, id: &str) -> IdeResult<IpcPath> {
let file = console_dir(host, id)?.join("console.sql");
if !file.exists() {
std::fs::write(&file, "")?;
}
Ok(file.into())
}
/// The query consoles of data source `id`: the default `console.sql`, then
/// `console_1.sql`, `console_2.sql`… in order. `create` adds the next one first
/// (DataGrip's New › Query Console).
pub fn consoles(host: &Host, id: &str, create: bool) -> IdeResult<Vec<IpcPath>> {
let dir = console_dir(host, id)?;
let default = dir.join("console.sql");
let mut numbered: Vec<(u32, PathBuf)> = std::fs::read_dir(&dir)?
.filter_map(|e| {
let path = e.ok()?.path();
let n = path.file_name()?.to_str()?.strip_prefix("console_")?.strip_suffix(".sql")?.parse().ok()?;
Some((n, path))
})
.collect();
numbered.sort();
if create {
// The default console comes first; once it exists, the next number.
if !default.exists() {
std::fs::write(&default, "")?;
} else {
let n = numbered.last().map_or(1, |(n, _)| n + 1);
let file = dir.join(format!("console_{n}.sql"));
std::fs::write(&file, "")?;
numbered.push((n, file));
}
}
let mut out: Vec<IpcPath> = Vec::new();
if default.exists() {
out.push(default.into());
}
out.extend(numbered.into_iter().map(|(_, p)| p.into()));
Ok(out)
}
/// `<dataDir>/consoles/db/<id>`: `<id>` for the default database, `<id>.<database>` for the others.
fn console_dir(host: &Host, id: &str) -> IdeResult<PathBuf> {
let (source, database) = ide_db::split_target(id);
if source.is_empty() || !source.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_') {
return Err(IdeError::invalid("invalid data source id"));
}
// One console per database: `<id>` for the default one, `<id>.<database>` for the others.
let name = match database {
Some(db) => {
let safe: String =
@@ -487,9 +530,5 @@ pub fn console_path(host: &Host, id: &str) -> IdeResult<IpcPath> {
};
let dir = host.data_dir.join("consoles").join("db").join(&name);
std::fs::create_dir_all(&dir)?;
let file = dir.join("console.sql");
if !file.exists() {
std::fs::write(&file, "")?;
}
Ok(file.into())
Ok(dir)
}
+1
View File
@@ -357,6 +357,7 @@ pub fn restricted_command_allowed(cmd: &str) -> bool {
| "docker_set_registry_password"
| "docker_run_env"
| "db_console_path"
| "db_consoles"
| "db_export_file"
| "vcs_write_patch"
| "app_metrics"
+37
View File
@@ -0,0 +1,37 @@
use ide_core::NullSink;
use ide_host::ops::db;
use ide_host::{Host, HostConfig};
use std::sync::Arc;
#[tokio::test]
async fn new_query_consoles_are_numbered_after_the_default_one() {
let tmp = tempfile::tempdir().unwrap();
let base = tmp.path();
let host = Arc::new(Host::new(HostConfig {
config_dir: base.join("config"),
data_dir: base.join("data"),
local_data_dir: base.join("data"),
languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()),
syntax: Arc::default(),
sink_for: Box::new(|_| Arc::new(NullSink)),
owner: |w| w,
runtime: tokio::runtime::Handle::current(),
project_environment: false,
}));
let names = |paths: Vec<ide_core::IpcPath>| -> Vec<String> {
paths.iter().map(|p| p.0.file_name().unwrap().to_string_lossy().into_owned()).collect()
};
assert!(db::consoles(&host, "pg", false).unwrap().is_empty());
// The first new console is the default one, then console_1, console_2…
assert_eq!(names(db::consoles(&host, "pg", true).unwrap()), ["console.sql"]);
assert_eq!(names(db::consoles(&host, "pg", true).unwrap()), ["console.sql", "console_1.sql"]);
let all = db::consoles(&host, "pg", true).unwrap();
assert_eq!(names(all.clone()), ["console.sql", "console_1.sql", "console_2.sql"]);
// Numbers sort numerically, and the default console path is the first one.
std::fs::write(all[0].0.with_file_name("console_10.sql"), "").unwrap();
assert_eq!(names(db::consoles(&host, "pg", false).unwrap())[3], "console_10.sql");
assert_eq!(db::console_path(&host, "pg").unwrap().0, all[0].0);
// Each database of a source has its own consoles.
assert!(db::consoles(&host, "pg:other", false).unwrap().is_empty());
assert!(db::consoles(&host, "../x", true).is_err());
}
+1
View File
@@ -365,6 +365,7 @@ async fn local_deployment_runs_on_the_project_host() {
"db_table_page",
"db_apply_edits",
"db_console_path",
"db_consoles",
"ssh_test",
"ssh_set_secret",
"ssh_password_saved",
+1
View File
@@ -66,6 +66,7 @@ async fn application_commands_work_in_restricted_projects_and_without_a_project(
"docker_set_registry_password",
"docker_run_env",
"db_console_path",
"db_consoles",
"db_export_file",
"vcs_write_patch",
"remote_bootstrap_list",
+14
View File
@@ -172,6 +172,20 @@ test("accepting a deleted version removes the file before staging", async ({ pag
]);
});
test("a long side shows only the lines it changed against the base", async ({ page }) => {
// Edits spread over a long file make the default diff give up and mark everything between them.
const base = Array.from({ length: 2000 }, (_, i) => `"node_modules/pkg-${i}": "1.0.${i}",`);
const bump = (at: number) => lines(...base.map((l, i) => (i % 100 === at ? l.replace('"1.0.', '"2.0.') : l)));
await mountMerge(page, [lines(...base), bump(3), bump(50)]);
for (const [name, line] of [
["Your version", 3],
["Their version", 50],
] as const) {
const deleted = page.getByRole("region", { name }).locator(".cm-deletedChunk").first().locator(".cm-deletedLine");
await expect(deleted).toHaveText([base[line]!]);
}
});
test("the result starts as the base and every change waits for a decision", async ({ page }) => {
await mountMerge(page);
await expect(status(page)).toHaveText("3 changes left, 2 conflicts");
+7
View File
@@ -362,3 +362,10 @@ pub async fn db_apply_edits(
pub fn db_console_path(state: State<'_, AppState>, id: String) -> IdeResult<IpcPath> {
ide_host::ops::db::console_path(&state.host, &id)
}
/// The query consoles of data source `id`; `create` adds the next one first.
#[tauri::command]
#[specta::specta]
pub fn db_consoles(state: State<'_, AppState>, id: String, create: bool) -> IdeResult<Vec<IpcPath>> {
ide_host::ops::db::consoles(&state.host, &id, create)
}
+1
View File
@@ -747,5 +747,6 @@ pub fn builder() -> tauri_specta::Builder<tauri::Wry> {
db::db_table_page,
db::db_apply_edits,
db::db_console_path,
db::db_consoles,
])
}
+2
View File
@@ -1731,6 +1731,8 @@ export const commands = {
dbTablePage: (request: RequestId, id: string, schema: string, table: string, filter: string | null, sort: DbSortKey[], offset: number, limit: number) => typedError<DbTablePage, IdeError>(__TAURI_INVOKE("db_table_page", { request, id, schema, table, filter, sort, offset, limit })),
dbApplyEdits: (id: string, schema: string, table: string, edits: DbRowEdit[]) => typedError<number | null, IdeError>(__TAURI_INVOKE("db_apply_edits", { id, schema, table, edits })),
dbConsolePath: (id: string) => typedError<IpcPath, IdeError>(__TAURI_INVOKE("db_console_path", { id })),
/** The query consoles of data source `id`; `create` adds the next one first. */
dbConsoles: (id: string, create: boolean) => typedError<IpcPath[], IdeError>(__TAURI_INVOKE("db_consoles", { id, create })),
};
/* Types */
+19
View File
@@ -38,6 +38,7 @@ import {
loadDatabases,
listsDatabases,
sourceById,
newConsole,
openConsole,
openHistory,
openSourceDialog,
@@ -198,6 +199,24 @@ export function activate(): () => void {
else toolWindowService().show(DB_TOOL_WINDOW, true);
},
},
{
id: "db.newConsole",
title: "New Query Console",
category: "Tools",
icon: "db-console",
keywords: ["database", "sql console"],
when: "projectOpen",
run: async ({ arg }) => {
const current = projectRequest();
if (!useDatabase.getState().loaded) await loadSources();
if (!current()) return;
const { sources, selectedSource } = useDatabase.getState();
const node = arg && typeof arg === "object" && "kind" in arg ? nodeTarget(arg as DbNode) : null;
const id = node ?? selectedSource ?? (sources.length === 1 ? sources[0]!.id : null);
if (id) await newConsole(id);
else toolWindowService().show(DB_TOOL_WINDOW, true);
},
},
{
id: "db.execute",
title: "Execute SQL Statement",
+23
View File
@@ -906,6 +906,29 @@ export async function openConsole(id: string): Promise<void> {
}
}
/** The query console files of data source `id`: `console.sql`, then `console_1.sql`, `console_2.sql`… */
export function consoleFiles(id: string): Promise<string[]> {
return call(commands.dbConsoles(id, false));
}
/** Opens one of the query consoles of data source `id`. */
export async function openConsoleFile(id: string, path: string): Promise<void> {
bindConsole(path, id);
await editorService().openFile(path, { focus: true });
}
/** Creates and opens another query console of data source `id` (DataGrip's New › Query Console). */
export async function newConsole(id: string): Promise<void> {
try {
const before = new Set(await consoleFiles(id));
const after = await call(commands.dbConsoles(id, true));
const path = after.find((p) => !before.has(p)) ?? after[after.length - 1];
if (path) await openConsoleFile(id, path);
} catch (e) {
notifications().notify({ level: "error", title: "Cannot open the query console", body: message(e) });
}
}
let nextTab = 1;
let nextRun = 1;
let nextLine = 1;
+16 -1
View File
@@ -22,7 +22,10 @@ import {
loadSchemas,
loadSources,
loadTables,
consoleFiles,
newConsole,
openConsole,
openConsoleFile,
openConsoleWith,
openDdl,
openObjectDdl,
@@ -42,6 +45,7 @@ import {
} from "./store";
import { tableInput } from "./tableInput";
import { tx } from "@/platform/i18n";
import { chooseItem } from "@/workbench/inputDialogs";
import { databaseRequest } from "./requests";
/** Context key: the Database tree has focus. */
@@ -279,7 +283,7 @@ export function registerDatabaseTreeActions(): () => void {
const id = n ? nodeTarget(n) : null;
const { sources } = useDatabase.getState();
const target = id ?? (sources.length === 1 ? (sources[0]!.id ?? null) : null);
if (target) void openConsole(target);
if (target) void jumpToConsole(target);
else toolWindowService().show(DB_TOOL_WINDOW, true);
},
}),
@@ -524,3 +528,14 @@ export function registerDatabaseTreeActions(): () => void {
}),
]);
}
/** One console opens directly; with several, DataGrip's list of them plus New Query Console. */
async function jumpToConsole(id: string): Promise<void> {
const files = await consoleFiles(id).catch(() => []);
if (files.length <= 1) return openConsole(id);
const names = files.map((f) => (f.split(/[\\/]/).pop() ?? f).replace(/\.sql$/, ""));
const create = tx("New Query Console");
const picked = await chooseItem({ title: "Query Consoles", items: [...names, create] });
if (picked === create) await newConsole(id);
else if (picked) await openConsoleFile(id, files[names.indexOf(picked)]!);
}
+2 -2
View File
@@ -66,7 +66,7 @@ async function sourceFromClipboard() {
/** The toolbar's "+" menu (IDEA: New). */
export function newMenu(): MenuItem[] {
return [{ kind: "action", action: "db.openConsole", label: "Query Console" }, sep, ...dataSourceItems()];
return [{ kind: "action", action: "db.newConsole", label: "Query Console" }, sep, ...dataSourceItems()];
}
function sqlScripts(n: DbNode, table: boolean): MenuItem {
@@ -88,7 +88,7 @@ export function nodeMenu(n: DbNode | null): MenuItem[] {
const driver = sourceById(id)?.driver ?? "sqlite";
const o = objectOf(n);
const t = tableOf(n);
const newConsole = act("db.openConsole", n, { label: "Query Console", icon: "db-console" });
const newConsole = act("db.newConsole", n, { label: "Query Console", icon: "db-console" });
const refresh = act("db.refresh", n);
const quickDoc = act("db.quickDoc", n);
const rename = act("db.rename", n, { disabled: !(n.kind === "source" || (o && canRename(driver, o))) });
+3
View File
@@ -401,6 +401,9 @@ describe("pull request helpers", () => {
"ssh://[email protected]/o/r.git",
"ssh://[email protected]:22/o/r.git",
"git://github.com/o/r",
// GitHub's SSH-over-HTTPS host.
"ssh://[email protected]:443/o/r.git",
"[email protected]:o/r.git",
])
expect(parseGitHubRemote(url), url).toEqual({ owner: "o", name: "r" });
expect(parseGitHubRemote("https://gitlab.com/o/r.git")).toBeNull();
+2 -2
View File
@@ -413,10 +413,10 @@ export function repositoryDisplayName(
return showOwner ? `${repo.owner}/${repo.name}` : repo.name;
}
/** `owner/name` of a github.com remote URL (https, ssh or scp-like), else null. */
/** `owner/name` of a github.com remote URL (https, ssh or scp-like; SSH also via ssh.github.com), else null. */
export function parseGitHubRemote(url: string): GHRepositoryCoordinates | null {
const m =
/^(?:https?:\/\/(?:[^@/]+@)?|ssh:\/\/(?:[^@/]+@)?|git:\/\/|(?:[^@/]+@)?)(?:www\.)?github\.com(?::\d+(?=\/))?[:/]+([^/]+)\/([^/]+?)(?:\.git)?\/?$/i.exec(
/^(?:(?:https?:\/\/(?:[^@/]+@)?|git:\/\/)(?:www\.)?|(?:ssh:\/\/(?:[^@/]+@)?|(?:[^@/]+@)?)(?:www\.|ssh\.)?)github\.com(?::\d+(?=\/))?[:/]+([^/]+)\/([^/]+?)(?:\.git)?\/?$/i.exec(
url.trim(),
);
return m ? { owner: m[1]!, name: m[2]! } : null;
+8 -1
View File
@@ -15,6 +15,7 @@ import { Button, Spinner, T } from "@/ui";
import { editorService, type EditorInput } from "@/workbench/contributions";
import { blameSlot, toggleAnnotations } from "./blame";
import { languageFor, viewerBase } from "./cm";
import { ideaDiffConfig } from "./diffOptions";
import { confirmDialog } from "./dialogs";
import { focusedDiffNavigator, setFocusedDiffNavigator, type DiffNavigator } from "./diffNavigator";
import { syncMergeScroll } from "./mergeScroll";
@@ -92,6 +93,10 @@ const writeAutoApply = (on: boolean) => {
}
};
// Each side against the base is compared line by line, as in the diff viewer. The default diff
// gives up on long files and marks the whole file as one changed block.
const SIDE_DIFF = ideaDiffConfig("none", "words");
export function MergeEditor({ input }: { input: EditorInput }) {
const { path } = input.data as MergeData;
const [state, setState] = useState<{
@@ -176,7 +181,9 @@ export function MergeEditor({ input }: { input: EditorInput }) {
EditorView.updateListener.of((u) => {
if (u.selectionSet) refreshMergeActions(actionHost);
}),
state.base !== null ? unifiedMergeView({ original: state.base, mergeControls: false, gutter: true }) : [],
state.base !== null
? unifiedMergeView({ original: state.base, mergeControls: false, gutter: true, diffConfig: SIDE_DIFF })
: [],
sideControls(which, controls),
mergeStripe(which),
mergeTheme,
@@ -7,6 +7,8 @@ describe("remoteHosting", () => {
["https://github.example.com/o/r", "GitHub", "github"],
["https://gitee.com/o/r.git", "Gitee", "github"],
["[email protected]:o/r.git", "Bitbucket", "bitbucket"],
["[email protected]:team/repo.git", "Bitbucket", "bitbucket"],
["[email protected]:o/r.git", "GitHub", "github"],
["ssh://[email protected]:2222/group/sub/r.git", "GitLab", "gitlab"],
["[email protected]:group/r.git", "git.example.com", "gitlab"],
])("%s → %s", (url, name, kind) => {
@@ -43,4 +45,10 @@ describe("fileWebUrl", () => {
"https://bitbucket.org/o/r/src/main/a.py#lines-5",
);
});
it("opens a Bitbucket Cloud SSH clone on bitbucket.org, not the SSH front host (#3372)", () => {
expect(fileWebUrl("[email protected]:team/repo.git", "main", "a.py", { line: 4 })).toBe(
"https://bitbucket.org/team/repo/src/main/a.py#lines-5",
);
});
});
+6 -1
View File
@@ -7,6 +7,7 @@ import { Chunk } from "@codemirror/merge";
import type { Text } from "@codemirror/state";
import type { EditorView } from "@codemirror/view";
import { bandAt, docOffset, extent, transferY } from "./diffScroll";
import { ideaDiffConfig } from "./diffOptions";
export type MergePane = "ours" | "result" | "theirs";
const PANES: readonly MergePane[] = ["ours", "result", "theirs"];
@@ -32,6 +33,10 @@ export class ScrollEchoes<K> {
}
}
// Lined up by IDEA's line comparison. `Chunk.build` with no config runs an unbounded
// character diff, which takes minutes on a long file such as a lockfile.
const LINES = ideaDiffConfig("none", "lines");
/** Starts scrolling `views` together; returns the function that stops it. */
export function syncMergeScroll(views: Record<MergePane, EditorView>): () => void {
const built = new Map<MergePane, { a: Text; b: Text; chunks: readonly Chunk[] }>();
@@ -40,7 +45,7 @@ export function syncMergeScroll(views: Record<MergePane, EditorView>): () => voi
const b = views.result.state.doc;
const hit = built.get(side);
if (hit && hit.a === a && hit.b === b) return hit.chunks;
const fresh = Chunk.build(a, b);
const fresh = Chunk.build(a, b, LINES);
built.set(side, { a, b, chunks: fresh });
return fresh;
};
+8
View File
@@ -139,6 +139,13 @@ export function stashLabel(message: string): { branch: string | null; text: stri
return { branch: m[1]!, text: m[2]!.trim() || message };
}
/** SSH front hosts that serve the same service as the web host in the value. */
const WEB_HOST_ALIASES: Record<string, string> = {
"ssh.bitbucket.org": "bitbucket.org",
"ssh.github.com": "github.com",
"altssh.gitlab.com": "gitlab.com",
};
/**
* Web page of a git remote URL (`[email protected]:o/r.git`, `ssh://git@host:22/o/r`,
* `https://user@host/o/r.git`), or null for local paths.
@@ -155,6 +162,7 @@ export function remoteWebUrl(url: string): string | null {
if (full) [, host, path] = full as unknown as [string, string, string];
else if (scp) [, host, path] = scp as unknown as [string, string, string];
else return null;
host = WEB_HOST_ALIASES[host.toLowerCase()] ?? host;
return `https://${host}/${path.replace(/^\/+/, "")}`;
}
+2
View File
@@ -2181,6 +2181,8 @@
"Python interpreter": "Python 解释器",
"Python: only your code (justMyCode). JavaScript: skips node_modules and Node.js internals.": "Python:仅您的代码 (justMyCode)。JavaScript:跳过 node_modules 和 Node.js 内部代码。",
"Query Console": "查询控制台",
"New Query Console": "新建查询控制台",
"Query Consoles": "查询控制台",
"Quick Documentation": "快速文档",
"Re-check installed tools": "重新检查已安装的工具",
"Re-reads the effective POMs and dependency trees with Maven": "使用 Maven 重新读取有效 POM 和依赖树",