58 { |
62 { |
59 const code = get_code(sym) |
63 const code = get_code(sym) |
60 return code ? String.fromCharCode(code) : "" |
64 return code ? String.fromCharCode(code) : "" |
61 } |
65 } |
62 |
66 |
63 export function update(entries: [Entry]) |
67 function update_entries(entries: [Entry]) |
64 { |
68 { |
65 symbol_entries = entries |
69 symbol_entries = entries |
66 names.clear |
70 names.clear |
67 codes.clear |
71 codes.clear |
68 for (const entry of entries) { |
72 for (const entry of entries) { |
80 for (const entry of names) { |
84 for (const entry of names) { |
81 if (entry[1].startsWith(prefix)) { result.push(entry[0]) } |
85 if (entry[1].startsWith(prefix)) { result.push(entry[0]) } |
82 } |
86 } |
83 return result.sort() |
87 return result.sort() |
84 } |
88 } |
|
89 |
|
90 |
|
91 /* prettify symbols mode */ |
|
92 |
|
93 interface PrettyStyleProperties |
|
94 { |
|
95 border?: string |
|
96 textDecoration?: string |
|
97 color?: string |
|
98 backgroundColor?: string |
|
99 } |
|
100 |
|
101 interface PrettyStyle extends PrettyStyleProperties |
|
102 { |
|
103 dark?: PrettyStyleProperties |
|
104 light?: PrettyStyleProperties |
|
105 } |
|
106 |
|
107 interface Substitution |
|
108 { |
|
109 ugly: string |
|
110 pretty: string |
|
111 pre?: string |
|
112 post?: string |
|
113 style?: PrettyStyle |
|
114 } |
|
115 |
|
116 interface LanguageEntry |
|
117 { |
|
118 language: DocumentSelector |
|
119 revealOn: string |
|
120 adjustCursorMovement: boolean |
|
121 substitutions: Substitution[] |
|
122 } |
|
123 |
|
124 interface PrettifySymbolsMode |
|
125 { |
|
126 onDidEnabledChange: (handler: (enabled: boolean) => void) => Disposable |
|
127 isEnabled: () => boolean, |
|
128 registerSubstitutions: (substitutions: LanguageEntry) => Disposable |
|
129 } |
|
130 |
|
131 export function init(context: ExtensionContext, entries: [Entry]) |
|
132 { |
|
133 update_entries(entries) |
|
134 |
|
135 const prettify_symbols_mode = |
|
136 extensions.getExtension<PrettifySymbolsMode>("siegebell.prettify-symbols-mode") |
|
137 if (prettify_symbols_mode) { |
|
138 prettify_symbols_mode.activate().then(() => |
|
139 { |
|
140 const substitutions = [] as [Substitution] |
|
141 for (const entry of names) { |
|
142 const sym = entry[0] |
|
143 substitutions.push( |
|
144 { |
|
145 ugly: library.escape_regex(sym), |
|
146 pretty: library.escape_regex(get_unicode(sym)) |
|
147 }) |
|
148 } |
|
149 for (const language of ["isabelle", "isabelle-ml", "isabelle-output"]) { |
|
150 context.subscriptions.push( |
|
151 prettify_symbols_mode.exports.registerSubstitutions( |
|
152 { |
|
153 language: language, |
|
154 revealOn: "none", |
|
155 adjustCursorMovement: true, |
|
156 substitutions: substitutions |
|
157 })) |
|
158 } |
|
159 }) |
|
160 } |
|
161 } |