浏览代码

Adopt monaco-editor-core that doesn't register html

Alex Dima 8 年之前
父节点
当前提交
83bf09fbef
共有 4 个文件被更改,包括 15 次插入3 次删除
  1. 1 1
      package.json
  2. 10 1
      src/monaco.contribution.ts
  3. 2 1
      src/php.ts
  4. 2 0
      test/php.test.ts

+ 1 - 1
package.json

@@ -26,7 +26,7 @@
     "jsdom-no-contextify": "^3.1.0",
     "merge-stream": "^1.0.0",
     "mocha": "^2.5.3",
-    "monaco-editor-core": "0.7.0",
+    "monaco-editor-core": "0.7.0-next.2",
     "object-assign": "^4.1.0",
     "rimraf": "^2.5.2",
     "typescript": "^1.8.10",

+ 10 - 1
src/monaco.contribution.ts

@@ -20,7 +20,7 @@ interface ILangImpl {
 
 let languageDefinitions:{[languageId:string]:ILang} = {};
 
-export function loadLanguage(languageId:string): monaco.Promise<void> {
+function _loadLanguage(languageId:string): monaco.Promise<void> {
 	let module = languageDefinitions[languageId].module;
 	return new _monaco.Promise<void>((c, e, p) => {
 		require<ILangImpl>([module], (mod) => {
@@ -31,6 +31,15 @@ export function loadLanguage(languageId:string): monaco.Promise<void> {
 	});
 }
 
+let languagePromises:{[languageId:string]: monaco.Promise<void>} = {};
+
+export function loadLanguage(languageId:string): monaco.Promise<void> {
+	if (!languagePromises[languageId]) {
+		languagePromises[languageId] = _loadLanguage(languageId);
+	}
+	return languagePromises[languageId];
+}
+
 function registerLanguage(def:ILang): void {
 	let languageId = def.id;
 

+ 2 - 1
src/php.ts

@@ -35,6 +35,7 @@ export const htmlTokenTypes = {
 	DELIM_START: 'start.delimiter.tag.html',
 	DELIM_END: 'end.delimiter.tag.html',
 	DELIM_COMMENT: 'comment.html',
+	COMMENT: 'comment.content.html',
 	getTag: (name: string) => {
 		return 'tag.html';
 	}
@@ -43,7 +44,7 @@ export const htmlTokenTypes = {
 export var language = <ILanguage> {
 	defaultToken: '',
 	tokenPostfix: '',
-	ignoreCase: true,
+	// ignoreCase: true,
 
 	// The main tokenizer for our languages
 	tokenizer: {

+ 2 - 0
test/php.test.ts

@@ -1840,6 +1840,8 @@ testTokenization(['php', 'css'], [
 	line: '<!--c--><?',
 	tokens: [
 		{ startIndex:0, type: htmlTokenTypes.DELIM_COMMENT },
+		{ startIndex:4, type: htmlTokenTypes.COMMENT },
+		{ startIndex:5, type: htmlTokenTypes.DELIM_COMMENT },
 		{ startIndex:8, type: 'metatag.php' }
 	]}],