@volar/language-service 1.2.0-alpha.13 → 1.2.0-alpha.15

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.
@@ -60,15 +60,13 @@ function register(context) {
60
60
  start: map.virtualFileDocument.positionAt(0),
61
61
  end: map.virtualFileDocument.positionAt(map.virtualFileDocument.getText().length),
62
62
  });
63
- if (virtualCodeEdits) {
64
- toPatchIndentUris.push({
65
- uri: map.virtualFileDocument.uri,
66
- isCodeBlock,
67
- });
68
- }
69
63
  }
70
64
  if (!virtualCodeEdits)
71
65
  continue;
66
+ toPatchIndentUris.push({
67
+ uri: map.virtualFileDocument.uri,
68
+ isCodeBlock,
69
+ });
72
70
  for (const textEdit of virtualCodeEdits) {
73
71
  const range = map.toSourceRange(textEdit.range);
74
72
  if (range) {
@@ -88,10 +86,42 @@ function register(context) {
88
86
  }
89
87
  if (level > 1) {
90
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
+ }
91
97
  for (const toPatchIndentUri of toPatchIndentUris) {
92
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
+ }
93
110
  let indentEdits = patchIndents(document, toPatchIndentUri.isCodeBlock, map.map, initialIndentLanguageId[map.virtualFileDocument.languageId] ? baseIndent : '');
94
- indentEdits = indentEdits.filter(edit => (0, common_1.isInsideRange)(range, edit.range));
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
+ });
95
125
  if (indentEdits.length > 0) {
96
126
  const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
97
127
  document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
@@ -14,7 +14,7 @@ const featureWorkers_1 = require("../utils/featureWorkers");
14
14
  function register(context) {
15
15
  return (uri) => __awaiter(this, void 0, void 0, function* () {
16
16
  var _a;
17
- const pluginLinks = (_a = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], (plugin, document) => { var _a; return (_a = plugin.findDocumentLinks) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => data.map(link => {
17
+ const pluginLinks = (_a = yield (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => { var _a; return (_a = plugin.findDocumentLinks) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => data.map(link => {
18
18
  if (!map)
19
19
  return link;
20
20
  const range = map.toSourceRange(link.range);
@@ -160,7 +160,7 @@ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
160
160
  for (const [_, map] of documents.getMapsByVirtualFileUri(tsUri)) {
161
161
  const tsEdits = tsResult.changes[tsUri];
162
162
  for (const tsEdit of tsEdits) {
163
- if (mode === 'rename') {
163
+ if (mode === 'rename' || mode === 'fileName') {
164
164
  let _data;
165
165
  const range = map.toSourceRange(tsEdit.range, data => {
166
166
  _data = data;
@@ -199,7 +199,7 @@ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
199
199
  version: (_f = versions[map.sourceFileDocument.uri]) !== null && _f !== void 0 ? _f : null,
200
200
  }, []);
201
201
  for (const tsEdit of tsDocEdit.edits) {
202
- if (mode === 'rename') {
202
+ if (mode === 'rename' || mode === 'fileName') {
203
203
  let _data;
204
204
  const range = map.toSourceRange(tsEdit.range, data => {
205
205
  _data = data;
@@ -1,34 +1,30 @@
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
- };
10
1
  Object.defineProperty(exports, "__esModule", { value: true });
11
2
  exports.register = void 0;
12
3
  const vscode = require("vscode-languageserver-protocol");
13
4
  const featureWorkers_1 = require("../utils/featureWorkers");
14
5
  function register(context) {
15
- return (uri, position) => __awaiter(this, void 0, void 0, function* () {
16
- return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename), (plugin, document, position) => { var _a, _b; return (_b = (_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.prepare) === null || _b === void 0 ? void 0 : _b.call(_a, document, position); }, (item, map) => {
6
+ return (uri, position) => {
7
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), (plugin, document, position) => { var _a, _b; return (_b = (_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.prepare) === null || _b === void 0 ? void 0 : _b.call(_a, document, position); }, (item, map) => {
17
8
  if (!map) {
18
9
  return item;
19
10
  }
20
11
  if (vscode.Range.is(item)) {
21
12
  return map.toSourceRange(item);
22
13
  }
14
+ return item;
23
15
  }, prepares => {
24
16
  for (const prepare of prepares) {
25
17
  if (vscode.Range.is(prepare)) {
26
18
  return prepare; // if has any valid range, ignore other errors
27
19
  }
28
20
  }
29
- return prepares[0];
21
+ const error = prepares[0];
22
+ const newError = new vscode.ResponseError(error.code, error.message);
23
+ newError.name = error.name;
24
+ newError.stack = error.stack;
25
+ return newError;
30
26
  });
31
- });
27
+ };
32
28
  }
33
29
  exports.register = register;
34
30
  //# sourceMappingURL=renamePrepare.js.map
package/out/types.d.ts CHANGED
@@ -88,6 +88,7 @@ export interface LanguageServicePluginInstance {
88
88
  getSignatureHelp?(document: TextDocument, position: vscode.Position, context?: vscode.SignatureHelpContext): NullableResult<vscode.SignatureHelp>;
89
89
  format?(document: TextDocument, range: vscode.Range, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>;
90
90
  formatOnType?(document: TextDocument, position: vscode.Position, key: string, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>;
91
+ getIndentSensitiveLines?(document: TextDocument): NullableResult<number[]>;
91
92
  definition?: {
92
93
  on?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>;
93
94
  onType?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-service",
3
- "version": "1.2.0-alpha.13",
3
+ "version": "1.2.0-alpha.15",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,15 +13,15 @@
13
13
  "directory": "packages/language-service"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "1.2.0-alpha.13",
17
- "@volar/shared": "1.2.0-alpha.13",
18
- "@volar/source-map": "1.2.0-alpha.13",
19
- "@volar/typescript-faster": "1.2.0-alpha.13",
16
+ "@volar/language-core": "1.2.0-alpha.15",
17
+ "@volar/shared": "1.2.0-alpha.15",
18
+ "@volar/source-map": "1.2.0-alpha.15",
19
+ "@volar/typescript-faster": "1.2.0-alpha.15",
20
20
  "vscode-html-languageservice": "^5.0.4",
21
21
  "vscode-json-languageservice": "^5.2.0",
22
22
  "vscode-languageserver-protocol": "^3.17.3",
23
23
  "vscode-languageserver-textdocument": "^1.0.8",
24
24
  "vscode-uri": "^3.0.7"
25
25
  },
26
- "gitHead": "2b935afad2e4e4e307ae525387f66516e496ba24"
26
+ "gitHead": "cfd47cc6a882a96dd8a35bdcc26a4607bd0347d2"
27
27
  }