TLDR; 我如何使用扩展名着色扩展名定义的语法,而不是实际上是用户必须启用的颜色主题?
我正在尝试将这个Sublime Text插件(ToDone)移植到VSCode.
它为待办事项列表创建语法,然后使用语法突出显示来强调重要任务,静音已完成的任务等.
我发现"editor.tokenColorCustomizations",通过自定义颜色主题.当我在用户设置中使用它时,它可以使用新语法,但是当我package.json#contributes在扩展清单的部分中使用它时,它会失败.
{
"contributes": {
"languages": [
{
"id": "todone",
"aliases": [
"ToDone",
"To-Done"
],
"extensions": [
".todone",
".todo"
]
}
],
"grammars": [
{
"language": "todone",
"scopeName": "text.todone",
"path": "./todone.tmLanguage"
}
],
"configurationDefaults": {
"[todone]": {
"editor.insertSpaces": false,
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "symbol.definition.task-heading.todone",
"settings": {
"foreground": "#ff8800"
}
}
]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,语法似乎没问题 - 它正是Sublime插件正在使用的内容,并且正确应用了用户设置中的颜色.此外,设置的格式似乎正常,因为"editor.insertSpaces"正在应用并且颜色在用户设置中存在时正在工作.
最后,我在扩展package.json中'Warning' 'Unknown editor configuration …
syntax-highlighting visual-studio-code vscode-extensions vscode-settings
我想在Jest单元测试中扩充但不完全替换模拟构造函数的实例.
我想为实例添加一些值,但保持Jest的自动模拟优点.
例如:
A.js
module.exports = class A {
constructor(value) {
this.value = value;
}
getValue() {
return this.value;
}
}
Run Code Online (Sandbox Code Playgroud)
为了得到一些自动模拟真棒:
jest.mock('./A');
Run Code Online (Sandbox Code Playgroud)
使用automock,实例有一个模拟.getValue()方法,但它们没有.value属性.
// SomeClass.js
module.exports = class SomeClass {
m(a, b) {}
}
// OtherModule.test.js
jest.mock('./SomeClass'); // this happens automatically with automocking
const SomeClass = require('./SomeClass')
const mMock = jest.fn()
SomeClass.mockImplementation(() => {
return {
m: mMock
}
})
const some = new SomeClass()
some.m('a', 'b')
console.log('Calls to …Run Code Online (Sandbox Code Playgroud)