src/Tools/VSCode/extension/src/symbol.ts
changeset 66070 65a68dcd95c3
parent 66060 b2bfbefd354f
child 66071 8b67040b80ce
--- a/src/Tools/VSCode/extension/src/symbol.ts	Mon Jun 12 15:20:07 2017 +0200
+++ b/src/Tools/VSCode/extension/src/symbol.ts	Mon Jun 12 15:40:40 2017 +0200
@@ -1,5 +1,9 @@
 'use strict';
 
+import * as library from './library'
+import { Disposable, DocumentSelector, ExtensionContext, extensions } from 'vscode';
+
+
 export type Symbol = string
 
 
@@ -60,7 +64,7 @@
   return code ? String.fromCharCode(code) : ""
 }
 
-export function update(entries: [Entry])
+function update_entries(entries: [Entry])
 {
   symbol_entries = entries
   names.clear
@@ -81,4 +85,77 @@
     if (entry[1].startsWith(prefix)) { result.push(entry[0]) }
   }
   return result.sort()
+}
+
+
+/* prettify symbols mode */
+
+interface PrettyStyleProperties
+{
+  border?: string
+  textDecoration?: string
+  color?: string
+  backgroundColor?: string
+}
+
+interface PrettyStyle extends PrettyStyleProperties
+{
+  dark?: PrettyStyleProperties
+  light?: PrettyStyleProperties
+}
+
+interface Substitution
+{
+  ugly: string
+  pretty: string
+  pre?: string
+  post?: string
+  style?: PrettyStyle
+}
+
+interface LanguageEntry
+{
+  language: DocumentSelector
+  revealOn: string
+  adjustCursorMovement: boolean
+  substitutions: Substitution[]
+}
+
+interface PrettifySymbolsMode
+{
+  onDidEnabledChange: (handler: (enabled: boolean) => void) => Disposable
+  isEnabled: () => boolean,
+  registerSubstitutions: (substitutions: LanguageEntry) => Disposable
+}
+
+export function init(context: ExtensionContext, entries: [Entry])
+{
+  update_entries(entries)
+
+  const prettify_symbols_mode =
+    extensions.getExtension<PrettifySymbolsMode>("siegebell.prettify-symbols-mode")
+  if (prettify_symbols_mode) {
+    prettify_symbols_mode.activate().then(() =>
+    {
+      const substitutions = [] as [Substitution]
+      for (const entry of names) {
+        const sym = entry[0]
+        substitutions.push(
+          {
+            ugly: library.escape_regex(sym),
+            pretty: library.escape_regex(get_unicode(sym))
+          })
+      }
+      for (const language of ["isabelle", "isabelle-ml", "isabelle-output"]) {
+        context.subscriptions.push(
+          prettify_symbols_mode.exports.registerSubstitutions(
+            {
+              language: language,
+              revealOn: "none",
+              adjustCursorMovement: true,
+              substitutions: substitutions
+            }))
+      }
+    })
+  }
 }
\ No newline at end of file