diff --git a/src/editor/core/model/document.ts b/src/editor/core/model/document.ts index 9823dfe00..e7dbae5da 100644 --- a/src/editor/core/model/document.ts +++ b/src/editor/core/model/document.ts @@ -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, }); diff --git a/src/editor/core/view/Banner.tsx b/src/editor/core/view/Banner.tsx index 3f86d625c..bb01e69eb 100644 --- a/src/editor/core/view/Banner.tsx +++ b/src/editor/core/view/Banner.tsx @@ -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 ( diff --git a/src/editor/core/view/banner.test.tsx b/src/editor/core/view/banner.test.tsx index eec809f80..6f9611827 100644 --- a/src/editor/core/view/banner.test.tsx +++ b/src/editor/core/view/banner.test.tsx @@ -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( + , + ); + expect(screen.queryByRole("status")).toBeNull(); + }); + it("shows the document notice through the banner extension point, before contributed ones", () => { const off = [ registerEditorBanner(documentBanner),