Skip to content

Commit

Permalink
Allow user to control whether top-bar info messages appear via
Browse files Browse the repository at this point in the history
showInformationMessages config
  • Loading branch information
Nick Giancola committed Nov 5, 2017
1 parent 37d2e1c commit d2227d4
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.5.1

## What's New
* Adds an `advancedNewFile.showInformationMessages` configuration option to
control whether top-bar notifications display. Enabled by default.

# 0.5.0

## What's New
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ files anywhere in your workspace.
* Additional option of adding `advancedNewFile.exclude` settings to workspace settings just like native `files.exlude` except it explicitly effects AdvancedNewFile plugin only. (thanks to [Kaffiend](https://github.com/Kaffiend))

## Configuration Example

```
"advancedNewFile": {
"exclude": {
"node_modules": true,
"node_modules_electron": true,
"dev": true,
"dist": true
}
},
"showInformationMessages": false
}
```

## Usage

* Command palette: "Advanced New File"
Expand Down
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,24 @@
"key": "alt+ctrl+n",
"mac": "alt+cmd+n"
}
]
],
"configuration": {
"type": "object",
"title": "AdvancedNewFile configuration",
"properties": {
"advancedNewFile.exclude": {
"type": ["object", "null"],
"additionalProperties": { "type": "boolean" },
"default": null,
"description": "Directories to ignore in auto-complete"
},
"advancedNewFile.showInformationMessages": {
"type": "boolean",
"default": true,
"description": "Control whether top-bar notifications display"
}
}
}
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
Expand Down
4 changes: 3 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ export function createFileOrFolder(absolutePath: string): string {

export function openFile(absolutePath: string): PromiseLike<string> {
if (isFolderDescriptor(absolutePath)) {
vscode.window.showInformationMessage(`Folder created: ${absolutePath}`);
if (vscode.workspace.getConfiguration('advancedNewFile').get('showInformationMessages', true)) {
vscode.window.showInformationMessage(`Folder created: ${absolutePath}`);
}
return Promise.resolve(absolutePath);
}

Expand Down
173 changes: 168 additions & 5 deletions test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,30 @@ describe('Advanced New File', () => {
});

describe('openFile', () => {
const mockGetConfiguration = function(config = { showInformationMessages: true }) {
return function(name) {
switch (name) {
case 'advancedNewFile':
return {
get: (configName) => config[configName]
};
default:
return {};
}
};
};

it('attempts to open the file', () => {
const textDocument = 'mock document';
const openTextDocument = chai.spy(() => Promise.resolve(textDocument));
const showTextDocument = chai.spy();

const advancedNewFile = proxyquire('../src/extension', {
vscode: {
workspace: { openTextDocument },
workspace: {
openTextDocument,
getConfiguration: mockGetConfiguration()
},
window: { showTextDocument }
}
});
Expand All @@ -305,7 +321,10 @@ describe('Advanced New File', () => {

const advancedNewFile = proxyquire('../src/extension', {
vscode: {
workspace: { openTextDocument },
workspace: {
openTextDocument,
getConfiguration: mockGetConfiguration()
},
window: { showTextDocument }
}
});
Expand All @@ -322,7 +341,10 @@ describe('Advanced New File', () => {

const advancedNewFile = proxyquire('../src/extension', {
vscode: {
workspace: { openTextDocument },
workspace: {
openTextDocument,
getConfiguration: mockGetConfiguration()
},
window: { showTextDocument }
}
});
Expand All @@ -340,7 +362,10 @@ describe('Advanced New File', () => {

const advancedNewFile = proxyquire('../src/extension', {
vscode: {
workspace: { openTextDocument },
workspace: {
openTextDocument,
getConfiguration: mockGetConfiguration()
},
window: { showTextDocument }
}
});
Expand All @@ -349,6 +374,73 @@ describe('Advanced New File', () => {
.to.eventually.be.rejectedWith('Could not open document');
});
});

context('file is a folder', () => {
it('does not attempt to open it', () => {
const openTextDocument = chai.spy();
const showInformationMessage = chai.spy();

const advancedNewFile = proxyquire('../src/extension', {
vscode: {
workspace: {
openTextDocument,
getConfiguration: mockGetConfiguration()
},
window: {
showInformationMessage
}
}
});

advancedNewFile.openFile('/path/to/folder/').then(() => {
expect(openTextDocument).not.to.have.been.called();
});
});

it('displays an informational message instead', () => {
const openTextDocument = chai.spy();
const showInformationMessage = chai.spy();

const advancedNewFile = proxyquire('../src/extension', {
vscode: {
workspace: {
openTextDocument,
getConfiguration: mockGetConfiguration()
},
window: {
showInformationMessage
}
}
});

advancedNewFile.openFile('/path/to/folder/').then(() => {
expect(showInformationMessage).to.have.been.called.with('Folder created: /path/to/folder/');
});
});

context('informational messages disabled in config', () => {
it('does not display an informational message', () => {
const openTextDocument = chai.spy();
const showInformationMessage = chai.spy();

const advancedNewFile = proxyquire('../src/extension', {
vscode: {
workspace: {
openTextDocument,
getConfiguration: mockGetConfiguration({ showInformationMessages: false })
},
window: {
showInformationMessage
}
}
});

advancedNewFile.openFile('/path/to/folder/').then(() => {
expect(showInformationMessage).not.to.have.been.called();
});
});
});
});
});

describe('cacheSelection', () => {
Expand Down Expand Up @@ -584,7 +676,7 @@ describe('Advanced New File', () => {
switch (name) {
case 'advancedNewFile':
return {
get: () => {}
get: (name, defaultValue) => defaultValue
};
default:
return {};
Expand Down Expand Up @@ -633,6 +725,77 @@ describe('Advanced New File', () => {
});
});

context('info messages disabled in settings', () => {
it('creates a folder at given path and does not show information ' +
'message', () => {
let command;
const registerCommand = (name, commandFn) => command = commandFn;

const textDocument = 'mock document';
const openTextDocument = chai.spy(() => Promise.resolve(textDocument));
const showTextDocument = chai.spy();
const showErrorMessage = chai.spy();
const showInformationMessage = chai.spy();

const advancedNewFile = proxyquire('../src/extension', {
vscode: {
commands: { registerCommand },
workspace: {
rootPath: tmpDir,
openTextDocument,
getConfiguration(name) {
switch (name) {
case 'advancedNewFile':
return {
get: (name, defaultValue) => false
};
default:
return {};
}
}
},
window: {
showErrorMessage,
showQuickPick: () => Promise.resolve({ label: 'path/to' }),
showInputBox: () => Promise.resolve('input/path/to/folder/'),
showInformationMessage,
showTextDocument
}
},
fs: {
statSync: () => {
return { isDirectory: () => true };
}
},
'vscode-cache': class Cache {
get() {}
has() { return false }
put() {}
}
});

const context = { subscriptions: [] };

advancedNewFile.activate(context);

const newFolderDescriptor =
path.join(tmpDir, 'path/to/input/path/to/folder/');

return command().then(() => {
expect(openTextDocument)
.to.not.have.been.called.with(newFolderDescriptor);

expect(showTextDocument)
.to.not.have.been.called.with(textDocument);

expect(showInformationMessage).to.not.have.been.called();

expect(fs.statSync(newFolderDescriptor).isDirectory())
.to.be.true;
});
});
});

context('no project opened in workspace', () => {
it('shows an error message', () => {
let command;
Expand Down

0 comments on commit d2227d4

Please sign in to comment.