瀏覽代碼

Adds monaco models for the lib d.ts files

Co-authored-by: Wesley Wigham <wwigham@gmail.com>
Orta 5 年之前
父節點
當前提交
7a46ec2649
共有 2 個文件被更改,包括 8 次插入4 次删除
  1. 0 3
      src/tsWorker.ts
  2. 8 1
      src/workerManager.ts

+ 0 - 3
src/tsWorker.ts

@@ -73,9 +73,6 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, monaco.language
 		} else if (fileName in this._extraLibs) {
 			// extra lib
 			text = this._extraLibs[fileName].content;
-
-		} else if (fileName in libFileMap) {
-			text = libFileMap[fileName];
 		} else {
 			return;
 		}

+ 8 - 1
src/workerManager.ts

@@ -6,6 +6,7 @@
 
 import { LanguageServiceDefaultsImpl } from './monaco.contribution';
 import { TypeScriptWorker } from './tsWorker';
+import { libFileMap } from './lib/lib'
 
 import IDisposable = monaco.IDisposable;
 import Uri = monaco.Uri;
@@ -60,6 +61,12 @@ export class WorkerManager {
 
 	private _getClient(): Promise<TypeScriptWorker> {
 		if (!this._client) {
+			// Adds all of the .d.ts lib files into Monaco as editor models,
+			// this allows themm to show up in peek (and allow editing if desired).
+			for (const key in libFileMap) {
+				monaco.editor.createModel(libFileMap[key], "ts", monaco.Uri.file(key))
+			}
+
 			this._worker = monaco.editor.createWebWorker<TypeScriptWorker>({
 
 				// module that exports the create() method and returns a `TypeScriptWorker` instance
@@ -72,7 +79,7 @@ export class WorkerManager {
 				// passed in to the create() method
 				createData: {
 					compilerOptions: this._defaults.getCompilerOptions(),
-					extraLibs: this._defaults.getExtraLibs()
+					extraLibs: this._defaults.getExtraLibs(),
 				}
 			});