@volar/language-service 1.2.0-alpha.8 → 1.3.0-alpha.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.
Files changed (60) hide show
  1. package/out/baseLanguageService.d.ts +6 -7
  2. package/out/baseLanguageService.js +7 -10
  3. package/out/documentFeatures/colorPresentations.d.ts +2 -2
  4. package/out/documentFeatures/documentColors.d.ts +2 -2
  5. package/out/documentFeatures/documentSymbols.d.ts +2 -2
  6. package/out/documentFeatures/documentSymbols.js +34 -6
  7. package/out/documentFeatures/foldingRanges.d.ts +2 -2
  8. package/out/documentFeatures/format.d.ts +2 -4
  9. package/out/documentFeatures/format.js +113 -151
  10. package/out/documentFeatures/linkedEditingRanges.d.ts +2 -2
  11. package/out/documentFeatures/selectionRanges.d.ts +2 -2
  12. package/out/index.d.ts +1 -1
  13. package/out/index.js +3 -3
  14. package/out/languageFeatures/autoInsert.d.ts +2 -2
  15. package/out/languageFeatures/callHierarchy.d.ts +2 -2
  16. package/out/languageFeatures/codeActionResolve.d.ts +2 -2
  17. package/out/languageFeatures/codeActionResolve.js +9 -3
  18. package/out/languageFeatures/codeActions.d.ts +5 -2
  19. package/out/languageFeatures/codeActions.js +17 -6
  20. package/out/languageFeatures/codeLens.d.ts +11 -4
  21. package/out/languageFeatures/codeLens.js +22 -14
  22. package/out/languageFeatures/codeLensResolve.d.ts +4 -2
  23. package/out/languageFeatures/codeLensResolve.js +19 -11
  24. package/out/languageFeatures/complete.d.ts +2 -2
  25. package/out/languageFeatures/completeResolve.d.ts +2 -2
  26. package/out/languageFeatures/definition.d.ts +2 -2
  27. package/out/languageFeatures/documentHighlights.d.ts +2 -2
  28. package/out/languageFeatures/documentLinks.d.ts +2 -2
  29. package/out/languageFeatures/documentLinks.js +1 -1
  30. package/out/languageFeatures/documentSemanticTokens.d.ts +2 -2
  31. package/out/languageFeatures/fileReferences.d.ts +2 -2
  32. package/out/languageFeatures/fileRename.d.ts +2 -2
  33. package/out/languageFeatures/fileRename.js +1 -1
  34. package/out/languageFeatures/hover.d.ts +2 -2
  35. package/out/languageFeatures/inlayHints.d.ts +2 -2
  36. package/out/languageFeatures/inlayHints.js +2 -3
  37. package/out/languageFeatures/references.d.ts +2 -2
  38. package/out/languageFeatures/rename.d.ts +3 -3
  39. package/out/languageFeatures/rename.js +54 -34
  40. package/out/languageFeatures/renamePrepare.d.ts +2 -2
  41. package/out/languageFeatures/renamePrepare.js +9 -13
  42. package/out/languageFeatures/signatureHelp.d.ts +2 -2
  43. package/out/languageFeatures/validation.d.ts +4 -2
  44. package/out/languageFeatures/validation.js +42 -9
  45. package/out/languageFeatures/workspaceSymbols.d.ts +2 -2
  46. package/out/languageFeatures/workspaceSymbols.js +3 -2
  47. package/out/transformer/documentSymbol.d.ts +2 -0
  48. package/out/transformer/documentSymbol.js +18 -0
  49. package/out/transformer/index.d.ts +2 -2
  50. package/out/transformer/index.js +5 -5
  51. package/out/transformer/workspaceSymbol.d.ts +2 -0
  52. package/out/transformer/workspaceSymbol.js +15 -0
  53. package/out/types.d.ts +65 -43
  54. package/out/utils/dedupe.d.ts +0 -1
  55. package/out/utils/dedupe.js +1 -13
  56. package/out/utils/featureWorkers.d.ts +4 -4
  57. package/out/utils/featureWorkers.js +27 -17
  58. package/package.json +9 -9
  59. package/out/languageFeatures/executeCommand.d.ts +0 -11
  60. package/out/languageFeatures/executeCommand.js +0 -32
@@ -1,10 +1,10 @@
1
1
  import { LanguageServiceHost } from '@volar/language-core';
2
- import * as executeCommand from './languageFeatures/executeCommand';
3
- import { Config, LanguageServiceRuntimeContext } from './types';
2
+ import { Config, LanguageServicePluginContext } from './types';
4
3
  import type * as ts from 'typescript/lib/tsserverlibrary';
5
4
  import type * as _ from 'vscode-languageserver-protocol';
6
5
  export type LanguageService = ReturnType<typeof createLanguageService>;
7
- export declare function createLanguageService(host: LanguageServiceHost, config: Config, env: LanguageServiceRuntimeContext['env'], documentRegistry?: ts.DocumentRegistry): {
6
+ export declare function createLanguageService(host: LanguageServiceHost, config: Config, env: LanguageServicePluginContext['env'], documentRegistry?: ts.DocumentRegistry): {
7
+ triggerCharacters: string[];
8
8
  format: (uri: string, options: _.FormattingOptions, range?: _.Range | undefined, onTypeParams?: {
9
9
  ch: string;
10
10
  position: _.Position;
@@ -12,7 +12,7 @@ export declare function createLanguageService(host: LanguageServiceHost, config:
12
12
  getFoldingRanges: (uri: string) => Promise<_.FoldingRange[] | undefined>;
13
13
  getSelectionRanges: (uri: string, positions: _.Position[]) => Promise<_.SelectionRange[] | undefined>;
14
14
  findLinkedEditingRanges: (uri: string, position: _.Position) => Promise<_.LinkedEditingRanges | undefined>;
15
- findDocumentSymbols: (uri: string) => Promise<_.SymbolInformation[] | undefined>;
15
+ findDocumentSymbols: (uri: string) => Promise<_.DocumentSymbol[] | undefined>;
16
16
  findDocumentColors: (uri: string) => Promise<_.ColorInformation[] | undefined>;
17
17
  getColorPresentations: (uri: string, color: _.Color, range: _.Range) => Promise<_.ColorPresentation[] | undefined>;
18
18
  doValidation: (uri: string, token?: _.CancellationToken | undefined, response?: ((result: _.Diagnostic[]) => void) | undefined) => Promise<_.Diagnostic[]>;
@@ -35,7 +35,7 @@ export declare function createLanguageService(host: LanguageServiceHost, config:
35
35
  doCodeLensResolve: (item: _.CodeLens) => Promise<_.CodeLens>;
36
36
  findDocumentHighlights: (uri: string, position: _.Position) => Promise<_.DocumentHighlight[] | undefined>;
37
37
  findDocumentLinks: (uri: string) => Promise<_.DocumentLink[]>;
38
- findWorkspaceSymbols: (query: string) => Promise<_.SymbolInformation[]>;
38
+ findWorkspaceSymbols: (query: string) => Promise<_.WorkspaceSymbol[]>;
39
39
  doAutoInsert: (uri: string, position: _.Position, autoInsertContext: {
40
40
  lastChange: {
41
41
  range: _.Range;
@@ -44,7 +44,6 @@ export declare function createLanguageService(host: LanguageServiceHost, config:
44
44
  text: string;
45
45
  };
46
46
  }) => Promise<NonNullable<string | _.TextEdit | null | undefined> | undefined>;
47
- doExecuteCommand: (command: string, args: executeCommand.ExecutePluginCommandArgs, executeCommandContext: import("./types").ExecuteCommandContext) => Promise<void>;
48
47
  getInlayHints: (uri: string, range: _.Range) => Promise<_.InlayHint[] | undefined>;
49
48
  callHierarchy: {
50
49
  doPrepare(uri: string, position: _.Position): Promise<_.CallHierarchyItem[] | undefined>;
@@ -52,5 +51,5 @@ export declare function createLanguageService(host: LanguageServiceHost, config:
52
51
  getOutgoingCalls(item: _.CallHierarchyItem): Promise<_.CallHierarchyOutgoingCall[]>;
53
52
  };
54
53
  dispose: () => void | undefined;
55
- context: LanguageServiceRuntimeContext<LanguageServiceHost>;
54
+ context: LanguageServicePluginContext;
56
55
  };
@@ -17,7 +17,6 @@ const definition = require("./languageFeatures/definition");
17
17
  const documentHighlight = require("./languageFeatures/documentHighlights");
18
18
  const documentLink = require("./languageFeatures/documentLinks");
19
19
  const semanticTokens = require("./languageFeatures/documentSemanticTokens");
20
- const executeCommand = require("./languageFeatures/executeCommand");
21
20
  const fileReferences = require("./languageFeatures/fileReferences");
22
21
  const fileRename = require("./languageFeatures/fileRename");
23
22
  const hover = require("./languageFeatures/hover");
@@ -38,13 +37,12 @@ const selectionRanges = require("./documentFeatures/selectionRanges");
38
37
  function createLanguageService(host, config, env, documentRegistry) {
39
38
  var _a;
40
39
  const languageContext = (0, language_core_1.createLanguageContext)(host, Object.values((_a = config.languages) !== null && _a !== void 0 ? _a : {}).filter(shared.notEmpty));
41
- const context = createLanguageServiceContext(host, languageContext, config, env, () => languageService, documentRegistry);
42
- const languageService = createLanguageServiceBase(context);
43
- return languageService;
40
+ const context = createLanguageServiceContext(host, languageContext, config, env, documentRegistry);
41
+ return createLanguageServiceBase(context);
44
42
  }
45
43
  exports.createLanguageService = createLanguageService;
46
- function createLanguageServiceContext(host, languageContext, config, env, getLanguageService, documentRegistry) {
47
- var _a, _b, _c;
44
+ function createLanguageServiceContext(host, languageContext, config, env, documentRegistry) {
45
+ var _a;
48
46
  const ts = (_a = host.getTypeScriptModule) === null || _a === void 0 ? void 0 : _a.call(host);
49
47
  const tsLs = ts === null || ts === void 0 ? void 0 : ts.createLanguageService(languageContext.typescript.languageServiceHost, documentRegistry);
50
48
  if (ts && tsLs) {
@@ -67,7 +65,7 @@ function createLanguageServiceContext(host, languageContext, config, env, getLan
67
65
  for (const pluginId in (_a = config.plugins) !== null && _a !== void 0 ? _a : {}) {
68
66
  const plugin = (_b = config.plugins) === null || _b === void 0 ? void 0 : _b[pluginId];
69
67
  if (plugin instanceof Function) {
70
- const _plugin = plugin(this, getLanguageService());
68
+ const _plugin = plugin(this);
71
69
  plugins[pluginId] = _plugin;
72
70
  }
73
71
  else if (plugin) {
@@ -77,8 +75,7 @@ function createLanguageServiceContext(host, languageContext, config, env, getLan
77
75
  }
78
76
  return plugins;
79
77
  },
80
- rules: (_b = config.rules) !== null && _b !== void 0 ? _b : {},
81
- rulesSettings: (_c = config.rulesSettings) !== null && _c !== void 0 ? _c : {},
78
+ config,
82
79
  typescript: ts && tsLs ? {
83
80
  module: ts,
84
81
  languageServiceHost: languageContext.typescript.languageServiceHost,
@@ -106,6 +103,7 @@ function createLanguageServiceContext(host, languageContext, config, env, getLan
106
103
  }
107
104
  function createLanguageServiceBase(context) {
108
105
  return {
106
+ triggerCharacters: Object.values(context.plugins).map(plugin => { var _a, _b; return (_b = (_a = plugin.complete) === null || _a === void 0 ? void 0 : _a.triggerCharacters) !== null && _b !== void 0 ? _b : []; }).flat(),
109
107
  format: format.register(context),
110
108
  getFoldingRanges: foldingRanges.register(context),
111
109
  getSelectionRanges: selectionRanges.register(context),
@@ -135,7 +133,6 @@ function createLanguageServiceBase(context) {
135
133
  findDocumentLinks: documentLink.register(context),
136
134
  findWorkspaceSymbols: workspaceSymbol.register(context),
137
135
  doAutoInsert: autoInsert.register(context),
138
- doExecuteCommand: executeCommand.register(context),
139
136
  getInlayHints: inlayHints.register(context),
140
137
  callHierarchy: callHierarchy.register(context),
141
138
  dispose: () => { var _a; return (_a = context.typescript) === null || _a === void 0 ? void 0 : _a.languageService.dispose(); },
@@ -1,3 +1,3 @@
1
- import type { LanguageServiceRuntimeContext } from '../types';
1
+ import type { LanguageServicePluginContext } from '../types';
2
2
  import * as vscode from 'vscode-languageserver-protocol';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, color: vscode.Color, range: vscode.Range) => Promise<vscode.ColorPresentation[] | undefined>;
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, color: vscode.Color, range: vscode.Range) => Promise<vscode.ColorPresentation[] | undefined>;
@@ -1,3 +1,3 @@
1
- import type { LanguageServiceRuntimeContext } from '../types';
1
+ import type { LanguageServicePluginContext } from '../types';
2
2
  import * as vscode from 'vscode-languageserver-protocol';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string) => Promise<vscode.ColorInformation[] | undefined>;
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.ColorInformation[] | undefined>;
@@ -1,3 +1,3 @@
1
- import type { LanguageServiceRuntimeContext } from '../types';
1
+ import type { LanguageServicePluginContext } from '../types';
2
2
  import * as vscode from 'vscode-languageserver-protocol';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string) => Promise<vscode.SymbolInformation[] | undefined>;
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.DocumentSymbol[] | undefined>;
@@ -1,16 +1,44 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  Object.defineProperty(exports, "__esModule", { value: true });
2
11
  exports.register = void 0;
3
12
  const featureWorkers_1 = require("../utils/featureWorkers");
4
13
  const transformer = require("../transformer");
5
- const vscode = require("vscode-languageserver-protocol");
14
+ const shared = require("@volar/shared");
15
+ const common_1 = require("../utils/common");
6
16
  function register(context) {
7
17
  return (uri) => {
8
- return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => { var _a; return (_a = plugin.findDocumentSymbols) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => map ? transformer.asSymbolInformations(data, location => {
9
- const range = map.toSourceRange(location.range);
10
- if (range) {
11
- return vscode.Location.create(map.sourceFileDocument.uri, range);
18
+ return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => __awaiter(this, void 0, void 0, function* () { var _a; return (_a = plugin.findDocumentSymbols) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }), (data, map) => map
19
+ ? data
20
+ .map(symbol => transformer.asDocumentSymbol(symbol, range => map.toSourceRange(range)))
21
+ .filter(shared.notEmpty)
22
+ : data, results => {
23
+ for (let i = 0; i < results.length; i++) {
24
+ for (let j = 0; j < results.length; j++) {
25
+ if (i === j)
26
+ continue;
27
+ results[i] = results[i].filter(child => {
28
+ var _a;
29
+ for (const parent of results[j]) {
30
+ if ((0, common_1.isInsideRange)(parent.range, child.range)) {
31
+ (_a = parent.children) !== null && _a !== void 0 ? _a : (parent.children = []);
32
+ parent.children.push(child);
33
+ return false;
34
+ }
35
+ }
36
+ return true;
37
+ });
38
+ }
12
39
  }
13
- }) : data, arr => arr.flat());
40
+ return results.flat();
41
+ });
14
42
  };
15
43
  }
16
44
  exports.register = register;
@@ -1,3 +1,3 @@
1
- import type { LanguageServiceRuntimeContext } from '../types';
1
+ import type { LanguageServicePluginContext } from '../types';
2
2
  import type * as _ from 'vscode-languageserver-protocol';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string) => Promise<_.FoldingRange[] | undefined>;
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<_.FoldingRange[] | undefined>;
@@ -1,8 +1,6 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import { TextDocument } from 'vscode-languageserver-textdocument';
3
- import type { LanguageServiceRuntimeContext } from '../types';
4
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, options: vscode.FormattingOptions, range?: vscode.Range, onTypeParams?: {
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, options: vscode.FormattingOptions, range?: vscode.Range, onTypeParams?: {
5
4
  ch: string;
6
5
  position: vscode.Position;
7
6
  }) => Promise<vscode.TextEdit[] | undefined>;
8
- export declare function isTsDocument(document: TextDocument): boolean;
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.isTsDocument = exports.register = void 0;
11
+ exports.register = void 0;
12
12
  const vscode = require("vscode-languageserver-protocol");
13
13
  const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
14
14
  const shared = require("@volar/shared");
@@ -23,13 +23,13 @@ function register(context) {
23
23
  const source = context.documents.getSourceByUri(document.uri);
24
24
  if (!source) {
25
25
  return onTypeParams
26
- ? yield tryFormat(document, onTypeParams.position, undefined, onTypeParams.ch)
26
+ ? yield tryFormat(document, onTypeParams.position, onTypeParams.ch)
27
27
  : yield tryFormat(document, range, undefined);
28
28
  }
29
+ const initialIndentLanguageId = (_b = yield ((_a = context.env.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.format.initialIndent'))) !== null && _b !== void 0 ? _b : { html: true };
29
30
  const originalSnapshot = source.snapshot;
30
31
  const rootVirtualFile = source.root;
31
32
  const originalDocument = document;
32
- const initialIndentLanguageId = (_b = yield ((_a = context.env.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.format.initialIndent'))) !== null && _b !== void 0 ? _b : { html: true };
33
33
  let level = 0;
34
34
  let edited = false;
35
35
  while (true) {
@@ -37,47 +37,37 @@ function register(context) {
37
37
  if (embeddedFiles.length === 0)
38
38
  break;
39
39
  let edits = [];
40
- let toPatchIndent;
40
+ const toPatchIndentUris = [];
41
41
  for (const embedded of embeddedFiles) {
42
42
  if (!embedded.capabilities.documentFormatting)
43
43
  continue;
44
+ const isCodeBlock = embedded.mappings.length === 1 && embedded.mappings[0].generatedRange[0] === 0 && embedded.mappings[0].generatedRange[1] === embedded.snapshot.getLength();
45
+ if (onTypeParams && !isCodeBlock)
46
+ continue;
44
47
  const maps = [...context.documents.getMapsByVirtualFileName(embedded.fileName)];
45
48
  const map = (_c = maps.find(map => map[1].sourceFileDocument.uri === document.uri)) === null || _c === void 0 ? void 0 : _c[1];
46
49
  if (!map)
47
50
  continue;
48
- const initialIndentBracket = typeof embedded.capabilities.documentFormatting === 'object' && initialIndentLanguageId[map.virtualFileDocument.languageId]
49
- ? embedded.capabilities.documentFormatting.initialIndentBracket
50
- : undefined;
51
- let _edits;
51
+ let virtualCodeEdits;
52
52
  if (onTypeParams) {
53
53
  const embeddedPosition = map.toGeneratedPosition(onTypeParams.position);
54
54
  if (embeddedPosition) {
55
- _edits = yield tryFormat(map.virtualFileDocument, embeddedPosition, initialIndentBracket, onTypeParams.ch);
55
+ virtualCodeEdits = yield tryFormat(map.virtualFileDocument, embeddedPosition, onTypeParams.ch);
56
56
  }
57
57
  }
58
58
  else {
59
- let genRange = map.toGeneratedRange(range);
60
- if (!genRange) {
61
- const firstMapping = map.map.mappings.sort((a, b) => a.sourceRange[0] - b.sourceRange[0])[0];
62
- const lastMapping = map.map.mappings.sort((a, b) => b.sourceRange[0] - a.sourceRange[0])[0];
63
- if (firstMapping && document.offsetAt(range.start) < firstMapping.sourceRange[0]
64
- && lastMapping && document.offsetAt(range.end) > lastMapping.sourceRange[1]) {
65
- genRange = {
66
- start: map.virtualFileDocument.positionAt(firstMapping.generatedRange[0]),
67
- end: map.virtualFileDocument.positionAt(lastMapping.generatedRange[1]),
68
- };
69
- }
70
- }
71
- if (genRange) {
72
- toPatchIndent = {
73
- sourceMapEmbeddedDocumentUri: map.virtualFileDocument.uri,
74
- };
75
- _edits = yield tryFormat(map.virtualFileDocument, genRange, initialIndentBracket);
76
- }
59
+ virtualCodeEdits = yield tryFormat(map.virtualFileDocument, {
60
+ start: map.virtualFileDocument.positionAt(0),
61
+ end: map.virtualFileDocument.positionAt(map.virtualFileDocument.getText().length),
62
+ });
77
63
  }
78
- if (!_edits)
64
+ if (!virtualCodeEdits)
79
65
  continue;
80
- for (const textEdit of _edits) {
66
+ toPatchIndentUris.push({
67
+ uri: map.virtualFileDocument.uri,
68
+ isCodeBlock,
69
+ });
70
+ for (const textEdit of virtualCodeEdits) {
81
71
  const range = map.toSourceRange(textEdit.range);
82
72
  if (range) {
83
73
  edits.push({
@@ -87,20 +77,57 @@ function register(context) {
87
77
  }
88
78
  }
89
79
  }
80
+ edits = edits.filter(edit => (0, common_1.isInsideRange)(range, edit.range));
90
81
  if (edits.length > 0) {
91
82
  const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
92
83
  document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
93
84
  context.core.virtualFiles.updateSource(shared.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
94
85
  edited = true;
95
86
  }
96
- if (toPatchIndent) {
97
- for (const [_, map] of context.documents.getMapsByVirtualFileUri(toPatchIndent === null || toPatchIndent === void 0 ? void 0 : toPatchIndent.sourceMapEmbeddedDocumentUri)) {
98
- const indentEdits = patchInterpolationIndent(document, map.map);
99
- if (indentEdits.length > 0) {
100
- const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
101
- document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
102
- context.core.virtualFiles.updateSource(shared.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
103
- edited = true;
87
+ if (level > 1) {
88
+ const baseIndent = options.insertSpaces ? ' '.repeat(options.tabSize) : '\t';
89
+ const editLines = new Set();
90
+ if (onTypeParams) {
91
+ for (const edit of edits) {
92
+ for (let line = edit.range.start.line; line <= edit.range.end.line; line++) {
93
+ editLines.add(line);
94
+ }
95
+ }
96
+ }
97
+ for (const toPatchIndentUri of toPatchIndentUris) {
98
+ for (const [_, map] of context.documents.getMapsByVirtualFileUri(toPatchIndentUri.uri)) {
99
+ const indentSensitiveLines = new Set();
100
+ for (const plugin of Object.values(context.plugins)) {
101
+ if (plugin.getIndentSensitiveLines) {
102
+ const lines = yield plugin.getIndentSensitiveLines(map.virtualFileDocument);
103
+ if (lines) {
104
+ for (const line of lines) {
105
+ indentSensitiveLines.add(line);
106
+ }
107
+ }
108
+ }
109
+ }
110
+ let indentEdits = patchIndents(document, toPatchIndentUri.isCodeBlock, map.map, initialIndentLanguageId[map.virtualFileDocument.languageId] ? baseIndent : '');
111
+ indentEdits = indentEdits.filter(edit => {
112
+ for (let line = edit.range.start.line; line <= edit.range.end.line; line++) {
113
+ if (indentSensitiveLines.has(line) && !edit.newText.includes('\n')) {
114
+ return false;
115
+ }
116
+ if (onTypeParams && !editLines.has(line)) {
117
+ return false;
118
+ }
119
+ if (!(0, common_1.isInsideRange)(range, edit.range)) {
120
+ return false;
121
+ }
122
+ }
123
+ return true;
124
+ });
125
+ if (indentEdits.length > 0) {
126
+ const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
127
+ document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
128
+ context.core.virtualFiles.updateSource(shared.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
129
+ edited = true;
130
+ }
104
131
  }
105
132
  }
106
133
  }
@@ -126,100 +153,25 @@ function register(context) {
126
153
  embeddedFilesByLevel.push(nextLevel);
127
154
  }
128
155
  }
129
- function tryFormat(document, range, initialIndentBracket, ch) {
156
+ function tryFormat(document, range, ch) {
130
157
  var _a, _b;
131
158
  return __awaiter(this, void 0, void 0, function* () {
132
- let formatDocument = document;
133
159
  let formatRange = range;
134
- if (initialIndentBracket) {
135
- formatDocument = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version, initialIndentBracket[0] + document.getText() + initialIndentBracket[1]);
136
- if (vscode.Position.is(range)) {
137
- formatRange = formatDocument.positionAt(document.offsetAt(range) + initialIndentBracket[0].length);
138
- }
139
- else {
140
- const startOffset = document.offsetAt(range.start);
141
- const endOffset = document.offsetAt(range.end);
142
- if (startOffset === 0 && endOffset === document.getText().length) {
143
- // full format
144
- formatRange = {
145
- start: formatDocument.positionAt(0),
146
- end: formatDocument.positionAt(formatDocument.getText().length),
147
- };
148
- }
149
- else {
150
- // range format
151
- formatRange = {
152
- start: formatDocument.positionAt(startOffset + initialIndentBracket[0].length),
153
- end: formatDocument.positionAt(endOffset + initialIndentBracket[0].length),
154
- };
155
- }
156
- }
157
- }
158
160
  for (const plugin of Object.values(context.plugins)) {
159
161
  let edits;
160
- let recover;
161
- if (formatDocument !== document && isTsDocument(formatDocument) && context.typescript) {
162
- const formatFileName = shared.uriToFileName(formatDocument.uri);
163
- const formatSnapshot = (0, common_1.stringToSnapshot)(formatDocument.getText());
164
- const host = context.typescript.languageServiceHost;
165
- const original = {
166
- getProjectVersion: host.getProjectVersion,
167
- getScriptVersion: host.getScriptVersion,
168
- getScriptSnapshot: host.getScriptSnapshot,
169
- };
170
- host.getProjectVersion = () => { var _a; return ((_a = original.getProjectVersion) === null || _a === void 0 ? void 0 : _a.call(original)) + '-' + formatDocument.version; };
171
- host.getScriptVersion = (fileName) => {
172
- var _a, _b;
173
- if (fileName === formatFileName) {
174
- return ((_a = original.getScriptVersion) === null || _a === void 0 ? void 0 : _a.call(original, fileName)) + '-' + formatDocument.version.toString();
175
- }
176
- return (_b = original.getScriptVersion) === null || _b === void 0 ? void 0 : _b.call(original, fileName);
177
- };
178
- host.getScriptSnapshot = (fileName) => {
179
- var _a;
180
- if (fileName === formatFileName) {
181
- return formatSnapshot;
182
- }
183
- return (_a = original.getScriptSnapshot) === null || _a === void 0 ? void 0 : _a.call(original, fileName);
184
- };
185
- recover = () => {
186
- host.getProjectVersion = original.getProjectVersion;
187
- host.getScriptVersion = original.getScriptVersion;
188
- host.getScriptSnapshot = original.getScriptSnapshot;
189
- };
190
- }
191
162
  try {
192
163
  if (ch !== undefined && vscode.Position.is(formatRange)) {
193
- edits = yield ((_a = plugin.formatOnType) === null || _a === void 0 ? void 0 : _a.call(plugin, formatDocument, formatRange, ch, options));
164
+ edits = yield ((_a = plugin.formatOnType) === null || _a === void 0 ? void 0 : _a.call(plugin, document, formatRange, ch, options));
194
165
  }
195
166
  else if (ch === undefined && vscode.Range.is(formatRange)) {
196
- edits = yield ((_b = plugin.format) === null || _b === void 0 ? void 0 : _b.call(plugin, formatDocument, formatRange, options));
167
+ edits = yield ((_b = plugin.format) === null || _b === void 0 ? void 0 : _b.call(plugin, document, formatRange, options));
197
168
  }
198
169
  }
199
170
  catch (err) {
200
- console.error(err);
171
+ console.warn(err);
201
172
  }
202
- recover === null || recover === void 0 ? void 0 : recover();
203
173
  if (!edits)
204
174
  continue;
205
- if (!edits.length)
206
- return edits;
207
- if (initialIndentBracket) {
208
- let newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(formatDocument, edits);
209
- newText = newText.substring(newText.indexOf(initialIndentBracket[0]) + initialIndentBracket[0].length, newText.lastIndexOf(initialIndentBracket[1]));
210
- if (newText === document.getText()) {
211
- edits = [];
212
- }
213
- else {
214
- edits = [{
215
- newText,
216
- range: {
217
- start: document.positionAt(0),
218
- end: document.positionAt(document.getText().length),
219
- },
220
- }];
221
- }
222
- }
223
175
  return edits;
224
176
  }
225
177
  });
@@ -227,51 +179,61 @@ function register(context) {
227
179
  });
228
180
  }
229
181
  exports.register = register;
230
- function patchInterpolationIndent(document, map) {
182
+ function patchIndents(document, isCodeBlock, map, initialIndent) {
231
183
  const indentTextEdits = [];
232
- for (const mapped of map.mappings) {
233
- const textRange = {
234
- start: document.positionAt(mapped.sourceRange[0]),
235
- end: document.positionAt(mapped.sourceRange[1]),
236
- };
237
- const text = document.getText(textRange);
238
- if (text.indexOf('\n') === -1)
239
- continue;
184
+ if (!isCodeBlock) {
185
+ initialIndent = '';
186
+ }
187
+ for (let i = 0; i < map.mappings.length; i++) {
188
+ const mapping = map.mappings[i];
189
+ const firstLineIndent = getBaseIndent(mapping.sourceRange[0]);
190
+ const text = document.getText().substring(mapping.sourceRange[0], mapping.sourceRange[1]);
240
191
  const lines = text.split('\n');
241
- const removeIndent = getRemoveIndent(lines);
242
- const baseIndent = getBaseIndent(mapped.sourceRange[0]);
243
- if (removeIndent === baseIndent)
192
+ const baseIndent = firstLineIndent + initialIndent;
193
+ let lineOffset = lines[0].length + 1;
194
+ let insertedFinalNewLine = false;
195
+ if (!text.trim())
244
196
  continue;
245
- for (let i = 1; i < lines.length; i++) {
246
- const line = lines[i];
247
- if (line.startsWith(removeIndent)) {
248
- lines[i] = line.replace(removeIndent, baseIndent);
249
- }
250
- else {
251
- lines[i] = baseIndent.replace(removeIndent, '') + line;
197
+ if (isCodeBlock && text.trimStart().length === text.length) {
198
+ indentTextEdits.push({
199
+ newText: '\n' + baseIndent,
200
+ range: {
201
+ start: document.positionAt(mapping.sourceRange[0]),
202
+ end: document.positionAt(mapping.sourceRange[0]),
203
+ },
204
+ });
205
+ }
206
+ if (isCodeBlock && text.trimEnd().length === text.length) {
207
+ indentTextEdits.push({
208
+ newText: '\n',
209
+ range: {
210
+ start: document.positionAt(mapping.sourceRange[1]),
211
+ end: document.positionAt(mapping.sourceRange[1]),
212
+ },
213
+ });
214
+ insertedFinalNewLine = true;
215
+ }
216
+ if (baseIndent && lines.length > 1) {
217
+ for (let i = 1; i < lines.length; i++) {
218
+ if (lines[i].trim() || i === lines.length - 1) {
219
+ const isLastLine = i === lines.length - 1 && !insertedFinalNewLine;
220
+ indentTextEdits.push({
221
+ newText: isLastLine ? firstLineIndent : baseIndent,
222
+ range: {
223
+ start: document.positionAt(mapping.sourceRange[0] + lineOffset),
224
+ end: document.positionAt(mapping.sourceRange[0] + lineOffset),
225
+ },
226
+ });
227
+ }
228
+ lineOffset += lines[i].length + 1;
252
229
  }
253
230
  }
254
- indentTextEdits.push({
255
- newText: lines.join('\n'),
256
- range: textRange,
257
- });
258
231
  }
259
232
  return indentTextEdits;
260
- function getRemoveIndent(lines) {
261
- const lastLine = lines[lines.length - 1];
262
- return lastLine.substring(0, lastLine.length - lastLine.trimStart().length);
263
- }
264
233
  function getBaseIndent(pos) {
265
234
  const startPos = document.positionAt(pos);
266
- const startLineText = document.getText({ start: startPos, end: { line: startPos.line, character: 0 } });
235
+ const startLineText = document.getText({ start: { line: startPos.line, character: 0 }, end: startPos });
267
236
  return startLineText.substring(0, startLineText.length - startLineText.trimStart().length);
268
237
  }
269
238
  }
270
- function isTsDocument(document) {
271
- return document.languageId === 'javascript' ||
272
- document.languageId === 'typescript' ||
273
- document.languageId === 'javascriptreact' ||
274
- document.languageId === 'typescriptreact';
275
- }
276
- exports.isTsDocument = isTsDocument;
277
239
  //# sourceMappingURL=format.js.map
@@ -1,3 +1,3 @@
1
- import type { LanguageServiceRuntimeContext } from '../types';
1
+ import type { LanguageServicePluginContext } from '../types';
2
2
  import * as vscode from 'vscode-languageserver-protocol';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position) => Promise<vscode.LinkedEditingRanges | undefined>;
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<vscode.LinkedEditingRanges | undefined>;
@@ -1,3 +1,3 @@
1
- import type { LanguageServiceRuntimeContext } from '../types';
1
+ import type { LanguageServicePluginContext } from '../types';
2
2
  import * as vscode from 'vscode-languageserver-protocol';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, positions: vscode.Position[]) => Promise<vscode.SelectionRange[] | undefined>;
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, positions: vscode.Position[]) => Promise<vscode.SelectionRange[] | undefined>;
package/out/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export * from '@volar/language-core';
2
2
  export * from './baseLanguageService';
3
3
  export * from './documents';
4
- export { executePluginCommand, ExecutePluginCommandArgs } from './languageFeatures/executeCommand';
5
4
  export { mergeWorkspaceEdits } from './languageFeatures/rename';
6
5
  export * from './types';
7
6
  export * as transformer from './transformer';
7
+ export { showReferencesCommand, ShowReferencesCommandData } from './languageFeatures/codeLensResolve';
package/out/index.js CHANGED
@@ -13,14 +13,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
13
13
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.transformer = exports.mergeWorkspaceEdits = exports.executePluginCommand = void 0;
16
+ exports.showReferencesCommand = exports.transformer = exports.mergeWorkspaceEdits = void 0;
17
17
  __exportStar(require("@volar/language-core"), exports);
18
18
  __exportStar(require("./baseLanguageService"), exports);
19
19
  __exportStar(require("./documents"), exports);
20
- var executeCommand_1 = require("./languageFeatures/executeCommand");
21
- Object.defineProperty(exports, "executePluginCommand", { enumerable: true, get: function () { return executeCommand_1.executePluginCommand; } });
22
20
  var rename_1 = require("./languageFeatures/rename");
23
21
  Object.defineProperty(exports, "mergeWorkspaceEdits", { enumerable: true, get: function () { return rename_1.mergeWorkspaceEdits; } });
24
22
  __exportStar(require("./types"), exports);
25
23
  exports.transformer = require("./transformer");
24
+ var codeLensResolve_1 = require("./languageFeatures/codeLensResolve");
25
+ Object.defineProperty(exports, "showReferencesCommand", { enumerable: true, get: function () { return codeLensResolve_1.showReferencesCommand; } });
26
26
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServicePluginInstance, LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position, autoInsertContext: Parameters<NonNullable<LanguageServicePluginInstance['doAutoInsert']>>[2]) => Promise<NonNullable<string | vscode.TextEdit | null | undefined> | undefined>;
2
+ import type { LanguageServicePluginInstance, LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, autoInsertContext: Parameters<NonNullable<LanguageServicePluginInstance['doAutoInsert']>>[2]) => Promise<NonNullable<string | vscode.TextEdit | null | undefined> | undefined>;
@@ -1,5 +1,5 @@
1
1
  import type * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
2
+ import type { LanguageServicePluginContext } from '../types';
3
3
  export interface PluginCallHierarchyData {
4
4
  uri: string;
5
5
  original: Pick<vscode.CallHierarchyItem, 'data'>;
@@ -8,7 +8,7 @@ export interface PluginCallHierarchyData {
8
8
  embeddedDocumentUri: string;
9
9
  } | undefined;
10
10
  }
11
- export declare function register(context: LanguageServiceRuntimeContext): {
11
+ export declare function register(context: LanguageServicePluginContext): {
12
12
  doPrepare(uri: string, position: vscode.Position): Promise<vscode.CallHierarchyItem[] | undefined>;
13
13
  getIncomingCalls(item: vscode.CallHierarchyItem): Promise<vscode.CallHierarchyIncomingCall[]>;
14
14
  getOutgoingCalls(item: vscode.CallHierarchyItem): Promise<vscode.CallHierarchyOutgoingCall[]>;
@@ -1,3 +1,3 @@
1
1
  import type { CodeAction } from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (item: CodeAction) => Promise<CodeAction>;
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (item: CodeAction) => Promise<CodeAction>;