дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 09:41:34 +02:00
Порівняти коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
90bb5576ae | ||
|
|
29af5994e3 | ||
|
|
226ac26954 | ||
|
|
658c38a193 | ||
|
|
20be9ff646 | ||
|
|
394e9919c7 | ||
|
|
e839e5dfb7 | ||
|
|
ff17c3753f | ||
|
|
5f970d97d5 | ||
|
|
16bf9b53a2 | ||
|
|
68dd88993b | ||
|
|
b50219b6fa | ||
|
|
7090a8db56 | ||
|
|
37c2a6048e | ||
|
|
d71434a0cb | ||
|
|
53f837b704 | ||
|
|
7c80b68787 |
No files matched your search
Створено
+39
-39
@@ -4180,7 +4180,7 @@ checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||
|
||||
[[package]]
|
||||
name = "ide-agent"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"encoding_rs",
|
||||
@@ -4204,7 +4204,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-analysis"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"ast-grep-core",
|
||||
"ide-core",
|
||||
@@ -4218,7 +4218,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-android"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"serde",
|
||||
@@ -4229,7 +4229,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-build"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"dirs 6.0.0",
|
||||
@@ -4245,7 +4245,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-cli"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"dirs 6.0.0",
|
||||
"serde",
|
||||
@@ -4259,7 +4259,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-clipboard"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"objc2 0.6.5",
|
||||
"objc2-app-kit 0.3.2",
|
||||
@@ -4268,7 +4268,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-core"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"encoding_rs",
|
||||
@@ -4286,7 +4286,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-coverage"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-run",
|
||||
@@ -4300,7 +4300,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-dap"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"ide-core",
|
||||
@@ -4323,7 +4323,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-db"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"bb8",
|
||||
"blake3",
|
||||
@@ -4353,7 +4353,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-docker"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"serde",
|
||||
@@ -4366,7 +4366,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-extension"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"blake3",
|
||||
@@ -4386,7 +4386,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-fonts"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"objc2-core-foundation",
|
||||
"objc2-core-text",
|
||||
@@ -4398,7 +4398,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-github"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-vcs",
|
||||
@@ -4411,7 +4411,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-host"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"blake3",
|
||||
@@ -4478,7 +4478,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-http"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"parking_lot",
|
||||
@@ -4496,7 +4496,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-index"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"criterion",
|
||||
@@ -4518,7 +4518,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-jsonrpc"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"futures",
|
||||
@@ -4535,7 +4535,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-language"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"criterion",
|
||||
@@ -4591,7 +4591,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-lsp"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"futures",
|
||||
@@ -4617,7 +4617,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-mcp"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"dunce",
|
||||
@@ -4636,7 +4636,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-notebook"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"ide-core",
|
||||
@@ -4659,7 +4659,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-plugin"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"dunce",
|
||||
@@ -4682,7 +4682,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-profiler"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-run",
|
||||
@@ -4695,7 +4695,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-remote"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"globset",
|
||||
@@ -4714,7 +4714,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-run"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"encoding_rs",
|
||||
@@ -4738,7 +4738,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-sdk"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"ide-core",
|
||||
@@ -4758,7 +4758,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-search"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"criterion",
|
||||
"globset",
|
||||
@@ -4778,7 +4778,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-spell"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"parking_lot",
|
||||
@@ -4791,7 +4791,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-ssh"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"dirs 6.0.0",
|
||||
"flate2",
|
||||
@@ -4812,7 +4812,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-syntax"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-language",
|
||||
@@ -4827,7 +4827,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-terminal"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"libc",
|
||||
@@ -4840,7 +4840,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-text"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"criterion",
|
||||
"ide-core",
|
||||
@@ -4853,7 +4853,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-tools"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"hex",
|
||||
@@ -4874,7 +4874,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-vcs"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"dunce",
|
||||
@@ -4895,7 +4895,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-vfs"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"chardetng",
|
||||
"dunce",
|
||||
@@ -4919,7 +4919,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-web"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"open",
|
||||
@@ -4935,7 +4935,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-workspace"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"dunce",
|
||||
@@ -6522,7 +6522,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "openidea"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"blake3",
|
||||
|
||||
+4
-2
@@ -5,7 +5,7 @@ members = ["crates/*", "src-tauri"]
|
||||
exclude = ["sdk", "plugins"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
edition = "2024"
|
||||
rust-version = "1.96"
|
||||
license = "Apache-2.0"
|
||||
@@ -132,7 +132,9 @@ debug = false
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
# Thin LTO: fat LTO's whole-program link outgrew the 16 GB release runners
|
||||
# (Linux arm64 was killed mid-link from v0.1.39 on).
|
||||
lto = "thin"
|
||||
opt-level = 3
|
||||
# Unwind, so a panic fails one task or command instead of quitting the IDE.
|
||||
panic = "unwind"
|
||||
|
||||
@@ -32,7 +32,7 @@ use std::path::{Component, Path, PathBuf};
|
||||
|
||||
pub const MANIFEST_FILE: &str = "plugin.toml";
|
||||
/// The plugin API (engine) version this host implements.
|
||||
pub const ENGINE_VERSION: &str = "1.4.0";
|
||||
pub const ENGINE_VERSION: &str = "1.5.0";
|
||||
/// The 0.1 API, still accepted for contribution-only packages and 0.1 components.
|
||||
pub const LEGACY_API: &str = "0.1";
|
||||
/// Marketplace categories, in the order they are shown.
|
||||
|
||||
@@ -1,9 +1,39 @@
|
||||
//! Storage policy and best-effort migration of rebuildable desktop data.
|
||||
|
||||
use std::ffi::OsString;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Moves the rebuildable local data (tools, language servers, indexes, caches);
|
||||
/// configuration and roaming data keep following the OS.
|
||||
pub const LOCAL_DATA_ENV: &str = "OPENIDEA_LOCAL_DATA_DIR";
|
||||
|
||||
/// `$OPENIDEA_LOCAL_DATA_DIR/<identifier>` when set, else the OS local data directory
|
||||
/// (Tauri's `app_local_data_dir`). The identifier keeps release and per-worktree
|
||||
/// debug builds apart under one root. A set but unusable path is an error, never a
|
||||
/// silent fallback to the OS location.
|
||||
pub fn local_data_dir(identifier: &str) -> Result<PathBuf, String> {
|
||||
resolve_local(std::env::var_os(LOCAL_DATA_ENV), dirs::data_local_dir(), identifier)
|
||||
}
|
||||
|
||||
fn resolve_local(var: Option<OsString>, os: Option<PathBuf>, identifier: &str) -> Result<PathBuf, String> {
|
||||
let Some(root) = var.filter(|v| !v.is_empty()).map(PathBuf::from) else {
|
||||
return os.map(|dir| dir.join(identifier)).ok_or_else(|| "cannot find the local data directory".into());
|
||||
};
|
||||
// The working directory depends on how the IDE was launched.
|
||||
if !root.is_absolute() {
|
||||
return Err(format!("{LOCAL_DATA_ENV} must be an absolute path: {}", root.display()));
|
||||
}
|
||||
let dir = root.join(identifier);
|
||||
let probe = dir.join(".openidea-write-check");
|
||||
fs::create_dir_all(&dir)
|
||||
.and_then(|()| fs::write(&probe, b""))
|
||||
.and_then(|()| fs::remove_file(&probe))
|
||||
.map_err(|error| format!("{LOCAL_DATA_ENV}: cannot write to {}: {error}", dir.display()))?;
|
||||
Ok(dir)
|
||||
}
|
||||
|
||||
/// Unknown entries and recovery/user content deliberately stay in roaming data.
|
||||
pub fn is_local(entry: &Path) -> bool {
|
||||
["tools", "language-server-runtimes", "index", "cache", "lsp", "notebook-runtime", "server", "logs"]
|
||||
@@ -276,6 +306,55 @@ fn relative_wrapper(text: &str, source: &Path) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn local_dir_follows_the_os_unless_the_variable_is_set() {
|
||||
let os = Some(PathBuf::from("/os-local"));
|
||||
for var in [None, Some(OsString::new())] {
|
||||
assert_eq!(
|
||||
resolve_local(var, os.clone(), "ai.l0ng.openidea").unwrap(),
|
||||
Path::new("/os-local/ai.l0ng.openidea")
|
||||
);
|
||||
}
|
||||
assert!(resolve_local(None, None, "id").is_err());
|
||||
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let root = tmp.path().join("missing/nested");
|
||||
let dir = resolve_local(Some(root.clone().into()), os.clone(), "ai.l0ng.openidea").unwrap();
|
||||
assert_eq!(dir, root.join("ai.l0ng.openidea"));
|
||||
assert!(dir.is_dir());
|
||||
assert_eq!(fs::read_dir(&dir).unwrap().count(), 0);
|
||||
// Debug worktrees have their own identifiers and stay apart under one root.
|
||||
assert_ne!(resolve_local(Some(root.clone().into()), None, "dev-a").unwrap(), dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_dir_rejects_relative_and_unwritable_paths() {
|
||||
for relative in ["local", "./local", "../local"] {
|
||||
let error = resolve_local(Some(relative.into()), Some("/os".into()), "id").unwrap_err();
|
||||
assert!(error.contains(LOCAL_DATA_ENV) && error.contains("absolute"), "{error}");
|
||||
}
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let blocker = tmp.path().join("file");
|
||||
fs::write(&blocker, "").unwrap();
|
||||
let error = resolve_local(Some(blocker.into()), Some("/os".into()), "id").unwrap_err();
|
||||
assert!(error.contains("cannot write"), "{error}");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn local_dir_rejects_an_existing_read_only_directory() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let dir = tmp.path().join("id");
|
||||
fs::create_dir(&dir).unwrap();
|
||||
fs::set_permissions(&dir, fs::Permissions::from_mode(0o555)).unwrap();
|
||||
// Root ignores permission bits.
|
||||
if fs::write(dir.join("probe"), "").is_err() {
|
||||
assert!(resolve_local(Some(tmp.path().into()), None, "id").unwrap_err().contains("cannot write"));
|
||||
}
|
||||
fs::set_permissions(&dir, fs::Permissions::from_mode(0o755)).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrappers_accept_mixed_separators_without_rewriting_neighbor_paths() {
|
||||
let text = "@echo off\r\n\"C:\\old\\tools/demo\\payload.exe\" \"C:\\old\\tools/demo-other\\x\" %*\r\n";
|
||||
|
||||
@@ -28,6 +28,8 @@ pub struct Reports(RwLock<State>);
|
||||
struct State {
|
||||
windows: HashMap<String, Window>,
|
||||
focused: Option<String>,
|
||||
/// Windows in the order they were last focused, the most recent last.
|
||||
focus_order: Vec<String>,
|
||||
remote: HashMap<String, PathBuf>,
|
||||
libraries: HashMap<String, Vec<PathBuf>>,
|
||||
}
|
||||
@@ -46,8 +48,16 @@ impl Reports {
|
||||
state.windows.entry(window.into()).or_default().focused = editor;
|
||||
if focused {
|
||||
state.focused = Some(window.into());
|
||||
state.focus_order.retain(|w| w != window);
|
||||
state.focus_order.push(window.into());
|
||||
}
|
||||
}
|
||||
/// Sorts `windows` by when they were last focused, the most recent first; windows
|
||||
/// never focused keep their order after them.
|
||||
pub(crate) fn most_recently_focused_first(&self, windows: &mut [String]) {
|
||||
let order = &self.0.read().focus_order;
|
||||
windows.sort_by_key(|w| std::cmp::Reverse(order.iter().position(|o| o == w)));
|
||||
}
|
||||
pub fn report_problems(&self, window: &str, reset: bool, files: Vec<FileProblems>) {
|
||||
let mut state = self.0.write();
|
||||
let problems = &mut state.windows.entry(window.into()).or_default().problems;
|
||||
@@ -68,6 +78,7 @@ impl Reports {
|
||||
state.windows.remove(window);
|
||||
state.remote.remove(window);
|
||||
state.libraries.remove(window);
|
||||
state.focus_order.retain(|w| w != window);
|
||||
if state.focused.as_deref() == Some(window) {
|
||||
state.focused = None;
|
||||
}
|
||||
@@ -122,3 +133,24 @@ impl Reports {
|
||||
files.into_iter().map(|(path, items)| FileProblems { path: path.into(), items }).collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn windows_sort_by_their_last_focus() {
|
||||
let reports = Reports::default();
|
||||
for window in ["a", "b", "a", "c"] {
|
||||
reports.set_focused_editor(window, None, true);
|
||||
}
|
||||
reports.set_focused_editor("b", None, false);
|
||||
let mut windows: Vec<String> = ["a", "b", "c", "never"].map(String::from).into();
|
||||
reports.most_recently_focused_first(&mut windows);
|
||||
assert_eq!(windows, ["c", "a", "b", "never"]);
|
||||
reports.forget_window("c");
|
||||
let mut windows: Vec<String> = ["never", "c", "b", "a"].map(String::from).into();
|
||||
reports.most_recently_focused_first(&mut windows);
|
||||
assert_eq!(windows, ["a", "b", "never", "c"]);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,11 @@ pub fn find_files(host: &Host, window: &str, query: String, limit: u32) -> IdeRe
|
||||
Ok(host.project(window)?.index.find_files(&query, limit as usize))
|
||||
}
|
||||
|
||||
pub async fn find_files_named(host: &Host, window: &str, name: String) -> IdeResult<Vec<IpcPath>> {
|
||||
let project = host.project(window)?;
|
||||
blocking(move || Ok(project.index.files_named(&name).into_iter().map(Into::into).collect())).await
|
||||
}
|
||||
|
||||
pub fn find_dirs(host: &Host, window: &str, query: String, limit: u32) -> IdeResult<Vec<FileMatch>> {
|
||||
Ok(host.project(window)?.index.find_dirs(&query, limit as usize))
|
||||
}
|
||||
@@ -167,6 +172,7 @@ pub(crate) fn register(d: &mut Dispatcher) {
|
||||
d.add("index_status", |c| async move { index_status(&c.host, &c.window) });
|
||||
d.add("index_file_extensions", |c| async move { index_file_extensions(&c.host, &c.window) });
|
||||
d.add("find_files", |c| async move { find_files(&c.host, &c.window, c.arg("query")?, c.arg("limit")?) });
|
||||
d.add("find_files_named", |c| async move { find_files_named(&c.host, &c.window, c.arg("name")?).await });
|
||||
d.add("find_dirs", |c| async move { find_dirs(&c.host, &c.window, c.arg("query")?, c.arg("limit")?) });
|
||||
d.add("find_symbols", |c| async move {
|
||||
find_symbols(&c.host, &c.window, c.arg("query")?, c.arg("filter")?, c.arg("limit")?)
|
||||
|
||||
@@ -110,6 +110,10 @@ pub trait PluginWorkspace: Send + Sync {
|
||||
fn trusted(&self, root: &Path) -> bool;
|
||||
/// Root of the project open in `window`.
|
||||
fn project_of(&self, window: &str) -> Option<PathBuf>;
|
||||
/// Windows showing the open project at `root`, the most recently focused first.
|
||||
fn project_windows(&self, _root: &Path) -> Vec<String> {
|
||||
Vec::new()
|
||||
}
|
||||
/// Shows `items` as producer `source`'s diagnostics of `path` (replacing earlier ones).
|
||||
fn publish_diagnostics(&self, source: &str, path: &Path, items: Vec<ide_core::Diagnostic>)
|
||||
-> Result<(), HostError>;
|
||||
@@ -1758,17 +1762,31 @@ impl HostApi for PluginApi {
|
||||
body: String,
|
||||
actions: Vec<ide_plugin::NotificationAction>,
|
||||
) -> Result<(), HostError> {
|
||||
if !actions.is_empty() {
|
||||
let commands = self.shared.ui.items("commands", Some(self.id()));
|
||||
if let Some(a) = actions.iter().find(|a| !commands.iter().any(|c| c.key == a.command)) {
|
||||
return Err(HostError::NotFound(format!("the plugin declares no command {:?}", a.command)));
|
||||
}
|
||||
}
|
||||
check_actions(self, &actions)?;
|
||||
let plugin_id = self.id().to_owned();
|
||||
self.shared.sink.emit(client, PluginEvent::Notification { plugin_id, level, title, body, actions });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn notify_project(
|
||||
&self,
|
||||
root: &Path,
|
||||
level: NotificationLevel,
|
||||
title: String,
|
||||
body: String,
|
||||
actions: Vec<ide_plugin::NotificationAction>,
|
||||
) -> Result<(), HostError> {
|
||||
check_actions(self, &actions)?;
|
||||
let windows = self.shared.workspace().map(|w| w.project_windows(root)).unwrap_or_default();
|
||||
let window = windows
|
||||
.into_iter()
|
||||
.find(|w| !self.shared.client_closed(w))
|
||||
.ok_or_else(|| HostError::NotFound(format!("the project {} is not open", root.display())))?;
|
||||
let plugin_id = self.id().to_owned();
|
||||
self.shared.sink.emit(Some(&window), PluginEvent::Notification { plugin_id, level, title, body, actions });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn copy_to_clipboard(&self, client: Option<&str>, text: String) -> Result<(), HostError> {
|
||||
let client = from_window(client, "copy to the clipboard")?;
|
||||
self.shared.sink.emit(Some(client), PluginEvent::CopyToClipboard { plugin_id: self.id().to_owned(), text });
|
||||
@@ -2718,6 +2736,15 @@ fn not_writable(path: &Path, e: ide_core::error::IdeError) -> HostError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Notification buttons must name commands the plugin declares.
|
||||
fn check_actions(api: &PluginApi, actions: &[ide_plugin::NotificationAction]) -> Result<(), HostError> {
|
||||
let commands = if actions.is_empty() { Vec::new() } else { api.shared.ui.items("commands", Some(api.id())) };
|
||||
match actions.iter().find(|a| !commands.iter().any(|c| c.key == a.command)) {
|
||||
Some(a) => Err(HostError::NotFound(format!("the plugin declares no command {:?}", a.command))),
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
/// [`PluginWorkspace`] over the desktop host's open projects.
|
||||
pub struct HostWorkspace(pub std::sync::Weak<crate::Host>);
|
||||
|
||||
@@ -3016,6 +3043,13 @@ impl PluginWorkspace for HostWorkspace {
|
||||
self.0.upgrade()?.project(window).ok().map(|p| p.root.clone())
|
||||
}
|
||||
|
||||
fn project_windows(&self, root: &Path) -> Vec<String> {
|
||||
let Some(host) = self.0.upgrade() else { return Vec::new() };
|
||||
let mut windows = host.windows_for_root(root);
|
||||
host.mcp_reports.most_recently_focused_first(&mut windows);
|
||||
windows
|
||||
}
|
||||
|
||||
fn publish_diagnostics(
|
||||
&self,
|
||||
source: &str,
|
||||
|
||||
@@ -290,6 +290,7 @@ pub fn restricted_command_allowed(cmd: &str) -> bool {
|
||||
| "deploy_coverage"
|
||||
| "deploy_test_connection"
|
||||
| "find_files"
|
||||
| "find_files_named"
|
||||
| "find_dirs"
|
||||
| "find_symbols"
|
||||
| "mark_recent"
|
||||
|
||||
@@ -126,6 +126,10 @@ impl PluginWorkspace for TestWorkspace {
|
||||
fn trusted(&self, _root: &Path) -> bool {
|
||||
self.trusted
|
||||
}
|
||||
fn project_windows(&self, root: &Path) -> Vec<String> {
|
||||
// `main` shows the fixture project; other open roots have no window left.
|
||||
if root == self.root { vec!["closing".into(), "main".into()] } else { Vec::new() }
|
||||
}
|
||||
fn project_of(&self, _window: &str) -> Option<PathBuf> {
|
||||
if let Some(left) = self.project_queries_left.lock().as_mut() {
|
||||
if *left == 0 {
|
||||
@@ -4801,6 +4805,40 @@ fn notification_actions_keep_commands_and_window_scope() {
|
||||
assert_eq!(f.status("jobs"), PluginStatus::Active, "a refused notification leaves the plugin running");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn project_notifications_go_to_a_window_of_that_project_only() {
|
||||
let f = fixture(Limits::default());
|
||||
f.install(&sample("jobs"));
|
||||
f.host.set_capability("jobs", "project.read", false).unwrap();
|
||||
f.host.forget_client("closing");
|
||||
let other = f.project.parent().unwrap().join("other");
|
||||
std::fs::create_dir(&other).unwrap();
|
||||
f.workspace.other_roots.lock().push(other.clone());
|
||||
f.take_events();
|
||||
let notifications = |f: &Fixture| {
|
||||
f.take_events()
|
||||
.into_iter()
|
||||
.filter_map(|(client, event)| match event {
|
||||
PluginEvent::Notification { title, actions, .. } => Some((client, title, actions)),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
// A scheduled call has no invoking window; a closing window is skipped.
|
||||
let path = f.project.join("notes.txt").to_string_lossy().into_owned();
|
||||
f.host.run_command("jobs", "notify-project", Some(&path), Invocation::default()).unwrap();
|
||||
let sent = notifications(&f);
|
||||
assert_eq!(sent.len(), 1);
|
||||
assert_eq!((sent[0].0.as_deref(), sent[0].1.as_str()), (Some("main"), "Project update"));
|
||||
assert_eq!((sent[0].2[0].command.as_str(), sent[0].2[0].argument.as_deref()), ("context", Some(path.as_str())));
|
||||
// A project without a window fails without falling back to another one, even when invoked from one.
|
||||
let path = other.join("notes.txt").to_string_lossy().into_owned();
|
||||
let error = f.host.run_command("jobs", "notify-project", Some(&path), f.inv()).unwrap_err().message;
|
||||
assert!(error.contains("not open"), "{error}");
|
||||
assert!(notifications(&f).is_empty());
|
||||
assert_eq!(f.status("jobs"), PluginStatus::Active);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn directory_prompts_and_project_requests_use_the_calling_window_without_a_capability() {
|
||||
use ide_plugin::Prompt;
|
||||
|
||||
@@ -234,6 +234,15 @@ impl ProjectIndex {
|
||||
matching::find_files(&d, &matching::Recents { paths: &recent }, query, limit)
|
||||
}
|
||||
|
||||
/// All indexed files with this exact basename, for resolving printed source locations.
|
||||
/// Unlike interactive fuzzy search, this must not truncate candidates before package matching.
|
||||
pub fn files_named(&self, name: &str) -> Vec<PathBuf> {
|
||||
let data = self.shared.data.read();
|
||||
let mut files: Vec<_> = data.files.iter().flatten().filter(|file| file.name() == name).collect();
|
||||
files.sort_by(|a, b| a.rel.len().cmp(&b.rel.len()).then_with(|| a.rel.cmp(&b.rel)));
|
||||
files.into_iter().map(|file| file.path.clone()).collect()
|
||||
}
|
||||
|
||||
/// Up to `limit` indexed files below `dir` (VCS-ignored ones left out) whose path relative to
|
||||
/// `dir` satisfies `matches`: a file list without walking the disk. `None` while nothing is
|
||||
/// indexed yet (first scan without a cache).
|
||||
|
||||
@@ -57,6 +57,27 @@ fn files(idx: &ProjectIndex, q: &str) -> Vec<String> {
|
||||
idx.find_files(q, 20).into_iter().map(|m| m.rel_path).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exact_file_names_keep_all_source_candidates() {
|
||||
let f = Fixture::new(&[
|
||||
("src/OtherOrders.kt", "package other"),
|
||||
("src/Orders.kt.bak", "backup"),
|
||||
("target/Orders.kt", "excluded"),
|
||||
("src/orders.kt", "different case"),
|
||||
]);
|
||||
for i in 0..65 {
|
||||
f.write(&format!("module{i}/Orders.kt"), &format!("package module{i}"));
|
||||
}
|
||||
let source = f.write("service/src/Orders.kt", "package com.example.orders");
|
||||
let idx = f.open();
|
||||
let candidates = idx.files_named("Orders.kt");
|
||||
assert_eq!(candidates.len(), 66);
|
||||
assert!(candidates.contains(&source));
|
||||
assert!(candidates.iter().all(|path| path.file_name().unwrap() == "Orders.kt"));
|
||||
assert_eq!(candidates, idx.files_named("Orders.kt"));
|
||||
assert!(idx.files_named("Missing.kt").is_empty());
|
||||
}
|
||||
|
||||
fn symbols(idx: &ProjectIndex, q: &str, filter: SymbolFilter) -> Vec<String> {
|
||||
idx.find_symbols(q, filter, 20).into_iter().map(|m| m.name).collect()
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ pub use syntax::{
|
||||
CSS_CLASS, CSS_ID, CSS_VARIABLE, ConfigurationKey, ExternalFold, ExternalSymbol, ExternalSyntax, ExternalToken,
|
||||
FileReference, Literal, LiteralKind, MAX_CACHED_TREES, MAX_PARSE_BYTES, ParsedTree, SpellingKind, SpellingRegion,
|
||||
Syntax, SyntaxCache, SyntaxCacheStats, SyntaxHighlightKind, SyntaxHighlights, TreeError, WebReference,
|
||||
WebReferenceKind, merge_visibility, set_external_syntax,
|
||||
WebReferenceKind, merge_visibility, set_external_syntax, shift_pos, shift_range,
|
||||
};
|
||||
|
||||
/// Parsed form of `languages/<id>.toml`. Backend-only; the UI gets [`LanguageInfo`].
|
||||
@@ -332,3 +332,15 @@ pub struct SymbolTag {
|
||||
pub container: Option<String>,
|
||||
pub range: Range,
|
||||
}
|
||||
|
||||
/// One inline TS/JS `<script>` block of a Vue SFC / HTML document.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct ScriptRegion {
|
||||
/// Document-absolute UTF-8 byte offset of `text`, for tree-sitter parsing.
|
||||
/// Convert to UTF-16 positions before exposing ranges through IPC.
|
||||
pub base: usize,
|
||||
/// The language the block's `lang` attribute picks.
|
||||
pub language: LanguageId,
|
||||
/// The script text.
|
||||
pub text: String,
|
||||
}
|
||||
@@ -195,8 +195,16 @@ impl SyntaxCache {
|
||||
|| {
|
||||
self.with_tree(doc, lang, version, text, |g, tree, text| {
|
||||
let query = g.outline_query()?;
|
||||
Some(outline::outline(g, query, tree, text))
|
||||
// HTML documents answer from the cached tree, with nested
|
||||
// <script> declarations.
|
||||
Some(outline::outline_nested(g, query, tree, text, &|rl, rt| self.syntax.outline(rl, rt)))
|
||||
})
|
||||
// Web containers (Vue SFC / Svelte / JSP) have no grammar of their
|
||||
// own, hence no cached tree: the syntax layer answers with a fresh
|
||||
// HTML parse, which the memo covers per version.
|
||||
// shortcut: no incremental re-parse for containers, upgrade when
|
||||
// their trees join the cache.
|
||||
.or_else(|| self.syntax.web_outline(lang, text))
|
||||
.or_else(|| super::external::outline(lang, text))
|
||||
},
|
||||
)
|
||||
@@ -256,8 +264,11 @@ impl SyntaxCache {
|
||||
let Some(result) = compute() else { return Vec::new() };
|
||||
if let Some(e) = &entry {
|
||||
let mut e = e.lock();
|
||||
// Not if the document moved on (or its tree was dropped) meanwhile.
|
||||
if e.version == version && e.tree.is_some() {
|
||||
// Containers without their own grammar memoize their web outline too.
|
||||
// Never store an answer after the document moves on.
|
||||
if e.version == version
|
||||
&& (e.tree.is_some() || (e.lang == *lang && self.syntax.web_grammar_name(lang) == Some("html")))
|
||||
{
|
||||
*slot(e.memo.at(version, lang)) = Some(Arc::new(result.clone()));
|
||||
}
|
||||
}
|
||||
@@ -474,6 +485,35 @@ mod tests {
|
||||
assert!(cache.outline(id, &LanguageId::new("plaintext"), 1, &text).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn web_outline_memo_tracks_versions_without_a_cached_tree() {
|
||||
for language in ["html", "vue", "svelte", "jsp"] {
|
||||
let cache = cache();
|
||||
let id = DocId::next();
|
||||
let lang = LanguageId::new(language);
|
||||
let mut doc = Document::new("<script setup lang=ts>const first = 1;</script>");
|
||||
cache.open(id, &lang, 0);
|
||||
let first = cache.outline(id, &lang, 0, &doc.text());
|
||||
let hits = cache.stats().hits;
|
||||
assert_eq!(cache.outline(id, &lang, 0, &doc.text()), first);
|
||||
assert_eq!(cache.stats().hits, hits + 1, "{language}: memo hit");
|
||||
|
||||
let edits = edit(&mut doc, 0, 0, "<script>const second = 2;</script>\n");
|
||||
cache.edit(id, doc.version(), &edits);
|
||||
let second = cache.outline(id, &lang, doc.version(), &doc.text());
|
||||
assert_ne!(second, first);
|
||||
assert_eq!(second, cache.syntax().outline(&lang, &doc.text()));
|
||||
// An older query must not replace the current version's memo.
|
||||
cache.outline(id, &lang, 0, "<script>const old = 0;</script>");
|
||||
let hits = cache.stats().hits;
|
||||
assert_eq!(cache.outline(id, &lang, doc.version(), &doc.text()), second);
|
||||
assert_eq!(cache.stats().hits, hits + 1);
|
||||
cache.clear();
|
||||
assert!(cache.entries.lock().get(&id).unwrap().lock().memo.outline.is_none());
|
||||
cache.close(id);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_mismatch_and_lifecycle() {
|
||||
let cache = cache();
|
||||
|
||||
@@ -96,6 +96,19 @@ pub(crate) fn byte_at(text: &str, pos: Pos) -> Option<usize> {
|
||||
Some(start + utf16_to_byte(&text[start..line_end], pos.col as usize))
|
||||
}
|
||||
|
||||
/// Shifts a position from a document suffix that starts at `base` into document
|
||||
/// coordinates: the suffix's first line continues `base`'s line, later lines
|
||||
/// add the base line. Used to map inline `<script>` region answers (Vue SFC /
|
||||
/// HTML) back onto the whole document; positions are 0-based lines / UTF-16 cols.
|
||||
pub fn shift_pos(pos: Pos, base: Pos) -> Pos {
|
||||
if pos.line == 0 { Pos::new(base.line, base.col + pos.col) } else { Pos::new(base.line + pos.line, pos.col) }
|
||||
}
|
||||
|
||||
/// [`shift_pos`] for both ends of a range.
|
||||
pub fn shift_range(range: Range, base: Pos) -> Range {
|
||||
Range::new(shift_pos(range.start, base), shift_pos(range.end, base))
|
||||
}
|
||||
|
||||
pub(crate) fn utf16_to_byte(s: &str, offset: usize) -> usize {
|
||||
let mut units = 0;
|
||||
for (i, c) in s.char_indices() {
|
||||
@@ -160,6 +173,18 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shifts_suffix_positions_into_document_coordinates() {
|
||||
let base = Pos::new(3, 7);
|
||||
assert_eq!(shift_pos(Pos::new(0, 2), base), Pos::new(3, 9));
|
||||
assert_eq!(shift_pos(Pos::new(0, 0), base), base);
|
||||
assert_eq!(shift_pos(Pos::new(2, 1), base), Pos::new(5, 1));
|
||||
assert_eq!(
|
||||
shift_range(Range::new(Pos::new(0, 1), Pos::new(1, 4)), base),
|
||||
Range::new(Pos::new(3, 8), Pos::new(4, 4))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_minified_line_is_linear() {
|
||||
// 200k symbols-worth of positions on one 4 MB line.
|
||||
|
||||
@@ -10,15 +10,17 @@ pub(crate) mod lines;
|
||||
mod literals;
|
||||
mod outline;
|
||||
mod selection;
|
||||
mod sfc;
|
||||
mod web;
|
||||
|
||||
use crate::{FoldRange, LanguageConfig, LanguageRegistry, SymbolTag};
|
||||
use crate::{FoldRange, LanguageConfig, LanguageRegistry, ScriptRegion, SymbolTag};
|
||||
pub use cache::{MAX_CACHED_TREES, SyntaxCache, SyntaxCacheStats};
|
||||
pub use configuration::ConfigurationKey;
|
||||
pub use external::{ExternalFold, ExternalSymbol, ExternalSyntax, ExternalToken, set_external_syntax};
|
||||
use grammars::{SPECS, Spec};
|
||||
pub use highlight::{SyntaxHighlightKind, SyntaxHighlights};
|
||||
use ide_core::{LanguageId, OutlineItem, Pos, Range};
|
||||
pub use lines::{shift_pos, shift_range};
|
||||
pub use literals::{Literal, LiteralKind, SpellingKind, SpellingRegion};
|
||||
pub use outline::merge_visibility;
|
||||
use std::cell::RefCell;
|
||||
@@ -165,6 +167,12 @@ impl Syntax {
|
||||
}
|
||||
|
||||
pub fn outline(&self, lang: &LanguageId, text: &str) -> Vec<OutlineItem> {
|
||||
// HTML containers (Vue SFC / Svelte / JSP have no grammar of their own;
|
||||
// HTML itself parses alike): HTML outline with each inline `<script>`'s
|
||||
// TS/JS declarations nested under its entry, in document coordinates.
|
||||
if let Some(items) = self.web_outline(lang, text) {
|
||||
return items;
|
||||
}
|
||||
self.analyze(lang, text, |g, tree, text| {
|
||||
let query = g.outline_query()?;
|
||||
Some(outline::outline(g, query, tree, text))
|
||||
@@ -172,6 +180,20 @@ impl Syntax {
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Outline of an HTML container document (html, vue, svelte, jsp): `None`
|
||||
/// for every other language, CSS containers included.
|
||||
pub(crate) fn web_outline(&self, lang: &LanguageId, text: &str) -> Option<Vec<OutlineItem>> {
|
||||
let g = self.web_grammar(lang)?;
|
||||
if g.spec.name != "html" || text.len() > MAX_PARSE_BYTES {
|
||||
return None;
|
||||
}
|
||||
let tree = parse(&g.language, text, None)?;
|
||||
let query = g.outline_query()?;
|
||||
Some(outline::outline_nested(g, query, &tree, text, &|region_lang, region_text| {
|
||||
self.outline(region_lang, region_text)
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn folding(&self, lang: &LanguageId, text: &str) -> Vec<FoldRange> {
|
||||
let tokens = self.comment_tokens(lang);
|
||||
self.analyze(lang, text, |g, tree, text| Some(folding::folding(g.spec, g.kinds(), tree, text, tokens)))
|
||||
@@ -248,6 +270,19 @@ impl Syntax {
|
||||
self.with_web_tree(lang, text, |_, _, tree| web::anchors(tree, text, name)).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Inline TS/JS `<script>` regions of a Vue SFC / HTML document, in
|
||||
/// document order. Empty for other languages or non-JavaScript blocks.
|
||||
pub fn script_regions(&self, lang: &LanguageId, text: &str) -> Vec<ScriptRegion> {
|
||||
self.with_web_tree(lang, text, |_g, _css, tree| sfc::script_regions(tree, text)).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// [`Self::script_regions`] of an already parsed document (`ParsedTree`
|
||||
/// lends the tree and text) — the cache-aware way for other crates, which
|
||||
/// reuses a cached incremental HTML tree instead of parsing again.
|
||||
pub fn script_regions_of(tree: &Tree, text: &str) -> Vec<ScriptRegion> {
|
||||
sfc::script_regions(tree, text)
|
||||
}
|
||||
|
||||
/// Highlighting from the grammar's own query; `None` without one.
|
||||
pub fn highlights(&self, lang: &LanguageId, text: &str) -> Option<SyntaxHighlights> {
|
||||
self.analyze(lang, text, |g, tree, text| {
|
||||
@@ -280,6 +315,13 @@ impl Syntax {
|
||||
self.grammar(lang).map(|g| g.spec.name)
|
||||
}
|
||||
|
||||
/// Name of the grammar web features parse `lang` with (html for Vue SFC /
|
||||
/// Svelte / JSP, css for SCSS / Less); `None` when `lang` has its own
|
||||
/// grammar or no web features. Lets other crates recognize containers.
|
||||
pub fn web_grammar_name(&self, lang: &LanguageId) -> Option<&'static str> {
|
||||
self.web_grammar(lang).map(|g| g.spec.name)
|
||||
}
|
||||
|
||||
/// Grammar name and tree-sitter language for `lang`, for engines that parse
|
||||
/// on their own (structural search patterns).
|
||||
pub fn ts_language(&self, lang: &LanguageId) -> Option<(&'static str, Language)> {
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
//! macro event operator key heading impl extension.
|
||||
|
||||
use super::Grammar;
|
||||
use super::lines::LineIndex;
|
||||
use super::lines::{LineIndex, shift_range};
|
||||
use crate::SymbolTag;
|
||||
use ide_core::{OutlineItem, SymbolKind, Visibility};
|
||||
use ide_core::{LanguageId, OutlineItem, Pos, SymbolKind, Visibility};
|
||||
use std::collections::HashMap;
|
||||
use tree_sitter::{Node, Query, QueryCursor, StreamingIterator, Tree};
|
||||
|
||||
@@ -296,6 +296,69 @@ pub(crate) fn outline(g: &Grammar, q: &OutlineQuery, tree: &Tree, text: &str) ->
|
||||
collect(g, q, tree, text).into_iter().map(convert).collect()
|
||||
}
|
||||
|
||||
/// [`outline`], plus, for the HTML grammar, each inline `<script>` region's
|
||||
/// TS/JS declarations nested under its `script` entry and shifted to document
|
||||
/// coordinates (Vue SFC / HTML documents). `block` outlines one region's
|
||||
/// language, answering in region-local coordinates.
|
||||
pub(crate) fn outline_nested(
|
||||
g: &Grammar,
|
||||
q: &OutlineQuery,
|
||||
tree: &Tree,
|
||||
text: &str,
|
||||
block: &impl Fn(&LanguageId, &str) -> Vec<OutlineItem>,
|
||||
) -> Vec<OutlineItem> {
|
||||
let mut items = outline(g, q, tree, text);
|
||||
if g.spec.name != "html" {
|
||||
return items;
|
||||
}
|
||||
let lines = LineIndex::new(text);
|
||||
for region in super::sfc::script_regions(tree, text) {
|
||||
let mut decls = block(®ion.language, ®ion.text);
|
||||
if decls.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let base = lines.pos(region.base);
|
||||
shift_outline(&mut decls, base);
|
||||
if !attach_script(&mut items, base, &mut Some(decls)) {
|
||||
// The region and the entry come from the same `script_element` node,
|
||||
// so this means the outline query no longer matches script elements.
|
||||
tracing::debug!("outline: no script entry for the <script> region at byte {}", region.base);
|
||||
}
|
||||
}
|
||||
items
|
||||
}
|
||||
|
||||
/// Recursively shifts region-local positions in `items` to document coordinates.
|
||||
fn shift_outline(items: &mut [OutlineItem], base: Pos) {
|
||||
for item in items {
|
||||
item.range = shift_range(item.range, base);
|
||||
item.selection_range = shift_range(item.selection_range, base);
|
||||
shift_outline(&mut item.children, base);
|
||||
}
|
||||
}
|
||||
|
||||
/// Nests `decls` under the innermost `script` entry covering `base`. The
|
||||
/// region and the entry both come from the same `script_element` node, so the
|
||||
/// entry always exists; a miss means the outline query no longer matches it.
|
||||
fn attach_script(items: &mut [OutlineItem], base: Pos, decls: &mut Option<Vec<OutlineItem>>) -> bool {
|
||||
let covers = |range: &ide_core::Range| {
|
||||
(range.start.line, range.start.col) <= (base.line, base.col)
|
||||
&& (base.line, base.col) < (range.end.line, range.end.col)
|
||||
};
|
||||
for item in items.iter_mut() {
|
||||
if item.name.eq_ignore_ascii_case("script") && covers(&item.range) {
|
||||
item.children.extend(decls.take().unwrap_or_default());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for item in items.iter_mut() {
|
||||
if attach_script(&mut item.children, base, decls) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub(crate) fn tags(g: &Grammar, q: &OutlineQuery, tree: &Tree, text: &str) -> Vec<SymbolTag> {
|
||||
fn walk(items: Vec<Built>, container: Option<&str>, out: &mut Vec<SymbolTag>) {
|
||||
for b in items {
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
//! Inline TS/JS `<script>` regions located with the HTML grammar's
|
||||
//! `script_element` nodes. The block's `lang` attribute selects the grammar.
|
||||
//!
|
||||
//! Blocks whose `type` attribute names anything but JavaScript are skipped
|
||||
//! (`application/json`, `text/template`, `importmap`, …), as are unknown
|
||||
//! `lang` values.
|
||||
|
||||
use super::web::walk;
|
||||
use crate::ScriptRegion;
|
||||
use ide_core::LanguageId;
|
||||
use tree_sitter::{Node, Tree};
|
||||
|
||||
/// The TS/JS grammar a `lang` attribute value names; `None` skips the block.
|
||||
fn lang_grammar(value: &str) -> Option<&'static str> {
|
||||
match value {
|
||||
"ts" | "typescript" => Some("typescript"),
|
||||
"tsx" => Some("tsx"),
|
||||
"" | "js" | "jsx" | "javascript" => Some("javascript"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// `true` when a `type` attribute value names JavaScript (or is absent).
|
||||
fn is_js_type(value: &str) -> bool {
|
||||
matches!(value, "" | "module" | "text/javascript" | "application/javascript")
|
||||
}
|
||||
|
||||
/// The `<script>` regions of a document parsed with the HTML grammar,
|
||||
/// in document order. `base` is each block's byte offset into the document.
|
||||
pub(crate) fn script_regions(tree: &Tree, text: &str) -> Vec<ScriptRegion> {
|
||||
let mut out = Vec::new();
|
||||
walk(tree.root_node(), &mut |n| {
|
||||
if n.kind() != "script_element" {
|
||||
return true;
|
||||
}
|
||||
let mut lang = "javascript";
|
||||
let mut skip = false;
|
||||
let mut c = n.walk();
|
||||
for ch in n.children(&mut c) {
|
||||
match ch.kind() {
|
||||
// The start tag precedes the raw text, so the attributes are
|
||||
// known before the region is taken.
|
||||
"start_tag" => {
|
||||
let mut c2 = ch.walk();
|
||||
for attr in ch.children(&mut c2) {
|
||||
if attr.kind() != "attribute" {
|
||||
continue;
|
||||
}
|
||||
let (name, value) = attribute(attr, text);
|
||||
match name.to_ascii_lowercase().as_str() {
|
||||
"lang" => match lang_grammar(&value.to_ascii_lowercase()) {
|
||||
Some(g) => lang = g,
|
||||
None => skip = true,
|
||||
},
|
||||
"type" if !is_js_type(&value.trim().to_ascii_lowercase()) => skip = true,
|
||||
"src" => skip = true,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
"raw_text" if !skip => {
|
||||
out.push(ScriptRegion {
|
||||
base: ch.start_byte(),
|
||||
language: LanguageId::new(lang),
|
||||
text: text[ch.start_byte()..ch.end_byte()].to_string(),
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
false // the raw text is not markup
|
||||
});
|
||||
out
|
||||
}
|
||||
|
||||
/// An attribute's `(name, value)`; a bare attribute (`setup`) has an empty value.
|
||||
fn attribute<'t>(attr: Node<'t>, text: &'t str) -> (&'t str, &'t str) {
|
||||
let mut c = attr.walk();
|
||||
let mut name = "";
|
||||
let mut value = "";
|
||||
for ch in attr.children(&mut c) {
|
||||
match ch.kind() {
|
||||
"attribute_name" => name = ch.utf8_text(text.as_bytes()).unwrap_or(""),
|
||||
"quoted_attribute_value" => {
|
||||
value = ch.named_child(0).and_then(|v| v.utf8_text(text.as_bytes()).ok()).unwrap_or("");
|
||||
}
|
||||
"attribute_value" => value = ch.utf8_text(text.as_bytes()).unwrap_or(""),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
(name, value)
|
||||
}
|
||||
@@ -759,6 +759,7 @@ fn outline_html_css_xml() {
|
||||
Field body
|
||||
Field div
|
||||
Field script
|
||||
Variable a
|
||||
",
|
||||
);
|
||||
check_outline(
|
||||
@@ -1409,3 +1410,231 @@ fn spelling_regions_cover_declared_names_only() {
|
||||
.collect();
|
||||
assert_eq!(names, ["Bird", "fly", "text"]);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Script regions of Vue SFCs and HTML documents
|
||||
|
||||
#[test]
|
||||
fn script_regions_skip_typed_blocks() {
|
||||
let src = "<html><body><script type=\"module\">var x = 1;</script>\
|
||||
<script type=\"application/json\">{\"a\":1}</script>\
|
||||
<script type=\"importmap\">{}</script>\
|
||||
<script>var y = 2;</script></body></html>";
|
||||
let regions = syntax().script_regions(&lang("html"), src);
|
||||
assert_eq!(regions.len(), 2, "module and plain scripts; json/importmap skipped");
|
||||
assert_eq!(regions[0].language.as_str(), "javascript");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_regions_pick_the_lang_attribute() {
|
||||
let src = "<script setup lang=\"tsx\">\nconst App = () => <div/>\n</script>\n";
|
||||
let regions = syntax().script_regions(&lang("vue"), src);
|
||||
assert_eq!(regions.len(), 1);
|
||||
assert_eq!(regions[0].language.as_str(), "tsx");
|
||||
assert!(regions[0].text.contains("const App"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_regions_empty_for_other_languages() {
|
||||
assert!(syntax().script_regions(&lang("rust"), "fn main() {}").is_empty());
|
||||
assert!(syntax().script_regions(&lang("vue"), "<template><div/></template>").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_regions_classify_attributes() {
|
||||
for language in ["vue", "html"] {
|
||||
for (attributes, expected) in [
|
||||
("", Some("javascript")),
|
||||
("setup lang=ts", Some("typescript")),
|
||||
("lang='typescript'", Some("typescript")),
|
||||
("lang=tsx", Some("tsx")),
|
||||
("lang=js", Some("javascript")),
|
||||
("lang=jsx", Some("javascript")),
|
||||
("LANG=TS", Some("typescript")),
|
||||
("type=module", Some("javascript")),
|
||||
("TYPE=' text/JAVASCRIPT '", Some("javascript")),
|
||||
("type=application/javascript", Some("javascript")),
|
||||
("type=application/json", None),
|
||||
("type='application/ld+json'", None),
|
||||
("type=text/template", None),
|
||||
("type=importmap", None),
|
||||
("type=speculationrules", None),
|
||||
("lang=coffee", None),
|
||||
("lang=ts type=application/json", None),
|
||||
("src='./external.ts' lang=ts", None),
|
||||
("SRC=external.js", None),
|
||||
("src", None),
|
||||
] {
|
||||
let src = format!("<script {attributes}>const value = 1;</script>");
|
||||
let regions = syntax().script_regions(&lang(language), &src);
|
||||
assert_eq!(regions.len(), usize::from(expected.is_some()), "{language}: {attributes}");
|
||||
if let Some(expected) = expected {
|
||||
assert_eq!(regions[0].language.as_str(), expected, "{attributes}");
|
||||
assert_eq!(regions[0].text, "const value = 1;");
|
||||
assert_eq!(&src[regions[0].base..regions[0].base + regions[0].text.len()], regions[0].text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_regions_preserve_document_offsets_and_line_endings() {
|
||||
use super::lines::LineIndex;
|
||||
|
||||
let src = "<template>中文😀</template>\r\n<script lang=ts>const 名 = '😀';\r\n</script>\r\n<script setup lang=jsx>const View = () => <div/>;</script>";
|
||||
let regions = syntax().script_regions(&lang("vue"), src);
|
||||
assert_eq!(regions.len(), 2);
|
||||
let idx = LineIndex::new(src);
|
||||
let doc = ide_text::Document::new(src);
|
||||
for (region, (body, pos)) in
|
||||
regions.iter().zip([("const 名 = '😀';\r\n", Pos::new(1, 16)), ("const View = () => <div/>;", Pos::new(3, 23))])
|
||||
{
|
||||
assert_eq!(region.base, src.find(body).unwrap());
|
||||
assert_eq!(region.text, body);
|
||||
assert_eq!(idx.pos(region.base), pos);
|
||||
assert_eq!(idx.pos(region.base), doc.byte_to_pos(src[..region.base].replace("\r\n", "\n").len()));
|
||||
assert_eq!(
|
||||
idx.pos(region.base + body.len()),
|
||||
doc.byte_to_pos(src[..region.base + body.len()].replace("\r\n", "\n").len())
|
||||
);
|
||||
if let Some(name) = body.find('名') {
|
||||
assert_eq!(
|
||||
idx.range(region.base + name, region.base + name + '名'.len_utf8()),
|
||||
Range::new(Pos::new(1, 22), Pos::new(1, 23))
|
||||
);
|
||||
}
|
||||
}
|
||||
let same_line = "<template>中文😀</template><script>let x = 1;</script>";
|
||||
let region = &syntax().script_regions(&lang("html"), same_line)[0];
|
||||
assert_eq!(LineIndex::new(same_line).pos(region.base), Pos::new(0, 33));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_regions_tolerate_incomplete_markup() {
|
||||
for src in [
|
||||
"<script",
|
||||
"<script lang=",
|
||||
"<script lang='ts",
|
||||
"<script>const unfinished =",
|
||||
"<template><div><script lang=ts>const x = 1;</script>",
|
||||
"<script></script>",
|
||||
"<script src='missing.js'>ignored</script><script>const x = 1;",
|
||||
] {
|
||||
for region in syntax().script_regions(&lang("vue"), src) {
|
||||
assert_eq!(src.get(region.base..region.base + region.text.len()), Some(region.text.as_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_regions_large_vue_document() {
|
||||
for count in [2_000, 4_000, 8_000] {
|
||||
let src =
|
||||
"<template><div>中文😀</div></template>\r\n<script setup lang=ts>const x = 1;</script>\r\n".repeat(count);
|
||||
let start = std::time::Instant::now();
|
||||
let regions = syntax().script_regions(&lang("vue"), &src);
|
||||
eprintln!("script regions: {} bytes, {count} blocks: {:?}", src.len(), start.elapsed());
|
||||
assert_eq!(regions.len(), count);
|
||||
assert!(regions.windows(2).all(|pair| pair[0].base < pair[1].base));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_regions_tolerate_deep_markup() {
|
||||
let src = "<div>".repeat(1_000) + "<script>const x = 1;</script>";
|
||||
let regions = syntax().script_regions(&lang("html"), &src);
|
||||
assert_eq!(regions.len(), 1);
|
||||
assert_eq!(regions[0].base, src.find("const").unwrap());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Outline with nested <script> declarations (Vue SFC / HTML)
|
||||
|
||||
#[test]
|
||||
fn html_outline_nests_script_declarations() {
|
||||
let src = "<html><body>\n<script>\nfunction boot() {}\nconst app = 1;\n</script>\n\
|
||||
<script type=\"application/json\">{\"a\": 1}</script>\n</body></html>";
|
||||
check_outline(
|
||||
"html",
|
||||
src,
|
||||
"
|
||||
Field html
|
||||
Field body
|
||||
Field script
|
||||
Function boot
|
||||
Constant app
|
||||
Field script
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vue_outline_nests_script_declarations_without_a_grammar() {
|
||||
let src = "<template>\n <div class=\"app\"/>\n</template>\n\
|
||||
<script setup lang=\"ts\">\ninterface Props { size: number }\nfunction scale(n: number) {}\n</script>\n\
|
||||
<style scoped>\n.app { color: red }\n</style>";
|
||||
check_outline(
|
||||
"vue",
|
||||
src,
|
||||
"
|
||||
Field template
|
||||
Field script
|
||||
Interface Props
|
||||
Property size
|
||||
Function scale
|
||||
Field style
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_outline_positions_are_document_coordinates() {
|
||||
use super::lines::LineIndex;
|
||||
let src = "<template><!-- 😀 --></template>\r\n<script lang=\"ts\">\r\nconst answer = 42;\r\n</script>";
|
||||
let outline = syntax().outline(&lang("vue"), src);
|
||||
let decl = &outline.iter().find(|i| i.name == "script").unwrap().children[0];
|
||||
// Cross-check against the document's own byte -> UTF-16 conversion.
|
||||
let idx = LineIndex::new(src);
|
||||
let at = src.find("answer").unwrap();
|
||||
assert_eq!(decl.selection_range, idx.range(at, at + "answer".len()));
|
||||
// `@def.constant` captures the declarator (`answer = 42`), not the `const` keyword.
|
||||
assert_eq!(decl.range, idx.range(at, src.find("42;").unwrap() + 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cached_outline_matches_syntax_outline_for_web_documents() {
|
||||
use ide_core::DocId;
|
||||
use std::sync::Arc;
|
||||
let cache = SyntaxCache::new(Arc::new(Syntax::new()));
|
||||
let id = DocId::next();
|
||||
let src = "<template><div/></template>\n<script lang=\"ts\">\nconst app = 1;\n</script>\n";
|
||||
cache.open(id, &lang("vue"), 0);
|
||||
assert_eq!(cache.outline(id, &lang("vue"), 0, src), syntax().outline(&lang("vue"), src));
|
||||
cache.open(id, &lang("html"), 0);
|
||||
assert_eq!(cache.outline(id, &lang("html"), 0, src), syntax().outline(&lang("html"), src));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_outlines_compose_positions_across_multiple_blocks() {
|
||||
use super::lines::LineIndex;
|
||||
|
||||
let src = "<template>中文😀</template><script lang=ts>/* 中文😀 */ function first() { return 1; }</script>\r\n<script setup lang=ts>/* 中文😀 */ const second = 2;\r\nfunction third() {}\r\n</script>";
|
||||
let lines = LineIndex::new(src);
|
||||
for id in ["html", "vue", "svelte", "jsp"] {
|
||||
let items = syntax().outline(&lang(id), src);
|
||||
let scripts: Vec<_> = items.iter().filter(|item| item.name == "script").collect();
|
||||
assert_eq!(scripts.len(), 2, "{id}");
|
||||
assert_eq!(scripts[0].children.len(), 1);
|
||||
assert_eq!(scripts[1].children.len(), 2);
|
||||
for (item, name) in scripts.iter().flat_map(|s| &s.children).zip(["first", "second", "third"]) {
|
||||
let byte = src.find(name).unwrap();
|
||||
assert_eq!(item.name, name);
|
||||
assert_eq!(item.selection_range, lines.range(byte, byte + name.len()), "{id}: {name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_outline_attaches_to_case_insensitive_html_tags() {
|
||||
check_outline("html", "<SCRIPT>function boot() {}</SCRIPT>", "Field SCRIPT\n Function boot");
|
||||
}
|
||||
@@ -81,13 +81,20 @@ fn css_regions<'t>(grammar: &str, tree: &Tree, text: &'t str) -> Vec<(usize, &'t
|
||||
}
|
||||
|
||||
/// Pre-order walk; `f` returns whether to descend.
|
||||
fn walk<'t>(n: Node<'t>, f: &mut dyn FnMut(Node<'t>) -> bool) {
|
||||
if !f(n) {
|
||||
return;
|
||||
}
|
||||
let mut c = n.walk();
|
||||
for child in n.children(&mut c) {
|
||||
walk(child, f);
|
||||
pub(crate) fn walk<'t>(n: Node<'t>, f: &mut dyn FnMut(Node<'t>) -> bool) {
|
||||
let mut cursor = n.walk();
|
||||
loop {
|
||||
if f(cursor.node()) && cursor.goto_first_child() {
|
||||
continue;
|
||||
}
|
||||
loop {
|
||||
if cursor.goto_next_sibling() {
|
||||
break;
|
||||
}
|
||||
if !cursor.goto_parent() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ use views_bindings::exports::openidea::plugin::view_provider as wit_view;
|
||||
use views_bindings::openidea::plugin::view_types as wit_vt;
|
||||
|
||||
/// The API version of the world above, `major.minor` of [`host_api`].
|
||||
pub const API_VERSION: &str = "1.4";
|
||||
pub const API_VERSION: &str = "1.5";
|
||||
const EPOCH_TICK: Duration = Duration::from_millis(10);
|
||||
pub(crate) const MAX_TEXT: usize = 1 << 20;
|
||||
pub(crate) const MAX_TITLE: usize = 256;
|
||||
@@ -259,6 +259,19 @@ pub trait HostApi: Send + Sync {
|
||||
body: String,
|
||||
actions: Vec<crate::NotificationAction>,
|
||||
) -> Result<(), HostError>;
|
||||
/// [`HostApi::notify`] in the most recently focused window of the open project at
|
||||
/// `root`; not-found (and nothing shown) once it has closed.
|
||||
fn notify_project(
|
||||
&self,
|
||||
root: &Path,
|
||||
level: NotificationLevel,
|
||||
title: String,
|
||||
body: String,
|
||||
actions: Vec<crate::NotificationAction>,
|
||||
) -> Result<(), HostError> {
|
||||
let _ = (root, level, title, body, actions);
|
||||
Err(HostError::NotFound("project notifications unavailable".into()))
|
||||
}
|
||||
fn copy_to_clipboard(&self, client: Option<&str>, text: String) -> Result<(), HostError> {
|
||||
let _ = (client, text);
|
||||
Ok(())
|
||||
|
||||
@@ -362,6 +362,25 @@ impl StoreData {
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks `ui.notify` buttons; the host checks that their commands are declared.
|
||||
fn notification_actions(actions: Vec<ui::NotificationAction>) -> Result<Vec<crate::NotificationAction>, wit::Error> {
|
||||
const MAX_ACTIONS: usize = 3;
|
||||
if actions.len() > MAX_ACTIONS {
|
||||
return Err(wit::Error::Invalid(format!("a notification has at most {MAX_ACTIONS} actions")));
|
||||
}
|
||||
let mut checked = Vec::with_capacity(actions.len());
|
||||
for a in actions {
|
||||
if a.label.trim().is_empty() || a.label.len() > 256 || a.label.chars().any(char::is_control) {
|
||||
return Err(wit::Error::Invalid(format!("invalid action label {:?}", a.label)));
|
||||
}
|
||||
if a.argument.as_ref().is_some_and(|arg| arg.len() > 64 << 10) {
|
||||
return Err(wit::Error::Invalid("an action argument is limited to 64 KiB".into()));
|
||||
}
|
||||
checked.push(crate::NotificationAction { label: a.label, command: a.command, argument: a.argument });
|
||||
}
|
||||
Ok(checked)
|
||||
}
|
||||
|
||||
impl ui::Host for StoreData {
|
||||
fn notify(
|
||||
&mut self,
|
||||
@@ -370,22 +389,29 @@ impl ui::Host for StoreData {
|
||||
body: String,
|
||||
actions: Vec<ui::NotificationAction>,
|
||||
) -> Fallible<()> {
|
||||
const MAX_ACTIONS: usize = 3;
|
||||
if actions.len() > MAX_ACTIONS {
|
||||
return Ok(Err(wit::Error::Invalid(format!("a notification has at most {MAX_ACTIONS} actions"))));
|
||||
}
|
||||
let mut checked = Vec::with_capacity(actions.len());
|
||||
for a in actions {
|
||||
if a.label.trim().is_empty() || a.label.len() > 256 || a.label.chars().any(char::is_control) {
|
||||
return Ok(Err(wit::Error::Invalid(format!("invalid action label {:?}", a.label))));
|
||||
}
|
||||
if a.argument.as_ref().is_some_and(|arg| arg.len() > 64 << 10) {
|
||||
return Ok(Err(wit::Error::Invalid("an action argument is limited to 64 KiB".into())));
|
||||
}
|
||||
checked.push(crate::NotificationAction { label: a.label, command: a.command, argument: a.argument });
|
||||
}
|
||||
let actions = match notification_actions(actions) {
|
||||
Ok(actions) => actions,
|
||||
Err(e) => return Ok(Err(e)),
|
||||
};
|
||||
let (title, body) = (clip(title, MAX_TITLE), clip(body, 16 << 10));
|
||||
Ok(self.host.notify(self.client(), notification_level(level), title, body, checked).map_err(to_wit))
|
||||
Ok(self.host.notify(self.client(), notification_level(level), title, body, actions).map_err(to_wit))
|
||||
}
|
||||
|
||||
fn notify_project(
|
||||
&mut self,
|
||||
target: Resource<ProjectRes>,
|
||||
level: wit::NotificationLevel,
|
||||
title: String,
|
||||
body: String,
|
||||
actions: Vec<ui::NotificationAction>,
|
||||
) -> Fallible<()> {
|
||||
let actions = match notification_actions(actions) {
|
||||
Ok(actions) => actions,
|
||||
Err(e) => return Ok(Err(e)),
|
||||
};
|
||||
let root = self.table.get(&target)?.root.clone();
|
||||
let (title, body) = (clip(title, MAX_TITLE), clip(body, 16 << 10));
|
||||
Ok(self.host.notify_project(&root, notification_level(level), title, body, actions).map_err(to_wit))
|
||||
}
|
||||
|
||||
fn show_notification(
|
||||
|
||||
@@ -91,15 +91,15 @@ fn the_sdk_carries_the_hosts_wit() {
|
||||
|
||||
#[test]
|
||||
fn the_version_check_runs_compatible_components_and_explains_the_rest() {
|
||||
let host = v("1.4.0");
|
||||
for ok in ["1.0.0", "1.3.0", "1.3.7", "1.4.0", "1.0.0-rc.1"] {
|
||||
let host = v("1.5.0");
|
||||
for ok in ["1.0.0", "1.3.0", "1.4.7", "1.5.0", "1.0.0-rc.1"] {
|
||||
assert_eq!(check_api(&v(ok), &host), Ok(()), "{ok}");
|
||||
}
|
||||
let newer = check_api(&v("1.5.0"), &host).unwrap_err();
|
||||
assert!(newer.contains("1.5") && newer.contains("update OpenIDEA"), "{newer}");
|
||||
let newer = check_api(&v("1.6.0"), &host).unwrap_err();
|
||||
assert!(newer.contains("1.6") && newer.contains("update OpenIDEA"), "{newer}");
|
||||
assert!(check_api(&v("2.0.0"), &host).unwrap_err().contains("update OpenIDEA"));
|
||||
let older = check_api(&v("0.2.0"), &host).unwrap_err();
|
||||
assert!(older.contains("rebuild it with the 1.4 SDK"), "{older}");
|
||||
assert!(older.contains("rebuild it with the 1.5 SDK"), "{older}");
|
||||
// 0.x: every minor is its own API.
|
||||
assert_eq!(check_api(&v("0.2.0"), &v("0.2.5")), Ok(()));
|
||||
assert!(check_api(&v("0.1.0"), &v("0.2.0")).is_err());
|
||||
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
4647fa9aec9732e3dd824efccd61b1c6b9c36645a3586f402f6a7a47419db61f
|
||||
9963d6606bb6b859bebe1f55892488944f6d5e3308e6c0109f38f4b1a67b01f5
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
6787b195df1057176ea9fcf11d0fcaf8cd347fc182fab94fe3a229063deed831
|
||||
7ab9937fdb2e78d0d62d9b85b78a0a6d9511224f85908c3a5a5e9c0d4b5e7e14
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
c2d17076337b1225ef8b0323b335a3b03bf022485088957c520e0cb797d7df7d
|
||||
cf1f91d8accf8339bf6e22bef5067bfe3cba75d38cd30d8748b0aa451ee2495b
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
415a4cd17c573aeeb1b45d4b1af55834eab5e686c4f624495323e4fb63c3ac71
|
||||
12ad7d649d752f2a40b28dee718a3e04b64597496ab43787c084e3cb774ccfe6
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
5f502b7650acd5d07bffba8016680248b5ceac0926013916ff351562e3c6d831
|
||||
4bfce353b3c94490c5f95a046cd2371042b243c326bd63c65619e1489d7ab889
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
19e8d460269999aeac7b4021bfedb803ad0d68c24ce1c22f058070fb406a64c3
|
||||
cfbd6aac217a7baea907affe4e1e7f89d1330843398e913e68b71f3a99cfb71b
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
63809abb0f8a4f40b0c0f465062cc8ba0ebfd03d41a108ff19866e6565eda931
|
||||
dcf00138820979f523bd93e1f6b08c627c6f061ae5b6e91b340646f905593cf3
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
99c968b98d8f1d895c428b4048451275bd322e7070aa0a020737097efea17eb1
|
||||
98e0e01e8405ae7501e89c0dab06e6672b5240a831b19e8fbf0604a3171b31e9
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
c40a0fd8c6cf791e70ba0335c6cf0b2c82b250670ebad59b185e3e8719172409
|
||||
fcee11f27ff9ae0038e8067712e269ccd49423372f692e9351c24f82906aafad
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
162774155d8b49d53b0c0c055736bd098723c66b02c0e1dc4389985982c57282
|
||||
5c777d7b146277fa803587d1788a7359b08478def00c4574dd565d784200e39a
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
39e3de11f69c09348906878367318157fca9a777f9ac1c4fb6ed303fa058e5a2
|
||||
825b9ee483796efd24fcfe358b94f4667d87e311475769ec9e41ba9af6d03a6a
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
4a3f595d2a6a9b79da7e316a3da86c287e9761ea670319c331467e7b10639663
|
||||
45b8cbd2ed7635ce04651937574dde9cf441dd619d76b8996f522c671950eaee
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
bede1f0eaec356e3e35302e65e85531870625560bc9a3197f1acb58969beb4bd
|
||||
e456b7ddf087ffbf2df62431bf9df47fad1929079c99a941a5deaf30599109f9
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
ad2dc0ad12adb9c6b25017b2cef78b7496e96d1bb6e88b24ea9b7b682120e786
|
||||
e0d8b590ad6ffd9569c6362802b2be909cb34b37b18cc8cc8492f9c460610e20
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
2c329cf7af36c9d65ed5b6be7c2a017c7a5a6214a4893cab7ae574acb76fe62f
|
||||
d2512203db3e5c6df93e9ccd5ff8daed8f1ebd28462b8caf7d500e814d3b6671
|
||||
@@ -75,6 +75,14 @@ impl Plugin for Jobs {
|
||||
)?;
|
||||
Ok(None)
|
||||
}
|
||||
"notify-project" => {
|
||||
// The argument is a path in the target project, as a scheduled check would have.
|
||||
let path = arg.unwrap_or_default();
|
||||
let project = host::project_of(path).ok_or("no project contains the path")?;
|
||||
let action = openidea_plugin::NotificationAction::new("Disable", "context").argument(path);
|
||||
project.notify(NotificationLevel::Info, "Project update", path, &[action])?;
|
||||
Ok(None)
|
||||
}
|
||||
"copy" => {
|
||||
host::copy_to_clipboard(arg.unwrap_or_default())?;
|
||||
Ok(None)
|
||||
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
39c85942177e937e48f32bcde86a0068dac484ba028a8d6785a5a2728db9e11b
|
||||
b32da5137b552cfad2557716343ed8ac9236b34fec018e3f2facc7b78b67e72a
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
30a8cc05a40c7b99a78700430ae87d025ad7567b44384fdb696119aa421f8174
|
||||
ae58467cdb6e98a491d739884eee96d239f80451de749950d81f4fd480edba58
|
||||
@@ -5,9 +5,9 @@ wit_bindgen::generate!({
|
||||
inline: "
|
||||
package fixture:misbehave;
|
||||
world misbehave {
|
||||
include openidea:plugin/plugin-syntax@1.4.0;
|
||||
export openidea:plugin/providers@1.4.0;
|
||||
export openidea:plugin/file-actions@1.4.0;
|
||||
include openidea:plugin/plugin-syntax@1.5.0;
|
||||
export openidea:plugin/providers@1.5.0;
|
||||
export openidea:plugin/file-actions@1.5.0;
|
||||
}
|
||||
",
|
||||
path: "../../../../../wit",
|
||||
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
5f9c92b23c00269ec2b5dc8829ce526a8fc4c0d76ecb2925ec9a06ffeac5f0b4
|
||||
e378c85a4fe395c7b172065a33a2f15ad76852ac42d4099d2cf1f64540e13143
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
d695409029a66c8a44f524072be1d47ed974fc8810f6fe1d8d068765184d4028
|
||||
23dc9ab1affb5b0c0166a5bb2bffb8a273a5c9eed0c06d402f16a1440b835639
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
d5e81a43dc2c5298d0aaafd70c0bd91ab6cc040d70224d2936349de41253735f
|
||||
d82fa182c8d5a029451addbf3b9792419446849911949e61052fca181d7758ce
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
c29076023ccedf2da8fd9e5a851a47bbe7131b97713c8140a20cd55608a1cc0d
|
||||
12337d77078aeb678567c0dc87c746a78454656ed52a2e51dd0bb81f19d90da3
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
616157bd77dc272f9e2dfed4c54c9d65fca110e55ad01f92b7c4f8a6136537b4
|
||||
9048b66162a39a518d117cd473f6192827bc05737ff5132324c54eb8295b060b
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
022f216f0f4ca5da56f4b2fabf5ee4a987d5e9f9a752feecbb438f9b00b1acf4
|
||||
274f7e74f19aabf9368c2b9a107494d82a2013d4adda645bde6d9ccda4007769
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
626f0e0c83e69704c0365c273b6f63d43278ee37786f38ed467ce908c30eadf7
|
||||
e9082dc0f4c9c4fc682e16821d36f7fa42be9c82b75ac28edbee6a869dc86b8b
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
aa141701049f5c6c0d045341c3337344ed7a368800f08237b1b7812cce216814
|
||||
0028a0439e8bb234fb0cc5138e1c27d5c2c8443bed12963a69f0bd8b3818ec7b
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
d6c40099cc959ef2dead996beeb4acd73c1327597cd029674026c6f2bc878300
|
||||
f3b633e9e34a5343f318e4e451ffe1c87a6d1ac6d0dc01a57588ea99380dd8d4
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
3201f643cf868f7a358ba812f9c90e06b982d864ed141b6b4c3fdeee13cb1559
|
||||
02fba523571a945b16055e83ee72400f69ecb64238556e933cfd5c2c92c8ea10
|
||||
@@ -33,7 +33,7 @@ pub use jvm::{JvmPresentation, JvmTypeKind, jvm_type_header};
|
||||
pub use types::*;
|
||||
|
||||
use ide_core::{CancellationToken, DocId, IdeError, LanguageId, Pos, Range};
|
||||
use ide_language::{ParsedTree, SyntaxCache, TreeError};
|
||||
use ide_language::{ParsedTree, Syntax, SyntaxCache, TreeError, shift_range};
|
||||
use kinds::Kinds;
|
||||
use lines::Lines;
|
||||
use std::sync::Arc;
|
||||
@@ -143,8 +143,15 @@ impl StructureService {
|
||||
|
||||
/// What the service can answer for `language`.
|
||||
pub fn support(&self, language: &LanguageId) -> StructureSupport {
|
||||
match self.cache.syntax().grammar_name(language) {
|
||||
Some(g) => StructureSupport { tree: true, locals: kinds::locals_source(g).is_some() },
|
||||
let syn = self.cache.syntax();
|
||||
// Web containers (Vue SFC / Svelte / JSP have no grammar of their own)
|
||||
// answer from the HTML tree; inline <script> regions add the block
|
||||
// grammar's tables — TypeScript / JavaScript ship locals.scm — so both
|
||||
// capabilities are on whenever HTML is.
|
||||
let g =
|
||||
syn.grammar_name(language).or_else(|| (syn.web_grammar_name(language) == Some("html")).then_some("html"));
|
||||
match g {
|
||||
Some(g) => StructureSupport { tree: true, locals: kinds::locals_source(g).is_some() || g == "html" },
|
||||
None => StructureSupport::default(),
|
||||
}
|
||||
}
|
||||
@@ -157,6 +164,17 @@ impl StructureService {
|
||||
range: Range,
|
||||
cancel: &CancellationToken,
|
||||
) -> StructureResult<Option<NodeAt>> {
|
||||
let bytes = Lines::new(snap.text).bytes(range);
|
||||
if let Some(at) = self.with_script_tree(snap, bytes, cancel, |cx, local, base| {
|
||||
Ok(nodes::node_at(cx, local).map(|at| shift_node_at(at, base)))
|
||||
})? {
|
||||
return Ok(at);
|
||||
}
|
||||
// Outside any <script> region a web container (template markup) has no
|
||||
// identifier to offer: an empty answer, not an error.
|
||||
if self.web_container(snap.language) {
|
||||
return Ok(None);
|
||||
}
|
||||
self.run(snap, cancel, |cx| Ok(nodes::node_at(cx, range)))
|
||||
}
|
||||
|
||||
@@ -178,6 +196,17 @@ impl StructureService {
|
||||
|
||||
/// Scope analysis for the identifier at `pos` (`locals.scm`).
|
||||
pub fn locals(&self, snap: &Snapshot, pos: Pos, cancel: &CancellationToken) -> StructureResult<Locals> {
|
||||
let byte = Lines::new(snap.text).byte(pos);
|
||||
if let Some(locals) = self.with_script_tree(snap, (byte, byte), cancel, |cx, local, base| {
|
||||
locals::locals(cx, local.start).map(|l| shift_locals(l, base))
|
||||
})? {
|
||||
return Ok(locals);
|
||||
}
|
||||
if self.web_container(snap.language) {
|
||||
// Template markup: no TypeScript identifier here; the frontend
|
||||
// treats `noIdentifier` as "nothing at this position".
|
||||
return Ok(Locals::NoIdentifier);
|
||||
}
|
||||
self.run(snap, cancel, |cx| locals::locals(cx, pos))
|
||||
}
|
||||
|
||||
@@ -255,6 +284,62 @@ impl StructureService {
|
||||
Ok(ranges)
|
||||
}
|
||||
|
||||
/// Whether `language` is an HTML container without a grammar of its own
|
||||
/// (Vue SFC / Svelte / JSP): structure answers come from the HTML tree
|
||||
/// plus the inline `<script>` regions' block grammars.
|
||||
fn web_container(&self, language: &LanguageId) -> bool {
|
||||
let syn = self.cache.syntax();
|
||||
syn.grammar_name(language).is_none() && syn.web_grammar_name(language) == Some("html")
|
||||
}
|
||||
|
||||
/// Runs `f` on the block grammar's tree when one of the document's inline
|
||||
/// `<script>` regions covers `bytes`; `f` sees the region's `Ctx`, the
|
||||
/// query converted into region coordinates, and the region's document
|
||||
/// `base`. `Ok(None)` when no region covers `bytes`.
|
||||
fn with_script_tree<R>(
|
||||
&self,
|
||||
snap: &Snapshot,
|
||||
bytes: (usize, usize),
|
||||
cancel: &CancellationToken,
|
||||
f: impl FnOnce(&Ctx, Range, Pos) -> StructureResult<R>,
|
||||
) -> StructureResult<Option<R>> {
|
||||
if cancel.is_cancelled() {
|
||||
return Err(StructureError::Cancelled);
|
||||
}
|
||||
let cancelled = || cancel.is_cancelled();
|
||||
let syn = self.cache.syntax();
|
||||
if syn.web_grammar_name(snap.language) != Some("html") {
|
||||
return Ok(None);
|
||||
}
|
||||
let extract = |p: ParsedTree<'_>| Syntax::script_regions_of(p.tree, p.text);
|
||||
let regions = match snap.doc {
|
||||
Some(doc) if syn.grammar_name(snap.language).is_some() => {
|
||||
self.cache.with_parsed(doc, snap.language, snap.version, snap.text, &cancelled, extract)
|
||||
}
|
||||
_ => syn.with_parsed(&LanguageId::new("html"), snap.text, &cancelled, extract),
|
||||
};
|
||||
let Some(region) = regions?.into_iter().find(|r| bytes.0 >= r.base && bytes.1 <= r.base + r.text.len()) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let base = Lines::new(snap.text).pos(region.base);
|
||||
let (a, b) = (bytes.0 - region.base, bytes.1 - region.base);
|
||||
syn.with_parsed(®ion.language, ®ion.text, &cancelled, |p| {
|
||||
let cx = Ctx {
|
||||
grammar: p.grammar,
|
||||
language: p.language,
|
||||
tree: p.tree,
|
||||
kinds: Kinds::for_grammar(p.grammar, p.language),
|
||||
lines: Lines::new(p.text),
|
||||
cancel,
|
||||
};
|
||||
let local = Range::new(cx.lines.pos(a), cx.lines.pos(b));
|
||||
f(&cx, local, base)
|
||||
})
|
||||
.map_err(StructureError::from)
|
||||
.and_then(|r| r)
|
||||
.map(Some)
|
||||
}
|
||||
|
||||
fn run<R>(
|
||||
&self,
|
||||
snap: &Snapshot,
|
||||
@@ -288,3 +373,28 @@ fn utf16_offset(text: &str, pos: Pos) -> u32 {
|
||||
let lines = Lines::new(text);
|
||||
lines::utf16_len(&text[..lines.byte(pos)])
|
||||
}
|
||||
|
||||
/// Shifts a `<script>` region's answer to document coordinates (`base` is the
|
||||
/// region start): the node and every ancestor move by [`shift_range`].
|
||||
fn shift_node_at(at: NodeAt, base: Pos) -> NodeAt {
|
||||
let shift = |n: SyntaxNode| SyntaxNode { range: shift_range(n.range, base), ..n };
|
||||
NodeAt { node: shift(at.node), ancestors: at.ancestors.into_iter().map(shift).collect() }
|
||||
}
|
||||
|
||||
/// [`shift_node_at`] for a `locals` answer: every range moves (`NotLocal`'s,
|
||||
/// the symbol's definition, scope, references and conflicts), names stay.
|
||||
fn shift_locals(l: Locals, base: Pos) -> Locals {
|
||||
match l {
|
||||
Locals::NoIdentifier => Locals::NoIdentifier,
|
||||
Locals::NotLocal { name, range, reason } => Locals::NotLocal { name, range: shift_range(range, base), reason },
|
||||
Locals::Local { symbol } => Locals::Local {
|
||||
symbol: LocalSymbol {
|
||||
definition: shift_range(symbol.definition, base),
|
||||
scope: shift_range(symbol.scope, base),
|
||||
references: symbol.references.into_iter().map(|r| shift_range(r, base)).collect(),
|
||||
conflicts: symbol.conflicts.into_iter().map(|r| shift_range(r, base)).collect(),
|
||||
..symbol
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -287,3 +287,123 @@ fn identifiers_in_files_loads_in_parallel_and_skips_misses() {
|
||||
let got: Vec<(String, usize)> = found.iter().map(|f| (f.path.display().to_string(), f.occurrences.len())).collect();
|
||||
assert_eq!(got, [("/p/a.ts".to_owned(), 1), ("/p/d.rs".to_owned(), 2)]);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Vue SFC / HTML: answers from the inline <script> regions' block grammars
|
||||
|
||||
#[test]
|
||||
fn web_containers_support_the_tree_and_locals() {
|
||||
let s = service();
|
||||
for id in ["vue", "html"] {
|
||||
let support = s.support(&lang(id));
|
||||
assert!(support.tree, "{id}");
|
||||
assert!(support.locals, "{id}");
|
||||
}
|
||||
let rust = s.support(&lang("rust"));
|
||||
assert!(rust.tree && rust.locals, "languages with their own grammar are unchanged");
|
||||
let plain = s.support(&lang("plaintext"));
|
||||
assert!(!plain.tree && !plain.locals);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn node_at_inside_a_script_region_answers_from_the_block_grammar() {
|
||||
let src = "<template>\n <div>{{ n }}</div>\n</template>\n<script lang=\"ts\">\nconst size = 1;\n</script>\n";
|
||||
let vue = lang("vue");
|
||||
// `size` inside the script: a TypeScript identifier, at document coordinates.
|
||||
let at = service().node_at(&snap(&vue, src), occ(src, "size", 1), &none()).unwrap().unwrap();
|
||||
assert_eq!(at.node.kind, "identifier");
|
||||
assert_eq!(at.node.range, occ(src, "size", 1), "document coordinates");
|
||||
assert_eq!(at.node.field.as_deref(), Some("name"));
|
||||
// Template markup is not TypeScript: an empty answer, not markup nodes.
|
||||
assert!(service().node_at(&snap(&vue, src), occ(src, "div", 1), &none()).unwrap().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn locals_inside_a_script_region_shift_every_range() {
|
||||
let src = "<template><div/></template>\n<script lang=\"ts\">\nfunction f() {\n let count = 0;\n count += 1;\n}\n</script>\n";
|
||||
let vue = lang("vue");
|
||||
let byte = occurrences(src, "count")[0];
|
||||
let l = service().locals(&snap(&vue, src), pos_of(src, byte), &none()).unwrap();
|
||||
let Locals::Local { symbol } = l else {
|
||||
panic!("expected a local, got {l:?}");
|
||||
};
|
||||
assert_eq!(symbol.name, "count");
|
||||
assert!(symbol.certain);
|
||||
assert_eq!(symbol.definition, occ(src, "count", 1), "definition in document coordinates");
|
||||
assert_eq!(symbol.references, vec![occ(src, "count", 2)], "references in document coordinates");
|
||||
// Template: no TypeScript identifier here, so nothing local.
|
||||
let byte = occurrences(src, "div")[0];
|
||||
let l = service().locals(&snap(&vue, src), pos_of(src, byte), &none()).unwrap();
|
||||
assert!(matches!(l, Locals::NoIdentifier));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn web_script_queries_honour_cancellation_outside_regions() {
|
||||
let cancel = CancellationToken::new();
|
||||
cancel.cancel();
|
||||
for id in ["html", "vue", "svelte", "jsp"] {
|
||||
let language = lang(id);
|
||||
let src = "<template>中文😀</template><script>let value = 1;</script>";
|
||||
let snap = snap(&language, src);
|
||||
assert_eq!(service().node_at(&snap, Range::point(Pos::new(0, 2)), &cancel), Err(StructureError::Cancelled));
|
||||
assert_eq!(service().locals(&snap, Pos::new(0, 2), &cancel), Err(StructureError::Cancelled));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn web_script_queries_compose_utf16_positions_and_isolate_blocks() {
|
||||
let src = "<template>中文😀</template><script lang=ts>/* 中文😀 */ function first() { let 名 = '😀'; 名; }</script>\r\n<script setup lang=ts>function second() {\r\nlet 名 = 2;\r\n名;\r\n}</script>";
|
||||
for id in ["html", "vue", "svelte", "jsp"] {
|
||||
let language = lang(id);
|
||||
for (at, def, reference) in [(2, 1, 2), (4, 3, 4)] {
|
||||
assert_local(id, src, "名", at, def, &[reference]);
|
||||
let r = occ(src, "名", at);
|
||||
let node = service().node_at(&snap(&language, src), r, &none()).unwrap().unwrap();
|
||||
assert_eq!(node.node.range, r);
|
||||
assert_eq!(node.node.kind, "identifier");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn web_script_queries_follow_open_document_edits() {
|
||||
use ide_core::{ChangeSet, TextChange};
|
||||
|
||||
for id in ["html", "vue", "svelte", "jsp"] {
|
||||
let cache = Arc::new(SyntaxCache::new(Arc::new(Syntax::new())));
|
||||
let service = StructureService::new(cache.clone());
|
||||
let language = lang(id);
|
||||
let id = DocId::next();
|
||||
let mut doc = ide_text::Document::new("<script>function f() { let x = 1; x; }</script>");
|
||||
cache.open(id, &language, 0);
|
||||
for version in 0..2 {
|
||||
let text = doc.text();
|
||||
let snap = Snapshot::doc(id, doc.version(), &language, &text);
|
||||
let range = occ(&text, "x", 2);
|
||||
let at = service.node_at(&snap, range, &none()).unwrap().unwrap();
|
||||
assert_eq!(at.node.range, range);
|
||||
let Locals::Local { symbol } = service.locals(&snap, range.start, &none()).unwrap() else {
|
||||
panic!("expected local");
|
||||
};
|
||||
assert_eq!(symbol.definition, occ(&text, "x", 1));
|
||||
assert_eq!(symbol.references, [range]);
|
||||
if version == 0 {
|
||||
let changes =
|
||||
ChangeSet { changes: vec![TextChange { from: 0, to: 0, insert: "<!-- 中文😀 -->\n".into() }] };
|
||||
let (_, edits) = doc.apply_detailed(doc.version(), &changes).unwrap();
|
||||
cache.edit(id, doc.version(), &edits);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn web_script_queries_preserve_parse_size_errors() {
|
||||
let src = " ".repeat(ide_language::MAX_PARSE_BYTES + 1);
|
||||
for id in ["html", "vue", "svelte", "jsp"] {
|
||||
let language = lang(id);
|
||||
let snap = snap(&language, &src);
|
||||
assert_eq!(service().node_at(&snap, Range::point(Pos::new(0, 0)), &none()), Err(StructureError::TooLarge));
|
||||
assert_eq!(service().locals(&snap, Pos::new(0, 0), &none()), Err(StructureError::TooLarge));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
# Data directories
|
||||
|
||||
OpenIDEA keeps its rebuildable data, such as downloaded tools, language servers,
|
||||
JDKs and index caches, in the operating system's local data directory:
|
||||
|
||||
- **Windows:** `%LOCALAPPDATA%\ai.l0ng.openidea`
|
||||
- **macOS:** `~/Library/Application Support/ai.l0ng.openidea`
|
||||
- **Linux:** `~/.local/share/ai.l0ng.openidea`
|
||||
|
||||
To keep this data elsewhere, for example on another drive, set
|
||||
`OPENIDEA_LOCAL_DATA_DIR` to an absolute path before starting OpenIDEA. The IDE
|
||||
then uses `<OPENIDEA_LOCAL_DATA_DIR>/ai.l0ng.openidea` and creates it when
|
||||
missing. If the path is relative or cannot be written, OpenIDEA shows an error
|
||||
and exits instead of falling back to the default location.
|
||||
|
||||
```bat
|
||||
setx OPENIDEA_LOCAL_DATA_DIR "E:\OpenIDEA"
|
||||
```
|
||||
|
||||
Settings, plugins, scratches and other user data stay in the operating system's
|
||||
data and configuration directories. Logs stay in their usual location, so they
|
||||
are still written when the variable is wrong. Existing data is not moved: quit
|
||||
OpenIDEA and move the old directory's contents to the new location, or let the
|
||||
IDE download tools and rebuild indexes again.
|
||||
@@ -360,3 +360,30 @@ test("keeps mermaid `<style>` rules scoped to the rendered svg after id rewritin
|
||||
expect(await css(reply, ".cluster rect", "fill")).not.toBe("rgb(0, 0, 0)");
|
||||
expect(await css(reply, ".flowchart-link", "fill")).toBe("none");
|
||||
});
|
||||
|
||||
test("keeps mermaid flowchart nodes and sequence control blocks off solid black", async ({ page }) => {
|
||||
const flow = [
|
||||
"```mermaid",
|
||||
"flowchart LR",
|
||||
' subgraph Client["Client"]',
|
||||
' A["Local agent"]',
|
||||
' B["Voice input"]',
|
||||
" end",
|
||||
' subgraph Cloud["Cloud"]',
|
||||
' C["Cloud agent"]',
|
||||
' D["Memory service"]',
|
||||
" end",
|
||||
" B --> A",
|
||||
" A --> C",
|
||||
" C --> D",
|
||||
"```",
|
||||
].join("\n");
|
||||
const sequence = ["```mermaid", "sequenceDiagram", " loop every minute", " A->>B: ping", " end", "```"].join(
|
||||
"\n",
|
||||
);
|
||||
const reply = await openReply(page, `Flow:\n\n${flow}\n\nSequence:\n\n${sequence}`);
|
||||
await expect(reply.locator("[data-mermaid-state='ok'] .mermaid-output svg")).toHaveCount(2);
|
||||
expect(await css(reply, ".node rect", "fill")).not.toBe("rgb(0, 0, 0)");
|
||||
expect(await css(reply, ".cluster rect", "fill")).not.toBe("rgb(0, 0, 0)");
|
||||
expect(await css(reply, ".labelBox", "fill")).not.toBe("rgb(0, 0, 0)");
|
||||
});
|
||||
@@ -300,7 +300,7 @@ test.describe("10,000-line files", () => {
|
||||
await expect.poll(async () => (await rendered(page)).b.words).toContainEqual(["computeFast", "modified"]);
|
||||
}
|
||||
// The last difference is reachable and still highlighted.
|
||||
await page.keyboard.press("Meta+ArrowDown");
|
||||
await page.keyboard.press("Meta+End");
|
||||
await page.keyboard.press("Shift+F7");
|
||||
await expect(counter(page)).toHaveText("42 of 42 differences");
|
||||
if (opts.mode === "unified") {
|
||||
|
||||
@@ -1,4 +1,40 @@
|
||||
import { expect, test } from "./fixtures";
|
||||
import { expect, stubDesktop, test } from "./fixtures";
|
||||
|
||||
for (const windowKind of ["project", "welcome", "lightEdit"]) {
|
||||
test(`manual update answers stay visible in ${windowKind} with saved Notifications layout and logging off`, async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
await stubDesktop(page);
|
||||
await page.evaluate(async (kind) => {
|
||||
const projectPath = "/src/platform/project.ts";
|
||||
const layoutPath = "/src/workbench/toolwindows/store.ts";
|
||||
const updatesPath = "/src/features/app/updates.tsx";
|
||||
const { useProject } = await import(/* @vite-ignore */ projectPath);
|
||||
const { useToolWindowLayout } = await import(/* @vite-ignore */ layoutPath);
|
||||
const { checkForUpdates } = await import(/* @vite-ignore */ updatesPath);
|
||||
const settings = useProject.getState().settings;
|
||||
useProject.setState({
|
||||
...(kind === "project" ? {} : { project: null, lightEdit: kind === "lightEdit" }),
|
||||
settings: {
|
||||
...settings,
|
||||
notifications: { balloons: false, groups: { updates: { display: "none", log: false } } },
|
||||
},
|
||||
});
|
||||
useToolWindowLayout.setState({
|
||||
visible: { ...useToolWindowLayout.getState().visible, right: "notifications" },
|
||||
maximized: null,
|
||||
});
|
||||
window.__ipc.handlers.app_check_update = () => ({
|
||||
enabled: true,
|
||||
update: { version: "99.0.0", currentVersion: "0.1.40", notes: null, date: null },
|
||||
});
|
||||
window.__ipc.handlers.app_update_announcement = () => true;
|
||||
await checkForUpdates();
|
||||
}, windowKind);
|
||||
await expect(page.getByRole("status").filter({ hasText: "OpenIDEA 99.0.0 is available" })).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "Install and Restart", exact: true })).toBeVisible();
|
||||
});
|
||||
}
|
||||
|
||||
test("Updates shows check status and keeps manual checks available when automatic checks are off", async ({
|
||||
workbench: page,
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"name": "openidea",
|
||||
"private": true,
|
||||
"description": "An open-source IDE inspired by IntelliJ IDEA",
|
||||
"version": "0.1.39",
|
||||
"version": "0.1.40",
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -37,7 +37,7 @@ sdk/rust/openidea-plugin/ # the Rust SDK (host API, Plugin trait, mock host)
|
||||
crates/ide-plugin/tests/fixtures/ # test plugins: hello, jobs, language-toy, misbehave, semantic-tokens, hover, commit, inlay-hints
|
||||
```
|
||||
|
||||
The plugin API is defined in [`wit/`](../wit/) (`openidea:plugin@1.4.0`, world
|
||||
The plugin API is defined in [`wit/`](../wit/) (`openidea:plugin@1.5.0`, world
|
||||
`plugin`).
|
||||
|
||||
## 1. Quick start
|
||||
@@ -365,9 +365,19 @@ are always available. Calling a gated function without its capability returns
|
||||
|
||||
## 3. Writing code (Rust SDK)
|
||||
|
||||
### API 1.5
|
||||
|
||||
API 1.5.0 is planned for the next OpenIDEA release. Use
|
||||
`engines.openidea = "^1.5"` and the matching SDK. Released 1.4 plugins keep
|
||||
working. New in 1.5:
|
||||
|
||||
- [Notifications for a project](#notifications-with-commands):
|
||||
`Project::notify` shows a notification in a window of that project only,
|
||||
also from scheduled or background work.
|
||||
|
||||
### API 1.4
|
||||
|
||||
API 1.4.0 is planned for the next OpenIDEA release. Use
|
||||
API 1.4.0 shipped with OpenIDEA 0.1.40. Use
|
||||
`engines.openidea = "^1.4"` and the matching SDK. Released 1.3 plugins keep
|
||||
working. New in 1.4:
|
||||
|
||||
@@ -525,6 +535,7 @@ then run `openidea-plugin check`.
|
||||
| `host::output_append(channel, text)`, `output_clear`, `output_reveal` | `output.{append,clear,reveal}` | API 1.4: read-only Output tabs; 32 named channels per plugin, each a 1 MiB UTF-8 ring buffer. Reveal requires the invoking window. |
|
||||
| `host::set_context(key, value)`, `remove_context` | `ui.{set,remove}-context` | Sets `plugin.<id>.<key>` for `when` clauses in the window the call came from (`true`, `3.5`, `"text"`; `ContextValue`). Key 1–64 of `A-Za-z0-9_-`, 100 per plugin; gone when the plugin stops. |
|
||||
| `host::notify(level, title, body)` | `ui.show-notification` | Balloon in the window the command or events came from (every window otherwise). |
|
||||
| `Project::notify(level, title, body, actions)` | `ui.notify-project` | API 1.5: balloon only in a window of that project (the most recently focused one), with or without an invoking window; see _Notifications with commands_. |
|
||||
| `host::copy_to_clipboard(text)` | `ui.copy-to-clipboard` | Copies `text` to the system clipboard. Needs `clipboard`. |
|
||||
| `host::open_url(url)` | `ui.open-url` | Opens an `http://` or `https://` URL in the user's default browser. |
|
||||
| `host::pick(title, items)`, `pick_many` | `ui.pick`, `ui.pick-many` | Picks key(s) from `PickItem`s, or `None` when dismissed. From a command/event or code-action resolution in its editor window (else `invalid`); waiting is excluded from the budget. |
|
||||
@@ -2254,8 +2265,8 @@ the API itself follows _Evolving the plugin API_ below.
|
||||
## 10. Evolving the plugin API
|
||||
|
||||
Released versions are frozen: 1.0.0 shipped with OpenIDEA 0.1.36, 1.1.0
|
||||
with 0.1.37, 1.2.0 with 0.1.38 and 1.3.0 with 0.1.39. API 1.4.0 is planned
|
||||
with the next release. wasmtime decides what stays compatible: it resolves interface names
|
||||
with 0.1.37, 1.2.0 with 0.1.38, 1.3.0 with 0.1.39 and 1.4.0 with 0.1.40.
|
||||
API 1.5.0 is planned with the next release. wasmtime decides what stays compatible: it resolves interface names
|
||||
by semver (a component importing `openidea:plugin/[email protected]` links against a
|
||||
host defining `@1.1.0`, and the host finds its exports the same way), but
|
||||
function types must match exactly — a record with another field count, or a
|
||||
@@ -2382,6 +2393,29 @@ its normal editor and project context. No capability is needed. Invalid or
|
||||
undeclared actions reject the whole notification. Labels are limited to 256
|
||||
bytes and arguments to 64 KiB. Plain `host::notify` behaves as before.
|
||||
|
||||
Both go to the window the command or event came from, or to every window when
|
||||
there is none (a scheduled call, for instance). To reach one project from such
|
||||
work, call `notify` on that [`Project`](#the-api) (API 1.5, `ui.notify-project`),
|
||||
with the same actions and limits:
|
||||
|
||||
```rust
|
||||
for project in host::projects()? {
|
||||
if let Some(update) = check_for_update(&project)? {
|
||||
let disable = NotificationAction::new("Disable automatic checks", "disable-checks")
|
||||
.argument(project.root()?);
|
||||
project.notify(NotificationLevel::Info, "Update available", &update, &[disable])?;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- It shows only in a window of that project: the most recently focused one
|
||||
when the project is open in several.
|
||||
- A button runs its command with an invocation from that window, so
|
||||
`ctx.project()` is the notification's project.
|
||||
- If the project has closed by the time of the call, the call fails with
|
||||
`Error::NotFound` and shows nothing; it never falls back to another window.
|
||||
A balloon already shown goes away with its window.
|
||||
|
||||
### Selecting plugin tests (API 1.4, unreleased)
|
||||
|
||||
A plugin using `framework = "plugin"` can implement `TestResults::select_tests`
|
||||
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
e3c11d8969a1b8b52e7e745b558d12f804ebf533e7f0f3fe614ffe6f7b9c9468
|
||||
bb67a1b003840ecc2d0c056a0b0af3474b08ac095239c1f4d02b7a7aab5b526c
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
b28ccfd442c6348e0826680ec97391cbe4ec6a93a27ff02e40f47341e21586b4
|
||||
a6289739f5b644ea559ba18298741205ea0bedce7bd1dd2b367309101e8ffb1e
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
d669a2600b0c59e91ac8a9b875a24bddf0eeddd404ce7b67da31733861a846b8
|
||||
767ff8329456fe3a1f324f571b22124707244a61ff5b6ea2c7ed88f909d202e8
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
a5f0ebce6d30e0dc03769ebe5cb82d3704c5ccc32207aa2b3f5500de7b1a9152
|
||||
edb2a28419861c6f2d7cd5c300fa9f3120df5c17fb94596814635a9d97bf56d7
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
ee3ccb648ca4b98a0359521c4cd895b5e7336fd65101563f2ca82b8cbaeedc3d
|
||||
debc0eccd6eb6a93bafecb0d6eca8feb26a3436d9154a278b877eaee567dce80
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
51f7167dd5ed21ed37e227bd3b100a5be5a57e7890a494c942fdd036b1307993
|
||||
6e7cea8633d117d65b293c35bf332d8f4474ab1fdea88aedb37aa189e130857d
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
cd860e7a652951aaa42029da23fdeee7a3c09ab1bfcbfb0d1bb6c89036fc8817
|
||||
e3a0ef77e0c7b54307751d24cc899a0cf782149ebf98833fc1d7b990b369cced
|
||||
Loaded 100 of 244 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Заблокувати користувача