Skip to content

Commit

Permalink
Merge pull request #20 from tahabasri/feature/fix-default-path-18
Browse files Browse the repository at this point in the history
Fix default path availability.
  • Loading branch information
tahabasri authored Apr 21, 2021
2 parents 93f8cb4 + f06b935 commit d270c96
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "snippets",
"displayName": "Snippets",
"description": "Manage your code snippets without quitting your editor.",
"version": "1.1.0",
"version": "1.1.1",
"preview": true,
"license": "SEE LICENSE IN LICENSE.txt",
"publisher": "tahabasri",
Expand Down
4 changes: 2 additions & 2 deletions src/config/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const enum Labels {
snippetFolderNameErrorMsg = "Snippet folder must have a non-empty name.",

snippetsDefaultPath = "Snippets will be saved to default location [{0}].",
snippetsInvalidPath = "Snippets path is not a valid JSON file, will revert back to default location [{0}].",
snippetsInvalidPath = "Snippets path [{0}] is not a valid JSON file, will revert back to default location [{1}].",
snippetsChangedPath = "Snippets location changed to [{0}]",
snippetsInvalidNewPath = "Snippets path is not a valid JSON file, will revert back to old location [{0}].",
snippetsInvalidNewPath = "Snippets path [{0}] is not a valid JSON file, will revert back to old location [{1}].",
snippetsNoNewPath = "Snippets will be saved to old location [{0}].",
}
23 changes: 17 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { ConfigurationTarget } from 'vscode';

export function activate(context: vscode.ExtensionContext) {
const defaultSnippetsPath = DataAccess.resolveFilename(context.globalStorageUri.fsPath);
// default snippets path should always be available
if (!fs.existsSync(context.globalStorageUri.fsPath)) {
fs.mkdirSync(context.globalStorageUri.fsPath);
}

const snippetsPathConfigKey = 'snippetsLocation';

// to be enabled whenever an explicit configuration update is requested (e.g getConfiguration#update)
Expand All @@ -27,12 +32,18 @@ export function activate(context: vscode.ExtensionContext) {
explicitUpdate = true;
// show different message depending on the state of settings :
// - show Labels.snippetsDefaultPath if there was no entry in settings
// - show Labels.snippetsDefaultPath if default path was mentionned in settings but wasn't available
// - show Labels.snippetsInvalidPath if there was an entry but it is not a valid JSON file
vscode.window.showInformationMessage(
StringUtility.formatString(
snippetsPath === "" ? Labels.snippetsDefaultPath : Labels.snippetsInvalidPath,
defaultSnippetsPath)
);
if (snippetsPath === "" || snippetsPath === defaultSnippetsPath) {
vscode.window.showInformationMessage(
StringUtility.formatString(Labels.snippetsDefaultPath, defaultSnippetsPath)
);
}else{
vscode.window.showInformationMessage(
StringUtility.formatString(Labels.snippetsInvalidPath, snippetsPath, defaultSnippetsPath)
);
}


snippetsPath = defaultSnippetsPath;
}
Expand Down Expand Up @@ -60,7 +71,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.window.showErrorMessage(error.message);
vscode.workspace.getConfiguration('snippets').update(snippetsPathConfigKey, snippetsPath, ConfigurationTarget.Global);
explicitUpdate = true;
vscode.window.showWarningMessage(StringUtility.formatString(Labels.snippetsInvalidNewPath, snippetsPath));
vscode.window.showWarningMessage(StringUtility.formatString(Labels.snippetsInvalidNewPath, newPath, snippetsPath));
}
} else {
// no new path given, fall back to default location
Expand Down

0 comments on commit d270c96

Please sign in to comment.