上一篇:使用Theia——建立插件html
extension/ data/ grammars go here lib/ ... src/ ... package.json ...
而后,在package.json文件中声明如下属性,这样新提供的语法能够与源代码和编译的文件一同发布。json
"files": [ "data", "lib", "src" ],
在扩展包中,咱们能够经过LanguageGrammarDefinitionContribution的contribution point来提供这一特性。服务器
@injectable() export class YourContribution implements LanguageGrammarDefinitionContribution { readonly id = 'languageId'; readonly scopeName = 'source.yourLanguage'; registerTextmateLanguage(registry: TextmateRegisty) { registry.registerTextmateGrammarScope(this.scopeName, { async getGrammarDefinition() { return { format: 'json', content: require('../data/yourGrammar.tmLanguage.json'), } } }); registry.mapLanguageIdToTextmateGrammar(this.id, this.scopeName); } }
若是使用.plist语法,则不能使用require来直接获取内容,由于Webpack将返回从服务器获取的文件的名称。这种状况下,能够使用下面的模式来获取文件的内容:async
@injectable() export class YourContribution implements LanguageGrammarDefinitionContribution { readonly id = 'languageId'; readonly scopeName = 'source.yourLanguage'; registerTextmateLanguage(registry: TextmateRegisty) { registry.registerTextmateGrammarScope(this.scopeName, { async getGrammarDefinition() { const response = await fetch(require('../data/yourGrammar.plist')); return { format: 'plist', content: await response.text(), } } }); registry.mapLanguageIdToTextmateGrammar(this.id, this.scopeName); } }