From d00358daeadc4c51fe781b7a361d6a02f12d15fc Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Sat, 26 Aug 2017 13:20:28 -0700 Subject: [PATCH] Add error msg when extensionsPath is not found --- package.json | 4 ++-- src/emmetHelper.ts | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 209917c..2f66aee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vscode-emmet-helper", - "version": "1.0.19", + "version": "1.0.20", "description": "Helper to use emmet modules in Visual Studio Code", "main": "./out/emmetHelper.js", "types": "./out/emmetHelper.d.ts", @@ -24,7 +24,7 @@ "vscode-languageserver-types": "^3.0.3" }, "scripts": { - "prepublish": "npm run compile", + "prepublish": "npm run compile && npm run test", "compile": "tsc -p ./ && cpy ./src/expand/*.js ./out/expand", "test": "mocha out/test" } diff --git a/src/emmetHelper.ts b/src/emmetHelper.ts index 257dac1..24cd4fa 100644 --- a/src/emmetHelper.ts +++ b/src/emmetHelper.ts @@ -444,13 +444,18 @@ function getVariables(variablesFromSettings: object): any { * Updates customizations from snippets.json and syntaxProfiles.json files in the directory configured in emmet.extensionsPath setting */ export function updateExtensionsPath(emmetExtensionsPath: string): Promise { - if (!emmetExtensionsPath || !emmetExtensionsPath.trim() || !path.isAbsolute(emmetExtensionsPath.trim()) || !dirExists(emmetExtensionsPath.trim())) { - customSnippetRegistry = {}; - snippetKeyCache.clear(); - profilesFromFile = {}; - variablesFromFile = {}; + if (!emmetExtensionsPath || !emmetExtensionsPath.trim()) { + resetSettingsFromFile(); return Promise.resolve(); } + if (!path.isAbsolute(emmetExtensionsPath.trim())) { + resetSettingsFromFile(); + return Promise.reject('The path provided in emmet.extensionsPath setting should be absoulte path'); + } + if (!dirExists(emmetExtensionsPath.trim())) { + resetSettingsFromFile(); + return Promise.reject(`The directory ${emmetExtensionsPath.trim()} doesnt exist. Update emmet.extensionsPath setting`); + } let dirPath = emmetExtensionsPath.trim(); let snippetsPath = path.join(dirPath, 'snippets.json'); @@ -516,6 +521,13 @@ function dirExists(dirPath: string): boolean { } } +function resetSettingsFromFile(){ + customSnippetRegistry = {}; + snippetKeyCache.clear(); + profilesFromFile = {}; + variablesFromFile = {}; +} + /** * Get the corresponding emmet mode for given vscode language mode * Eg: jsx for typescriptreact/javascriptreact or pug for jade