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

..
Автор SHA1 Повідомлення Дата
l0ng-ai c73d64a942 fix(mcp): a late diagnostics publication for an older text version isn't fresh
check_files counted any publication after the last text change as an
answer for the current text, but a server may publish late for the
version before it. A publication tagged with a version older than the
document's is still shown, but no longer counts as fresh.
2026-11-13 15:43:22 +08:00
54 змінених файлів з 130 додано та 1416 видалено

No files matched your search

Створено
+44 -44
Переглянути файл
@@ -4144,7 +4144,7 @@ checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
[[package]]
name = "ide-agent"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"dunce",
"encoding_rs",
@@ -4168,7 +4168,7 @@ dependencies = [
[[package]]
name = "ide-analysis"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"ast-grep-core",
"ide-core",
@@ -4182,7 +4182,7 @@ dependencies = [
[[package]]
name = "ide-android"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"ide-core",
"serde",
@@ -4193,7 +4193,7 @@ dependencies = [
[[package]]
name = "ide-build"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"blake3",
"chardetng",
@@ -4211,7 +4211,7 @@ dependencies = [
[[package]]
name = "ide-cli"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"dirs 6.0.0",
"serde",
@@ -4225,7 +4225,7 @@ dependencies = [
[[package]]
name = "ide-clipboard"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"gtk",
"objc2 0.6.5",
@@ -4235,7 +4235,7 @@ dependencies = [
[[package]]
name = "ide-core"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"dunce",
"encoding_rs",
@@ -4252,7 +4252,7 @@ dependencies = [
[[package]]
name = "ide-coverage"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"ide-core",
"ide-run",
@@ -4266,7 +4266,7 @@ dependencies = [
[[package]]
name = "ide-dap"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"futures",
"ide-core",
@@ -4292,7 +4292,7 @@ dependencies = [
[[package]]
name = "ide-db"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"base64 0.22.1",
"bb8",
@@ -4328,7 +4328,7 @@ dependencies = [
[[package]]
name = "ide-docker"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"ide-core",
"serde",
@@ -4341,7 +4341,7 @@ dependencies = [
[[package]]
name = "ide-extension"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"base64 0.22.1",
"blake3",
@@ -4362,7 +4362,7 @@ dependencies = [
[[package]]
name = "ide-fonts"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"objc2-core-foundation",
"objc2-core-text",
@@ -4374,7 +4374,7 @@ dependencies = [
[[package]]
name = "ide-github"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"ide-core",
"ide-vcs",
@@ -4387,7 +4387,7 @@ dependencies = [
[[package]]
name = "ide-heap"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"criterion",
"ide-core",
@@ -4405,7 +4405,7 @@ dependencies = [
[[package]]
name = "ide-host"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"base64 0.22.1",
"blake3",
@@ -4476,7 +4476,7 @@ dependencies = [
[[package]]
name = "ide-http"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"ide-core",
"ide-vfs",
@@ -4495,7 +4495,7 @@ dependencies = [
[[package]]
name = "ide-index"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"blake3",
"criterion",
@@ -4517,7 +4517,7 @@ dependencies = [
[[package]]
name = "ide-jdwp"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"ide-jvm-inspect",
"proptest",
@@ -4529,7 +4529,7 @@ dependencies = [
[[package]]
name = "ide-jsonrpc"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"encoding_rs",
"futures",
@@ -4546,7 +4546,7 @@ dependencies = [
[[package]]
name = "ide-jvm-attach"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"libc",
"tempfile",
@@ -4555,7 +4555,7 @@ dependencies = [
[[package]]
name = "ide-jvm-inspect"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"futures",
"serde",
@@ -4566,7 +4566,7 @@ dependencies = [
[[package]]
name = "ide-language"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"blake3",
"criterion",
@@ -4623,7 +4623,7 @@ dependencies = [
[[package]]
name = "ide-lsp"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"dunce",
"encoding_rs",
@@ -4651,7 +4651,7 @@ dependencies = [
[[package]]
name = "ide-mcp"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"bytes",
"dunce",
@@ -4670,7 +4670,7 @@ dependencies = [
[[package]]
name = "ide-notebook"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"futures",
"ide-core",
@@ -4693,7 +4693,7 @@ dependencies = [
[[package]]
name = "ide-plugin"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"blake3",
"dunce",
@@ -4716,7 +4716,7 @@ dependencies = [
[[package]]
name = "ide-profiler"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"ide-core",
"ide-jvm-attach",
@@ -4730,7 +4730,7 @@ dependencies = [
[[package]]
name = "ide-remote"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"dunce",
"futures",
@@ -4750,7 +4750,7 @@ dependencies = [
[[package]]
name = "ide-run"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"dunce",
"encoding_rs",
@@ -4774,7 +4774,7 @@ dependencies = [
[[package]]
name = "ide-scaffold"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"ide-core",
"ide-tools",
@@ -4790,7 +4790,7 @@ dependencies = [
[[package]]
name = "ide-sdk"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"dunce",
"ide-core",
@@ -4811,7 +4811,7 @@ dependencies = [
[[package]]
name = "ide-search"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"criterion",
"encoding_rs",
@@ -4832,7 +4832,7 @@ dependencies = [
[[package]]
name = "ide-spell"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"ide-core",
"parking_lot",
@@ -4845,7 +4845,7 @@ dependencies = [
[[package]]
name = "ide-ssh"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"dirs 6.0.0",
"flate2",
@@ -4870,7 +4870,7 @@ dependencies = [
[[package]]
name = "ide-syntax"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"ide-core",
"ide-language",
@@ -4885,7 +4885,7 @@ dependencies = [
[[package]]
name = "ide-terminal"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"ide-core",
"libc",
@@ -4898,7 +4898,7 @@ dependencies = [
[[package]]
name = "ide-text"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"criterion",
"ide-core",
@@ -4911,7 +4911,7 @@ dependencies = [
[[package]]
name = "ide-tools"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"flate2",
"hex",
@@ -4932,7 +4932,7 @@ dependencies = [
[[package]]
name = "ide-vcs"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"blake3",
"dunce",
@@ -4953,7 +4953,7 @@ dependencies = [
[[package]]
name = "ide-vfs"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"chardetng",
"dunce",
@@ -4977,7 +4977,7 @@ dependencies = [
[[package]]
name = "ide-web"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"dirs 6.0.0",
"ide-core",
@@ -4993,7 +4993,7 @@ dependencies = [
[[package]]
name = "ide-workspace"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"blake3",
"dunce",
@@ -6594,7 +6594,7 @@ dependencies = [
[[package]]
name = "openidea"
version = "0.1.44"
version = "0.1.43"
dependencies = [
"base64 0.22.1",
"blake3",
+1 -1
Переглянути файл
@@ -5,7 +5,7 @@ members = ["crates/*", "src-tauri"]
exclude = ["sdk", "plugins"]
[workspace.package]
version = "0.1.44"
version = "0.1.43"
edition = "2024"
rust-version = "1.96"
license = "Apache-2.0"
+3 -32
Переглянути файл
@@ -225,15 +225,6 @@ fn same_file(a: &Path, b: &Path) -> bool {
}
}
/// The bytes of `path` (`Some(None)`: no file there), or `None` when it is there but can't be read.
fn existing(path: &Path) -> Option<Option<Vec<u8>>> {
match std::fs::read(path) {
Ok(bytes) => Some(Some(bytes)),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Some(None),
Err(_) => None,
}
}
fn crlf_to_lf(bytes: &[u8]) -> Vec<u8> {
let mut out = Vec::with_capacity(bytes.len());
for (i, &b) in bytes.iter().enumerate() {
@@ -425,8 +416,7 @@ pub(crate) fn accept(
let target = |rel: &str| -> IdeResult<Option<Option<Vec<u8>>>> {
let in_task = repo.root().join(rel);
let current = std::fs::read(&in_task).ok();
// A file there that can't be read is the checkout's own: never written over.
let Some(local_bytes) = existing(&local_root.join(rel)) else { return Ok(None) };
let local_bytes = std::fs::read(local_root.join(rel)).ok();
if local_bytes == current {
return Ok(Some(current));
}
@@ -503,8 +493,8 @@ pub(crate) fn accept(
continue;
};
let task_bytes = std::fs::read(repo.root().join(&change.rel_path)).ok();
let at_new = existing(&new_path);
if at_new.as_ref().is_none_or(|at_new| at_new.is_some() && *at_new != task_bytes) {
let at_new = std::fs::read(&new_path).ok();
if at_new.is_some() && at_new != task_bytes {
skipped.push(skip(&change.rel_path));
continue;
}
@@ -996,25 +986,6 @@ mod tests {
assert_eq!(std::fs::read_to_string(repo.join("a.txt")).unwrap(), "one\ntwo\n");
}
#[cfg(unix)]
#[test]
fn accept_leaves_a_checkout_file_it_cannot_read() {
use std::os::unix::fs::PermissionsExt;
let (_tmp, repo, created) = accept_repo();
std::fs::write(created.path.join("new.txt"), "task\n").unwrap();
std::fs::write(repo.join("new.txt"), "mine\n").unwrap();
std::fs::set_permissions(repo.join("new.txt"), std::fs::Permissions::from_mode(0o200)).unwrap();
if std::fs::read(repo.join("new.txt")).is_ok() {
eprintln!("running as a user that reads any file; nothing to check");
return;
}
let changes = listed(&created.path, &created.base_commit);
let outcome = accept(&repo, &created.path, &created.base_commit, &changes).unwrap();
std::fs::set_permissions(repo.join("new.txt"), std::fs::Permissions::from_mode(0o644)).unwrap();
assert_eq!(outcome.skipped.iter().map(|s| s.path.as_str()).collect::<Vec<_>>(), ["new.txt"]);
assert_eq!(std::fs::read_to_string(repo.join("new.txt")).unwrap(), "mine\n");
}
#[cfg(windows)]
#[test]
fn accept_does_not_write_into_the_checkouts_git_folder_through_its_short_name() {
-9
Переглянути файл
@@ -270,13 +270,6 @@ fn run(
/// The first error lines of a failed build, for the tool window.
pub(crate) fn error_summary(text: &str) -> String {
// The JVM's "could not find or load main class" (localized) when `gradlew` has no jar.
if text.contains("org.gradle.wrapper.GradleWrapperMain") {
return "gradle/wrapper/gradle-wrapper.jar is missing (often excluded by a `*.jar` rule in .gitignore). \
Restore it, run `gradle wrapper` with an installed Gradle, or choose Distribution: Local installation \
in Settings › Build, Execution, Deployment › Gradle."
.to_owned();
}
let lines: Vec<&str> = text
.lines()
.filter(|l| {
@@ -916,8 +909,6 @@ mod tests {
let text = "[INFO] x\n[ERROR] Failed to execute goal\n[ERROR] \n[ERROR] Re-run Maven using -X\n";
assert_eq!(error_summary(text), "Failed to execute goal");
assert_eq!(error_summary("one\nlast line\n\n"), "last line");
let missing_jar = "错误: 找不到或无法加载主类 org.gradle.wrapper.GradleWrapperMain\n";
assert!(error_summary(missing_jar).starts_with("gradle/wrapper/gradle-wrapper.jar is missing"));
}
#[test]
+1 -1
Переглянути файл
@@ -753,7 +753,7 @@ impl Pool {
return crate::oracle::OraclePool::connect(source, password, &setup).await.map(Pool::Oracle);
}
if source.driver == DbDriver::Snowflake {
return crate::snowflake::SnowflakePool::connect(source, password, setup, root).await.map(Pool::Snowflake);
return crate::snowflake::SnowflakePool::connect(source, password, setup).await.map(Pool::Snowflake);
}
let timeout = setup.connect_timeout.unwrap_or(Duration::from_secs(30));
let init = Arc::new(setup.statements);
+9 -12
Переглянути файл
@@ -1491,21 +1491,18 @@ impl DbManager {
let Some(session) = session else { return Ok(()) };
let mut held = session.lock().await;
let Some(mut conn) = held.take() else { return Ok(()) };
if let Err(e) = conn.command(if commit { "COMMIT" } else { "ROLLBACK" }).await {
// Discarding a Snowflake connection doesn't end its session, which the data source's
// other targets share: the transaction stays open, so it stays held to be ended again.
if matches!(conn, conn::Held::Snowflake(..)) {
*held = Some(conn);
} else {
let result = async {
conn.command(if commit { "COMMIT" } else { "ROLLBACK" }).await?;
conn.restore_default().await
}
.await;
match result {
Ok(()) => Ok(()),
Err(e) => {
conn.discard().await;
Err(e)
}
return Err(e);
}
if let Err(e) = conn.restore_default().await {
conn.discard().await;
return Err(e);
}
Ok(())
}
#[allow(clippy::too_many_arguments)]
+17 -84
Переглянути файл
@@ -107,15 +107,6 @@ struct Lane {
context: parking_lot::Mutex<Option<String>>,
}
/// What [`SnowflakePool::statement`] does when the session is gone and it signs in again.
#[derive(Clone, Copy)]
enum Lost<'a> {
/// Runs the statement again on the new session, after this `USE` when there is one.
Enter(Option<&'a str>),
/// Fails: the statement was part of a transaction that ended with the session.
Fail,
}
const CONSOLE: usize = 0;
const METADATA: usize = 1;
@@ -261,12 +252,7 @@ fn gunzip(bytes: Vec<u8>) -> IdeResult<Vec<u8>> {
}
impl SnowflakePool {
pub(crate) async fn connect(
source: &DataSource,
secret: Option<&str>,
setup: Setup,
root: Option<&std::path::Path>,
) -> IdeResult<Self> {
pub(crate) async fn connect(source: &DataSource, secret: Option<&str>, setup: Setup) -> IdeResult<Self> {
let settings = source.snowflake();
let endpoint = account::endpoint(source)?;
let user = source.user.trim();
@@ -317,14 +303,12 @@ impl SnowflakePool {
lane: CONSOLE,
};
// Everything that makes a session what it is, the secret included (hashed: the key is only compared).
// The data source and its project too: its databases share a session, but another data source
// with the same settings, or the same one in another project (a plugin's source has the same id
// in every project), gets its own: its statements and transactions are not this one's. A browser
// sign-in is still shared through the cached ID token.
// The data source too: its databases share a session, but another data source with the same
// settings gets its own (its statements and transactions are not this one's). A browser sign-in
// is still shared through the cached ID token.
let key = blake3::hash(
format!(
"{:?}\0{}\0{}\0{user}\0{:?}\0{}\0{}\0{}\0{}\0{:?}\0{:?}",
root,
"{}\0{}\0{user}\0{:?}\0{}\0{}\0{}\0{}\0{:?}\0{:?}",
source.id,
api.address(),
settings.auth,
@@ -657,18 +641,13 @@ impl SnowflakePool {
() = self.closed.cancelled() => return Err(closed()),
turn = self.lane().turn.lock() => turn,
};
// A `USE` needs no schema to run in, and may be what makes the schema reachable. Ending a
// transaction needs none either, and must not fail because the schema is gone meanwhile.
let context = match first_word(sql).as_str() {
"USE" | "COMMIT" | "ROLLBACK" => None,
_ => {
self.enter(schema, cancel).await?;
self.context(schema)
}
};
// A `USE` needs no schema to run in, and may be what makes the schema reachable.
if first_word(sql) != "USE" {
self.enter(schema, cancel).await?;
}
// These can move the session to another database or schema.
let moves = matches!(first_word(sql).as_str(), "USE" | "CALL" | "EXECUTE");
let result = self.statement(sql, skip, max_rows, Lost::Enter(context.as_deref()), cancel).await;
let result = self.statement(sql, skip, max_rows, cancel).await;
if moves {
*self.lane().context.lock() = None;
}
@@ -684,7 +663,7 @@ impl SnowflakePool {
// Refused (the session's role may not use this database or schema): the statement
// does not run, since the session is still wherever it was, which may be another
// target's database. Tried again with the next statement.
if let Err(error) = self.statement(&wanted, 0, 0, Lost::Enter(None), cancel).await {
if let Err(error) = self.statement(&wanted, 0, 0, cancel).await {
return Err(IdeError {
message: format!("{wanted} failed, so the statement was not run: {}", error.message),
..error
@@ -704,11 +683,11 @@ impl SnowflakePool {
let _turn = self.lane().turn.lock().await;
let cancel = CancellationToken::new();
self.enter(None, &cancel).await?;
self.statement("BEGIN", 0, 0, Lost::Enter(self.context(None).as_deref()), &cancel).await?;
self.statement("BEGIN", 0, 0, &cancel).await?;
let changes = async {
let mut total = 0;
for (sql, expect_one) in statements {
let changed = self.statement(sql, 0, 0, Lost::Fail, &cancel).await?.affected.unwrap_or(0.0) as u64;
let changed = self.statement(sql, 0, 0, &cancel).await?.affected.unwrap_or(0.0) as u64;
if *expect_one && changed != 1 {
return Err(IdeError::invalid(format!(
"{sql}: expected to change 1 row, changed {changed}; nothing was saved"
@@ -721,24 +700,22 @@ impl SnowflakePool {
.await;
match changes {
Ok(total) => {
self.statement("COMMIT", 0, 0, Lost::Fail, &cancel).await?;
self.statement("COMMIT", 0, 0, &cancel).await?;
Ok(total)
}
Err(error) => {
let _ = self.statement("ROLLBACK", 0, 0, Lost::Fail, &cancel).await;
let _ = self.statement("ROLLBACK", 0, 0, &cancel).await;
Err(error)
}
}
}
/// One statement on the session; the caller holds the session's turn. `lost`: what to do when
/// the session is gone and a new one is signed in to.
/// One statement on the session; the caller holds the session's turn.
async fn statement(
&self,
sql: &str,
skip: usize,
max_rows: usize,
lost: Lost<'_>,
cancel: &CancellationToken,
) -> IdeResult<QueryResult> {
let started = Instant::now();
@@ -769,24 +746,7 @@ impl SnowflakePool {
Ok(Outcome::Done(result)) => return Ok(*result),
Ok(Outcome::Expired { gone }) if !renewed => {
renewed = true;
if !gone {
tokens = self.renew(&tokens).await?;
continue;
}
if let Lost::Fail = lost {
// The transaction ended with the session: nothing of it was saved.
let _ = self.login().await;
return Err(IdeError::new(
ErrorKind::Io,
"Snowflake: the session was lost during the transaction; nothing was saved",
));
}
// The new session is under the login's database and schema, which may be another
// target's: back to this one's before the statement runs again.
tokens = self.login().await?;
if let Lost::Enter(Some(wanted)) = lost {
self.reenter(wanted, &tokens, cancel).await?;
}
tokens = if gone { self.login().await? } else { self.renew(&tokens).await? };
}
Ok(Outcome::Expired { .. }) => {
return Err(IdeError::new(ErrorKind::Io, "Snowflake: the session expired; reconnect"));
@@ -796,33 +756,6 @@ impl SnowflakePool {
}
}
/// [`enter`](Self::enter) on a session just signed in to (its `tokens`), within [`statement`](Self::statement).
async fn reenter(&self, wanted: &str, tokens: &Tokens, cancel: &CancellationToken) -> IdeResult<()> {
let request_id = uuid();
let outcome = tokio::select! {
biased;
() = cancel.cancelled() => return Err(IdeError::cancelled()),
() = self.closed.cancelled() => return Err(closed()),
outcome = self.run(wanted, 0, 0, tokens, &request_id, Instant::now()) => outcome,
};
match outcome {
Ok(Outcome::Done(_)) => {
*self.lane().context.lock() = Some(wanted.to_owned());
Ok(())
}
Ok(Outcome::Expired { .. }) => {
Err(IdeError::new(ErrorKind::Io, "Snowflake: the session expired; reconnect"))
}
Err(error) => {
let error = self.shared.api.scrub.clean(error);
Err(IdeError {
message: format!("{wanted} failed, so the statement was not run: {}", error.message),
..error
})
}
}
}
async fn run(
&self,
sql: &str,
+2 -72
Переглянути файл
@@ -407,64 +407,13 @@ async fn a_lost_session_signs_in_again() {
let (listener, port) = bind().await;
let gone = r#"{"success":false,"code":"390114","message":"Authentication token has expired. The user must authenticate again."}"#;
let again = r#"{"success":true,"data":{"token":"session-token-3","masterToken":"master-token-3"}}"#;
let status = json!({ "success": true, "data": { "rowtype": [{ "name": "status", "type": "text" }],
"rowset": [["Statement executed successfully."]], "queryResultFormat": "json", "statementTypeId": 0x5000 } })
.to_string();
let server = serve(listener, vec![ok(LOGIN_OK), ok(gone), ok(again), ok(status), ok(one()), ok(CLOSED_OK)]);
let server = serve(listener, vec![ok(LOGIN_OK), ok(gone), ok(again), ok(one()), ok(CLOSED_OK)]);
let pool = Pool::connect(&source(port), None, None).await.unwrap();
pool.execute("select 1", 5, &CancellationToken::new()).await.unwrap();
pool.close().await;
let seen = server.await.unwrap();
assert!(seen[2].line().starts_with("POST /session/v1/login-request?"), "{}", seen[2].line());
// The new session enters the target's schema before the statement runs again.
assert_eq!(seen[3].json()["sqlText"], "USE SCHEMA \"ANALYTICS\".\"PUBLIC\"");
assert_eq!(seen[4].json()["sqlText"], "select 1");
assert_eq!(seen[4].header("authorization"), Some("Snowflake Token=\"session-token-3\""));
}
#[tokio::test]
async fn a_lost_session_runs_the_statement_in_its_own_database_again() {
let (listener, port) = bind().await;
let gone = r#"{"success":false,"code":"390114","message":"Authentication token has expired. The user must authenticate again."}"#;
let again = r#"{"success":true,"data":{"token":"session-token-3","masterToken":"master-token-3"}}"#;
let status = || {
json!({ "success": true, "data": { "rowtype": [{ "name": "status", "type": "text" }],
"rowset": [["Statement executed successfully."]], "queryResultFormat": "json", "statementTypeId": 0x5000 } })
.to_string()
};
// Raw Data entered, the statement finds the session gone, a new login (under ANALYTICS),
// Raw Data entered again, the statement.
let replies = vec![ok(LOGIN_OK), ok(status()), ok(gone), ok(again), ok(status()), ok(one()), ok(CLOSED_OK)];
let server = serve(listener, replies);
let first = Pool::connect(&source(port), None, None).await.unwrap();
let mut other = source(port);
other.database = "Raw Data".into();
other.options.default_schema = String::new();
let second = Pool::connect(&other, None, None).await.unwrap();
second.execute("delete from t", 1, &CancellationToken::new()).await.unwrap();
first.close().await;
second.close().await;
let sent: Vec<String> =
server.await.unwrap()[1..6].iter().map(|r| r.json()["sqlText"].as_str().unwrap_or("").to_owned()).collect();
let raw = "USE DATABASE \"Raw Data\"";
assert_eq!(sent, [raw, "delete from t", "", raw, "delete from t"]);
}
#[tokio::test]
async fn a_transaction_ends_even_when_its_schema_is_gone() {
let (listener, port) = bind().await;
let status = json!({ "success": true, "data": { "rowtype": [{ "name": "status", "type": "text" }],
"rowset": [["Statement executed successfully."]], "queryResultFormat": "json", "statementTypeId": 0x5000 } })
.to_string();
let server = serve(listener, vec![ok(LOGIN_OK), ok(status), ok(CLOSED_OK)]);
let pool = Pool::connect(&source(port), None, None).await.unwrap();
// The console's schema was dropped since it was picked: ending the transaction doesn't switch to it.
let mut console = crate::conn::Held::acquire(&pool).await.unwrap();
console.apply_context(Some("Dropped")).await.unwrap();
console.execute(&pool, "ROLLBACK", 0, &CancellationToken::new()).await.unwrap();
pool.close().await;
let seen = server.await.unwrap();
assert_eq!(seen[1].json()["sqlText"], "ROLLBACK");
assert_eq!(seen[3].header("authorization"), Some("Snowflake Token=\"session-token-3\""));
}
#[tokio::test]
@@ -856,25 +805,6 @@ async fn data_sources_with_the_same_settings_have_their_own_sessions() {
assert_eq!(seen[3].header("authorization"), Some("Snowflake Token=\"session-token-2\""));
}
#[tokio::test]
async fn one_data_source_in_two_projects_has_a_session_in_each() {
let (listener, port) = bind().await;
let second = r#"{"success":true,"data":{"token":"session-token-2","masterToken":"master-token-2"}}"#;
let server = serve(listener, vec![ok(LOGIN_OK), ok(second), ok(one()), ok(one()), ok(CLOSED_OK), ok(CLOSED_OK)]);
// A plugin's data source has the same id in every project.
let first = Pool::connect(&source(port), None, Some(std::path::Path::new("/projects/a"))).await.unwrap();
let other = Pool::connect(&source(port), None, Some(std::path::Path::new("/projects/b"))).await.unwrap();
let cancel = CancellationToken::new();
first.execute("select 1", 1, &cancel).await.unwrap();
other.execute("select 2", 1, &cancel).await.unwrap();
first.close().await;
other.close().await;
let seen = server.await.unwrap();
assert!(seen[1].line().starts_with("POST /session/v1/login-request?"), "{}", seen[1].line());
assert_eq!(seen[2].header("authorization"), Some("Snowflake Token=\"session-token-1\""));
assert_eq!(seen[3].header("authorization"), Some("Snowflake Token=\"session-token-2\""));
}
#[tokio::test]
async fn metadata_runs_on_its_own_session_beside_a_busy_console() {
let (listener, port) = bind().await;
-27
Переглянути файл
@@ -323,18 +323,6 @@ fn resolve_gradle_command(root: &Path, build_dir: &Path, s: &Settings, use_wrapp
}
let wrapper = build_dir.join(if cfg!(windows) { "gradlew.bat" } else { "gradlew" });
if use_wrapper && wrapper.is_file() {
// `gradlew` can't start without its jar, which `.gitignore`s with `*.jar` often leave
// out: run the distribution the wrapper already unpacked instead.
if build_dir.join("gradle/wrapper/gradle-wrapper.jar").is_file() {
return wrapper;
}
let home = setting_path(root, &g.user_home)
.or_else(|| std::env::var_os("GRADLE_USER_HOME").map(PathBuf::from))
.or_else(|| Some(crate::home_dir()?.join(".gradle")));
if let Some(gradle) = home.and_then(|home| unpacked_wrapper_distribution(build_dir, &home)) {
return gradle;
}
// Nothing to run instead: the wrapper's failure explains what is missing.
return wrapper;
}
pinned::pinned_install(build_dir, Tool::Gradle)
@@ -342,21 +330,6 @@ fn resolve_gradle_command(root: &Path, build_dir: &Path, s: &Settings, use_wrapp
.unwrap_or_else(|| name.into())
}
/// `bin/gradle` of the distribution `gradle/wrapper/gradle-wrapper.properties` names, once the
/// wrapper has unpacked it in `<gradle_user_home>/wrapper/dists` (and marked it complete).
fn unpacked_wrapper_distribution(build_dir: &Path, gradle_user_home: &Path) -> Option<PathBuf> {
let properties = std::fs::read_to_string(build_dir.join("gradle/wrapper/gradle-wrapper.properties")).ok()?;
let url = properties.lines().find_map(|line| line.trim().strip_prefix("distributionUrl="))?;
let zip = url.trim().replace("\\:", ":").rsplit('/').next()?.to_owned();
let name = zip.strip_suffix(".zip")?;
let gradle = if cfg!(windows) { "gradle.bat" } else { "gradle" };
// One directory per distribution URL hash, each holding the unpacked `gradle-<version>`.
let hashes = std::fs::read_dir(gradle_user_home.join("wrapper/dists").join(name)).ok()?;
hashes.flatten().map(|e| e.path()).filter(|dir| dir.join(format!("{zip}.ok")).is_file()).find_map(|dir| {
std::fs::read_dir(&dir).ok()?.flatten().map(|e| e.path().join("bin").join(gradle)).find(|p| p.is_file())
})
}
fn gradle_run_jdk<'a>(
release: Option<u32>,
configured: Option<&'a crate::java::Jdk>,
-31
Переглянути файл
@@ -1866,37 +1866,6 @@ fn max_java_picks_an_older_jdk() {
assert_eq!(free.env["JAVA_HOME"], j25.home.to_string_lossy());
}
/// #3086: `gradle-wrapper.jar` excluded by a `*.jar` rule in `.gitignore`: `gradlew` can't
/// start, so the distribution the wrapper already unpacked runs instead.
#[test]
fn gradle_wrapper_without_its_jar_runs_the_unpacked_distribution() {
use crate::apply::gradle_command;
let tmp = tempfile::tempdir().unwrap();
let root = tmp.path();
let plain = if cfg!(windows) { "gradle.bat" } else { "gradle" };
let wrapper = root.join(if cfg!(windows) { "gradlew.bat" } else { "gradlew" });
std::fs::write(&wrapper, "").unwrap();
std::fs::create_dir_all(root.join("gradle/wrapper")).unwrap();
std::fs::write(
root.join("gradle/wrapper/gradle-wrapper.properties"),
"distributionUrl=https\\://services.gradle.org/distributions/gradle-4.10-bin.zip\n",
)
.unwrap();
let mut settings = Settings::default();
settings.languages.java.gradle.user_home = "user-home".into();
let hash = root.join("user-home/wrapper/dists/gradle-4.10-bin/7ddd1b3f");
let gradle = hash.join("gradle-4.10/bin").join(plain);
std::fs::create_dir_all(gradle.parent().unwrap()).unwrap();
std::fs::write(&gradle, "").unwrap();
// Not marked complete: possibly half unpacked.
assert_eq!(gradle_command(root, root, &settings), wrapper);
std::fs::write(hash.join("gradle-4.10-bin.zip.ok"), "").unwrap();
assert_eq!(gradle_command(root, root, &settings), gradle);
// With its jar the wrapper runs as usual.
std::fs::write(root.join("gradle/wrapper/gradle-wrapper.jar"), "").unwrap();
assert_eq!(gradle_command(root, root, &settings), wrapper);
}
#[test]
fn gradle_settings_precedence() {
use crate::apply::{gradle_command, gradle_env};
-91
Переглянути файл
@@ -1,91 +0,0 @@
import type { Page } from "@playwright/test";
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
const expected =
'[\n {\n "id": 9223372036854775807,\n "amount": 1.0000000000000000002,\n "note": "9007199254740993",\n "empty": null\n }\n]';
async function seedResult(page: Page) {
await stubDesktop(page);
await page.evaluate(async () => {
window.__ipc.handlers.clipboard_write_text = () => null;
window.__ipc.handlers.db_export_file = () => null;
window.__ipc.handlers["plugin:path|resolve_directory"] = () => "/tmp";
const storePath = "/src/features/database/store.ts";
const contributionsPath = "/src/workbench/contributions.ts";
const { useDatabase, RESULTS_VIEW } = await import(storePath);
const { showServiceView } = await import(contributionsPath);
const text = "SELECT id, amount, note, empty FROM numbers";
useDatabase.setState({
loaded: true,
sources: [{ id: "exact", name: "Exact numbers", driver: "postgres", readOnly: true }],
consoles: { "exact-console.sql": "exact" },
results: [
{
id: 1,
title: "Result 1",
path: "exact-console.sql",
sourceId: "exact",
outcome: {
statement: { text, from: 0, to: text.length },
error: null,
result: {
statement: text,
columns: [
{ name: "id", typeName: "BIGINT" },
{ name: "amount", typeName: "NUMERIC(38,19)" },
{ name: "note", typeName: "TEXT" },
{ name: "empty", typeName: "TEXT" },
],
rows: [["9223372036854775807", "1.0000000000000000002", "9007199254740993", null]],
affected: null,
hasMore: false,
elapsedMs: 1,
executionMs: 1,
},
},
page: 0,
pageSize: 500,
},
],
activeResult: 1,
});
showServiceView(RESULTS_VIEW);
});
await expect(page.getByRole("grid", { name: "Result 1", exact: true }).getByRole("gridcell")).toHaveCount(4);
}
async function openExport(page: Page) {
await page.getByRole("button", { name: "Export Data", exact: true }).click();
await page.getByRole("menuitem", { name: "Export Data…", exact: true }).click();
const dialog = page.getByRole("dialog", { name: "Export Data", exact: true });
await dialog.getByRole("button", { name: "Extractor", exact: true }).click();
await page.getByRole("option", { name: "JSON", exact: true }).click();
return dialog;
}
test("Copy as JSON preserves exact numeric values", async ({ workbench: page }) => {
await seedResult(page);
await page.getByRole("button", { name: "Export Data", exact: true }).click();
await page.getByRole("menuitem", { name: "Copy as JSON", exact: true }).click();
await expect.poll(() => ipcCalls(page, "clipboard_write_text")).toHaveLength(1);
expect((await ipcCalls(page, "clipboard_write_text"))[0]!.text).toBe(expected);
});
test("Export Data preserves exact preview and clipboard values", async ({ workbench: page }) => {
await seedResult(page);
const dialog = await openExport(page);
await expect(dialog.getByLabel("Export preview", { exact: true })).toHaveText(expected);
await dialog.getByRole("button", { name: "Copy to Clipboard", exact: true }).click();
await expect.poll(() => ipcCalls(page, "clipboard_write_text")).toHaveLength(1);
expect((await ipcCalls(page, "clipboard_write_text"))[0]!.text).toBe(expected);
});
test("Export Data preserves exact preview and exported file values", async ({ workbench: page }) => {
await seedResult(page);
const dialog = await openExport(page);
await expect(dialog.getByLabel("Export preview", { exact: true })).toHaveText(expected);
await dialog.getByRole("textbox", { name: "Output file", exact: true }).fill("/tmp/exact-numbers.json");
await dialog.getByRole("button", { name: "Export to File", exact: true }).click();
await expect.poll(() => ipcCalls(page, "db_export_file")).toHaveLength(1);
expect((await ipcCalls(page, "db_export_file"))[0]).toEqual({ path: "/tmp/exact-numbers.json", text: expected });
});
-103
Переглянути файл
@@ -1,103 +0,0 @@
import type { Page } from "@playwright/test";
import { expect, test } from "./fixtures";
const integers = ["9007199254740993", "9007199254740992", "-9007199254740992", "-9007199254740993"];
const decimals = ["1.0000000000000000002", "1.0000000000000000001", "-0.0000000000000000001", "0"];
async function seedResult(page: Page, values: string[], type: string) {
await page.evaluate(
async ({ values, type }) => {
const storePath = "/src/features/database/store.ts";
const contributionsPath = "/src/workbench/contributions.ts";
const { useDatabase, RESULTS_VIEW } = await import(storePath);
const { showServiceView } = await import(contributionsPath);
const text = "SELECT value FROM exact_numbers";
useDatabase.setState({
loaded: true,
sources: [{ id: "exact", name: "Exact numbers", driver: "postgres", readOnly: true }],
consoles: { "exact-console.sql": "exact" },
results: [
{
id: 1,
title: "Result 1",
path: "exact-console.sql",
sourceId: "exact",
outcome: {
statement: { text, from: 0, to: text.length },
error: null,
result: {
statement: text,
columns: [{ name: "value", typeName: type }],
rows: values.map((value) => [value]),
affected: null,
hasMore: false,
elapsedMs: 1,
executionMs: 1,
},
},
page: 0,
pageSize: 500,
},
],
activeResult: 1,
});
showServiceView(RESULTS_VIEW);
},
{ values, type },
);
await expect(page.getByRole("grid", { name: "Result 1", exact: true }).getByRole("gridcell")).toHaveCount(
values.length,
);
}
for (const [name, values, type, ascending] of [
["BIGINT", integers, "BIGINT", [integers[3]!, integers[2]!, integers[1]!, integers[0]!]],
["DECIMAL", decimals, "NUMERIC(38,19)", [decimals[2]!, decimals[3]!, decimals[1]!, decimals[0]!]],
] as const) {
test(`${name}: result headers sort exact values ascending, descending and back to query order`, async ({
workbench: page,
}) => {
await seedResult(page, [...values], type);
const grid = page.getByRole("grid", { name: "Result 1", exact: true });
const cells = grid.getByRole("gridcell");
const header = grid.getByRole("columnheader", { name: /^value\b/ }).getByText("value", { exact: true });
await expect(cells).toHaveText([...values]);
await header.click();
await expect(cells).toHaveText([...ascending]);
await header.click();
await expect(cells).toHaveText([...ascending].reverse());
await header.click();
await expect(cells).toHaveText([...values]);
});
}
test("precise filter values are ordered and filtering composes with result sorting", async ({ workbench: page }) => {
await seedResult(page, [...integers], "BIGINT");
const grid = page.getByRole("grid", { name: "Result 1", exact: true });
await grid.getByRole("button", { name: "Filter value", exact: true }).click();
const values = page.getByRole("group", { name: "Values", exact: true });
const ascending = [integers[3]!, integers[2]!, integers[1]!, integers[0]!];
await expect(values.locator("label")).toHaveText(ascending);
await values.getByRole("checkbox", { name: integers[3], exact: true }).uncheck();
await page.keyboard.press("Escape");
await grid
.getByRole("columnheader", { name: /^value\b/ })
.getByText("value", { exact: true })
.click();
await expect(grid.getByRole("gridcell")).toHaveText(ascending.slice(1));
});
test("selection aggregates preserve exact minimum and maximum values", async ({ workbench: page }) => {
await seedResult(page, [...decimals], "NUMERIC(38,19)");
const grid = page.getByRole("grid", { name: "Result 1", exact: true });
await grid.getByRole("gridcell").first().click();
await grid
.getByRole("gridcell")
.last()
.click({ modifiers: ["Shift"] });
await page.getByRole("button", { name: "Show Record / Value / Aggregates", exact: true }).click();
const panel = page.getByRole("complementary", { name: "Value panel", exact: true });
await panel.getByRole("tab", { name: "Aggregates", exact: true }).click();
await expect(panel.getByRole("row", { name: `Min ${decimals[2]}`, exact: true })).toBeVisible();
await expect(panel.getByRole("row", { name: `Max ${decimals[0]}`, exact: true })).toBeVisible();
});
+1 -1
Переглянути файл
@@ -2,7 +2,7 @@
"name": "openidea",
"private": true,
"description": "An open-source IDE inspired by IntelliJ IDEA",
"version": "0.1.44",
"version": "0.1.43",
"license": "Apache-2.0",
"type": "module",
"scripts": {
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// The commit being prepared in the window the current command or event came
/// from (the Commit tool window, or the Commit dialog while it is open): the
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Plugin-owned project data sources. Requires database.sources and project trust.
/// Runs on the Database subsystem's host, including on remote project servers.
+1 -4
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Project-scoped decorations (API 1.4). Requires project.read; paths must be inside
/// an open project. Sets belong to the plugin and disappear when it stops.
@@ -19,7 +19,4 @@ interface decorations {
set-file: func(path: string, set-id: string, item: file-decoration) -> result<_, error>;
/// Remove this tree set from every file/project.
clear-file: func(set-id: string) -> result<_, error>;
/// Replace this set's tree annotation for a file with a note shown after its name (API 1.7):
/// one line of at most 200 characters, with an optional tooltip.
set-file-note: func(path: string, set-id: string, note: string, tooltip: option<string>) -> result<_, error>;
}
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// What the pane beside the Services tree shows for a plugin's node.
interface detail-types {
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Optional export (world `plugin-diagnostics`): problems in the current,
/// possibly unsaved document, for the languages declared with the
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// HTTP endpoints found in a project (`[[contributes.endpoints]]`).
interface endpoints-provider {
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Workbench events, delivered in batches to `event-handler.handle`.
interface events {
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
interface lifecycle {
use types.{context, error};
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// What other plugins contributed to the extension points this plugin declares
/// (`[[extension-points]]` in `plugin.toml`; the contributors list this plugin
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Optional export (world `plugin-file-actions`): quick fixes and
/// refactorings that create, rename or delete files, next to the text edits
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Files outside the open projects: the configuration of the program a
/// plugin integrates with, a tool installed elsewhere, a licence file.
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Writes to the IDE log, tagged with the plugin id.
interface log {
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Optional export (world `plugin-hover`): Markdown added to the hover of
/// documents of the languages declared with the `hover` provider kind,
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Cross-file associations a plugin publishes for the files it declares under
/// `[[contributes.documentIndexers]]`. The host calls `index` in cancellable
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Embedded languages. The host routes plugin providers and configured language
/// servers inside these ranges, preserving host-document UTF-16 coordinates.
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Optional export (world `plugin-inlay-hints`): inline hints in documents of
/// the languages declared with the `inlay-hints` provider kind, including
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Problems in files, shown in the editor and the Problems view.
interface diagnostics {
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Additional language features, called only for declared API 1.4 provider kinds.
/// Editor calls have a 50 ms soft / 500 ms hard budget; formatting has 5 seconds.
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Discovery of the IDE's built-in MCP server; never exposes its URL or token.
interface mcp {
+1 -1
Переглянути файл
@@ -8,7 +8,7 @@
/// `fs` and `workspace`, and everything else goes through the imports below,
/// gated by the capabilities granted in `plugin.toml` (a missing one returns
/// `error::denied`).
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
world plugin {
import log;
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Editor features a plugin provides for the languages it declares under
/// `[[contributes.providers]]` (the host calls only declared kinds). They run
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Project-scoped targets owned by the registering plugin (API 1.4).
interface run-targets {
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Launches this plugin's configurations in the invoking window's Run tool window.
interface run {
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Optional export (world `plugin-semantic-tokens`): semantic colouring of
/// documents of the languages declared with the `semantic-tokens` provider
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Shared types. Positions are 0-based lines and UTF-16 code unit columns,
/// as in the editor and LSP.
+1 -7
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
/// Declarative views: tool windows declared
/// under `[[contributes.views]]` and custom editors under
@@ -149,12 +149,6 @@ interface views {
open-content-tab: func(tab: content-tab) -> result<_, error>;
/// Answers content-tab-action in its originating window.
reply-content-tab: func(request-id: string, reply: content-tab-reply) -> result<_, error>;
/// Opens two texts in the diff viewer of the window the call came from
/// (API 1.7): a review's file before and after, say. `file-name` (a name or
/// relative path, at most 256 characters) picks the syntax highlighting and
/// names the tab when `diff.title` is absent. Only from a command or event
/// of a window; each side at most 1 MiB.
open-diff: func(diff: content-diff, file-name: option<string>) -> result<_, error>;
/// The view (or every custom editor of that id) shows outdated content:
/// the IDE renders it again.
+1 -1
Переглянути файл
@@ -1,4 +1,4 @@
package openidea:plugin@1.7.0;
package openidea:plugin@1.6.0;
interface workspace {
use types.{error, location};
+1 -1
Переглянути файл
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "OpenIDEA",
"version": "0.1.44",
"version": "0.1.43",
"identifier": "ai.l0ng.openidea",
"build": {
"beforeDevCommand": "pnpm dev",
+1 -71
Переглянути файл
@@ -1,11 +1,9 @@
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { writeClipboardText } from "@/platform/clipboard";
import { describe, expect, it, vi } from "vitest";
import { commands } from "@/platform/ipc";
import { ExportDialog } from "./ExportDialog";
import { cellPreview } from "./cellPreview";
vi.mock("@/platform/clipboard", () => ({ writeClipboardText: vi.fn(async () => {}) }));
vi.mock("./store", () => ({ closeDialog: vi.fn() }));
vi.mock("@/workbench/contributions", async (importOriginal) => ({
...(await importOriginal<typeof import("@/workbench/contributions")>()),
@@ -13,8 +11,6 @@ vi.mock("@/workbench/contributions", async (importOriginal) => ({
}));
vi.mock("@tauri-apps/api/path", () => ({ homeDir: async () => "/home/test" }));
afterEach(() => vi.restoreAllMocks());
describe("large value export", () => {
it("bounds preview values while exporting every row in full", async () => {
const full = JSON.stringify({ text: "\u4e2d text ".repeat(200_000), tail: "complete" });
@@ -42,69 +38,3 @@ describe("large value export", () => {
dbExportFile.mockRestore();
});
});
describe("exact numeric export", () => {
it.each(["Copy to Clipboard", "Export to File"])("keeps preview and %s values exact", async (action) => {
const dbExportFile = vi.spyOn(commands, "dbExportFile").mockResolvedValue({ status: "ok", data: null });
vi.mocked(writeClipboardText).mockClear();
const expected =
'[\n {\n "id": 9223372036854775807,\n "amount": 1.0000000000000000002,\n "note": "9007199254740993",\n "empty": null\n }\n]';
render(
<ExportDialog
data={{
columns: [
{ name: "id", type: "BIGINT" },
{ name: "amount", type: "NUMERIC(38,19)" },
{ name: "note", type: "TEXT" },
{ name: "empty", type: "TEXT" },
],
rows: [["9223372036854775807", "1.0000000000000000002", "9007199254740993", null]],
table: "numbers",
driver: "postgres",
}}
source="public.numbers"
initialFormat="json"
/>,
);
expect(screen.getByLabelText("Export preview").textContent).toBe(expected);
await waitFor(() => expect(screen.getByLabelText("Output file")).toHaveValue("/home/test/numbers.json"));
fireEvent.click(screen.getByRole("button", { name: action }));
if (action === "Copy to Clipboard") {
await waitFor(() => expect(writeClipboardText).toHaveBeenCalledWith(expected));
} else {
await waitFor(() => expect(dbExportFile).toHaveBeenCalledWith("/home/test/numbers.json", expected));
}
});
});
it.each(["Copy to Clipboard", "Export to File"])(
"%s includes numeric rows beyond the preview limit",
async (action) => {
const dbExportFile = vi.spyOn(commands, "dbExportFile").mockResolvedValue({ status: "ok", data: null });
vi.mocked(writeClipboardText).mockClear();
const rows = Array.from({ length: 101 }, (_, i) => [(9223372036854775807n - BigInt(i)).toString()]);
render(
<ExportDialog
data={{ columns: [{ name: "id", type: "BIGINT" }], rows, table: "numbers", driver: "postgres" }}
source="public.numbers"
initialFormat="json"
/>,
);
const preview = screen.getByLabelText("Export preview").textContent!;
expect(preview).toContain('"id": 9223372036854775807');
expect(preview).not.toContain(rows[100]![0]!);
expect(preview).toContain("… 1 more rows");
await waitFor(() => expect(screen.getByLabelText("Output file")).toHaveValue("/home/test/numbers.json"));
fireEvent.click(screen.getByRole("button", { name: action }));
let text: string;
if (action === "Copy to Clipboard") {
await waitFor(() => expect(writeClipboardText).toHaveBeenCalled());
text = vi.mocked(writeClipboardText).mock.calls[0]![0];
} else {
await waitFor(() => expect(dbExportFile).toHaveBeenCalled());
text = dbExportFile.mock.calls[0]![1];
}
expect(JSON.parse(text)).toHaveLength(101);
expect(text).toContain(`"id": ${rows[100]![0]}`);
},
);
+6 -14
Переглянути файл
@@ -200,9 +200,6 @@ function Pager({ tab }: { tab: ResultTab }) {
);
}
/** Unsubmitted edits by the rows they were made on, kept while another result tab is shown. */
const keptEdits = new WeakMap<DbQueryResult, PendingEdits>();
function Result({ tab }: { tab: ResultTab }) {
const [view, setView] = useState<"table" | "chart">("table");
const [panel, setPanel] = useState<DataPanel | null>(null);
@@ -278,19 +275,14 @@ function Result({ tab }: { tab: ResultTab }) {
sources.some((s) => s !== null);
// The pending edits belong to the result they were made on: fresh rows (a
// re-run, another page) start over, without an effect. They outlive the pane,
// which remounts when another result tab is selected.
const [pending, setPending] = useState<{ outcome: DbQueryResult | null; edits: PendingEdits }>(() => ({
outcome: r ?? null,
edits: (r && keptEdits.get(r)) ?? emptyEdits(),
}));
// re-run, another page) start over, without an effect.
const [pending, setPending] = useState<{ outcome: DbQueryResult | null; edits: PendingEdits }>({
outcome: null,
edits: emptyEdits(),
});
const edits = pending.outcome === r ? pending.edits : emptyEdits();
const setEdits = (f: (e: PendingEdits) => PendingEdits) =>
setPending((previous) => {
const next = f(previous.outcome === r ? previous.edits : emptyEdits());
if (r) keptEdits.set(r, next);
return { outcome: r ?? null, edits: next };
});
setPending((previous) => ({ outcome: r, edits: f(previous.outcome === r ? previous.edits : emptyEdits()) }));
const loaded = r?.rows.length ?? 0;
const rowCount = loaded + edits.inserts.length;
const value = useCallback(
-197
Переглянути файл
@@ -1,197 +0,0 @@
import { describe, expect, it } from "vitest";
import type { DbDriver } from "@/platform/ipc";
import { exportData, type ExportData, type ExportFormat } from "./export";
const data = (value: string, type = "NUMERIC", driver: DbDriver = "postgres"): ExportData => ({
columns: [{ name: "value", type }],
rows: [[value]],
table: "numbers",
driver,
});
const jsonNumber = (value: string) => `[\n {\n "value": ${value}\n }\n]`;
describe("exact JSON number export", () => {
it.each([
["9007199254740993", "BIGINT", "postgres"],
["9223372036854775807", "BIGINT", "postgres"],
["-9223372036854775808", "BIGINT", "sqlite"],
["18446744073709551615", "BIGINT UNSIGNED", "mysql"],
["-9007199254740993", "Int64", "clickhouse"],
["12345678901234567890123456789012345678", "NUMBER(38,0)", "snowflake"],
["1.0000000000000000002", "DECIMAL(38,19)", "sqlServer"],
["-1.0000000000000000002", "NUMERIC(38,19)", "postgres"],
["1234567890.12345678901234567890", "DECIMAL(38,20)", "mysql"],
["0.0000000000000000001", "NUMERIC", "postgres"],
["1e-400", "NUMERIC", "postgres"],
["1e-325", "NUMERIC", "postgres"],
["1e-9007199254740993", "NUMERIC", "postgres"],
["-2e-999999999999999999999", "NUMERIC", "postgres"],
["99999999999999999999.99999999999999999999", "NUMERIC", "postgres"],
["0.10000000000000000000000000001", "DECIMAL(38,29)", "mysql"],
["1.797693134862315708145274237317043567981e308", "DOUBLE", "mysql"],
["-2e-400", "NUMERIC", "postgres"],
["1.0000000000000000002E+100", "NUMERIC", "postgres"],
] as const)("preserves %s (%s, %s) as a JSON number", (value, type, driver) => {
const json = exportData("json", data(value, type, driver));
expect(json).toBe(jsonNumber(value));
expect(typeof JSON.parse(json)[0].value).toBe("number");
});
it.each([
["+9007199254740993", "9007199254740993"],
["09007199254740993", "9007199254740993"],
["-09223372036854775807", "-9223372036854775807"],
[" \t+001.0000000000000000002\n", "1.0000000000000000002"],
[".0000000000000000001", "0.0000000000000000001"],
["-.0000000000000000001", "-0.0000000000000000001"],
["0001.", "1"],
["+001.25e-003", "1.25e-003"],
["1.e-400", "1e-400"],
["-000.0000000000000000001", "-0.0000000000000000001"],
["+.0000000000000000001E-400", "0.0000000000000000001E-400"],
])("normalizes %s to valid JSON without rounding", (value, expected) => {
const json = exportData("json", data(value));
expect(json).toBe(jsonNumber(expected));
expect(typeof JSON.parse(json)[0].value).toBe("number");
});
it.each(["0", "-0", "-000.000e99999", "42", "-12.5", "+1", ".5", "1.", "", " \t ", "0x10", "0b10", "0o10"])(
"keeps ordinary numeric coercion for %s",
(value) => {
expect(JSON.parse(exportData("json", data(value)))).toEqual([
{ value: JSON.parse(JSON.stringify(Number(value))) },
]);
},
);
it.each(["NaN", "Infinity", "-Infinity", "1e400", "-1e999999999999999999999", "1e", '0,"injected":true', "1\n2"])(
"keeps non-finite or invalid numeric text %s quoted",
(value) => {
expect(JSON.parse(exportData("json", data(value)))).toEqual([{ value }]);
},
);
it.each(["TEXT", "VARCHAR(100)", "jsonb", "BOOLEAN", "POINT", "INTERVAL"])(
"keeps numeric-looking %s as text",
(type) => {
expect(JSON.parse(exportData("json", data("9007199254740993", type)))).toEqual([{ value: "9007199254740993" }]);
},
);
it.each(["", "unknown", "NULL"])("preserves exact numbers inferred from %s types", (type) => {
expect(exportData("json", data("9007199254740993", type))).toBe(jsonNumber("9007199254740993"));
});
it("keeps a mixed unknown column as text", () => {
const d = { ...data("9007199254740993", "unknown"), rows: [["9007199254740993"], ["text"]] };
expect(JSON.parse(exportData("json", d))).toEqual([{ value: "9007199254740993" }, { value: "text" }]);
});
it("escapes column names and text and keeps NULL and missing cells", () => {
const d: ExportData = {
columns: [
{ name: 'a"\n', type: "TEXT" },
{ name: "empty", type: "NUMERIC" },
{ name: "missing", type: "TEXT" },
],
rows: [['中文 \\ \t "quote"\n\u0000', null]],
table: "numbers",
driver: "postgres",
};
expect(exportData("json", d)).toBe(
JSON.stringify([{ ['a"\n']: '中文 \\ \t "quote"\n\u0000', empty: null, missing: null }], null, 2),
);
});
it("keeps duplicate columns last-wins, integer key order and literal __proto__ keys", () => {
const d: ExportData = {
columns: [
{ name: "2", type: "NUMERIC" },
{ name: "10", type: "TEXT" },
{ name: "1", type: "TEXT" },
{ name: "2", type: "TEXT" },
{ name: "__proto__", type: "TEXT" },
],
rows: [["9007199254740993", "ten", "one", "9007199254740993", "literal"]],
table: "numbers",
driver: "postgres",
};
const row = Object.fromEntries([
["2", "9007199254740993"],
["10", "ten"],
["1", "one"],
["__proto__", "literal"],
]);
const json = exportData("json", d);
expect(json).toBe(JSON.stringify([row], null, 2));
expect(Object.hasOwn(JSON.parse(json)[0], "__proto__")).toBe(true);
});
it("keeps empty results, zero-column rows and ignored extra cells", () => {
expect(exportData("json", { ...data("1"), rows: [] })).toBe("[]");
expect(exportData("json", { ...data("1"), columns: [], rows: [[], []] })).toBe("[\n {},\n {}\n]");
expect(exportData("json", { ...data("1"), rows: [["1", "ignored"]] })).toBe(jsonNumber("1"));
});
it("keeps all-NULL inference samples from changing later values to numbers", () => {
const rows = [...Array.from({ length: 50 }, () => [null]), ["9007199254740993"]];
const json = exportData("json", { ...data("", "unknown"), rows });
expect(JSON.parse(json)[50]).toEqual({ value: "9007199254740993" });
});
it("keeps numeric inference when later rows include text and NULL", () => {
const rows = [...Array.from({ length: 50 }, () => ["9007199254740993"]), ["text"], [null]];
const json = exportData("json", { ...data("", "unknown"), rows });
expect(json.match(/"value": 9007199254740993/g)).toHaveLength(50);
expect(JSON.parse(json).slice(50)).toEqual([{ value: "text" }, { value: null }]);
});
it("retains the exact numeric value when the last duplicate column is numeric", () => {
const d: ExportData = {
...data(""),
columns: [
{ name: "value", type: "TEXT" },
{ name: "value", type: "BIGINT" },
],
rows: [["discarded", "9223372036854775807"]],
};
expect(exportData("json", d)).toBe(jsonNumber("9223372036854775807"));
});
it("agrees with independent integer arithmetic over 250 decimal scales and exponents", () => {
let seed = 0x20261113;
const random = () => (seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0);
const exponents = [-450, -400, -40, -1, 0, 1, 40, 200];
for (let i = 0; i < 250; i++) {
const absolute = 10n ** 36n + BigInt(random()) * 10n ** 27n + BigInt(random());
const coefficient = i % 2 ? absolute : -absolute;
const scale = (random() >>> 16) % 45;
const exponent = exponents[(random() >>> 16) % exponents.length]!;
const digits = absolute.toString().padStart(scale + 1, "0");
const mantissa = scale ? `${digits.slice(0, -scale)}.${digits.slice(-scale)}` : digits;
const sign = coefficient < 0n ? "-" : i % 3 ? "" : "+";
const input = `\t${sign}${i % 5 ? "" : "00"}${mantissa}E${exponent >= 0 ? "+" : ""}${exponent} `;
const json = exportData("json", data(input));
expect(typeof JSON.parse(json)[0].value, input).toBe("number");
const token = /"value": ([^\n]+)\n/.exec(json)![1]!;
const [whole, exp = "0"] = token.toLowerCase().split("e");
const point = whole!.indexOf(".");
const actual = BigInt(whole!.replace(".", ""));
const power = Number(exp) - (point < 0 ? 0 : whole!.length - point - 1);
const expectedPower = exponent - scale;
const common = Math.min(power, expectedPower);
expect(actual * 10n ** BigInt(power - common), input).toBe(coefficient * 10n ** BigInt(expectedPower - common));
}
});
it("writes long numbers without losing trailing digits or expanding exponents", () => {
const value = `1.${"0".repeat(20_000)}1e-400`;
expect(exportData("json", data(value))).toBe(jsonNumber(value));
});
});
it.each<ExportFormat>(["csv", "tsv", "sql", "markdown", "onerow"])("%s retains exact numeric digits", (format) => {
const value = "9223372036854775807";
expect(exportData(format, data(value))).toContain(value);
});
+7 -19
Переглянути файл
@@ -49,19 +49,6 @@ function laidOut(d: ExportData, o: ExportOptions): { head: string[] | null; rows
return { head: null, rows: head.map((h, c) => [...(o.columnHeader ? [h] : []), ...rows.map((r) => r[c] ?? null)]) };
}
/** Normalize decimal text to JSON syntax without rounding its digits. */
function jsonCell(v: Cell, numeric: boolean): string {
if (v === null) return "null";
const number = numeric ? Number(v) : NaN;
if (!Number.isFinite(number)) return JSON.stringify(v);
const parts = /^([+-]?)(\d*)(?:\.(\d*))?([eE][+-]?\d+)?$/.exec(v.trim());
if (!parts) return JSON.stringify(number);
const whole = parts[2]!.replace(/^0+/, "") || "0";
const fraction = parts[3] ?? "";
if (!/[1-9]/.test(whole + fraction)) return "0";
return `${parts[1] === "-" ? "-" : ""}${whole}${fraction ? `.${fraction}` : ""}${parts[4] ?? ""}`;
}
export function exportData(
format: ExportFormat,
d: ExportData,
@@ -84,12 +71,13 @@ export function exportData(
return toTsv(t.head, t.rows);
}
case "json": {
const rows = d.rows.map((r) => {
const cells = Object.fromEntries(names.map((n, i) => [n, jsonCell(r[i] ?? null, numeric[i]!)]));
const members = Object.entries(cells).map(([name, value]) => ` ${JSON.stringify(name)}: ${value}`);
return members.length ? ` {\n${members.join(",\n")}\n }` : " {}";
});
return rows.length ? `[\n${rows.join(",\n")}\n]` : "[]";
const value = (v: Cell, i: number) =>
v === null ? null : numeric[i] && Number.isFinite(Number(v)) ? Number(v) : v;
return JSON.stringify(
d.rows.map((r) => Object.fromEntries(names.map((n, i) => [n, value(r[i] ?? null, i)]))),
null,
2,
);
}
case "sql": {
const literal = (v: Cell, i: number) =>
-120
Переглянути файл
@@ -33,95 +33,6 @@ const rows: Cell[][] = [
];
const value = (r: number, c: number) => rows[r]?.[c] ?? null;
describe("exact numeric cell comparison", () => {
it.each([
["9007199254740992", "9007199254740993"],
["9223372036854775806", "9223372036854775807"],
["-9007199254740993", "-9007199254740992"],
["-9223372036854775808", "-9223372036854775807"],
["1.0000000000000000001", "1.0000000000000000002"],
["-1.0000000000000000002", "-1.0000000000000000001"],
["0.99999999999999999999", "1.00000000000000000001"],
["12.00000000000000000001", "12.0000000000000000001"],
["1e400", "2e400"],
["-2e400", "-1e400"],
["1e-400", "2e-400"],
["-2e-400", "-1e-400"],
["0", "1e-400"],
["-1e-400", "-0"],
["1e9007199254740992", "1e9007199254740993"],
["1e-9007199254740993", "1e-9007199254740992"],
["9e999999999999999999999999", "1e1000000000000000000000000"],
["000.000000000000000000001", "0.000000000000000000002"],
["123456789012345678901234567890", "123456789012345678901234567891"],
["10", "9e1"],
])("orders %s before %s in both directions", (smaller, larger) => {
expect(compareCells(smaller, larger)).toBeLessThan(0);
expect(compareCells(larger, smaller)).toBeGreaterThan(0);
});
it.each([
["1", "01"],
["1", "1.000"],
["1", "10e-1"],
["1.25", "0012500E-4"],
["-1.25", "-125e-2"],
["0", "-0"],
["-0.000e999999999999999999999999", "00e-999999999999999999999999"],
["1e400", "10e399"],
["1e-400", "100e-402"],
["1e9007199254740993", "10e9007199254740992"],
])("keeps equivalent values equal: %s and %s", (a, b) => {
expect(compareCells(a, b)).toBe(0);
expect(compareCells(b, a)).toBe(0);
});
it("keeps NULL and non-numeric text ordering", () => {
for (const text of ["", "NaN", "Infinity", "+1", ".5", "1.", "1e", "abc"]) {
expect(compareCells(null, text)).toBeLessThan(0);
expect(compareCells(text, null)).toBeGreaterThan(0);
expect(compareCells(text, "2")).toBe(text < "2" ? -1 : 1);
expect(compareCells(text, text)).toBe(0);
}
});
it("compares long significant digits without expanding the exponent", () => {
const prefix = `1${"0".repeat(20_000)}`;
expect(compareCells(`${prefix}1e999999999999999999999999`, `${prefix}2e999999999999999999999999`)).toBeLessThan(0);
});
it("agrees with independent rational arithmetic across decimal scales and exponents", () => {
let seed = 0x12345678;
const random = () => (seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0);
const samples = Array.from({ length: 120 }, (_, i) => {
const coefficient = (2n ** 60n + BigInt(random() % 2048)) * (i % 3 === 0 ? -1n : 1n);
const scale = random() % 25;
const exponent = (random() % 41) - 20;
const digits = (coefficient < 0n ? -coefficient : coefficient).toString().padStart(scale + 1, "0");
const decimal = scale ? `${digits.slice(0, -scale)}.${digits.slice(-scale)}` : digits;
return {
text: `${coefficient < 0n ? "-" : ""}${decimal}e${exponent}`,
numerator: coefficient * 10n ** BigInt(Math.max(0, exponent)),
denominator: 10n ** BigInt(scale + Math.max(0, -exponent)),
};
});
for (const a of samples) {
for (const b of samples) {
const left = a.numerator * b.denominator;
const right = b.numerator * a.denominator;
const expected = left === right ? 0 : left < right ? -1 : 1;
expect(Math.sign(compareCells(a.text, b.text)), `${a.text} vs ${b.text}`).toBe(expected);
}
}
const ordered = samples.toSorted((a, b) => compareCells(a.text, b.text));
for (let i = 1; i < ordered.length; i++) {
const a = ordered[i - 1]!;
const b = ordered[i]!;
expect(a.numerator * b.denominator <= b.numerator * a.denominator).toBe(true);
}
});
});
describe("local filter and sort", () => {
it("compares numbers by value, NULL first", () => {
expect(["10", "9", null, "abc"].sort(compareCells)).toEqual([null, "9", "10", "abc"]);
@@ -152,27 +63,6 @@ describe("local filter and sort", () => {
f = toggleFilterValue(f, 1, all, "Beijing", true);
expect(f.has(1)).toBe(false);
});
it.each([false, true])("sorts exact values, preserving equal rows (descending: %s)", (descending) => {
const cells: Cell[] = ["9007199254740993", "1.0000000000000000002", "9007199254740992", "1", "1.000", null];
const order = visibleRows(cells.length, (r) => cells[r]!, new Map(), { column: 0, descending });
expect(order).toEqual(descending ? [0, 2, 1, 3, 4, 5] : [5, 3, 4, 1, 2, 0]);
});
it("sorts after filtering and keeps newly added rows last", () => {
const cells = ["9007199254740993", "9007199254740992", "1.0000000000000000002", "-999"];
const filter: LocalFilter = new Map([[0, new Set([cells[0]!, cells[1]!])]]);
expect(visibleRows(cells.length, (r) => cells[r]!, filter, { column: 0, descending: false }, 3)).toEqual([1, 0, 3]);
});
it("orders precise filter values before applying the limit and retains their counts", () => {
const cells = ["9007199254740993", "9007199254740992", "9007199254740992", "1.0000000000000000002", "1"];
expect(distinctValues(cells.length, (r) => cells[r]!, 0, 3)).toEqual([
{ value: "1", count: 1 },
{ value: "1.0000000000000000002", count: 1 },
{ value: "9007199254740992", count: 2 },
]);
});
});
describe("aggregates", () => {
@@ -189,16 +79,6 @@ describe("aggregates", () => {
});
expect(aggregates(["b", "a", "b"])).toMatchObject({ distinct: 2, sum: null, avg: null, min: "a", max: "b" });
});
it.each([
["9007199254740992", "9007199254740993"],
["-9007199254740993", "-9007199254740992"],
["1.0000000000000000001", "1.0000000000000000002"],
["1e-400", "2e-400"],
["1e400", "2e400"],
])("preserves exact minimum %s and maximum %s", (min, max) => {
expect(aggregates([max, null, min])).toMatchObject({ min, max });
});
});
describe("chart series", () => {
+2 -32
Переглянути файл
@@ -13,44 +13,14 @@ export interface LocalSort {
descending: boolean;
}
const NUMBER = /^(-?)(\d+)(?:\.(\d+))?(?:e([+-]?\d+))?$/i;
function decimalKey(value: string) {
const parts = NUMBER.exec(value)!;
const fraction = parts[3] ?? "";
const digits = (parts[2]! + fraction).replace(/^0+/, "");
if (!digits) return null;
let end = digits.length;
while (digits[end - 1] === "0") end--;
return {
negative: parts[1] === "-",
digits: digits.slice(0, end),
order: BigInt(parts[4] ?? "0") + BigInt(digits.length) - BigInt(fraction.length),
};
}
function compareNumbers(a: string, b: string): number {
const difference = Number(a) - Number(b);
// Distinct floating-point values keep decimal order; rounded ties need the original digits.
if (difference) return difference;
const left = decimalKey(a);
const right = decimalKey(b);
if (!left) return !right ? 0 : right.negative ? 1 : -1;
if (!right) return left.negative ? -1 : 1;
if (left.negative !== right.negative) return left.negative ? -1 : 1;
const direction = left.negative ? -1 : 1;
// Compare decimal orders without expanding even enormous exponents into zeroes.
if (left.order !== right.order) return direction * (left.order < right.order ? -1 : 1);
if (left.digits === right.digits) return 0;
return direction * (left.digits < right.digits ? -1 : 1);
}
const NUMBER = /^-?\d+(\.\d+)?(e[+-]?\d+)?$/i;
/** Numbers by value, then text; NULL first (as most databases sort ascending). */
export function compareCells(a: Cell, b: Cell): number {
if (a === b) return 0;
if (a === null) return -1;
if (b === null) return 1;
if (NUMBER.test(a) && NUMBER.test(b)) return compareNumbers(a, b);
if (NUMBER.test(a) && NUMBER.test(b)) return Number(a) - Number(b);
return a < b ? -1 : 1;
}
-23
Переглянути файл
@@ -235,29 +235,6 @@ describe("editable result grid", () => {
expect(backend.applyEdits).not.toHaveBeenCalled();
});
it("keeps unsubmitted edits while another result tab is shown", async () => {
const first = show("SELECT * FROM users WHERE id < 10", [{ name: "id" }, { name: "name" }], [["1", "Ann"]]);
const second: ResultTab = {
...first,
id: nextId++,
title: "Result 2",
outcome: { ...first.outcome, result: { ...first.outcome.result! } },
};
useDatabase.setState((s) => ({ results: [...s.results, second] }));
await act(async () => render(<ResultsView />));
fireEvent.doubleClick(await screen.findByRole("gridcell", { name: "Ann" }));
const input = screen.getByRole("textbox", { name: "Edit name" });
fireEvent.change(input, { target: { value: "Bob" } });
fireEvent.keyDown(input, { key: "Enter" });
await act(async () => useDatabase.setState({ activeResult: second.id }));
expect(screen.getByRole("button", { name: "Submit" }).hasAttribute("disabled")).toBe(true);
await act(async () => useDatabase.setState({ activeResult: first.id }));
expect(screen.getByRole("gridcell", { name: "Bob" })).toBeTruthy();
expect(screen.getByRole("button", { name: "Submit" }).hasAttribute("disabled")).toBe(false);
});
it("keeps an aliased column read-only while the plain ones stay editable", async () => {
show("SELECT id, name AS n FROM users", [{ name: "id" }, { name: "n" }], [["1", "Ann"]]);
await act(async () => render(<ResultsView />));
-34
Переглянути файл
@@ -92,40 +92,6 @@ describe("file naming", () => {
expect(ids).toContain(id);
expect(new Set(ids).size).toBe(ids.length);
});
it("ships a Jupyter Notebook template that the notebook editor accepts", () => {
const jupyter = tpl("jupyter");
expect(jupyter).toMatchObject({ extension: "ipynb", icon: "file-jupyter", nameStyle: "asis" });
expect(jupyter.enabled).not.toBe(false);
for (const kind of jupyter.kinds) {
const { text } = renderFileTemplate(kind.body, { name: "analysis", fileName: "analysis.ipynb" });
const notebook = JSON.parse(text);
// The rules of the backend's validate_notebook.
expect(notebook.nbformat).toBe(4);
expect(Number.isInteger(notebook.nbformat_minor)).toBe(true);
expect(notebook.metadata).toEqual(expect.any(Object));
expect(Array.isArray(notebook.cells)).toBe(true);
for (const cell of notebook.cells as Array<Record<string, unknown>>) {
expect(typeof cell.cell_type).toBe("string");
expect(cell.metadata).toEqual(expect.any(Object));
expect(cell.source).toEqual(expect.any(Array));
}
}
});
it("names the titled notebook after the file", () => {
const titled = tpl("jupyter").kinds.find((k) => k.id === "titled")!;
const { text } = renderFileTemplate(titled.body, { name: "report", fileName: "report.ipynb" });
expect(JSON.parse(text).cells[0]).toMatchObject({
cell_type: "markdown",
source: ["# report"],
});
});
it("plans the notebook file name from the entered name", () => {
expect(planFile(tpl("jupyter"), "/p/notebooks", "analysis")?.path).toBe("/p/notebooks/analysis.ipynb");
expect(planFile(tpl("jupyter"), "/p", "analysis.ipynb")?.path).toBe("/p/analysis.ipynb");
});
});
describe("PHP namespaces", () => {
-189
Переглянути файл
@@ -1,189 +0,0 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { createFromTemplate } from "../files/create";
import { renderFileTemplate, type FileTemplate } from "../files/model";
import { BUILTIN_FILE_TEMPLATES } from "../files/builtins";
import { activate as activateTemplates } from "../index";
import { menuGroupItems } from "@/workbench/contributions";
import { useProject } from "@/platform/project";
const files = vi.hoisted(() => new Map<string, string>());
const calls = vi.hoisted(() => ({
bytes: vi.fn(),
empty: vi.fn(),
openFile: vi.fn(),
notify: vi.fn(),
resolve: vi.fn(),
rollback: vi.fn(),
}));
const view = vi.hoisted(() => ({
state: { doc: { length: 0, toString: () => "" }, selection: { main: { head: 0 } } },
dispatch: vi.fn(),
focus: vi.fn(),
}));
vi.mock("@/platform/ipc", async (original) => ({
...(await original<typeof import("@/platform/ipc")>()),
isTauri: () => true,
call: (result: unknown) => result,
commands: {
fsCreateFileBytes: (path: string, data: number[]) => {
calls.bytes(path);
files.set(path, new TextDecoder().decode(new Uint8Array(data)));
return Promise.resolve(null);
},
fsCreateFile: (path: string) => {
calls.empty(path);
files.set(path, "");
return Promise.resolve(null);
},
fsReadDir: () => Promise.resolve([]),
},
}));
vi.mock("@/editor/api", async (original) => ({
...(await original<typeof import("@/editor/api")>()),
editorsFor: (path: string) => (/\.py$/.test(path) ? [{ view }] : []),
activeEditor: () => null,
}));
vi.mock("@/platform/actions", async (original) => ({
...(await original<typeof import("@/platform/actions")>()),
executeAction: vi.fn(async () => true),
}));
vi.mock("@/workbench/contributions", async (original) => ({
...(await original<typeof import("@/workbench/contributions")>()),
editorService: () => ({
openFile: async (path: string) => void calls.openFile(path),
saveAll: async () => {},
}),
maybeEditorService: () => ({ activePath: () => null }),
notifications: () => ({ notify: calls.notify }),
resolveFileEditor: (path: string) => {
calls.resolve(path);
// A notebook: its own editor kind, no CodeMirror view.
return Promise.resolve(
/\.ipynb$/.test(path)
? { input: { kind: "notebook", key: `notebook:${path}` }, admit: () => {}, rollback: calls.rollback }
: null,
);
},
}));
const NOTEBOOK_BODY = `{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": ["# $NAME$"]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
`;
const notebook: FileTemplate = {
id: "user.jupyter",
name: "Jupyter Notebook",
icon: "file-jupyter",
extension: "ipynb",
nameStyle: "asis",
kinds: [{ id: "notebook", label: "Notebook", body: NOTEBOOK_BODY }],
};
afterEach(() => {
files.clear();
vi.clearAllMocks();
useProject.setState({ project: null });
});
describe("createFromTemplate", () => {
it("writes the rendered body before a notebook editor takes the file", async () => {
useProject.setState({ project: { root: "/p", name: "p" } as never });
const path = await createFromTemplate(notebook, notebook.kinds[0]!, "/p", "analysis");
expect(path).toBe("/p/analysis.ipynb");
expect(files.get(path)).toBe(NOTEBOOK_BODY.replace("$NAME$", "analysis"));
expect(JSON.parse(files.get(path)!)).toMatchObject({
nbformat: 4,
cells: [{ cell_type: "markdown", source: ["# analysis"] }],
});
expect(calls.empty).not.toHaveBeenCalled();
// The kind owns the document, so there is no "could not insert" warning.
expect(calls.notify).not.toHaveBeenCalled();
expect(calls.resolve).toHaveBeenCalledWith(path);
// The probe's acquisitions (the notebook backend session) are released.
expect(calls.rollback).toHaveBeenCalledTimes(1);
expect(calls.openFile).toHaveBeenCalledWith(path);
// The body is on disk before the editor reads it.
expect(calls.bytes.mock.invocationCallOrder[0]!).toBeLessThan(calls.openFile.mock.invocationCallOrder[0]!);
});
it("inserts a text template into the editor view, caret at $END$", async () => {
const py: FileTemplate = {
...notebook,
id: "user.py",
extension: "py",
kinds: [{ id: "script", label: "Script", body: "print(1)\n$END$" }],
};
const path = await createFromTemplate(py, py.kinds[0]!, "/p", "main");
expect(calls.bytes).not.toHaveBeenCalled();
expect(calls.empty).toHaveBeenCalledWith(path);
expect(view.dispatch).toHaveBeenCalledWith(
expect.objectContaining({ changes: { from: 0, insert: "print(1)\n" }, userEvent: "input" }),
);
expect(calls.notify).not.toHaveBeenCalled();
});
it("creates an empty file when the template renders nothing", async () => {
const empty: FileTemplate = { ...notebook, kinds: [{ id: "blank", label: "Empty", body: "" }] };
const path = await createFromTemplate(empty, empty.kinds[0]!, "/p", "blank");
expect(calls.empty).toHaveBeenCalledWith(path);
expect(files.get(path)).toBe("");
expect(calls.bytes).not.toHaveBeenCalled();
expect(calls.notify).not.toHaveBeenCalled();
});
it("renders the notebook body a text template would have got", () => {
const { text } = renderFileTemplate(NOTEBOOK_BODY, { name: "report", fileName: "report.ipynb" });
expect(JSON.parse(text)).toMatchObject({
nbformat: 4,
cells: [{ cell_type: "markdown", source: ["# report"] }],
});
});
});
describe("built-in Jupyter Notebook", () => {
const builtin = BUILTIN_FILE_TEMPLATES.find((t) => t.id === "jupyter")!;
it("writes the titled notebook body before the notebook editor takes the file", async () => {
const titled = builtin.kinds.find((k) => k.id === "titled")!;
const path = await createFromTemplate(builtin, titled, "/p", "analysis");
expect(path).toBe("/p/analysis.ipynb");
expect(JSON.parse(files.get(path)!)).toMatchObject({
nbformat: 4,
cells: [{ cell_type: "markdown", source: ["# analysis"] }],
});
expect(calls.notify).not.toHaveBeenCalled();
});
it("is listed in the New menu with its icon, without duplicating entries", () => {
const dispose = activateTemplates();
try {
const items = menuGroupItems("new", { paths: ["/p"] });
const actions = items.filter((i) => i.kind === "action");
const row = actions.find((i) => i.kind === "action" && i.action === "templates.new.jupyter");
expect(row).toMatchObject({ label: "Jupyter Notebook", icon: "file-jupyter" });
const ids = actions.map((i) => i.action);
expect(new Set(ids).size).toBe(ids.length);
} finally {
dispose();
}
});
});
-56
Переглянути файл
@@ -4,51 +4,6 @@ import type { FileTemplate, TemplateFragment } from "./model";
/** Includes tab: fragments file templates pull in with `#parse("…")`. */
export const BUILTIN_INCLUDES: readonly TemplateFragment[] = [{ name: "File Header", body: "" }];
/** Opens empty: the notebook editor adds the first cell. */
const JUPYTER_NOTEBOOK_BODY = `{
"cells": [],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
`;
/** Starts with a Markdown heading named after the file. */
const JUPYTER_TITLED_NOTEBOOK_BODY = `{
"cells": [
{
"cell_type": "markdown",
"id": "cell-title",
"metadata": {},
"source": [
"# $NAME$"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
`;
/** Code tab: the members the built-in test templates generate. */
export const BUILTIN_CODE_TEMPLATES: readonly TemplateFragment[] = [
{
@@ -173,17 +128,6 @@ export const BUILTIN_FILE_TEMPLATES: readonly FileTemplate[] = [
{ id: "script", label: "Script", body: 'def main():\n $END$\n\n\nif __name__ == "__main__":\n main()\n' },
],
},
{
id: "jupyter",
name: "Jupyter Notebook",
icon: "file-jupyter",
extension: "ipynb",
nameStyle: "asis",
kinds: [
{ id: "notebook", label: "Notebook", body: JUPYTER_NOTEBOOK_BODY },
{ id: "titled", label: "Notebook with a title", body: JUPYTER_TITLED_NOTEBOOK_BODY },
],
},
{
id: "go",
name: "Go File",
+3 -21
Переглянути файл
@@ -7,7 +7,7 @@ import { call, commands, isTauri } from "@/platform/ipc";
import { dirname, useProject } from "@/platform/project";
import { currentRoots } from "@/platform/projectRoots";
import { activeEditor, editorsFor, type TextEditorHandle } from "@/editor/api";
import { editorService, maybeEditorService, notifications, resolveFileEditor } from "@/workbench/contributions";
import { editorService, maybeEditorService, notifications } from "@/workbench/contributions";
import {
GO_PACKAGE_RE,
caretAfterReformat,
@@ -112,23 +112,10 @@ export function defaultDirectory(): string | null {
return path ? dirname(path) : (useProject.getState().project?.root ?? null);
}
/** Whether a non-text editor opens `path`; the probe's acquisitions are released. */
async function providedEditor(path: string): Promise<boolean> {
const resolution = await resolveFileEditor(path).catch(() => null);
if (!resolution) return false;
try {
await resolution.rollback();
} catch {
// Released on a best-effort basis; opening resolves the editor again.
}
return true;
}
/**
* Creates `input` (a name, possibly with sub-directories) in `directory`
* from `kind`, opens it and inserts the rendered body with the caret at
* `$END$` (a file a non-text editor opens, like a notebook, gets the body on
* disk instead). Throws with a user-facing message on failure.
* `$END$`. Throws with a user-facing message on failure.
*/
export async function createFromTemplate(
t: FileTemplate,
@@ -157,16 +144,11 @@ export async function createFromTemplate(
templateIncludes(),
);
if (cancelled?.()) return plan.path;
// A provided editor (a notebook shows cells, not text) reads the file from
// disk and has no view to insert into, so its body is written on create.
const provided = await providedEditor(plan.path);
if (provided && text) await call(commands.fsCreateFileBytes(plan.path, [...new TextEncoder().encode(text)]));
else await call(commands.fsCreateFile(plan.path));
await call(commands.fsCreateFile(plan.path));
notifyFileOperation({ kind: "created", paths: [plan.path] });
onCreated?.();
await new Promise((r) => setTimeout(r, 0));
await editorService().openFile(plan.path, { focus: true });
if (provided) return plan.path;
const handle = await waitForEditor(plan.path);
if (!handle) {
notifications().notify({
-84
Переглянути файл
@@ -23,7 +23,6 @@ vi.mock("../CommitChooser", () => ({ chooseLogCommit: (commits: Commit[]) => api
import { commitKey } from "../multiRoot";
import { useVcs } from "../store";
import { DEFAULT_LOG_OPTIONS, useLogOptions } from "../logOptions";
import * as logPresentation from "../logPresentation";
import {
displayedLogGraph,
emptyFilters,
@@ -71,7 +70,6 @@ beforeEach(() => {
commits: [],
selection: [],
selected: null,
seek: null,
done: false,
fragments: { expanded: new Set(), collapsed: new Set(), merges: new Set() },
generation: useGitLog.getState().generation + 1,
@@ -79,7 +77,6 @@ beforeEach(() => {
});
afterEach(async () => {
vi.restoreAllMocks();
api.log.mockResolvedValue(ok([]));
await reloadLog();
});
@@ -298,85 +295,4 @@ describe("commit navigation", () => {
expect(api.log).toHaveBeenCalledTimes(1);
expect(api.log.mock.calls[0]?.[1]).toMatchObject({ seek: target.id, branches: ["HEAD"] });
});
it.each([10, 300])("does not rebuild the displayed graph for each of %i loaded commits", async (count) => {
const commits = Array.from({ length: count }, (_, i) => c(`commit${i}`, i + 1 < count ? [`commit${i + 1}`] : []));
useGitLog.setState({ commits, done: true });
const present = vi.spyOn(logPresentation, "presentLogGraph");
await goToParent(commits[0]!);
expect(useGitLog.getState().selected).toBe("commit1");
expect(api.log).not.toHaveBeenCalled();
expect(present.mock.calls.length).toBeLessThanOrEqual(3);
});
it("reveals a commit beyond thirty fallback pages when seek does not find it", async () => {
const history = Array.from({ length: PAGE * 32 + 7 }, (_, i) => c(`commit${i}`));
const target = history.at(-1)!;
api.log.mockImplementation(async (_repo: string, q: LogQuery) => ok(history.slice(q.skip, q.skip + q.limit)));
await revealCommit(target.id, "/repo");
expect(api.log.mock.calls[0]?.[1].seek).toBe(target.id);
expect(api.log.mock.calls.length).toBeGreaterThan(31);
expect(useGitLog.getState().selected).toBe(commitKey({ ...target, repo: "/repo" }));
});
it("finds an old parent beyond thirty pages with one graph snapshot per check", async () => {
const tip = { ...c("tip", ["parent"]), repo: "/repo" };
const history = [
tip,
...Array.from({ length: PAGE * 31 }, (_, i) =>
c(`commit${i}`, i + 1 < PAGE * 31 ? [`commit${i + 1}`] : ["parent"]),
),
c("parent"),
];
useGitLog.setState({ commits: [tip] });
api.log.mockImplementation(async (_repo: string, q: LogQuery) => ok(history.slice(q.skip, q.skip + q.limit)));
const present = vi.spyOn(logPresentation, "presentLogGraph");
await goToParent(tip);
expect(api.log.mock.calls.length).toBeGreaterThan(30);
expect(useGitLog.getState().selected).toBe(commitKey({ ...c("parent"), repo: "/repo" }));
expect(present.mock.calls.length).toBeLessThanOrEqual(api.log.mock.calls.length + 3);
});
it("recomputes collapsed parent adjacency after loading another page", async () => {
const tip = { ...c("tip", ["middle"]), repo: "/repo" };
useGitLog.setState({ commits: [tip] });
useLogOptions.setState({ collapseLinear: true });
api.log.mockResolvedValue(ok([c("middle", ["base"]), c("base")]));
await goToParent(tip);
expect(api.log).toHaveBeenCalledTimes(1);
expect(useGitLog.getState().selected).toBe(commitKey({ ...c("base"), repo: "/repo" }));
});
it("navigates the displayed parent of a linearized merge", async () => {
const commits = [c("merge", ["main", "side"]), c("side", ["base"]), c("main", ["base"]), c("base")];
useGitLog.setState({ commits, done: true });
useLogOptions.setState({ linearizeMerges: true });
await goToParent(commits[0]!);
expect(useGitLog.getState().selected).toBe("side");
expect(api.choose).not.toHaveBeenCalled();
});
it("does not confuse parent hashes shared by different repositories", async () => {
const tip = { ...c("tip", ["parent"]), repo: "/a" };
useVcs.setState({ roots: ["/a", "/b"] });
useGitLog.setState({
commits: [tip, { ...c("parent"), repo: "/b" }, { ...c("parent"), repo: "/a" }],
done: true,
});
await goToParent(tip);
expect(useGitLog.getState().selected).toBe(commitKey({ ...c("parent"), repo: "/a" }));
expect(api.choose).not.toHaveBeenCalled();
});
});
+5 -11
Переглянути файл
@@ -1196,18 +1196,12 @@ export function displayedLogGraph() {
export async function goToParent(c: Commit) {
const generation = useGitLog.getState().generation;
const find = () => {
const { graph, commits } = displayedLogGraph();
const parents = graph.find((x) => x.id === commitKey(c))?.parents ?? [];
return { parents, candidates: commits.filter((x) => parents.includes(commitKey(x))) };
};
if (!find().parents.length) return;
await pageUntil(() => {
const { parents, candidates } = find();
return candidates.length === parents.length;
});
const parents = () => displayedLogGraph().graph.find((x) => x.id === commitKey(c))?.parents ?? [];
if (!parents().length) return;
const find = () => displayedLogGraph().commits.filter((x) => parents().includes(commitKey(x)));
await pageUntil(() => find().length === parents().length);
if (useGitLog.getState().generation !== generation) return;
const { candidates } = find();
const candidates = find();
const chosen = candidates.length > 1 ? await chooseLogCommit(candidates, "Select Parent Commit") : candidates[0];
if (chosen && useGitLog.getState().generation === generation) selectCommit(commitKey(chosen), true);
}