@@ -16,7 +16,8 @@ interface PackageManifest {
1616 commands ?: Array < { command : string } > ;
1717 configuration ?: { properties ?: Record < string , unknown > } ;
1818 configurationDefaults ?: Record < string , unknown > ;
19- grammars ?: Array < { scopeName : string ; injectTo ?: string [ ] ; path : string } > ;
19+ languages ?: Array < { id : string ; aliases ?: string [ ] ; filenames ?: string [ ] } > ;
20+ grammars ?: Array < { language ?: string ; scopeName : string ; injectTo ?: string [ ] ; path : string } > ;
2021 } ;
2122}
2223
@@ -70,6 +71,50 @@ test("associates the build.mcpp file with the C++ language", () => {
7071 assert . equal ( associations ?. [ "*.mcpp" ] , undefined ) ;
7172} ) ;
7273
74+ test ( "ships TOML highlighting for the exact mcpp.toml filename" , ( ) => {
75+ const manifest = JSON . parse ( readFileSync ( path . join ( root , "package.json" ) , "utf8" ) ) as PackageManifest ;
76+ const language = manifest . contributes ?. languages ?. find ( ( item ) => item . id === "mcpp-toml" ) ;
77+ assert . deepEqual ( language , {
78+ id : "mcpp-toml" ,
79+ aliases : [ "mcpp TOML" , "mcpp.toml" ] ,
80+ filenames : [ "mcpp.toml" ] ,
81+ } ) ;
82+
83+ const grammar = manifest . contributes ?. grammars ?. find ( ( item ) => item . language === "mcpp-toml" ) ;
84+ assert . deepEqual ( grammar , {
85+ language : "mcpp-toml" ,
86+ scopeName : "source.toml.mcpp" ,
87+ path : "./syntaxes/mcpp-toml.tmLanguage.json" ,
88+ } ) ;
89+
90+ const grammarText = readFileSync ( path . join ( root , "syntaxes/mcpp-toml.tmLanguage.json" ) , "utf8" ) ;
91+ const grammarDocument = JSON . parse ( grammarText ) as {
92+ repository ?: Record < string , { match ?: string } > ;
93+ } ;
94+ for ( const key of [ "comment" , "table" , "key" , "string" , "datetime" , "number" , "boolean" , "punctuation" ] ) {
95+ assert . ok ( grammarDocument . repository ?. [ key ] , `missing TOML grammar rule: ${ key } ` ) ;
96+ }
97+
98+ const tablePattern = new RegExp ( grammarDocument . repository ?. table . match ?? "" ) ;
99+ assert . match ( "[package]" , tablePattern ) ;
100+ assert . match ( "[[target.generated]]" , tablePattern ) ;
101+
102+ const keyPattern = new RegExp ( grammarDocument . repository ?. key . match ?? "" ) ;
103+ assert . match ( 'standard = "c++23"' , keyPattern ) ;
104+ assert . match ( '"quoted.key" = true' , keyPattern ) ;
105+
106+ for ( const scope of [
107+ "comment.line.number-sign.toml" ,
108+ "entity.name.section.toml" ,
109+ "variable.other.key.toml" ,
110+ "string.quoted.double.toml" ,
111+ "constant.numeric.toml" ,
112+ "constant.language.boolean.toml" ,
113+ ] ) {
114+ assert . match ( grammarText , new RegExp ( scope . replaceAll ( "." , "\\." ) ) ) ;
115+ }
116+ } ) ;
117+
73118test ( "ships an injection grammar with module-specific scopes" , ( ) => {
74119 const manifest = JSON . parse ( readFileSync ( path . join ( root , "package.json" ) , "utf8" ) ) as PackageManifest ;
75120 const grammar = manifest . contributes ?. grammars ?. find ( ( item ) => item . scopeName === "source.cpp.mcpp-modules" ) ;
0 commit comments