patch for vscode encoding "UTF-8-Isabelle": clone of "utf8", no symbols yet;
authorwenzelm
Tue, 08 Mar 2022 17:02:24 +0100
changeset 75246 f32e5d4cf1a3
parent 75245 0fc0ed9a3ad7
child 75247 4a9809ee1a85
patch for vscode encoding "UTF-8-Isabelle": clone of "utf8", no symbols yet;
src/Tools/VSCode/extension/src/isabelle_encoding.ts
src/Tools/VSCode/patches/isabelle_encoding.patch
--- a/src/Tools/VSCode/extension/src/isabelle_encoding.ts	Tue Mar 08 15:51:18 2022 +0100
+++ b/src/Tools/VSCode/extension/src/isabelle_encoding.ts	Tue Mar 08 17:02:24 2022 +0100
@@ -1,6 +1,6 @@
 /*  Author:     Makarius
 
-UTF-8-Isabelle symbol encoding: minimal dependencies, for use inside VSCode.
+UTF-8-Isabelle symbol encoding: for use inside VSCode.
 */
 
 'use strict';
@@ -33,7 +33,8 @@
 
 /* encoding */
 
-export const UTF8_Isabelle = 'utf8-isabelle';
+export const ENCODING = 'utf8isabelle';
+export const LABEL = 'UTF-8-Isabelle';
 
 export interface Options {
   stripBOM?: boolean;
@@ -51,7 +52,7 @@
   end(): string | undefined;
 }
 
-export async function getEncoder(encoding: string, options?: Options): Promise<IEncoderStream> {
+export function getEncoder(): IEncoderStream {
   const utf8_encoder = new TextEncoder();
   return {
     write(input: string): Uint8Array {
@@ -63,7 +64,7 @@
   };
 }
 
-export async function getDecoder(encoding: string, options?: Options): Promise<IDecoderStream> {
+export function getDecoder(): IDecoderStream {
   const utf8TextDecoder = new TextDecoder();
   return {
     write(input: Uint8Array): string {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tools/VSCode/patches/isabelle_encoding.patch	Tue Mar 08 17:02:24 2022 +0100
@@ -0,0 +1,54 @@
+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',