@lsproxy/polyfill 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/fix-all.d.ts.map +1 -1
- package/dist/fix-all.js +7 -49
- package/dist/fix-all.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/organize-imports.d.ts +3 -0
- package/dist/organize-imports.d.ts.map +1 -0
- package/dist/organize-imports.js +53 -0
- package/dist/organize-imports.js.map +1 -0
- package/dist/quickfix-aggregation.d.ts +18 -0
- package/dist/quickfix-aggregation.d.ts.map +1 -0
- package/dist/quickfix-aggregation.js +92 -0
- package/dist/quickfix-aggregation.js.map +1 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +6 -1
- package/dist/registry.js.map +1 -1
- package/package.json +10 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Pradeep Mouli
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/fix-all.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix-all.d.ts","sourceRoot":"","sources":["../src/fix-all.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fix-all.d.ts","sourceRoot":"","sources":["../src/fix-all.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AA2BrD,eAAO,MAAM,MAAM,EAAE,kBA8BpB,CAAC"}
|
package/dist/fix-all.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { aggregateQuickFixes, isCodeAction } from './quickfix-aggregation.js';
|
|
1
2
|
function hasDiagnosticProvider(capabilities) {
|
|
2
3
|
return Boolean(capabilities.diagnosticProvider);
|
|
3
4
|
}
|
|
@@ -13,32 +14,10 @@ function requestsFixAll(params) {
|
|
|
13
14
|
return false;
|
|
14
15
|
return only.some((kind) => kind === 'source.fixAll' || kind === 'source');
|
|
15
16
|
}
|
|
16
|
-
function isCodeAction(item) {
|
|
17
|
-
return typeof item.command !== 'string';
|
|
18
|
-
}
|
|
19
17
|
function pickFix(candidates) {
|
|
20
18
|
const actions = candidates.filter(isCodeAction);
|
|
21
19
|
return actions.find((a) => a.isPreferred) ?? actions[0];
|
|
22
20
|
}
|
|
23
|
-
function supportsResolve(capabilities) {
|
|
24
|
-
const provider = capabilities.codeActionProvider;
|
|
25
|
-
return typeof provider === 'object' && provider.resolveProvider === true;
|
|
26
|
-
}
|
|
27
|
-
function comparePositions(a, b) {
|
|
28
|
-
return a.line !== b.line ? a.line - b.line : a.character - b.character;
|
|
29
|
-
}
|
|
30
|
-
function rangesOverlap(a, b) {
|
|
31
|
-
return comparePositions(a.start, b.end) < 0 && comparePositions(b.start, a.end) < 0;
|
|
32
|
-
}
|
|
33
|
-
function mergeEdits(existing, incoming) {
|
|
34
|
-
const merged = [...existing];
|
|
35
|
-
for (const edit of incoming) {
|
|
36
|
-
if (merged.some((m) => rangesOverlap(m.range, edit.range)))
|
|
37
|
-
continue;
|
|
38
|
-
merged.push(edit);
|
|
39
|
-
}
|
|
40
|
-
return merged;
|
|
41
|
-
}
|
|
42
21
|
export const fixAll = {
|
|
43
22
|
id: 'fix-all',
|
|
44
23
|
appliesTo(capabilities) {
|
|
@@ -49,33 +28,12 @@ export const fixAll = {
|
|
|
49
28
|
async augmentCodeActions(actions, params, backend) {
|
|
50
29
|
if (!requestsFixAll(params))
|
|
51
30
|
return actions;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const candidates = (await backend.sendRequest('textDocument/codeAction', {
|
|
59
|
-
textDocument: params.textDocument,
|
|
60
|
-
range: diagnostic.range,
|
|
61
|
-
context: { diagnostics: [diagnostic], only: ['quickfix'] }
|
|
62
|
-
}));
|
|
63
|
-
let fix = candidates ? pickFix(candidates) : undefined;
|
|
64
|
-
if (fix && !fix.edit?.changes && fix.command && supportsResolve(capabilities)) {
|
|
65
|
-
fix = (await backend.sendRequest('codeAction/resolve', fix));
|
|
66
|
-
}
|
|
67
|
-
if (!fix?.edit?.changes)
|
|
68
|
-
continue;
|
|
69
|
-
let mergedAny = false;
|
|
70
|
-
for (const [uri, edits] of Object.entries(fix.edit.changes)) {
|
|
71
|
-
if (edits.length === 0)
|
|
72
|
-
continue;
|
|
73
|
-
changes[uri] = mergeEdits(changes[uri] ?? [], edits);
|
|
74
|
-
mergedAny = true;
|
|
75
|
-
}
|
|
76
|
-
if (mergedAny)
|
|
77
|
-
mergedCount += 1;
|
|
78
|
-
}
|
|
31
|
+
// The backend may implement source.fixAll without advertising it in
|
|
32
|
+
// codeActionKinds (e.g. codeActionProvider: true with no explicit kind
|
|
33
|
+
// list) — if it already returned one, don't synthesize a duplicate.
|
|
34
|
+
if (actions.some((a) => a.kind === 'source.fixAll'))
|
|
35
|
+
return actions;
|
|
36
|
+
const { changes, mergedCount } = await aggregateQuickFixes(params, backend, pickFix);
|
|
79
37
|
if (mergedCount === 0)
|
|
80
38
|
return actions;
|
|
81
39
|
return [
|
package/dist/fix-all.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix-all.js","sourceRoot":"","sources":["../src/fix-all.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fix-all.js","sourceRoot":"","sources":["../src/fix-all.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9E,SAAS,qBAAqB,CAAC,YAAgC;IAC7D,OAAO,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,uBAAuB,CAAC,YAAgC;IAC/D,MAAM,QAAQ,GAAG,YAAY,CAAC,kBAAkB,CAAC;IACjD,OAAO,CACL,OAAO,QAAQ,KAAK,QAAQ;QAC5B,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;QACvC,QAAQ,CAAC,eAAe,CAAC,QAAQ,CAAC,eAAwB,CAAC,CAC5D,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,MAAwB;IAC9C,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;IACjC,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IACxB,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,eAAe,IAAI,IAAI,KAAK,QAAQ,CAAC,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from './resolve-backfill.js';
|
|
3
3
|
export { fixAll } from './fix-all.js';
|
|
4
|
+
export { organizeImports } from './organize-imports.js';
|
|
4
5
|
export { BUILTIN_POLYFILLS, applicablePolyfills } from './registry.js';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organize-imports.d.ts","sourceRoot":"","sources":["../src/organize-imports.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAiCrD,eAAO,MAAM,eAAe,EAAE,kBA8B7B,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { aggregateQuickFixes, isCodeAction } from './quickfix-aggregation.js';
|
|
2
|
+
function hasDiagnosticProvider(capabilities) {
|
|
3
|
+
return Boolean(capabilities.diagnosticProvider);
|
|
4
|
+
}
|
|
5
|
+
function alreadyAdvertisesOrganizeImports(capabilities) {
|
|
6
|
+
const provider = capabilities.codeActionProvider;
|
|
7
|
+
return (typeof provider === 'object' &&
|
|
8
|
+
Array.isArray(provider.codeActionKinds) &&
|
|
9
|
+
provider.codeActionKinds.includes('source.organizeImports'));
|
|
10
|
+
}
|
|
11
|
+
function requestsOrganizeImports(params) {
|
|
12
|
+
const only = params.context.only;
|
|
13
|
+
if (!only)
|
|
14
|
+
return false;
|
|
15
|
+
return only.some((kind) => kind === 'source.organizeImports' || kind === 'source');
|
|
16
|
+
}
|
|
17
|
+
const IMPORT_FIX_TITLE = /import/i;
|
|
18
|
+
function isImportRelatedFix(action) {
|
|
19
|
+
return IMPORT_FIX_TITLE.test(action.title);
|
|
20
|
+
}
|
|
21
|
+
function pickImportFix(candidates) {
|
|
22
|
+
const actions = candidates.filter(isCodeAction).filter(isImportRelatedFix);
|
|
23
|
+
return actions.find((a) => a.isPreferred) ?? actions[0];
|
|
24
|
+
}
|
|
25
|
+
export const organizeImports = {
|
|
26
|
+
id: 'organize-imports',
|
|
27
|
+
appliesTo(capabilities) {
|
|
28
|
+
return (Boolean(capabilities.codeActionProvider) &&
|
|
29
|
+
hasDiagnosticProvider(capabilities) &&
|
|
30
|
+
!alreadyAdvertisesOrganizeImports(capabilities));
|
|
31
|
+
},
|
|
32
|
+
async augmentCodeActions(actions, params, backend) {
|
|
33
|
+
if (!requestsOrganizeImports(params))
|
|
34
|
+
return actions;
|
|
35
|
+
// The backend may implement source.organizeImports without advertising
|
|
36
|
+
// it in codeActionKinds (e.g. codeActionProvider: true with no explicit
|
|
37
|
+
// kind list) — if it already returned one, don't synthesize a duplicate.
|
|
38
|
+
if (actions.some((a) => a.kind === 'source.organizeImports'))
|
|
39
|
+
return actions;
|
|
40
|
+
const { changes, mergedCount } = await aggregateQuickFixes(params, backend, pickImportFix);
|
|
41
|
+
if (mergedCount === 0)
|
|
42
|
+
return actions;
|
|
43
|
+
return [
|
|
44
|
+
...actions,
|
|
45
|
+
{
|
|
46
|
+
title: 'Organize imports',
|
|
47
|
+
kind: 'source.organizeImports',
|
|
48
|
+
edit: { changes }
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=organize-imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organize-imports.js","sourceRoot":"","sources":["../src/organize-imports.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9E,SAAS,qBAAqB,CAAC,YAAgC;IAC7D,OAAO,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,gCAAgC,CAAC,YAAgC;IACxE,MAAM,QAAQ,GAAG,YAAY,CAAC,kBAAkB,CAAC;IACjD,OAAO,CACL,OAAO,QAAQ,KAAK,QAAQ;QAC5B,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;QACvC,QAAQ,CA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AAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,wBAAwB,CAAC;YAAE,OAAO,OAAO,CAAC;QAE7E,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,mBAAmB,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;QAC3F,IAAI,WAAW,KAAK,CAAC;YAAE,OAAO,OAAO,CAAC;QAEtC,OAAO;YACL,GAAG,OAAO;YACV;gBACE,KAAK,EAAE,kBAAkB;gBACzB,IAAI,EAAE,wBAAwB;gBAC9B,IAAI,EAAE,EAAE,OAAO,EAAE;aAClB;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CodeAction, CodeActionParams, Command, Position, TextEdit } from '@lspeasy/core';
|
|
2
|
+
import type { LSPClient } from '@lspeasy/client';
|
|
3
|
+
export declare function isCodeAction(item: Command | CodeAction): item is CodeAction;
|
|
4
|
+
export declare function comparePositions(a: Position, b: Position): number;
|
|
5
|
+
export declare function rangesOverlap(a: TextEdit['range'], b: TextEdit['range']): boolean;
|
|
6
|
+
export declare function mergeEdits(existing: TextEdit[], incoming: TextEdit[]): TextEdit[];
|
|
7
|
+
export interface AggregationResult {
|
|
8
|
+
changes: Record<string, TextEdit[]>;
|
|
9
|
+
mergedCount: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Fetches diagnostics for the document, requests a `quickfix` for each one,
|
|
13
|
+
* lets `selectFix` choose which candidate (if any) to keep, resolves
|
|
14
|
+
* command-only fixes via `codeAction/resolve` when the backend supports it,
|
|
15
|
+
* and merges every chosen fix's edits into one non-overlapping edit map.
|
|
16
|
+
*/
|
|
17
|
+
export declare function aggregateQuickFixes(params: CodeActionParams, backend: LSPClient, selectFix: (candidates: (Command | CodeAction)[]) => CodeAction | undefined): Promise<AggregationResult>;
|
|
18
|
+
//# sourceMappingURL=quickfix-aggregation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickfix-aggregation.d.ts","sourceRoot":"","sources":["../src/quickfix-aggregation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,UAAU,EACV,gBAAgB,EAChB,OAAO,EAIP,QAAQ,EAKR,QAAQ,EAET,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,IAAI,UAAU,CAE3E;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,MAAM,CAEjE;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,OAAO,CAEjF;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAOjF;AAkDD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,SAAS,EAClB,SAAS,EAAE,CAAC,UAAU,EAAE,CAAC,OAAO,GAAG,UAAU,CAAC,EAAE,KAAK,UAAU,GAAG,SAAS,GAC1E,OAAO,CAAC,iBAAiB,CAAC,CAwC5B"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export function isCodeAction(item) {
|
|
2
|
+
return typeof item.command !== 'string';
|
|
3
|
+
}
|
|
4
|
+
export function comparePositions(a, b) {
|
|
5
|
+
return a.line !== b.line ? a.line - b.line : a.character - b.character;
|
|
6
|
+
}
|
|
7
|
+
export function rangesOverlap(a, b) {
|
|
8
|
+
return comparePositions(a.start, b.end) < 0 && comparePositions(b.start, a.end) < 0;
|
|
9
|
+
}
|
|
10
|
+
export function mergeEdits(existing, incoming) {
|
|
11
|
+
const merged = [...existing];
|
|
12
|
+
for (const edit of incoming) {
|
|
13
|
+
if (merged.some((m) => rangesOverlap(m.range, edit.range)))
|
|
14
|
+
continue;
|
|
15
|
+
merged.push(edit);
|
|
16
|
+
}
|
|
17
|
+
return merged;
|
|
18
|
+
}
|
|
19
|
+
function supportsResolve(capabilities) {
|
|
20
|
+
const provider = capabilities.codeActionProvider;
|
|
21
|
+
return typeof provider === 'object' && provider.resolveProvider === true;
|
|
22
|
+
}
|
|
23
|
+
function isTextDocumentEdit(entry) {
|
|
24
|
+
return 'edits' in entry;
|
|
25
|
+
}
|
|
26
|
+
function isPlainTextEdit(edit) {
|
|
27
|
+
return 'newText' in edit;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Merges a WorkspaceEdit's edits into one per-URI map, reading both the
|
|
31
|
+
* legacy `changes` field and the newer `documentChanges` field (many modern
|
|
32
|
+
* servers — rust-analyzer, newer tsserver-based tooling — return edits
|
|
33
|
+
* exclusively via the latter). Resource operations (create/rename/delete)
|
|
34
|
+
* and snippet edits are intentionally skipped: neither can be represented
|
|
35
|
+
* as a plain `TextEdit` in the synthesized composite action.
|
|
36
|
+
*/
|
|
37
|
+
function collectEditsByUri(edit) {
|
|
38
|
+
const byUri = {};
|
|
39
|
+
for (const [uri, edits] of Object.entries(edit?.changes ?? {})) {
|
|
40
|
+
if (edits.length === 0)
|
|
41
|
+
continue;
|
|
42
|
+
byUri[uri] = [...(byUri[uri] ?? []), ...edits];
|
|
43
|
+
}
|
|
44
|
+
for (const entry of edit?.documentChanges ?? []) {
|
|
45
|
+
if (!isTextDocumentEdit(entry))
|
|
46
|
+
continue;
|
|
47
|
+
const textEdits = entry.edits.filter(isPlainTextEdit);
|
|
48
|
+
if (textEdits.length === 0)
|
|
49
|
+
continue;
|
|
50
|
+
const uri = entry.textDocument.uri;
|
|
51
|
+
byUri[uri] = [...(byUri[uri] ?? []), ...textEdits];
|
|
52
|
+
}
|
|
53
|
+
return byUri;
|
|
54
|
+
}
|
|
55
|
+
function isEditEmpty(edit) {
|
|
56
|
+
return Object.keys(collectEditsByUri(edit)).length === 0;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Fetches diagnostics for the document, requests a `quickfix` for each one,
|
|
60
|
+
* lets `selectFix` choose which candidate (if any) to keep, resolves
|
|
61
|
+
* command-only fixes via `codeAction/resolve` when the backend supports it,
|
|
62
|
+
* and merges every chosen fix's edits into one non-overlapping edit map.
|
|
63
|
+
*/
|
|
64
|
+
export async function aggregateQuickFixes(params, backend, selectFix) {
|
|
65
|
+
const report = (await backend.sendRequest('textDocument/diagnostic', { textDocument: params.textDocument }));
|
|
66
|
+
const diagnostics = report.kind === 'full' ? (report.items ?? []) : [];
|
|
67
|
+
const capabilities = backend.getServerCapabilities() ?? {};
|
|
68
|
+
const changes = {};
|
|
69
|
+
let mergedCount = 0;
|
|
70
|
+
for (const diagnostic of diagnostics) {
|
|
71
|
+
const candidates = (await backend.sendRequest('textDocument/codeAction', {
|
|
72
|
+
textDocument: params.textDocument,
|
|
73
|
+
range: diagnostic.range,
|
|
74
|
+
context: { diagnostics: [diagnostic], only: ['quickfix'] }
|
|
75
|
+
}));
|
|
76
|
+
let fix = candidates ? selectFix(candidates) : undefined;
|
|
77
|
+
if (fix && isEditEmpty(fix.edit) && fix.command && supportsResolve(capabilities)) {
|
|
78
|
+
fix = (await backend.sendRequest('codeAction/resolve', fix));
|
|
79
|
+
}
|
|
80
|
+
if (!fix)
|
|
81
|
+
continue;
|
|
82
|
+
const editsByUri = collectEditsByUri(fix.edit);
|
|
83
|
+
if (Object.keys(editsByUri).length === 0)
|
|
84
|
+
continue;
|
|
85
|
+
for (const [uri, edits] of Object.entries(editsByUri)) {
|
|
86
|
+
changes[uri] = mergeEdits(changes[uri] ?? [], edits);
|
|
87
|
+
}
|
|
88
|
+
mergedCount += 1;
|
|
89
|
+
}
|
|
90
|
+
return { changes, mergedCount };
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=quickfix-aggregation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickfix-aggregation.js","sourceRoot":"","sources":["../src/quickfix-aggregation.ts"],"names":[],"mappings":"AAmBA,MAAM,UAAU,YAAY,CAAC,IAA0B;IACrD,OAAO,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,CAAW,EAAE,CAAW;IACvD,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,CAAoB,EAAE,CAAoB;IACtE,OAAO,gBAAgB,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,gBAAgB,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACtF,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,QAAoB,EAAE,QAAoB;IACnE,MAAM,MAAM,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;YAAE,SAAS;QACrE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,MAAM,CAAC;A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C;YACjF,GAAG,GAAG,CAAC,MAAO,OAAO,CAAC,WAA2D,CAC/E,oBAAoB,EACpB,GAAG,CACJ,CAAe,CAAC;QACnB,CAAC;QACD,IAAI,CAAC,GAAG;YAAE,SAAS;QAEnB,MAAM,UAAU,GAAG,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QAEnD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YACtD,OAAO,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC;QACD,WAAW,IAAI,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AAClC,CAAC"}
|
package/dist/registry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAKrD,eAAO,MAAM,iBAAiB,EAAE,SAAS,kBAAkB,EAI1D,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,CAE1F"}
|
package/dist/registry.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { resolveBackfill } from './resolve-backfill.js';
|
|
2
2
|
import { fixAll } from './fix-all.js';
|
|
3
|
-
|
|
3
|
+
import { organizeImports } from './organize-imports.js';
|
|
4
|
+
export const BUILTIN_POLYFILLS = [
|
|
5
|
+
resolveBackfill,
|
|
6
|
+
fixAll,
|
|
7
|
+
organizeImports
|
|
8
|
+
];
|
|
4
9
|
export function applicablePolyfills(capabilities) {
|
|
5
10
|
return BUILTIN_POLYFILLS.filter((p) => p.appliesTo(capabilities));
|
|
6
11
|
}
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,iBAAiB,GAAkC;IAC9D,eAAe;IACf,MAAM;IACN,eAAe;CAChB,CAAC;AAEF,MAAM,UAAU,mBAAmB,CAAC,YAAgC;IAClE,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;AACpE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lsproxy/polyfill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "CodeAction capability polyfills for lsproxy backends that don't natively support them",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "https://github.com/pradeepmouli/lspeasy.git",
|
|
21
|
-
"directory": "
|
|
21
|
+
"directory": "packages/polyfill"
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"exports": {
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "tsgo --build",
|
|
41
|
-
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
42
|
-
"type-check": "tsgo --noEmit"
|
|
43
|
-
},
|
|
44
39
|
"dependencies": {
|
|
45
|
-
"@lspeasy/client": "
|
|
46
|
-
"@lspeasy/core": "
|
|
40
|
+
"@lspeasy/client": "3.1.6",
|
|
41
|
+
"@lspeasy/core": "2.6.1"
|
|
47
42
|
},
|
|
48
43
|
"devDependencies": {
|
|
49
44
|
"typescript": "^6.0.3"
|
|
50
45
|
},
|
|
51
46
|
"engines": {
|
|
52
47
|
"node": ">=22.0.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsgo --build",
|
|
51
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
52
|
+
"type-check": "tsgo --noEmit"
|
|
53
53
|
}
|
|
54
|
-
}
|
|
54
|
+
}
|