From 6c73d7f7082cbf05db48b5742596f8eacf579e0d Mon Sep 17 00:00:00 2001 From: placatus Date: Fri, 1 Mar 2019 00:01:35 +0200 Subject: [PATCH] Fixed typos and other improvements per code review --- scripts/bundle.js | 3 +-- src/languageFeatures.ts | 2 +- src/monaco.contribution.ts | 29 +++++++++++++++++++---------- src/monaco.d.ts | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/scripts/bundle.js b/scripts/bundle.js index 6f39f345..bb9bfe13 100644 --- a/scripts/bundle.js +++ b/scripts/bundle.js @@ -58,9 +58,8 @@ function bundleOne(moduleId, exclude) { } function updateImports(moduleId) { - console.log(`ESM: updating relative imports paths for ${moduleId}...`); const filePath = path.join(REPO_ROOT, 'release/esm/' + moduleId + '.js'); - var fileContents = fs.readFileSync(filePath).toString(); + let fileContents = fs.readFileSync(filePath).toString(); fileContents = fileContents.replace(/vs\/basic-languages\//g, "../../basic-languages/"); fs.writeFileSync(filePath, fileContents); } \ No newline at end of file diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index c8dd261b..fed6a084 100644 --- a/src/languageFeatures.ts +++ b/src/languageFeatures.ts @@ -134,7 +134,7 @@ export class DiagnostcsAdapter extends Adapter { } } }); - let redoDiagosticsCallback = () => { + const redoDiagosticsCallback = () => { // redo diagnostics when options change for (const model of monaco.editor.getModels()) { onModelRemoved(model); diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index ee5972d2..336be899 100644 --- a/src/monaco.contribution.ts +++ b/src/monaco.contribution.ts @@ -27,12 +27,12 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript. private _languageId: string; private _eagerExtraLibSync: boolean = true; - constructor(langualgeId: string, compilerOptions: monaco.languages.typescript.CompilerOptions, diagnosticsOptions: monaco.languages.typescript.DiagnosticsOptions) { + constructor(languageId: string, compilerOptions: monaco.languages.typescript.CompilerOptions, diagnosticsOptions: monaco.languages.typescript.DiagnosticsOptions) { this._extraLibs = Object.create(null); this._workerMaxIdleTime = 2 * 60 * 1000; this.setCompilerOptions(compilerOptions); this.setDiagnosticsOptions(diagnosticsOptions); - this._languageId = langualgeId; + this._languageId = languageId; } get onDidChange(): IEvent { @@ -57,12 +57,14 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript. } if (this._extraLibs[filePath]) { - this._extraLibs[filePath].version++; - this._extraLibs[filePath].content = content; + if(this._extraLibs[filePath].content !== content) { + this._extraLibs[filePath].version++; + this._extraLibs[filePath].content = content; + } } else { this._extraLibs[filePath] = { content: content, - version: 1 + version: 1, }; } if (this._eagerExtraLibSync) { @@ -78,12 +80,14 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript. }; } - async syncExtraLibs() { + async syncExtraLibs(): Promise { try { let worker; - // we don't care if the get language worker fails. - // This happens because the worker initialzies much slower than the addExtraLib calls try { + // we don't care if the get language worker fails. + // This happens if addExtraLib is called before the worker has initialized. + // however, when the worker has finished downloading and initializes, + // it does so with the latest extraLibs so no sync issue can appear worker = await getLanguageWorker(this._languageId); } catch (ignored) { return; @@ -191,8 +195,13 @@ const languageDefaultOptions = { const languageDefaults: { [name: string]: LanguageServiceDefaultsImpl } = {}; -function setupLanguageServiceDefaults(languageId, isTypescript) { - const languageOptions = languageDefaultOptions[isTypescript ? "typescript" : "javascript"] +/** + * Generate the LanguageServiceDefaults for a new langauage with the given name + * @param languageId Name of the language + * @param isTypescriptBased Whether the language inherits from a typescript base or a javascript one + */ +function setupLanguageServiceDefaults(languageId: string, isTypescriptBased: boolean) { + const languageOptions = isTypescriptBased ? languageDefaultOptions.typescript : languageDefaultOptions.javascript; languageDefaults[languageId] = new LanguageServiceDefaultsImpl(languageId, languageOptions.compilerOptions, languageOptions.diagnosticsOptions); } diff --git a/src/monaco.d.ts b/src/monaco.d.ts index 44ae26d7..cc696a82 100644 --- a/src/monaco.d.ts +++ b/src/monaco.d.ts @@ -174,7 +174,7 @@ declare module monaco.languages.typescript { /** * If EagerExtraLibSync is disabled, call this to trigger the changes. */ - syncExtraLibs(): void; + syncExtraLibs(): Promise; } export var typescriptDefaults: LanguageServiceDefaults;