Skip to content

Commit

Permalink
feat: implement VS Code's semantic colouring engine 🎨 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrossmann committed May 4, 2020
1 parent 87f7a7e commit 574fe92
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/generators/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { mkui } from './mkui'
import { mktokens } from './mktokens'
import { mktokens, mksemantictokens } from './mktokens'

export {
mkui,
mktokens,
mksemantictokens,
}
47 changes: 47 additions & 0 deletions packages/generators/mktokens/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,53 @@ function mktokens({ code, colours, tilts = false }) {
]
}

function mksemantictokens({ code, tilts = false }) {
return {
class: code.classes,
comment: code.comments,
enum: code.types,
enumMember: code.primitives,
// TODO
// event: '#ff0000',

function: code.functions,
interface: code.types,
keyword: code.language,
label: code.preprocessor,
macro: code.preprocessor,
member: code.functions,
namespace: code.classes,
number: code.primitives,
operator: code.language,
parameter: {
foreground: code.variables,
fontStyle: tilts ? 'italic' : '',
},

property: code.variables,
regexp: code.regexp.sequences,
string: code.strings,
struct: code.types,
type: code.types,
typeParameter: code.types,
variable: code.variables,

'property.readonly': `${code.variables}BB`,
'variable.readonly': `${code.variables}BB`,
'variable.defaultLibrary': code.primitives,

// '*.deprecated': ui.problems.error.hex(),
// '*.readonly': '#ff0000',
// '*.static': '#ff0000',
// '*.abstract': '#ff0000',
// '*.async': '#ff0000',
// '*.modification': '#ff0000',
// '*.documentation': '#ff0000',
// '*.defaultLibrary': '#ff0000',
}
}

export {
mktokens,
mksemantictokens,
}
3 changes: 2 additions & 1 deletion src/themes/bright-tilted/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkui, mktokens } from '@remedy/generators'
import { mkui, mktokens, mksemantictokens } from '@remedy/generators'
import * as ui from '../bright/ui'
import * as code from '../bright/code'
import * as colours from '../bright/colours'
Expand All @@ -8,4 +8,5 @@ export default {
type: 'vs',
colors: mkui({ ui, code }),
tokenColors: mktokens({ code, colours, tilts: true }),
semanticTokenColors: mksemantictokens({ code, tilts: true }),
}
3 changes: 2 additions & 1 deletion src/themes/bright/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkui, mktokens } from '@remedy/generators'
import { mkui, mktokens, mksemantictokens } from '@remedy/generators'
import * as ui from './ui'
import * as code from './code'
import * as colours from './colours'
Expand All @@ -8,4 +8,5 @@ export default {
type: 'vs',
colors: mkui({ ui, code }),
tokenColors: mktokens({ code, colours }),
semanticTokenColors: mksemantictokens({ code, tilts: false }),
}
4 changes: 3 additions & 1 deletion src/themes/dark-tilted/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkui, mktokens } from '@remedy/generators'
import { mkui, mktokens, mksemantictokens } from '@remedy/generators'
import * as ui from '../dark/ui'
import * as code from '../dark/code'
import * as colours from '../dark/colours'
Expand All @@ -8,4 +8,6 @@ export default {
type: 'vs-dark',
colors: mkui({ ui, code }),
tokenColors: mktokens({ code, colours, tilts: true }),
semanticHighlighting: true,
semanticTokenColors: mksemantictokens({ code, tilts: true }),
}
3 changes: 2 additions & 1 deletion src/themes/dark/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkui, mktokens } from '@remedy/generators'
import { mkui, mktokens, mksemantictokens } from '@remedy/generators'
import * as ui from './ui'
import * as code from './code'
import * as colours from './colours'
Expand All @@ -8,4 +8,5 @@ export default {
type: 'vs-dark',
colors: mkui({ ui, code }),
tokenColors: mktokens({ code, colours }),
semanticTokenColors: mksemantictokens({ code, tilts: false }),
}

0 comments on commit 574fe92

Please sign in to comment.