src/Tools/VSCode/patches/isabelle_encoding.patch
author nipkow
Tue, 17 Jun 2025 14:11:40 +0200
changeset 82733 8b537e1af2ec
parent 75246 f32e5d4cf1a3
permissions -rw-r--r--
reinstated intersection of lists as inter_list_set

diff --git a/src/vs/workbench/services/textfile/common/encoding.ts b/src/vs/workbench/services/textfile/common/encoding.ts
--- a/src/vs/workbench/services/textfile/common/encoding.ts
+++ b/src/vs/workbench/services/textfile/common/encoding.ts
@@ -6,6 +6,7 @@
 import { Readable, ReadableStream, newWriteableStream, listenStream } from 'vs/base/common/stream';
 import { VSBuffer, VSBufferReadable, VSBufferReadableStream } from 'vs/base/common/buffer';
 import { IDisposable } from 'vs/base/common/lifecycle';
+import * as isabelle_encoding from './isabelle_encoding';
 
 export const UTF8 = 'utf8';
 export const UTF8_with_bom = 'utf8bom';
@@ -78,7 +79,9 @@ class DecoderStream implements IDecoderStream {
 	 */
 	static async create(encoding: string): Promise<DecoderStream> {
 		let decoder: IDecoderStream | undefined = undefined;
-		if (encoding !== UTF8) {
+		if (encoding === isabelle_encoding.ENCODING) {
+			decoder = isabelle_encoding.getDecoder();
+		} else if (encoding !== UTF8) {
 			const iconv = await import('@vscode/iconv-lite-umd');
 			decoder = iconv.getDecoder(toNodeEncoding(encoding));
 		} else {
@@ -212,7 +215,9 @@ export function toDecodeStream(source: VSBufferReadableStream, options: IDecodeS
 
 export async function toEncodeReadable(readable: Readable<string>, encoding: string, options?: { addBOM?: boolean }): Promise<VSBufferReadable> {
 	const iconv = await import('@vscode/iconv-lite-umd');
-	const encoder = iconv.getEncoder(toNodeEncoding(encoding), options);
+	const encoder =
+		encoding === isabelle_encoding.ENCODING ?
+			isabelle_encoding.getEncoder() : iconv.getEncoder(toNodeEncoding(encoding), options);
 
 	let bytesWritten = false;
 	let done = false;
@@ -262,7 +267,7 @@ export async function toEncodeReadable(readable: Readable<string>, encoding: str
 export async function encodingExists(encoding: string): Promise<boolean> {
 	const iconv = await import('@vscode/iconv-lite-umd');
 
-	return iconv.encodingExists(toNodeEncoding(encoding));
+	return encoding === isabelle_encoding.ENCODING || iconv.encodingExists(toNodeEncoding(encoding));
 }
 
 export function toNodeEncoding(enc: string | null): string {
@@ -479,6 +484,11 @@ export function detectEncodingFromBuffer({ buffer, bytesRead }: IReadResult, aut
 }
 
 export const SUPPORTED_ENCODINGS: { [encoding: string]: { labelLong: string; labelShort: string; order: number; encodeOnly?: boolean; alias?: string } } = {
+	utf8isabelle: {
+		labelLong: isabelle_encoding.LABEL,
+		labelShort: isabelle_encoding.LABEL,
+		order: 0,
+	},
 	utf8: {
 		labelLong: 'UTF-8',
 		labelShort: 'UTF-8',