volar-service-typescript 0.0.3 → 0.0.5

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.
Files changed (106) hide show
  1. package/out/configs/getFormatCodeSettings.d.ts +2 -2
  2. package/out/features/callHierarchy.d.ts +7 -0
  3. package/out/features/callHierarchy.js +125 -0
  4. package/out/features/codeAction.d.ts +26 -0
  5. package/out/features/codeAction.js +263 -0
  6. package/out/features/codeActionResolve.d.ts +9 -0
  7. package/out/features/codeActionResolve.js +51 -0
  8. package/out/features/completions/basic.d.ts +16 -0
  9. package/out/features/completions/basic.js +349 -0
  10. package/out/features/completions/directiveComment.d.ts +3 -0
  11. package/out/features/completions/directiveComment.js +77 -0
  12. package/out/features/completions/jsDoc.d.ts +3 -0
  13. package/out/features/completions/jsDoc.js +105 -0
  14. package/out/features/completions/resolve.d.ts +5 -0
  15. package/out/features/completions/resolve.js +169 -0
  16. package/out/features/definition.d.ts +3 -0
  17. package/out/features/definition.js +20 -0
  18. package/out/features/diagnostics.d.ts +10 -0
  19. package/out/features/diagnostics.js +120 -0
  20. package/out/features/documentHighlight.d.ts +3 -0
  21. package/out/features/documentHighlight.js +32 -0
  22. package/out/features/documentSymbol.d.ts +3 -0
  23. package/out/features/documentSymbol.js +117 -0
  24. package/out/features/fileReferences.d.ts +3 -0
  25. package/out/features/fileReferences.js +19 -0
  26. package/out/features/fileRename.d.ts +3 -0
  27. package/out/features/fileRename.js +25 -0
  28. package/out/features/foldingRanges.d.ts +3 -0
  29. package/out/features/foldingRanges.js +55 -0
  30. package/out/features/formatting.d.ts +7 -0
  31. package/out/features/formatting.js +52 -0
  32. package/out/features/hover.d.ts +3 -0
  33. package/out/features/hover.js +66 -0
  34. package/out/features/implementation.d.ts +3 -0
  35. package/out/features/implementation.js +20 -0
  36. package/out/features/inlayHints.d.ts +3 -0
  37. package/out/features/inlayHints.js +34 -0
  38. package/out/features/prepareRename.d.ts +8 -0
  39. package/out/features/prepareRename.js +27 -0
  40. package/out/features/references.d.ts +3 -0
  41. package/out/features/references.js +20 -0
  42. package/out/features/rename.d.ts +5 -0
  43. package/out/features/rename.js +116 -0
  44. package/out/features/selectionRanges.d.ts +3 -0
  45. package/out/features/selectionRanges.js +32 -0
  46. package/out/features/semanticTokens.d.ts +3 -0
  47. package/out/features/semanticTokens.js +128 -0
  48. package/out/features/signatureHelp.d.ts +3 -0
  49. package/out/features/signatureHelp.js +63 -0
  50. package/out/features/typeDefinition.d.ts +3 -0
  51. package/out/features/typeDefinition.js +20 -0
  52. package/out/features/workspaceSymbol.d.ts +3 -0
  53. package/out/features/workspaceSymbol.js +86 -0
  54. package/out/index.d.ts +9 -5
  55. package/out/index.js +265 -183
  56. package/out/languageServiceHost.d.ts +3 -0
  57. package/out/languageServiceHost.js +199 -0
  58. package/out/protocol.const.js +5 -5
  59. package/out/services/callHierarchy.d.ts +1 -1
  60. package/out/services/callHierarchy.js +1 -2
  61. package/out/services/codeAction.d.ts +1 -1
  62. package/out/services/codeAction.js +36 -15
  63. package/out/services/codeActionResolve.d.ts +2 -2
  64. package/out/services/completions/basic.d.ts +1 -1
  65. package/out/services/completions/basic.js +56 -29
  66. package/out/services/completions/directiveComment.d.ts +1 -1
  67. package/out/services/completions/directiveComment.js +13 -5
  68. package/out/services/completions/jsDoc.d.ts +1 -1
  69. package/out/services/completions/jsDoc.js +7 -8
  70. package/out/services/completions/resolve.d.ts +2 -2
  71. package/out/services/completions/resolve.js +3 -4
  72. package/out/services/definition.d.ts +1 -1
  73. package/out/services/diagnostics.d.ts +1 -1
  74. package/out/services/diagnostics.js +7 -31
  75. package/out/services/documentHighlight.d.ts +1 -1
  76. package/out/services/documentHighlight.js +1 -25
  77. package/out/services/documentSymbol.d.ts +1 -1
  78. package/out/services/documentSymbol.js +30 -19
  79. package/out/services/fileReferences.d.ts +1 -1
  80. package/out/services/foldingRanges.d.ts +1 -1
  81. package/out/services/foldingRanges.js +10 -28
  82. package/out/services/formatting.d.ts +1 -1
  83. package/out/services/hover.d.ts +1 -1
  84. package/out/services/hover.js +5 -3
  85. package/out/services/inlayHints.d.ts +1 -1
  86. package/out/services/inlayHints.js +7 -27
  87. package/out/services/prepareRename.d.ts +4 -2
  88. package/out/services/prepareRename.js +1 -25
  89. package/out/services/references.d.ts +1 -1
  90. package/out/services/rename.d.ts +1 -1
  91. package/out/services/rename.js +16 -35
  92. package/out/services/selectionRanges.d.ts +1 -1
  93. package/out/services/selectionRanges.js +4 -25
  94. package/out/services/semanticTokens.d.ts +1 -1
  95. package/out/services/signatureHelp.d.ts +1 -1
  96. package/out/services/signatureHelp.js +3 -27
  97. package/out/services/tsconfig.d.ts +1 -1
  98. package/out/services/tsconfig.js +13 -7
  99. package/out/services/workspaceSymbol.d.ts +1 -1
  100. package/out/services/workspaceSymbol.js +22 -16
  101. package/out/types.d.ts +5 -1
  102. package/out/utils/transforms.d.ts +1 -1
  103. package/out/utils/transforms.js +41 -34
  104. package/out/utils/typeConverters.d.ts +1 -1
  105. package/out/utils/typeConverters.js +24 -28
  106. package/package.json +8 -6
@@ -1,5 +1,5 @@
1
1
  import { SharedContext } from '../types';
2
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
3
- import * as vscode from 'vscode-languageserver-protocol';
3
+ import type { FormattingOptions } from '@volar/language-service';
4
4
  import type { TextDocument } from 'vscode-languageserver-textdocument';
5
- export declare function getFormatCodeSettings(ctx: SharedContext, document: TextDocument, options?: vscode.FormattingOptions): Promise<ts.FormatCodeSettings>;
5
+ export declare function getFormatCodeSettings(ctx: SharedContext, document: TextDocument, options?: FormattingOptions): Promise<ts.FormatCodeSettings>;
@@ -0,0 +1,7 @@
1
+ import type * as vscode from '@volar/language-service';
2
+ import { SharedContext } from '../types';
3
+ export declare function register(ctx: SharedContext): {
4
+ doPrepare: (uri: string, position: vscode.Position) => vscode.CallHierarchyItem[];
5
+ getIncomingCalls: (item: vscode.CallHierarchyItem) => vscode.CallHierarchyIncomingCall[];
6
+ getOutgoingCalls: (item: vscode.CallHierarchyItem) => vscode.CallHierarchyOutgoingCall[];
7
+ };
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.register = void 0;
27
+ const PConst = __importStar(require("../protocol.const"));
28
+ const modifiers_1 = require("../utils/modifiers");
29
+ const typeConverters = __importStar(require("../utils/typeConverters"));
30
+ const path_1 = require("path");
31
+ const shared_1 = require("../shared");
32
+ function register(ctx) {
33
+ function doPrepare(uri, position) {
34
+ const document = ctx.getTextDocument(uri);
35
+ if (!document)
36
+ return [];
37
+ const fileName = ctx.env.uriToFileName(document.uri);
38
+ const offset = document.offsetAt(position);
39
+ const calls = (0, shared_1.safeCall)(() => ctx.typescript.languageService.prepareCallHierarchy(fileName, offset));
40
+ if (!calls)
41
+ return [];
42
+ const items = Array.isArray(calls) ? calls : [calls];
43
+ return items.map(item => fromProtocolCallHierarchyItem(item));
44
+ }
45
+ function getIncomingCalls(item) {
46
+ const document = ctx.getTextDocument(item.uri);
47
+ if (!document)
48
+ return [];
49
+ const fileName = ctx.env.uriToFileName(item.uri);
50
+ const offset = document.offsetAt(item.selectionRange.start);
51
+ const calls = (0, shared_1.safeCall)(() => ctx.typescript.languageService.provideCallHierarchyIncomingCalls(fileName, offset));
52
+ if (!calls)
53
+ return [];
54
+ const items = Array.isArray(calls) ? calls : [calls];
55
+ return items.map(item => fromProtocolCallHierarchyIncomingCall(item));
56
+ }
57
+ function getOutgoingCalls(item) {
58
+ const document = ctx.getTextDocument(item.uri);
59
+ if (!document)
60
+ return [];
61
+ const fileName = ctx.env.uriToFileName(item.uri);
62
+ const offset = document.offsetAt(item.selectionRange.start);
63
+ const calls = (0, shared_1.safeCall)(() => ctx.typescript.languageService.provideCallHierarchyOutgoingCalls(fileName, offset));
64
+ if (!calls)
65
+ return [];
66
+ const items = Array.isArray(calls) ? calls : [calls];
67
+ return items.map(item => fromProtocolCallHierarchyOutgoingCall(item, document));
68
+ }
69
+ return {
70
+ doPrepare,
71
+ getIncomingCalls,
72
+ getOutgoingCalls,
73
+ };
74
+ function isSourceFileItem(item) {
75
+ return item.kind === PConst.Kind.script || item.kind === PConst.Kind.module && item.selectionSpan.start === 0;
76
+ }
77
+ function fromProtocolCallHierarchyItem(item) {
78
+ const rootPath = ctx.typescript.languageService.getProgram()?.getCompilerOptions().rootDir ?? '';
79
+ const document = ctx.getTextDocument(ctx.env.fileNameToUri(item.file)); // TODO
80
+ const useFileName = isSourceFileItem(item);
81
+ const name = useFileName ? path_1.posix.basename(item.file) : item.name;
82
+ const detail = useFileName ? path_1.posix.relative(rootPath, path_1.posix.dirname(item.file)) : item.containerName ?? '';
83
+ const result = {
84
+ kind: typeConverters.SymbolKind.fromProtocolScriptElementKind(item.kind),
85
+ name,
86
+ detail,
87
+ uri: ctx.env.fileNameToUri(item.file),
88
+ range: {
89
+ start: document.positionAt(item.span.start),
90
+ end: document.positionAt(item.span.start + item.span.length),
91
+ },
92
+ selectionRange: {
93
+ start: document.positionAt(item.selectionSpan.start),
94
+ end: document.positionAt(item.selectionSpan.start + item.selectionSpan.length),
95
+ },
96
+ };
97
+ const kindModifiers = item.kindModifiers ? (0, modifiers_1.parseKindModifier)(item.kindModifiers) : undefined;
98
+ if (kindModifiers?.has(PConst.KindModifiers.deprecated)) {
99
+ result.tags = [1];
100
+ }
101
+ return result;
102
+ }
103
+ function fromProtocolCallHierarchyIncomingCall(item) {
104
+ const document = ctx.getTextDocument(ctx.env.fileNameToUri(item.from.file));
105
+ return {
106
+ from: fromProtocolCallHierarchyItem(item.from),
107
+ fromRanges: item.fromSpans.map(fromSpan => ({
108
+ start: document.positionAt(fromSpan.start),
109
+ end: document.positionAt(fromSpan.start + fromSpan.length),
110
+ })),
111
+ };
112
+ }
113
+ function fromProtocolCallHierarchyOutgoingCall(item, document) {
114
+ return {
115
+ to: fromProtocolCallHierarchyItem(item.to),
116
+ fromRanges: item.fromSpans.map(fromSpan => ({
117
+ start: document.positionAt(fromSpan.start),
118
+ end: document.positionAt(fromSpan.start + fromSpan.length),
119
+ })),
120
+ };
121
+ }
122
+ }
123
+ exports.register = register;
124
+ ;
125
+ //# sourceMappingURL=callHierarchy.js.map
@@ -0,0 +1,26 @@
1
+ import type * as vscode from '@volar/language-service';
2
+ import { SharedContext } from '../types';
3
+ export interface FixAllData {
4
+ type: 'fixAll';
5
+ uri: string;
6
+ fileName: string;
7
+ fixIds: {}[];
8
+ }
9
+ export interface RefactorData {
10
+ type: 'refactor';
11
+ uri: string;
12
+ fileName: string;
13
+ refactorName: string;
14
+ actionName: string;
15
+ range: {
16
+ pos: number;
17
+ end: number;
18
+ };
19
+ }
20
+ export interface OrganizeImportsData {
21
+ type: 'organizeImports';
22
+ uri: string;
23
+ fileName: string;
24
+ }
25
+ export type Data = FixAllData | RefactorData | OrganizeImportsData;
26
+ export declare function register(ctx: SharedContext): (uri: string, range: vscode.Range, context: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
@@ -0,0 +1,263 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.register = void 0;
27
+ const rename_1 = require("./rename");
28
+ const fixNames = __importStar(require("../utils/fixNames"));
29
+ const getFormatCodeSettings_1 = require("../configs/getFormatCodeSettings");
30
+ const getUserPreferences_1 = require("../configs/getUserPreferences");
31
+ const shared_1 = require("../shared");
32
+ const codeActionResolve_1 = require("./codeActionResolve");
33
+ function register(ctx) {
34
+ let resolveCommandSupport = ctx.env.clientCapabilities?.textDocument?.codeAction?.resolveSupport?.properties?.includes('command');
35
+ let resolveEditSupport = ctx.env.clientCapabilities?.textDocument?.codeAction?.resolveSupport?.properties?.includes('edit');
36
+ if (!ctx.env.clientCapabilities) {
37
+ resolveCommandSupport = true;
38
+ resolveEditSupport = true;
39
+ }
40
+ return async (uri, range, context) => {
41
+ const document = ctx.getTextDocument(uri);
42
+ if (!document)
43
+ return;
44
+ const [formatOptions, preferences] = await Promise.all([
45
+ (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
46
+ (0, getUserPreferences_1.getUserPreferences)(ctx, document),
47
+ ]);
48
+ const fileName = ctx.env.uriToFileName(document.uri);
49
+ const start = document.offsetAt(range.start);
50
+ const end = document.offsetAt(range.end);
51
+ let result = [];
52
+ const onlyQuickFix = matchOnlyKind(`${'quickfix'}.ts`);
53
+ if (!context.only || onlyQuickFix) {
54
+ for (const error of context.diagnostics) {
55
+ const codeFixes = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getCodeFixesAtPosition(fileName, document.offsetAt(error.range.start), document.offsetAt(error.range.end), [Number(error.code)], formatOptions, preferences)) ?? [];
56
+ for (const codeFix of codeFixes) {
57
+ result = result.concat(transformCodeFix(codeFix, [error], onlyQuickFix ?? ''));
58
+ }
59
+ }
60
+ }
61
+ if (context.only) {
62
+ for (const only of context.only) {
63
+ if (only.split('.')[0] === 'refactor') {
64
+ const refactors = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getApplicableRefactors(fileName, { pos: start, end: end }, preferences, undefined, only)) ?? [];
65
+ for (const refactor of refactors) {
66
+ result = result.concat(transformRefactor(refactor));
67
+ }
68
+ }
69
+ }
70
+ }
71
+ else {
72
+ const refactors = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getApplicableRefactors(fileName, { pos: start, end: end }, preferences, undefined, undefined)) ?? [];
73
+ for (const refactor of refactors) {
74
+ result = result.concat(transformRefactor(refactor));
75
+ }
76
+ }
77
+ const onlySourceOrganizeImports = matchOnlyKind(`${'source.organizeImports'}.ts`);
78
+ if (onlySourceOrganizeImports) {
79
+ const action = {
80
+ title: 'Organize Imports',
81
+ kind: onlySourceOrganizeImports,
82
+ };
83
+ const data = {
84
+ type: 'organizeImports',
85
+ uri,
86
+ fileName,
87
+ };
88
+ if (resolveEditSupport) {
89
+ action.data = data;
90
+ }
91
+ else {
92
+ (0, codeActionResolve_1.resolveOrganizeImportsCodeAction)(ctx, action, data, formatOptions, preferences);
93
+ }
94
+ result.push(action);
95
+ }
96
+ const onlySourceFixAll = matchOnlyKind(`${'source.fixAll'}.ts`);
97
+ if (onlySourceFixAll) {
98
+ const action = {
99
+ title: 'Fix All',
100
+ kind: onlySourceFixAll,
101
+ };
102
+ const data = {
103
+ uri,
104
+ type: 'fixAll',
105
+ fileName,
106
+ fixIds: [
107
+ fixNames.classIncorrectlyImplementsInterface,
108
+ fixNames.awaitInSyncFunction,
109
+ fixNames.unreachableCode,
110
+ ],
111
+ };
112
+ if (resolveEditSupport) {
113
+ action.data = data;
114
+ }
115
+ else {
116
+ (0, codeActionResolve_1.resolveFixAllCodeAction)(ctx, action, data, formatOptions, preferences);
117
+ }
118
+ result.push(action);
119
+ }
120
+ const onlyRemoveUnused = matchOnlyKind(`${'source'}.removeUnused.ts`);
121
+ if (onlyRemoveUnused) {
122
+ const action = {
123
+ title: 'Remove all unused code',
124
+ kind: onlyRemoveUnused,
125
+ };
126
+ const data = {
127
+ uri,
128
+ type: 'fixAll',
129
+ fileName,
130
+ fixIds: [
131
+ // not working and throw
132
+ fixNames.unusedIdentifier,
133
+ // TODO: remove patching
134
+ 'unusedIdentifier_prefix',
135
+ 'unusedIdentifier_deleteImports',
136
+ 'unusedIdentifier_delete',
137
+ 'unusedIdentifier_infer',
138
+ ],
139
+ };
140
+ if (resolveEditSupport) {
141
+ action.data = data;
142
+ }
143
+ else {
144
+ (0, codeActionResolve_1.resolveFixAllCodeAction)(ctx, action, data, formatOptions, preferences);
145
+ }
146
+ result.push(action);
147
+ }
148
+ const onlyAddMissingImports = matchOnlyKind(`${'source'}.addMissingImports.ts`);
149
+ if (onlyAddMissingImports) {
150
+ const action = {
151
+ title: 'Add all missing imports',
152
+ kind: onlyAddMissingImports,
153
+ };
154
+ const data = {
155
+ uri,
156
+ type: 'fixAll',
157
+ fileName,
158
+ fixIds: [
159
+ // not working and throw
160
+ fixNames.fixImport,
161
+ // TODO: remove patching
162
+ 'fixMissingImport',
163
+ ],
164
+ };
165
+ if (resolveEditSupport) {
166
+ action.data = data;
167
+ }
168
+ else {
169
+ (0, codeActionResolve_1.resolveFixAllCodeAction)(ctx, action, data, formatOptions, preferences);
170
+ }
171
+ result.push(action);
172
+ }
173
+ for (const codeAction of result) {
174
+ if (codeAction.diagnostics === undefined) {
175
+ codeAction.diagnostics = context.diagnostics;
176
+ }
177
+ }
178
+ return result;
179
+ function matchOnlyKind(kind) {
180
+ if (context.only) {
181
+ for (const only of context.only) {
182
+ const a = only.split('.');
183
+ const b = kind.split('.');
184
+ if (a.length <= b.length) {
185
+ let matchNums = 0;
186
+ for (let i = 0; i < a.length; i++) {
187
+ if (a[i] == b[i]) {
188
+ matchNums++;
189
+ }
190
+ }
191
+ if (matchNums === a.length)
192
+ return only;
193
+ }
194
+ }
195
+ }
196
+ }
197
+ function transformCodeFix(codeFix, diagnostics, kind) {
198
+ const edit = (0, rename_1.fileTextChangesToWorkspaceEdit)(codeFix.changes, ctx);
199
+ const codeActions = [];
200
+ const fix = {
201
+ title: codeFix.description,
202
+ kind,
203
+ edit,
204
+ };
205
+ fix.diagnostics = diagnostics;
206
+ codeActions.push(fix);
207
+ if (codeFix.fixAllDescription && codeFix.fixId) {
208
+ const fixAll = {
209
+ title: codeFix.fixAllDescription,
210
+ kind,
211
+ };
212
+ const data = {
213
+ uri,
214
+ type: 'fixAll',
215
+ fileName,
216
+ fixIds: [codeFix.fixId],
217
+ };
218
+ if (resolveEditSupport) {
219
+ fixAll.data = data;
220
+ }
221
+ else {
222
+ (0, codeActionResolve_1.resolveFixAllCodeAction)(ctx, fixAll, data, formatOptions, preferences);
223
+ }
224
+ fixAll.diagnostics = diagnostics;
225
+ codeActions.push(fixAll);
226
+ }
227
+ return codeActions;
228
+ }
229
+ function transformRefactor(refactor) {
230
+ const codeActions = [];
231
+ for (const action of refactor.actions) {
232
+ const codeAction = {
233
+ title: action.description,
234
+ kind: action.kind,
235
+ };
236
+ if (action.notApplicableReason) {
237
+ codeAction.disabled = { reason: action.notApplicableReason };
238
+ }
239
+ if (refactor.inlineable) {
240
+ codeAction.isPreferred = true;
241
+ }
242
+ const data = {
243
+ uri,
244
+ type: 'refactor',
245
+ fileName,
246
+ range: { pos: start, end: end },
247
+ refactorName: refactor.name,
248
+ actionName: action.name,
249
+ };
250
+ if (resolveCommandSupport && resolveEditSupport) {
251
+ codeAction.data = data;
252
+ }
253
+ else if (!codeAction.disabled && document) {
254
+ (0, codeActionResolve_1.resolveRefactorCodeAction)(ctx, codeAction, data, document, formatOptions, preferences);
255
+ }
256
+ codeActions.push(codeAction);
257
+ }
258
+ return codeActions;
259
+ }
260
+ };
261
+ }
262
+ exports.register = register;
263
+ //# sourceMappingURL=codeAction.js.map
@@ -0,0 +1,9 @@
1
+ import type * as ts from 'typescript/lib/tsserverlibrary';
2
+ import type * as vscode from '@volar/language-service';
3
+ import type { TextDocument } from 'vscode-languageserver-textdocument';
4
+ import { SharedContext } from '../types';
5
+ import { Data, FixAllData, RefactorData } from './codeAction';
6
+ export declare function register(ctx: SharedContext): (codeAction: vscode.CodeAction) => Promise<vscode.CodeAction>;
7
+ export declare function resolveFixAllCodeAction(ctx: SharedContext, codeAction: vscode.CodeAction, data: FixAllData, formatOptions: ts.FormatCodeSettings, preferences: ts.UserPreferences): void;
8
+ export declare function resolveRefactorCodeAction(ctx: SharedContext, codeAction: vscode.CodeAction, data: RefactorData, document: TextDocument, formatOptions: ts.FormatCodeSettings, preferences: ts.UserPreferences): void;
9
+ export declare function resolveOrganizeImportsCodeAction(ctx: SharedContext, codeAction: vscode.CodeAction, data: Data, formatOptions: ts.FormatCodeSettings, preferences: ts.UserPreferences): void;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveOrganizeImportsCodeAction = exports.resolveRefactorCodeAction = exports.resolveFixAllCodeAction = exports.register = void 0;
4
+ const getFormatCodeSettings_1 = require("../configs/getFormatCodeSettings");
5
+ const getUserPreferences_1 = require("../configs/getUserPreferences");
6
+ const shared_1 = require("../shared");
7
+ const rename_1 = require("./rename");
8
+ function register(ctx) {
9
+ return async (codeAction) => {
10
+ const data = codeAction.data;
11
+ const document = ctx.getTextDocument(data.uri);
12
+ const [formatOptions, preferences] = document ? await Promise.all([
13
+ (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
14
+ (0, getUserPreferences_1.getUserPreferences)(ctx, document),
15
+ ]) : [{}, {}];
16
+ if (data?.type === 'fixAll') {
17
+ resolveFixAllCodeAction(ctx, codeAction, data, formatOptions, preferences);
18
+ }
19
+ else if (data?.type === 'refactor' && document) {
20
+ resolveRefactorCodeAction(ctx, codeAction, data, document, formatOptions, preferences);
21
+ }
22
+ else if (data?.type === 'organizeImports') {
23
+ resolveOrganizeImportsCodeAction(ctx, codeAction, data, formatOptions, preferences);
24
+ }
25
+ return codeAction;
26
+ };
27
+ }
28
+ exports.register = register;
29
+ function resolveFixAllCodeAction(ctx, codeAction, data, formatOptions, preferences) {
30
+ const fixes = data.fixIds.map(fixId => (0, shared_1.safeCall)(() => ctx.typescript.languageService.getCombinedCodeFix({ type: 'file', fileName: data.fileName }, fixId, formatOptions, preferences)));
31
+ const changes = fixes.map(fix => fix?.changes ?? []).flat();
32
+ codeAction.edit = (0, rename_1.fileTextChangesToWorkspaceEdit)(changes, ctx);
33
+ }
34
+ exports.resolveFixAllCodeAction = resolveFixAllCodeAction;
35
+ function resolveRefactorCodeAction(ctx, codeAction, data, document, formatOptions, preferences) {
36
+ const editInfo = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getEditsForRefactor(data.fileName, formatOptions, data.range, data.refactorName, data.actionName, preferences));
37
+ if (!editInfo) {
38
+ return;
39
+ }
40
+ codeAction.edit = (0, rename_1.fileTextChangesToWorkspaceEdit)(editInfo.edits, ctx);
41
+ if (editInfo.renameLocation !== undefined && editInfo.renameFilename !== undefined) {
42
+ codeAction.command = ctx.commands.rename.create(document.uri, document.positionAt(editInfo.renameLocation));
43
+ }
44
+ }
45
+ exports.resolveRefactorCodeAction = resolveRefactorCodeAction;
46
+ function resolveOrganizeImportsCodeAction(ctx, codeAction, data, formatOptions, preferences) {
47
+ const changes = (0, shared_1.safeCall)(() => ctx.typescript.languageService.organizeImports({ type: 'file', fileName: data.fileName }, formatOptions, preferences));
48
+ codeAction.edit = (0, rename_1.fileTextChangesToWorkspaceEdit)(changes ?? [], ctx);
49
+ }
50
+ exports.resolveOrganizeImportsCodeAction = resolveOrganizeImportsCodeAction;
51
+ //# sourceMappingURL=codeActionResolve.js.map
@@ -0,0 +1,16 @@
1
+ import { SharedContext } from '../../types';
2
+ import type * as ts from 'typescript/lib/tsserverlibrary';
3
+ import type * as vscode from '@volar/language-service';
4
+ export interface Data {
5
+ uri: string;
6
+ fileName: string;
7
+ offset: number;
8
+ originalItem: {
9
+ name: ts.CompletionEntry['name'];
10
+ source: ts.CompletionEntry['source'];
11
+ data: ts.CompletionEntry['data'];
12
+ labelDetails: ts.CompletionEntry['labelDetails'];
13
+ };
14
+ }
15
+ export declare function register(ctx: SharedContext): (uri: string, position: vscode.Position, options?: ts.GetCompletionsAtPositionOptions | undefined) => Promise<vscode.CompletionList | undefined>;
16
+ export declare function handleKindModifiers(item: vscode.CompletionItem, tsEntry: ts.CompletionEntry | ts.CompletionEntryDetails): void;