瀏覽代碼

Fix microsoft/monaco-editor#858 C++ includes

Peng Lyu 7 年之前
父節點
當前提交
7eb290dff4
共有 2 個文件被更改,包括 15 次插入6 次删除
  1. 8 6
      src/cpp/cpp.test.ts
  2. 7 0
      src/cpp/cpp.ts

+ 8 - 6
src/cpp/cpp.test.ts

@@ -391,17 +391,19 @@ testTokenization('cpp', [
 	[{
 		line: '#include<iostream>',
 		tokens: [
-			{ startIndex: 0, type: 'keyword.cpp' },
-			{ startIndex: 8, type: 'delimiter.angle.cpp' },
-			{ startIndex: 9, type: 'identifier.cpp' },
-			{ startIndex: 17, type: 'delimiter.angle.cpp' }
+			{ startIndex: 0, type: 'keyword.directive.include.cpp' },
+			{ startIndex: 8, type: 'keyword.directive.include.begin.cpp' },
+			{ startIndex: 9, type: 'string.include.identifier.cpp' },
+			{ startIndex: 17, type: 'keyword.directive.include.end.cpp' }
 		]
 	}, {
 		line: '#include "/path/to/my/file.h"',
 		tokens: [
-			{ startIndex: 0, type: 'keyword.cpp' },
+			{ startIndex: 0, type: 'keyword.directive.include.cpp' },
 			{ startIndex: 8, type: '' },
-			{ startIndex: 9, type: 'string.cpp' }
+			{ startIndex: 9, type: 'keyword.directive.include.begin.cpp' },
+			{ startIndex: 10, type: 'string.include.identifier.cpp' },
+			{ startIndex: 28, type: 'keyword.directive.include.end.cpp' }
 		]
 	}, {
 		line: '',

+ 7 - 0
src/cpp/cpp.ts

@@ -268,6 +268,8 @@ export const language = <ILanguage>{
 			// [[ attributes ]].
 			[/\[\[.*\]\]/, 'annotation'],
 
+			[/^\s*#include/, { token: 'keyword.directive.include', next: '@include' }],
+
 			// Preprocessor directive
 			[/^\s*#\s*\w+/, 'keyword'],
 
@@ -338,6 +340,11 @@ export const language = <ILanguage>{
 				}
 			],
 			[/.*/, 'string.raw']
+		],
+
+		include: [
+			[/(\s*)(<)([^<>]*)(>)/, ['', 'keyword.directive.include.begin', 'string.include.identifier', { token: 'keyword.directive.include.end', next: '@pop'}]],
+			[/(\s*)(")([^"]*)(")/, ['', 'keyword.directive.include.begin', 'string.include.identifier', { token: 'keyword.directive.include.end', next: '@pop'}]]
 		]
 	},
 };