mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 19:40:10 +01:00
Use C++ formatting for C++ splits in testdata files. (#7385)
Refactor the textmate grammar to use a different scope for testdata files. Move the existing handling for `CHECK:STDOUT:` there, and add handling for C++ file splits there too. Assisted-by: Gemini via Antigravity
This commit is contained in:
+1
-1
@@ -8,8 +8,8 @@ exports_files(
|
||||
[
|
||||
"package.json",
|
||||
"carbon.tmLanguage.json",
|
||||
"carbon-testdata.tmLanguage.json",
|
||||
"semir.tmLanguage.json",
|
||||
"carbon-check-test.tmLanguage.json",
|
||||
"language-configuration.json",
|
||||
"images/icon.png",
|
||||
],
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
||||
"scopeName": "source.carbon-check-test",
|
||||
"injectionSelector": "L:source.carbon",
|
||||
"patterns": [
|
||||
{
|
||||
"begin": "^(\\s*//\\s*CHECK:STDOUT:)",
|
||||
"beginCaptures": {
|
||||
"1": {
|
||||
"name": "comment.line.carbon"
|
||||
}
|
||||
},
|
||||
"end": "$",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "source.carbon-semir"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
||||
"name": "carbon-testdata",
|
||||
"scopeName": "source.carbon-testdata",
|
||||
"fileTypes": [],
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#cpp-file-splits"
|
||||
},
|
||||
{
|
||||
"include": "#check-stdout"
|
||||
},
|
||||
{
|
||||
"include": "source.carbon"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"cpp-file-splits": {
|
||||
"patterns": [
|
||||
{
|
||||
"comment": "C++ file split in test files",
|
||||
"begin": "^//\\s*---\\s*([^\\s]+\\.(h|hh|hpp|hxx|h\\+\\+|cpp|cc|cxx|c\\+\\+|c|H|HH|HPP|HXX|H\\+\\+|CPP|CC|CXX|C\\+\\+|C))\\s*$",
|
||||
"beginCaptures": {
|
||||
"0": { "name": "comment.line.carbon" }
|
||||
},
|
||||
"end": "^(?=//\\s*---)",
|
||||
"contentName": "meta.embedded.block.cpp",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "source.cpp"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"check-stdout": {
|
||||
"patterns": [
|
||||
{
|
||||
"comment": "Highlight compile output / SemIR in CHECK:STDOUT lines",
|
||||
"begin": "^(\\s*//\\s*CHECK:STDOUT:)",
|
||||
"beginCaptures": {
|
||||
"1": {
|
||||
"name": "comment.line.carbon"
|
||||
}
|
||||
},
|
||||
"end": "$",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "source.carbon-semir"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,16 @@
|
||||
"main": "./dist/extension.js",
|
||||
"contributes": {
|
||||
"languages": [
|
||||
{
|
||||
"id": "carbon-testdata",
|
||||
"aliases": [
|
||||
"Carbon Testdata"
|
||||
],
|
||||
"filenamePatterns": [
|
||||
"**/testdata/**/*.carbon"
|
||||
],
|
||||
"configuration": "./language-configuration.json"
|
||||
},
|
||||
{
|
||||
"id": "carbon",
|
||||
"aliases": [
|
||||
@@ -39,6 +49,11 @@
|
||||
}
|
||||
],
|
||||
"grammars": [
|
||||
{
|
||||
"language": "carbon-testdata",
|
||||
"scopeName": "source.carbon-testdata",
|
||||
"path": "./carbon-testdata.tmLanguage.json"
|
||||
},
|
||||
{
|
||||
"language": "carbon",
|
||||
"scopeName": "source.carbon",
|
||||
@@ -48,13 +63,6 @@
|
||||
"language": "semir",
|
||||
"scopeName": "source.carbon-semir",
|
||||
"path": "./semir.tmLanguage.json"
|
||||
},
|
||||
{
|
||||
"scopeName": "source.carbon-check-test",
|
||||
"path": "./carbon-check-test.tmLanguage.json",
|
||||
"injectTo": [
|
||||
"source.carbon"
|
||||
]
|
||||
}
|
||||
],
|
||||
"configuration": {
|
||||
|
||||
@@ -36,7 +36,7 @@ function updateSplitLineNumbers(editor: TextEditor | undefined) {
|
||||
return;
|
||||
}
|
||||
const document = editor.document;
|
||||
if (!document.fileName.includes('/testdata/')) {
|
||||
if (document.languageId !== 'carbon-testdata') {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,10 @@ export function activate(context: ExtensionContext) {
|
||||
};
|
||||
|
||||
const clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [{ language: 'carbon' }],
|
||||
documentSelector: [
|
||||
{ language: 'carbon' },
|
||||
{ language: 'carbon-testdata' },
|
||||
],
|
||||
};
|
||||
|
||||
// Create and start the client.
|
||||
|
||||
Reference in New Issue
Block a user