дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 08:43:07 +02:00
Порівняти коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
4dd8a89e4f |
No files matched your search
@@ -422,10 +422,6 @@ pub struct PluginHost {
|
||||
initial_load: (Mutex<bool>, Condvar),
|
||||
/// `on-startup-finished` has fired.
|
||||
startup_finished: AtomicBool,
|
||||
/// Language, file and view activation events fired so far (with their project), so a plugin
|
||||
/// installed or synced afterwards (a remote server gets its packages after the window opened
|
||||
/// files) still activates for a Twig file that is already open.
|
||||
fired_activations: Mutex<Vec<(ActivationEvent, Option<PathBuf>)>>,
|
||||
/// The theme last announced with `ThemeChanged`.
|
||||
announced_theme: Mutex<Option<ActiveTheme>>,
|
||||
/// [`PluginLanguages::revision`] last announced with `LanguagesChanged`.
|
||||
@@ -545,7 +541,6 @@ impl PluginHost {
|
||||
lifecycle: Mutex::new(()),
|
||||
initial_load: (Mutex::new(false), Condvar::new()),
|
||||
startup_finished: AtomicBool::new(false),
|
||||
fired_activations: Mutex::new(Vec::new()),
|
||||
announced_theme: Mutex::new(None),
|
||||
announced_languages: AtomicU64::new(0),
|
||||
announced_skills: AtomicU64::new(0),
|
||||
@@ -704,16 +699,6 @@ impl PluginHost {
|
||||
|
||||
/// Fires an activation event from the UI (`on-language:rust`, `on-file:…`, `on-view:…`).
|
||||
pub fn activation_event(&self, event: &ActivationEvent, project: Option<&Path>) {
|
||||
{
|
||||
let mut fired = self.fired_activations.lock();
|
||||
let entry = (event.clone(), project.map(Path::to_path_buf));
|
||||
if !fired.contains(&entry) {
|
||||
if fired.len() >= MAX_FIRED_ACTIVATIONS {
|
||||
fired.remove(0);
|
||||
}
|
||||
fired.push(entry);
|
||||
}
|
||||
}
|
||||
let targets: Vec<_> = self
|
||||
.plugins
|
||||
.read()
|
||||
@@ -3111,12 +3096,8 @@ impl PluginHost {
|
||||
meta.pending = pending;
|
||||
meta.status = if plugin.manifest().wasm.is_some() { PluginStatus::Inactive } else { PluginStatus::Static };
|
||||
}
|
||||
let eager = (plugin.manifest().activation.contains(&ActivationEvent::StartupFinished)
|
||||
&& self.startup_finished.load(Ordering::Acquire))
|
||||
|| self.fired_activations.lock().iter().any(|(event, project)| {
|
||||
(plugin.dev_root.is_none() || plugin.dev_root == *project)
|
||||
&& plugin.manifest().activation.iter().any(|a| activation_matches(a, event))
|
||||
});
|
||||
let eager = plugin.manifest().activation.contains(&ActivationEvent::StartupFinished)
|
||||
&& self.startup_finished.load(Ordering::Acquire);
|
||||
if eager {
|
||||
let _ = self.ensure_active(plugin, None);
|
||||
}
|
||||
@@ -3744,9 +3725,6 @@ fn counts(m: &Manifest) -> Vec<ContributionCount> {
|
||||
m.declaration_counts().into_iter().map(|(point, count)| ContributionCount { point, count }).collect()
|
||||
}
|
||||
|
||||
/// How many fired activation events [`PluginHost::activation_event`] remembers (oldest dropped first).
|
||||
const MAX_FIRED_ACTIVATIONS: usize = 512;
|
||||
|
||||
fn activation_matches(declared: &ActivationEvent, fired: &ActivationEvent) -> bool {
|
||||
match (declared, fired) {
|
||||
(ActivationEvent::Language(a), ActivationEvent::Language(b)) => a == b || a == "*",
|
||||
|
||||
@@ -1590,28 +1590,6 @@ fn misbehave_with_language(dir: &Path) -> PathBuf {
|
||||
pkg
|
||||
}
|
||||
|
||||
/// A language activation fired before the plugin was there (a remote server gets the desktop's
|
||||
/// packages after the window opened its files; a plugin installed with such a file open)
|
||||
/// activates it once it loads; one that never fired doesn't.
|
||||
#[test]
|
||||
fn plugins_loaded_after_their_activation_event_fired_activate() {
|
||||
use ide_extension::ActivationEvent;
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let host = Arc::new(
|
||||
PluginHost::new(tmp.path().join("plugins"), Arc::new(|_: Option<&str>, _| {}), Limits::default()).unwrap(),
|
||||
);
|
||||
host.load_all();
|
||||
host.startup_finished();
|
||||
host.activation_event(&ActivationEvent::Language("other".into()), None);
|
||||
host.install_from_dir(&misbehave_with_language(tmp.path()), &Consent::all()).unwrap();
|
||||
assert_eq!(host.info_of("misbehave").unwrap().status, PluginStatus::Inactive);
|
||||
host.uninstall("misbehave").unwrap();
|
||||
|
||||
host.activation_event(&ActivationEvent::Language("mis".into()), None);
|
||||
host.install_from_dir(&misbehave_with_language(tmp.path()), &Consent::all()).unwrap();
|
||||
assert!(eventually(|| host.info_of("misbehave").is_ok_and(|i| i.status == PluginStatus::Active)));
|
||||
}
|
||||
|
||||
/// Edit-path calls stop waiting at the soft deadline (the result is
|
||||
/// dropped, the instance kept) and are interrupted at the hard one.
|
||||
#[test]
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { EditorState } from "@codemirror/state";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { ensureSyntaxTree } from "@codemirror/language";
|
||||
import { java } from "@codemirror/lang-java";
|
||||
import { expressionAt } from "../editor/valueTooltip";
|
||||
|
||||
/** The expression around the `|` in `line`. */
|
||||
@@ -37,36 +35,3 @@ describe("expression at the mouse for Quick Evaluate (#4772)", () => {
|
||||
expect(at("a.getB().c|()", false)).toBe("c");
|
||||
});
|
||||
});
|
||||
|
||||
/** The expression around the `|` in a Java statement. */
|
||||
function inJava(statement: string, calls: boolean) {
|
||||
const prefix = "class A { void f() { ";
|
||||
const doc = `${prefix}${statement} } }`;
|
||||
const pos = doc.indexOf("|");
|
||||
const view = new EditorView({ state: EditorState.create({ doc: doc.replace("|", ""), extensions: java() }) });
|
||||
ensureSyntaxTree(view.state, view.state.doc.length, 1000);
|
||||
const text = expressionAt(view, pos, { calls })?.text ?? null;
|
||||
view.destroy();
|
||||
return text;
|
||||
}
|
||||
|
||||
describe("expression of an operator (#7000)", () => {
|
||||
it("takes the expression the operator belongs to, as IDEA does", () => {
|
||||
for (const calls of [false, true]) {
|
||||
expect(inJava("if (a > 1 |&& !flag) {}", calls)).toBe("a > 1 && !flag");
|
||||
expect(inJava("if (a |> 1 && !flag) {}", calls)).toBe("a > 1");
|
||||
expect(inJava("if (a > 1 && |!flag) {}", calls)).toBe("!flag");
|
||||
expect(inJava("x = c |? 1 : 2;", calls)).toBe("c ? 1 : 2");
|
||||
// An identifier is still just the identifier.
|
||||
expect(inJava("if (|a > 1 && !flag) {}", calls)).toBe("a");
|
||||
}
|
||||
});
|
||||
|
||||
it("leaves calls, increments and assignments to Quick Evaluate", () => {
|
||||
expect(inJava("if (s.length() |> 0) {}", false)).toBeNull();
|
||||
expect(inJava("if (s.length() |> 0) {}", true)).toBe("s.length() > 0");
|
||||
expect(inJava("if (a |!= b) {}", false)).toBe("a != b");
|
||||
expect(inJava("x = a |+ i++;", false)).toBeNull();
|
||||
expect(inJava("x |= 1;", true)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -3,7 +3,6 @@
|
||||
* while suspended, hovering an expression (or the selection under the mouse)
|
||||
* evaluates it in the selected frame.
|
||||
*/
|
||||
import { syntaxTree } from "@codemirror/language";
|
||||
import type { EditorState, Extension } from "@codemirror/state";
|
||||
import type { DebugSessionId, Variable } from "@/bindings";
|
||||
import { closeHoverTooltips, hoverTooltip, ViewPlugin, type EditorView, type ViewUpdate } from "@codemirror/view";
|
||||
@@ -50,29 +49,10 @@ function openOf(t: string, i: number): number {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Syntax nodes of an operator's expression (Lezer's Java, JS, Python, C++, Rust, Go grammars). */
|
||||
const OPERATOR_EXPRESSION = /^(Binary|Unary|Ternary|Conditional)Expr(ession)?$/;
|
||||
/** A call, an increment or an assignment: a plain hover doesn't evaluate those. */
|
||||
const SIDE_EFFECTS = /[\p{L}\p{N}_$)\]]\s*\(|\+\+|--|(^|[^=!<>])=(?!=)/u;
|
||||
|
||||
/**
|
||||
* As in IDEA, on an operator the expression it belongs to: `&&` gives `a > 1 && !flag`, `>` gives
|
||||
* `a > 1`, `!` gives `!flag`. Without `calls` (a hover), not when evaluating it could change state.
|
||||
*/
|
||||
function operatorExpressionAt(state: EditorState, pos: number, calls: boolean) {
|
||||
const token = syntaxTree(state).resolveInner(pos, 1);
|
||||
const parent = token.parent;
|
||||
if (token.firstChild || !parent || !OPERATOR_EXPRESSION.test(parent.name)) return null;
|
||||
const text = state.sliceDoc(parent.from, parent.to);
|
||||
if (text.includes("\n") || (!calls && SIDE_EFFECTS.test(text))) return null;
|
||||
return { from: parent.from, to: parent.to, text };
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifier (with `a.b.c` member access) around `pos`, or the selection containing it. With
|
||||
* `calls`, as for Quick Evaluate: member chains through calls and indexing (`a.getB().c`,
|
||||
* `items[i].name`) and the call of the identifier itself (`o.getX()`, `f(a, b)`). On an operator,
|
||||
* the expression it belongs to.
|
||||
* `items[i].name`) and the call of the identifier itself (`o.getX()`, `f(a, b)`).
|
||||
*/
|
||||
export function expressionAt(
|
||||
view: EditorView,
|
||||
@@ -89,9 +69,7 @@ export function expressionAt(
|
||||
const t = line.text;
|
||||
let start = pos - line.from;
|
||||
let end = start;
|
||||
if (!IDENT.test(t[end] ?? "") && !IDENT.test(t[start - 1] ?? "")) {
|
||||
return /\s/.test(t[end] ?? " ") ? null : operatorExpressionAt(state, pos, calls);
|
||||
}
|
||||
if (!IDENT.test(t[end] ?? "") && !IDENT.test(t[start - 1] ?? "")) return null;
|
||||
while (end < t.length && IDENT.test(t[end]!)) end++;
|
||||
for (;;) {
|
||||
while (start > 0 && IDENT.test(t[start - 1]!)) start--;
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { useEditorRegistry } from "@/editor/api";
|
||||
import { createMemoryPluginsBackend, setPluginsBackend } from "../backend";
|
||||
import { trackActivationEvents } from "../bridge";
|
||||
|
||||
afterEach(() => {
|
||||
setPluginsBackend(null);
|
||||
useEditorRegistry.setState({ active: null });
|
||||
});
|
||||
|
||||
describe("activation events", () => {
|
||||
it("fires on-language when the open file's language is recognized later", () => {
|
||||
const backend = createMemoryPluginsBackend();
|
||||
const activationEvent = vi.spyOn(backend, "activationEvent");
|
||||
setPluginsBackend(backend);
|
||||
const ctx = (language: string) => ({ active: { ctx: { path: "/p/page.twig", language } } }) as never;
|
||||
useEditorRegistry.setState(ctx("plaintext"));
|
||||
const stop = trackActivationEvents();
|
||||
// A remote server redetects the file once it has the plugin's language.
|
||||
useEditorRegistry.setState(ctx("twig"));
|
||||
stop();
|
||||
expect(activationEvent.mock.calls.filter(([kind]) => kind === "language").map(([, arg]) => arg)).toEqual([
|
||||
"plaintext",
|
||||
"twig",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -130,7 +130,7 @@ function scheduleRefresh() {
|
||||
* Fires `on-language:<id>` and `on-file:<project-relative path>` for files
|
||||
* opened in the editor; the backend activates the plugins waiting for them.
|
||||
*/
|
||||
export function trackActivationEvents(): () => void {
|
||||
function trackActivationEvents(): () => void {
|
||||
const seenLanguages = new Set<string>();
|
||||
const report = (ctx: { path: string | null; language: string } | undefined) => {
|
||||
if (!ctx?.path) return;
|
||||
@@ -148,11 +148,8 @@ export function trackActivationEvents(): () => void {
|
||||
}
|
||||
};
|
||||
report(useEditorRegistry.getState().active?.ctx);
|
||||
// Also when the open file's language changes: a remote project learns plugin languages after the
|
||||
// window restored its tabs, so a `.twig` file is plain text until the server redetects it.
|
||||
return useEditorRegistry.subscribe((s, prev) => {
|
||||
if (s.active?.ctx.path !== prev.active?.ctx.path || s.active?.ctx.language !== prev.active?.ctx.language)
|
||||
report(s.active?.ctx);
|
||||
if (s.active?.ctx.path !== prev.active?.ctx.path) report(s.active?.ctx);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Заблокувати користувача