Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Version 5.3.0 (Unreleased)

- Fixed the statistics status bar to apply `todo.statistics.statusbar.alignment` and `todo.statistics.statusbar.priority` changes without requiring an extension reload.
- Fixed fulfilled promise batches so errors in optional rejection observers do not discard successful results.
- Fixed dependency indexing so one unreadable or removed Todo file no longer hides dependencies from other workspace files.
- Fixed embedded todo parsing for file paths that start with a number.
Expand Down
38 changes: 34 additions & 4 deletions src/statusbars/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class Statistics {
itemProps;
config;
tokens;
layout: {
alignment: vscode.StatusBarAlignment;
priority: number;
};

constructor() {
this.item = this._initItem();
Expand All @@ -19,14 +23,39 @@ class Statistics {
this.update();
}

_initItem() {
const alignment =
_getLayout() {
return {
alignment:
Config.getKey('statistics.statusbar.alignment') === 'right'
? vscode.StatusBarAlignment.Right
: vscode.StatusBarAlignment.Left,
priority = Config.getKey('statistics.statusbar.priority');
priority: Config.getKey('statistics.statusbar.priority'),
};
}

_initItem() {
const layout = this._getLayout();

this.layout = layout;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

layout is never declared as a class property. On current develop, both npm test and TypeScript compilation fail with TS2339 at this assignment and the reads in _updateLayout. Add the field (with an appropriate layout type) and rerun the full suite; I reproduced two failing statusbar specs after integration.


return vscode.window.createStatusBarItem(layout.alignment, layout.priority);
}

_updateLayout() {
const layout = this._getLayout();

if (
this.layout &&
this.layout.alignment === layout.alignment &&
this.layout.priority === layout.priority
)
return;

return vscode.window.createStatusBarItem(alignment, priority);
const previousItem = this.item;

this.item = this._initItem();
this.itemProps = {};
if (previousItem) previousItem.dispose();
}

_setItemProp(prop, value, _set = true) {
Expand All @@ -42,6 +71,7 @@ class Statistics {
}

update() {
this._updateLayout();
this.config = Config.get();
this.tokens = Utils.statistics.tokens.global;

Expand Down
97 changes: 97 additions & 0 deletions test/statusbar-layout-settings.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { expect } from 'chai';

function loadStatistics(settings) {
const NodeModule = require('module');
const originalLoad = NodeModule._load;
const statusItems = [];
const config = {
getKey(key) {
return settings[key];
},
get() {
return {
statistics: {
statusbar: {
alignment: settings.alignment,
priority: settings.priority,
enabled: true,
color: '',
command: '',
text: '',
tooltip: '',
},
},
};
},
};
const vscode = {
StatusBarAlignment: { Left: 'left', Right: 'right' },
window: {
createStatusBarItem(alignment, priority) {
const item = {
alignment,
priority,
show() {},
hide() {},
dispose() {
this.disposed = true;
},
};
statusItems.push(item);
return item;
},
activeTextEditor: {},
},
};
const utils = {
editor: { isSupported: () => true },
statistics: {
tokens: { global: {} },
condition: { is: () => true },
template: { render: (value) => value },
},
};
const subjectPath = require.resolve('../src/statusbars/statistics');
const cached = require.cache[subjectPath];

NodeModule._load = function (request, parent, isMain) {
if (request === 'vscode') return vscode;
if (request === '../config') return { default: config };
if (request === '../utils') return { default: utils };

return originalLoad.call(this, request, parent, isMain);
};

try {
delete require.cache[subjectPath];
return { instance: require(subjectPath).default, statusItems };
} finally {
NodeModule._load = originalLoad;
delete require.cache[subjectPath];
if (cached) require.cache[subjectPath] = cached;
}
}

describe('Status bar layout settings', () => {
it('applies alignment and priority changes to the live statistics item', () => {
const settings = {
alignment: 'left',
priority: 1,
'statistics.statusbar.alignment': 'left',
'statistics.statusbar.priority': 1,
'statistics.statusbar.enabled': true,
};
const { instance, statusItems } = loadStatistics(settings);

settings.alignment = 'right';
settings.priority = 42;
settings['statistics.statusbar.alignment'] = 'right';
settings['statistics.statusbar.priority'] = 42;
instance.update();

expect(statusItems).to.have.length(2);
expect(statusItems[0].disposed).to.equal(true);
expect(statusItems[1].alignment).to.equal('right');
expect(statusItems[1].priority).to.equal(42);
});
});