Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow for multiple languages #116

Merged
merged 1 commit into from
Jul 24, 2022
Merged
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
28 changes: 18 additions & 10 deletions client/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
const isSANB = require('is-string-and-not-blank');

let client;
let validate;

const AllFixesRequest = {
type: new RequestType('textDocument/xo/allFixes')
Expand Down Expand Up @@ -43,17 +44,17 @@ function activate(context) {
}
};

validate = JSON.stringify(xoOptions.get('validate'));
const documentSelector = [];
for (const language of xoOptions.get('validate')) {
documentSelector.push(
{language, scheme: 'file'},
{language, scheme: 'untitled'}
);
}

const clientOptions = {
documentSelector: [
{language: 'javascript', scheme: 'file'},
{language: 'javascript', scheme: 'untitled'},
{language: 'javascriptreact', scheme: 'file'},
{language: 'javascriptreact', scheme: 'untitled'},
{language: 'typescript', scheme: 'file'},
{language: 'typescript', scheme: 'untitled'},
{language: 'typescriptreact', scheme: 'file'},
{language: 'typescriptreact', scheme: 'untitled'}
],
documentSelector,
synchronize: {
configurationSection: 'xo',
fileEvents: [
Expand All @@ -79,6 +80,13 @@ function activate(context) {
})
);

vscode.workspace.onDidChangeConfiguration(() => {
const xoOptions = vscode.workspace.getConfiguration('xo');
if (validate !== JSON.stringify(xoOptions.get('validate'))) {
vscode.commands.executeCommand('workbench.action.reloadWindow');
}
});

const statusBar = vscode.window.createStatusBarItem('xoStatusBarItem', 2, 0);
statusBar.text = 'XO';
statusBar.command = 'xo.showOutputChannel';
Expand Down
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@
],
"default": null,
"description": "Absolute path to a node binary to run the xo server, defaults to VSCode's internally bundled node version."
},
"xo.validate": {
"scope": "resource",
"type": "array",
"items": {
"type": "string"
},
"default": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"description": "An array of languages with which to activate the plugin. Defaults: [ \"javascript\", \"javascriptreact\", \"typescript\", \"typescriptreact\" ]"
}
}
},
Expand Down
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ To use: pull up the command pallete (usually `F1` or `Ctrl + Shift + P`) and cho

![](media/fix.gif)

## Additional Languages

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. For example, to add Vue, you could do the following:

```json
{
"xo.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue"
]
}
```

## Settings

Enable the linter in the VS Code Settings, this is on by default.
Expand Down