fix(editor): show no read-only banner above library sources (#7788)

Library sources opened from a language server or from the External Libraries showed a "Library source (read-only)" banner above the editor. They now open read-only without a notice, as the status bar's lock already shows the state; the banner stays for decompiled classes, Git revisions, generated C# sources and whenever there is something to act on (sources to download or choose).

Fixes #7735
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-12-03 18:47:06 +08:00
1 джерело 9087fa61d9
коміт d41bccc50c
3 files changed
+18 -11

No files matched your search

+5 -5
Переглянути файл
@@ -113,7 +113,7 @@ export function docCommentFolds(state: EditorState, info: LanguageInfo | undefin
);
}
export type Banner = "binary" | "tooLarge" | "codeInsightDisabled" | "readOnly" | "library" | null;
export type Banner = "binary" | "tooLarge" | "codeInsightDisabled" | "readOnly" | null;
/** A view attached to a document outside the tab system (see `attachment.ts`). */
export interface DocAttachmentTarget {
@@ -155,11 +155,11 @@ const GRAMMAR_SUPPLEMENTED = new Set(["kotlin", "shellscript", "fsharp", "fsharp
function bannerFor(info: DocumentInfo): Banner {
// Virtual documents (library classes) get their own notice from the editor area.
if (info.uri) return null;
if (isLibraryPath(info.path)) return "library";
if (info.readOnly && !info.text.length) return "binary";
if (info.tooLarge ?? (info.readOnly && info.large)) return "tooLarge";
if (info.large) return "codeInsightDisabled";
return info.readOnly ? "readOnly" : null;
// Library sources are read-only without a notice, as in IDEA; the status bar's lock shows it.
return info.readOnly && !isLibraryPath(info.path) ? "readOnly" : null;
}
/** Ranges touched since the last save (in current-document coordinates). */
@@ -659,8 +659,8 @@ export class DocModel {
this.setMeta({
readOnly,
banner: readOnly
? (banner ?? (this.virtual ? null : "readOnly"))
: banner === "readOnly" || banner === "library"
? (banner ?? (this.virtual || isLibraryPath(this.path) ? null : "readOnly"))
: banner === "readOnly"
? null
: banner,
});
+6 -6
Переглянути файл
@@ -14,7 +14,6 @@ const TEXT = {
tooLarge: "The file is too large: editing and code insight are disabled.",
codeInsightDisabled: "Code insight is disabled for this file because of its size.",
readOnly: "The file is read-only.",
library: "Library source (read-only).",
} as const;
/** Notice above read-only / binary / too-large documents. */
@@ -23,15 +22,14 @@ export const documentBanner: EditorBannerContribution = {
order: -10,
useBanner: (path) => {
const banner = useDocMeta((s) => s[path]?.banner ?? null);
return banner
? { text: TEXT[banner], icon: banner === "readOnly" || banner === "library" ? "lock" : "info" }
: null;
return banner ? { text: TEXT[banner], icon: banner === "readOnly" ? "lock" : "info" } : null;
},
};
/**
* Notice above a library class opened from a language server (IDEA's
* "Decompiled .class file" / library source bar): read-only, with its origin.
* Notice above a class opened from a language server (IDEA's "Decompiled .class file" bar):
* read-only, with its origin. Library sources get none unless there is something to act on;
* the status bar's lock shows they are read-only.
*/
export function VirtualBanner({
decompiled,
@@ -60,6 +58,8 @@ export function VirtualBanner({
if (sources.choose)
actions.push({ label: "Choose Sources…", run: () => void executeAction("editor.chooseSources", path) });
}
const librarySource = !decompiled && !gitRevisionOf(path) && !path.startsWith("csharp:");
if (librarySource && !reason && !actions.length && !sources.message && !sources.busy) return null;
return (
<Banner icon={decompiled ? "info" : "lock"} level="warning" actions={actions}>
<span>
+7
Переглянути файл
@@ -30,6 +30,13 @@ describe("editor banners", () => {
expect(screen.getByTitle("Example.Library")).toBeTruthy();
});
it("shows no notice above a library source with nothing to act on", () => {
render(
<VirtualBanner path="jdt://contents/rt.jar/java.util/HashMap.java" decompiled={false} description="rt.jar" />,
);
expect(screen.queryByRole("status")).toBeNull();
});
it("shows the document notice through the banner extension point, before contributed ones", () => {
const off = [
registerEditorBanner(documentBanner),