volar-service-typescript 0.0.43-patch.1 → 0.0.44

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.
@@ -1,5 +1,5 @@
1
1
  import type { FormattingOptions, ServiceContext } from '@volar/language-service';
2
2
  import type * as ts from 'typescript';
3
3
  import type { TextDocument } from 'vscode-languageserver-textdocument';
4
- export declare function getFormatCodeSettings(ctx: ServiceContext, document: TextDocument, options?: FormattingOptions): Promise<ts.FormatCodeSettings>;
4
+ export declare function getFormatCodeSettings(ctx: ServiceContext, document: TextDocument, options: FormattingOptions | undefined): Promise<ts.FormatCodeSettings>;
5
5
  //# sourceMappingURL=getFormatCodeSettings.d.ts.map
@@ -8,6 +8,7 @@ async function getUserPreferences(ctx, document) {
8
8
  if (ctx.language.typescript) {
9
9
  currentDirectory = ctx.language.typescript.languageServiceHost.getCurrentDirectory();
10
10
  }
11
+ const documentUri = ctx.decodeEmbeddedDocumentUri(document.uri)?.[0] ?? document.uri;
11
12
  const config = await ctx.env.getConfiguration?.((0, shared_1.getConfigTitle)(document)) ?? {};
12
13
  const preferencesConfig = config?.preferences ?? {};
13
14
  const preferences = {
@@ -16,7 +17,7 @@ async function getUserPreferences(ctx, document) {
16
17
  importModuleSpecifierPreference: getImportModuleSpecifierPreference(preferencesConfig),
17
18
  importModuleSpecifierEnding: getImportModuleSpecifierEndingPreference(preferencesConfig),
18
19
  jsxAttributeCompletionStyle: getJsxAttributeCompletionStyle(preferencesConfig),
19
- allowTextChangesInNewFiles: document.uri.startsWith('file://'),
20
+ allowTextChangesInNewFiles: documentUri.startsWith('file://'),
20
21
  providePrefixAndSuffixTextForRename: (preferencesConfig.renameShorthandProperties ?? true) === false ? false : (preferencesConfig.useAliasesForRenames ?? true),
21
22
  allowRenameOfImportPath: true,
22
23
  includeAutomaticOptionalChainCompletions: config.suggest?.includeAutomaticOptionalChainCompletions ?? true,
@@ -133,6 +133,7 @@ function create(ts, { isValidationEnabled = async (document, context) => {
133
133
  const getDocumentSemanticTokens = semanticTokens.register(ts, ctx);
134
134
  /* typescript-language-features is hardcode true */
135
135
  const renameInfoOptions = { allowRenameOfImportPath: true };
136
+ let formattingOptions;
136
137
  return {
137
138
  provide: {
138
139
  'typescript/languageService': () => languageService,
@@ -141,6 +142,14 @@ function create(ts, { isValidationEnabled = async (document, context) => {
141
142
  dispose() {
142
143
  languageService.dispose();
143
144
  },
145
+ provideDocumentFormattingEdits(_document, _range, options) {
146
+ formattingOptions = options;
147
+ return undefined;
148
+ },
149
+ provideOnTypeFormattingEdits(_document, _position, _key, options) {
150
+ formattingOptions = options;
151
+ return undefined;
152
+ },
144
153
  async provideCompletionItems(document, position, completeContext, token) {
145
154
  if (!isSemanticDocument(document)) {
146
155
  return;
@@ -181,7 +190,7 @@ function create(ts, { isValidationEnabled = async (document, context) => {
181
190
  const { fileName, offset } = data;
182
191
  const document = ctx.getTextDocument(data.uri);
183
192
  const [formatOptions, preferences] = await Promise.all([
184
- (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
193
+ (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, formattingOptions),
185
194
  (0, getUserPreferences_1.getUserPreferences)(ctx, document),
186
195
  ]);
187
196
  const details = (0, shared_1.safeCall)(() => ctx.languageService.getCompletionEntryDetails(fileName, offset, data.originalItem.name, formatOptions, data.originalItem.source, preferences, data.originalItem.data));
@@ -280,7 +289,7 @@ function create(ts, { isValidationEnabled = async (document, context) => {
280
289
  }
281
290
  if (renameInfo.fileToRename) {
282
291
  const [formatOptions, preferences] = await Promise.all([
283
- (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
292
+ (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, formattingOptions),
284
293
  (0, getUserPreferences_1.getUserPreferences)(ctx, document),
285
294
  ]);
286
295
  return renameFile(renameInfo.fileToRename, newName, formatOptions, preferences);
@@ -320,12 +329,12 @@ function create(ts, { isValidationEnabled = async (document, context) => {
320
329
  return;
321
330
  }
322
331
  return worker(token, () => {
323
- return getCodeActions(document, range, context);
332
+ return getCodeActions(document, range, context, formattingOptions);
324
333
  });
325
334
  },
326
335
  async resolveCodeAction(codeAction, token) {
327
336
  return await worker(token, () => {
328
- return doCodeActionResolve(codeAction);
337
+ return doCodeActionResolve(codeAction, formattingOptions);
329
338
  }) ?? codeAction;
330
339
  },
331
340
  provideInlayHints(document, range, token) {
@@ -535,7 +544,7 @@ function create(ts, { isValidationEnabled = async (document, context) => {
535
544
  return worker(token, async () => {
536
545
  const document = ctx.getTextDocument(oldUri);
537
546
  const [formatOptions, preferences] = await Promise.all([
538
- (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
547
+ (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, formattingOptions),
539
548
  (0, getUserPreferences_1.getUserPreferences)(ctx, document),
540
549
  ]);
541
550
  const fileToRename = ctx.uriToFileName(oldUri);
@@ -24,5 +24,5 @@ export interface OrganizeImportsData {
24
24
  fileName: string;
25
25
  }
26
26
  export type Data = FixAllData | RefactorData | OrganizeImportsData;
27
- export declare function register(ctx: SharedContext): (document: TextDocument, range: vscode.Range, context: vscode.CodeActionContext) => Promise<vscode.CodeAction[]>;
27
+ export declare function register(ctx: SharedContext): (document: TextDocument, range: vscode.Range, context: vscode.CodeActionContext, formattingOptions: vscode.FormattingOptions | undefined) => Promise<vscode.CodeAction[]>;
28
28
  //# sourceMappingURL=codeAction.d.ts.map
@@ -7,16 +7,32 @@ const shared_1 = require("../shared");
7
7
  const fixNames = require("../utils/fixNames");
8
8
  const codeActionResolve_1 = require("./codeActionResolve");
9
9
  const lspConverters_1 = require("../utils/lspConverters");
10
+ const renameCommandRefactors = new Set([
11
+ 'refactor.rewrite.property.generateAccessors',
12
+ 'refactor.extract.type',
13
+ 'refactor.extract.interface',
14
+ 'refactor.extract.typedef',
15
+ 'refactor.extract.constant',
16
+ 'refactor.extract.function',
17
+ ]);
10
18
  function register(ctx) {
11
19
  let resolveCommandSupport = ctx.env.clientCapabilities?.textDocument?.codeAction?.resolveSupport?.properties?.includes('command');
12
20
  let resolveEditSupport = ctx.env.clientCapabilities?.textDocument?.codeAction?.resolveSupport?.properties?.includes('edit');
21
+ let loged = false;
22
+ const wranUnsupportResolve = () => {
23
+ if (loged) {
24
+ return;
25
+ }
26
+ loged = true;
27
+ console.warn('[volar-service-typescript] The language client lacks support for the command/edit properties in the resolve code action. Therefore, the code action resolve is pre-calculated.');
28
+ };
13
29
  if (!ctx.env.clientCapabilities) {
14
30
  resolveCommandSupport = true;
15
31
  resolveEditSupport = true;
16
32
  }
17
- return async (document, range, context) => {
33
+ return async (document, range, context, formattingOptions) => {
18
34
  const [formatOptions, preferences] = await Promise.all([
19
- (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
35
+ (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, formattingOptions),
20
36
  (0, getUserPreferences_1.getUserPreferences)(ctx, document),
21
37
  ]);
22
38
  const fileName = ctx.uriToFileName(document.uri);
@@ -63,6 +79,7 @@ function register(ctx) {
63
79
  action.data = data;
64
80
  }
65
81
  else {
82
+ wranUnsupportResolve();
66
83
  (0, codeActionResolve_1.resolveOrganizeImportsCodeAction)(ctx, action, data, formatOptions, preferences);
67
84
  }
68
85
  result.push(action);
@@ -87,6 +104,7 @@ function register(ctx) {
87
104
  action.data = data;
88
105
  }
89
106
  else {
107
+ wranUnsupportResolve();
90
108
  (0, codeActionResolve_1.resolveFixAllCodeAction)(ctx, action, data, formatOptions, preferences);
91
109
  }
92
110
  result.push(action);
@@ -115,6 +133,7 @@ function register(ctx) {
115
133
  action.data = data;
116
134
  }
117
135
  else {
136
+ wranUnsupportResolve();
118
137
  (0, codeActionResolve_1.resolveFixAllCodeAction)(ctx, action, data, formatOptions, preferences);
119
138
  }
120
139
  result.push(action);
@@ -140,6 +159,7 @@ function register(ctx) {
140
159
  action.data = data;
141
160
  }
142
161
  else {
162
+ wranUnsupportResolve();
143
163
  (0, codeActionResolve_1.resolveFixAllCodeAction)(ctx, action, data, formatOptions, preferences);
144
164
  }
145
165
  result.push(action);
@@ -194,6 +214,7 @@ function register(ctx) {
194
214
  fixAll.data = data;
195
215
  }
196
216
  else {
217
+ wranUnsupportResolve();
197
218
  (0, codeActionResolve_1.resolveFixAllCodeAction)(ctx, fixAll, data, formatOptions, preferences);
198
219
  }
199
220
  fixAll.diagnostics = diagnostics;
@@ -222,10 +243,15 @@ function register(ctx) {
222
243
  refactorName: refactor.name,
223
244
  actionName: action.name,
224
245
  };
225
- if (resolveCommandSupport && resolveEditSupport) {
246
+ const hasCommand = renameCommandRefactors.has(action.kind);
247
+ if (hasCommand && resolveCommandSupport && resolveEditSupport) {
248
+ codeAction.data = data;
249
+ }
250
+ else if (!hasCommand && resolveEditSupport) {
226
251
  codeAction.data = data;
227
252
  }
228
- else if (!codeAction.disabled && document) {
253
+ else if (!codeAction.disabled) {
254
+ wranUnsupportResolve();
229
255
  (0, codeActionResolve_1.resolveRefactorCodeAction)(ctx, codeAction, data, document, formatOptions, preferences);
230
256
  }
231
257
  codeActions.push(codeAction);
@@ -3,7 +3,7 @@ import type * as ts from 'typescript';
3
3
  import type { TextDocument } from 'vscode-languageserver-textdocument';
4
4
  import type { SharedContext } from './types';
5
5
  import type { Data, FixAllData, RefactorData } from './codeAction';
6
- export declare function register(ctx: SharedContext): (codeAction: vscode.CodeAction) => Promise<vscode.CodeAction>;
6
+ export declare function register(ctx: SharedContext): (codeAction: vscode.CodeAction, formattingOptions: vscode.FormattingOptions | undefined) => Promise<vscode.CodeAction>;
7
7
  export declare function resolveFixAllCodeAction(ctx: SharedContext, codeAction: vscode.CodeAction, data: FixAllData, formatOptions: ts.FormatCodeSettings, preferences: ts.UserPreferences): void;
8
8
  export declare function resolveRefactorCodeAction(ctx: SharedContext, codeAction: vscode.CodeAction, data: RefactorData, document: TextDocument, formatOptions: ts.FormatCodeSettings, preferences: ts.UserPreferences): void;
9
9
  export declare function resolveOrganizeImportsCodeAction(ctx: SharedContext, codeAction: vscode.CodeAction, data: Data, formatOptions: ts.FormatCodeSettings, preferences: ts.UserPreferences): void;
@@ -6,11 +6,11 @@ const getUserPreferences_1 = require("../configs/getUserPreferences");
6
6
  const shared_1 = require("../shared");
7
7
  const lspConverters_1 = require("../utils/lspConverters");
8
8
  function register(ctx) {
9
- return async (codeAction) => {
9
+ return async (codeAction, formattingOptions) => {
10
10
  const data = codeAction.data;
11
11
  const document = ctx.getTextDocument(data.uri);
12
12
  const [formatOptions, preferences] = await Promise.all([
13
- (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
13
+ (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, formattingOptions),
14
14
  (0, getUserPreferences_1.getUserPreferences)(ctx, document),
15
15
  ]);
16
16
  if (data?.type === 'fixAll') {
@@ -509,17 +509,32 @@ function convertFileTextChanges(changes, fileNameToUri, getTextDocument) {
509
509
  workspaceEdit.documentChanges = [];
510
510
  }
511
511
  const uri = fileNameToUri(change.fileName);
512
- const doc = getTextDocument(uri);
513
512
  if (change.isNewFile) {
514
513
  workspaceEdit.documentChanges.push({ kind: 'create', uri });
514
+ workspaceEdit.documentChanges.push({
515
+ textDocument: {
516
+ uri,
517
+ version: null, // fix https://github.com/johnsoncodehk/volar/issues/2025
518
+ },
519
+ edits: change.textChanges.map(edit => ({
520
+ newText: edit.newText,
521
+ range: {
522
+ start: { line: 0, character: edit.span.start },
523
+ end: { line: 0, character: edit.span.start + edit.span.length },
524
+ },
525
+ })),
526
+ });
527
+ }
528
+ else {
529
+ const doc = getTextDocument(uri);
530
+ workspaceEdit.documentChanges.push({
531
+ textDocument: {
532
+ uri,
533
+ version: null, // fix https://github.com/johnsoncodehk/volar/issues/2025
534
+ },
535
+ edits: change.textChanges.map(edit => convertTextChange(edit, doc)),
536
+ });
515
537
  }
516
- workspaceEdit.documentChanges.push({
517
- textDocument: {
518
- uri,
519
- version: null, // fix https://github.com/johnsoncodehk/volar/issues/2025
520
- },
521
- edits: change.textChanges.map(edit => convertTextChange(edit, doc)),
522
- });
523
538
  }
524
539
  return workspaceEdit;
525
540
  }
@@ -1,5 +1,5 @@
1
1
  import type * as ts from 'typescript';
2
2
  export declare namespace SymbolKind {
3
- function fromProtocolScriptElementKind(kind: ts.ScriptElementKind): 2 | 5 | 10 | 22 | 11 | 6 | 7 | 13 | 12 | 9 | 26 | 15;
3
+ function fromProtocolScriptElementKind(kind: ts.ScriptElementKind): 2 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 15 | 22 | 26;
4
4
  }
5
5
  //# sourceMappingURL=typeConverters.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volar-service-typescript",
3
- "version": "0.0.43-patch.1",
3
+ "version": "0.0.44",
4
4
  "description": "Integrate TypeScript into Volar",
5
5
  "homepage": "https://github.com/volarjs/services/tree/master/packages/typescript",
6
6
  "bugs": "https://github.com/volarjs/services/issues",
@@ -41,5 +41,6 @@
41
41
  "@volar/language-service": {
42
42
  "optional": true
43
43
  }
44
- }
44
+ },
45
+ "gitHead": "c4fa09f8f3858532e806d6b2ec9c65eecb66b1a1"
45
46
  }