Skip to content

Commit 4560501

Browse files
committed
fix: fixes source.fixAll.xo code action on save
1 parent 74eeece commit 4560501

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

client/extension.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import {
1010
LanguageClient,
1111
TransportKind,
12-
type DocumentSelector,
1312
type LanguageClientOptions,
1413
type ServerOptions
1514
} from 'vscode-languageclient/node';
@@ -95,7 +94,7 @@ export async function activate(context: ExtensionContext) {
9594
// that may possibly affect the options xo should be using
9695
workspace.createFileSystemWatcher('**/.eslintignore'),
9796
workspace.createFileSystemWatcher('**/.xo-confi{g.cjs,g.json,g.js,g}'),
98-
workspace.createFileSystemWatcher('**/xo.confi{g.cjs,g.js,g}'),
97+
workspace.createFileSystemWatcher('**/xo.confi{g.cjs,g.js,g.ts,g.cts,g.mts}'),
9998
workspace.createFileSystemWatcher('**/package.json')
10099
].map((watcher) => watcher.onDidChange(restart)),
101100
/**

server/server.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as process from 'node:process';
22
import * as path from 'node:path';
33
import {
4+
type CodeAction,
45
createConnection,
56
ProposedFeatures,
67
TextDocuments,
@@ -17,7 +18,6 @@ import {
1718
type TextDocumentIdentifier,
1819
type DidChangeConfigurationParams,
1920
type TextDocumentChangeEvent,
20-
type CodeAction,
2121
type DocumentRangeFormattingParams
2222
} from 'vscode-languageserver/node';
2323
import {TextDocument} from 'vscode-languageserver-textdocument';
@@ -202,7 +202,11 @@ class LintServer {
202202
documentFormattingProvider: true,
203203
documentRangeFormattingProvider: true,
204204
codeActionProvider: {
205-
codeActionKinds: [CodeActionKind.QuickFix, CodeActionKind.SourceFixAll]
205+
codeActionKinds: [
206+
CodeActionKind.QuickFix,
207+
CodeActionKind.SourceFixAll,
208+
`${CodeActionKind.SourceFixAll}.xo`
209+
]
206210
}
207211
}
208212
};
@@ -345,14 +349,15 @@ class LintServer {
345349
}
346350

347351
const codeActions: CodeAction[] = [];
348-
if (
349-
context.only?.includes(CodeActionKind.SourceFixAll) || // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
350-
context.only?.includes(`${CodeActionKind.SourceFixAll}.xo`)
351-
) {
352+
353+
const isFixAll = context.only?.includes(CodeActionKind.SourceFixAll);
354+
const isFixAllXo = context.only?.includes(`${CodeActionKind.SourceFixAll}.xo`);
355+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
356+
if (isFixAll || isFixAllXo) {
352357
const fixes = await this.getDocumentFormatting(params.textDocument.uri);
353358
const codeAction: CodeAction = {
354359
title: 'Fix all XO auto-fixable problems',
355-
kind: CodeActionKind.SourceFixAll,
360+
kind: isFixAllXo ? `${CodeActionKind.SourceFixAll}.xo` : CodeActionKind.SourceFixAll,
356361
edit: {
357362
changes: {
358363
[document.uri]: fixes.edits

test/lsp/code-actions.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('Server code actions', async () => {
112112
assert.deepEqual(codeActions, [
113113
{
114114
title: 'Fix all XO auto-fixable problems',
115-
kind: 'source.fixAll',
115+
kind: 'source.fixAll.xo',
116116
edit: {changes: {uri: []}}
117117
}
118118
]);

test/lsp/initialization.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Server.handleInitialize', async () => {
1717
textDocumentSync: {openClose: true, change: 2},
1818
documentFormattingProvider: true,
1919
documentRangeFormattingProvider: true,
20-
codeActionProvider: {codeActionKinds: ['quickfix', 'source.fixAll']}
20+
codeActionProvider: {codeActionKinds: ['quickfix', 'source.fixAll', 'source.fixAll.xo']}
2121
}
2222
});
2323
});

0 commit comments

Comments
 (0)