aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/highlighting.ts
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-31 13:11:49 +0000
committerGitHub <[email protected]>2019-12-31 13:11:49 +0000
commit46952985a087db5be5ca846b5109fccae8845df2 (patch)
treebb62a5d32f3999cd1bc430cef64ce13320f8132b /editors/code/src/highlighting.ts
parent7c4d4e113bc039712aa3996e57eaef19d12bd9ff (diff)
parent26bd7a896b4bbc4a2432df47dceff939aac921fa (diff)
Merge #2702
2702: Drop support for legacy colorization r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'editors/code/src/highlighting.ts')
-rw-r--r--editors/code/src/highlighting.ts106
1 files changed, 41 insertions, 65 deletions
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index 5e9cbe0de..d383d87ef 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -3,8 +3,7 @@ import * as lc from 'vscode-languageclient';
3import * as seedrandom_ from 'seedrandom'; 3import * as seedrandom_ from 'seedrandom';
4const seedrandom = seedrandom_; // https://github.com/jvandemo/generator-angular2-library/issues/221#issuecomment-355945207 4const seedrandom = seedrandom_; // https://github.com/jvandemo/generator-angular2-library/issues/221#issuecomment-355945207
5 5
6import { loadThemeColors, TextMateRuleSettings } from './scopes'; 6import { ColorTheme, TextMateRuleSettings } from './color_theme';
7import * as scopesMapper from './scopes_mapper';
8 7
9import { Ctx } from './ctx'; 8import { Ctx } from './ctx';
10 9
@@ -168,69 +167,16 @@ class Highlighter {
168 } 167 }
169} 168}
170 169
171function initDecorations(): Map< 170function initDecorations(): Map<string, vscode.TextEditorDecorationType> {
172 string, 171 const theme = ColorTheme.load();
173 vscode.TextEditorDecorationType 172 const res = new Map()
174> { 173 TAG_TO_SCOPES.forEach((scopes, tag) => {
175 const themeColors = loadThemeColors(); 174 if (!scopes) throw `unmapped tag: ${tag}`
176 175 let rule = theme.lookup(scopes)
177 const decoration = ( 176 const decor = createDecorationFromTextmate(rule);
178 tag: string, 177 res.set(tag, decor)
179 textDecoration?: string, 178 })
180 ): [string, vscode.TextEditorDecorationType] => { 179 return res;
181 const rule = scopesMapper.toRule(tag, it => themeColors.get(it));
182
183 if (rule) {
184 const decor = createDecorationFromTextmate(rule);
185 return [tag, decor];
186 } else {
187 const fallBackTag = 'ralsp.' + tag;
188 // console.log(' ');
189 // console.log('Missing theme for: <"' + tag + '"> for following mapped scopes:');
190 // console.log(scopesMapper.find(tag));
191 // console.log('Falling back to values defined in: ' + fallBackTag);
192 // console.log(' ');
193 const color = new vscode.ThemeColor(fallBackTag);
194 const decor = vscode.window.createTextEditorDecorationType({
195 color,
196 textDecoration,
197 });
198 return [tag, decor];
199 }
200 };
201
202 const decorations: Iterable<[
203 string,
204 vscode.TextEditorDecorationType,
205 ]> = [
206 decoration('comment'),
207 decoration('string'),
208 decoration('keyword'),
209 decoration('keyword.control'),
210 decoration('keyword.unsafe'),
211 decoration('function'),
212 decoration('parameter'),
213 decoration('constant'),
214 decoration('type.builtin'),
215 decoration('type.generic'),
216 decoration('type.lifetime'),
217 decoration('type.param'),
218 decoration('type.self'),
219 decoration('type'),
220 decoration('text'),
221 decoration('attribute'),
222 decoration('literal'),
223 decoration('literal.numeric'),
224 decoration('literal.char'),
225 decoration('literal.byte'),
226 decoration('macro'),
227 decoration('variable'),
228 decoration('variable.mut', 'underline'),
229 decoration('field'),
230 decoration('module'),
231 ];
232
233 return new Map<string, vscode.TextEditorDecorationType>(decorations);
234} 180}
235 181
236function createDecorationFromTextmate( 182function createDecorationFromTextmate(
@@ -267,3 +213,33 @@ function createDecorationFromTextmate(
267 } 213 }
268 return vscode.window.createTextEditorDecorationType(decorationOptions); 214 return vscode.window.createTextEditorDecorationType(decorationOptions);
269} 215}
216
217// sync with tags from `syntax_highlighting.rs`.
218const TAG_TO_SCOPES = new Map<string, string[]>([
219 ["field", ["entity.name.field"]],
220 ["function", ["entity.name.function"]],
221 ["module", ["entity.name.module"]],
222 ["constant", ["entity.name.constant"]],
223 ["macro", ["entity.name.macro"]],
224
225 ["variable", ["variable"]],
226 ["variable.mut", ["variable", "meta.mutable"]],
227
228 ["type", ["entity.name.type"]],
229 ["type.builtin", ["entity.name.type", "support.type.primitive"]],
230 ["type.self", ["entity.name.type.parameter.self"]],
231 ["type.param", ["entity.name.type.parameter"]],
232 ["type.lifetime", ["entity.name.type.lifetime"]],
233
234 ["literal.byte", ["constant.character.byte"]],
235 ["literal.char", ["constant.character"]],
236 ["literal.numeric", ["constant.numeric"]],
237
238 ["comment", ["comment"]],
239 ["string", ["string.quoted"]],
240 ["attribute", ["meta.attribute"]],
241
242 ["keyword", ["keyword"]],
243 ["keyword.unsafe", ["keyword.other.unsafe"]],
244 ["keyword.control", ["keyword.control"]],
245]);