Skip to content

Commit

Permalink
feat: relevant statusbar
Browse files Browse the repository at this point in the history
  • Loading branch information
spence-s committed Sep 15, 2022
1 parent 2fd9c78 commit 60dce01
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 27 deletions.
7 changes: 5 additions & 2 deletions client/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ function activate(context) {
vscode.commands.executeCommand('workbench.action.reloadWindow');
}

statusBar();
statusBar(client);
});

context.subscriptions.push(statusBar());
vscode.workspace.onDidOpenTextDocument(() => statusBar(client));
vscode.workspace.onDidCloseTextDocument(() => statusBar(client));

context.subscriptions.push(statusBar(client));
}

function deactivate() {
Expand Down
39 changes: 28 additions & 11 deletions client/status-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,39 @@ const vscode = require('vscode');
let statusBar;

function updateStatusBar() {
const xoOptions = vscode.workspace.getConfiguration('xo');
const xoConfig = vscode.workspace.getConfiguration('xo');
const statusBarOption = xoConfig.get('statusBar');

statusBar = statusBar ? statusBar : vscode.window.createStatusBarItem('xoStatusBarItem', 2, 0);
if (statusBarOption === 'Never') {
if (statusBar) {
statusBar.hide();
}

statusBar.text = '$(xo-logo)';
return;
}

statusBar = statusBar ? statusBar : vscode.window.createStatusBarItem('xoStatusBarItem', 2, 0);
statusBar.text = '$(xo-logo)';
statusBar.command = 'xo.showOutputChannel';

// const foregroundColor = new vscode.ThemeColor('statusBarItem.foreground');
// const backgroundColor = new vscode.ThemeColor('statusBarItem.background');
// statusBar.color = foregroundColor;
// statusBar.backgroundColor = backgroundColor;
const showStatusBar = xoOptions.get('showStatusBar');

if (showStatusBar) statusBar.show();
else statusBar.hide();
const latestDocument = vscode.window.activeTextEditor?.document;
const fileTypes = xoConfig.get('validate', []);

const shouldShowStatusBar =
statusBarOption === 'Always' ||
(statusBarOption === 'Relevant' &&
vscode.workspace.textDocuments.find(
(textDocument) =>
(textDocument.fileName === latestDocument?.fileName &&
fileTypes.includes(textDocument.languageId)) ||
textDocument.fileName.startsWith('extension-output')
));

if (shouldShowStatusBar) {
statusBar.show();
} else {
statusBar.hide();
}

return statusBar;
}
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,16 @@
],
"description": "An array of languages with which to activate the plugin. Defaults: [ \"javascript\", \"javascriptreact\", \"typescript\", \"typescriptreact\" ]"
},
"xo.showStatusBar": {
"xo.statusBar": {
"scope": "resource",
"type": "boolean",
"default": true,
"description": "Show Status Bar"
"type": "string",
"enum": [
"Relevant",
"Always",
"Never"
],
"default": "Relevant",
"description": "When to show status bar item"
}
}
},
Expand Down
21 changes: 11 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ Reloads XO server.

## Settings

| Setting | Type | Default | Description |
| --------------------- | ---------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `xo.enable` | `boolean` | `true` | Turn the `xo` extension on and off in your workspace |
| `xo.format.enable` | `boolean` | `false` | Enable the `xo` extension to format documents. Requires `xo.enable` to be turned on. |
| `xo.validate` | `string[]` | "javascript", <br/> "javascriptreact", <br/> "typescript", <br/> "typescriptreact", <br/> "vue" | By default, the XO extension is configured to activate for Javascript, Javascript + React, Typescript, and Typescript + React. You may add more languages in the VS Code Settings. |
| `xo.options` | `object` | `null` | Supply any [xo option](https://github.com/xojs/xo#config). The options set here will override any configurations found by `xo` in your local workspace |
| `xo.overrideSeverity` | `info\|warning\|error` | `null` | XO extension will report all diagnostics in VSCode as the desired severity type. By default `xo` reports the severity type based on the linting rules set up in the local workspace |
| `xo.debounce` | `number` | 0 | You can adjust a debounce (in milliseconds) that helps optimize performance for large files. If you notice that lint results are jumping all over the place, or a long delay in fixing files, turn this up. The max is 350ms. |
| `xo.path` | `string` | `null` | If you want to resolve xo from a custom path - such as a global node_modules folder, supply an absolute or relative path (with respect to the workspace folder directory). Could use with Deno, yarn pnp, or to have the xo library lint itself. By default xo is resolved from the workspace folders node_modules directory. <br/><br/>examples:<br/>`"xo.path": "/path/to/node_modules/xo/index.js"` <br/> `"xo.path": "./node_modules/xo/index.js"` |
| `xo.runtime` | `string` | `null` | By default, VSCode starts xo with its own bundled nodejs version. This may cause different results from the cli if you are using a different version of node. You can set a runtime path so that you are always using the same node version. <br/><br/>example:<br/>`"xo.runtime": "/usr/local/bin/node"` |
| Setting | Type | Default | Description |
| --------------------- | ------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `xo.enable` | `boolean` | `true` | Turn the `xo` extension on and off in your workspace |
| `xo.format.enable` | `boolean` | `false` | Enable the `xo` extension to format documents. Requires `xo.enable` to be turned on. |
| `xo.validate` | `string[]` | "javascript", <br/> "javascriptreact", <br/> "typescript", <br/> "typescriptreact", <br/> "vue" | By default, the XO extension is configured to activate for Javascript, Javascript + React, Typescript, and Typescript + React. You may add more languages in the VS Code Settings. |
| `xo.options` | `object` | `null` | Supply any [xo option](https://github.com/xojs/xo#config). The options set here will override any configurations found by `xo` in your local workspace |
| `xo.overrideSeverity` | `info\|warning\|error` | `null` | XO extension will report all diagnostics in VSCode as the desired severity type. By default `xo` reports the severity type based on the linting rules set up in the local workspace |
| `xo.debounce` | `number` | 0 | You can adjust a debounce (in milliseconds) that helps optimize performance for large files. If you notice that lint results are jumping all over the place, or a long delay in fixing files, turn this up. The max is 350ms. |
| `xo.path` | `string` | `null` | If you want to resolve xo from a custom path - such as a global node_modules folder, supply an absolute or relative path (with respect to the workspace folder directory). Could use with Deno, yarn pnp, or to have the xo library lint itself. By default xo is resolved from the workspace folders node_modules directory. <br/><br/>examples:<br/>`"xo.path": "/path/to/node_modules/xo/index.js"` <br/> `"xo.path": "./node_modules/xo/index.js"` |
| `xo.runtime` | `string` | `null` | By default, VSCode starts xo with its own bundled nodejs version. This may cause different results from the cli if you are using a different version of node. You can set a runtime path so that you are always using the same node version. <br/><br/>example:<br/>`"xo.runtime": "/usr/local/bin/node"` |
| `xo.statusBar` | `Relevant\|Always\|Never` | `"Relevant"` | When to show the status bar icon. |

## Recent Updates

Expand Down

0 comments on commit 60dce01

Please sign in to comment.