@volar/language-service 1.2.0-alpha.11 → 1.2.0-alpha.12
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/out/documentFeatures/format.js +33 -34
- package/package.json +6 -6
|
@@ -41,8 +41,8 @@ function register(context) {
|
|
|
41
41
|
for (const embedded of embeddedFiles) {
|
|
42
42
|
if (!embedded.capabilities.documentFormatting)
|
|
43
43
|
continue;
|
|
44
|
-
const
|
|
45
|
-
if (onTypeParams && !
|
|
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
46
|
continue;
|
|
47
47
|
const maps = [...context.documents.getMapsByVirtualFileName(embedded.fileName)];
|
|
48
48
|
const map = (_c = maps.find(map => map[1].sourceFileDocument.uri === document.uri)) === null || _c === void 0 ? void 0 : _c[1];
|
|
@@ -60,10 +60,15 @@ 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
|
+
}
|
|
63
69
|
}
|
|
64
70
|
if (!virtualCodeEdits)
|
|
65
71
|
continue;
|
|
66
|
-
toPatchIndentUris.push(map.virtualFileDocument.uri);
|
|
67
72
|
for (const textEdit of virtualCodeEdits) {
|
|
68
73
|
const range = map.toSourceRange(textEdit.range);
|
|
69
74
|
if (range) {
|
|
@@ -84,8 +89,8 @@ function register(context) {
|
|
|
84
89
|
if (level > 1) {
|
|
85
90
|
const baseIndent = options.insertSpaces ? ' '.repeat(options.tabSize) : '\t';
|
|
86
91
|
for (const toPatchIndentUri of toPatchIndentUris) {
|
|
87
|
-
for (const [
|
|
88
|
-
let indentEdits =
|
|
92
|
+
for (const [_, map] of context.documents.getMapsByVirtualFileUri(toPatchIndentUri.uri)) {
|
|
93
|
+
let indentEdits = patchIndents(document, toPatchIndentUri.isCodeBlock, map.map, initialIndentLanguageId[map.virtualFileDocument.languageId] ? baseIndent : '');
|
|
89
94
|
indentEdits = indentEdits.filter(edit => (0, common_1.isInsideRange)(range, edit.range));
|
|
90
95
|
if (indentEdits.length > 0) {
|
|
91
96
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
|
|
@@ -144,21 +149,22 @@ function register(context) {
|
|
|
144
149
|
});
|
|
145
150
|
}
|
|
146
151
|
exports.register = register;
|
|
147
|
-
function
|
|
148
|
-
const insertFirstNewline = typeof data === 'object' ? data.insertFirstNewline : false;
|
|
149
|
-
const insertFinalNewline = typeof data === 'object' ? data.insertFinalNewline : false;
|
|
152
|
+
function patchIndents(document, isCodeBlock, map, initialIndent) {
|
|
150
153
|
const indentTextEdits = [];
|
|
154
|
+
if (!isCodeBlock) {
|
|
155
|
+
initialIndent = '';
|
|
156
|
+
}
|
|
151
157
|
for (let i = 0; i < map.mappings.length; i++) {
|
|
152
158
|
const mapping = map.mappings[i];
|
|
153
159
|
const firstLineIndent = getBaseIndent(mapping.sourceRange[0]);
|
|
154
160
|
const text = document.getText().substring(mapping.sourceRange[0], mapping.sourceRange[1]);
|
|
155
|
-
if (text.indexOf('\n') === -1) {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
161
|
const lines = text.split('\n');
|
|
159
162
|
const baseIndent = firstLineIndent + initialIndent;
|
|
160
163
|
let lineOffset = lines[0].length + 1;
|
|
161
|
-
|
|
164
|
+
let insertedFinalNewLine = false;
|
|
165
|
+
if (!text.trim())
|
|
166
|
+
continue;
|
|
167
|
+
if (isCodeBlock && text.trimStart().length === text.length) {
|
|
162
168
|
indentTextEdits.push({
|
|
163
169
|
newText: '\n' + baseIndent,
|
|
164
170
|
range: {
|
|
@@ -167,11 +173,22 @@ function patchInterpolationIndent(document, map, initialIndent, data) {
|
|
|
167
173
|
},
|
|
168
174
|
});
|
|
169
175
|
}
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
|
|
176
|
+
if (isCodeBlock && text.trimEnd().length === text.length) {
|
|
177
|
+
indentTextEdits.push({
|
|
178
|
+
newText: '\n',
|
|
179
|
+
range: {
|
|
180
|
+
start: document.positionAt(mapping.sourceRange[1]),
|
|
181
|
+
end: document.positionAt(mapping.sourceRange[1]),
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
insertedFinalNewLine = true;
|
|
185
|
+
}
|
|
186
|
+
if (baseIndent && lines.length > 1) {
|
|
187
|
+
for (let i = 1; i < lines.length; i++) {
|
|
188
|
+
if (lines[i] !== '' || i === lines.length - 1) {
|
|
189
|
+
const isLastLine = i === lines.length - 1 && !insertedFinalNewLine;
|
|
173
190
|
indentTextEdits.push({
|
|
174
|
-
newText: baseIndent,
|
|
191
|
+
newText: isLastLine ? firstLineIndent : baseIndent,
|
|
175
192
|
range: {
|
|
176
193
|
start: document.positionAt(mapping.sourceRange[0] + lineOffset),
|
|
177
194
|
end: document.positionAt(mapping.sourceRange[0] + lineOffset),
|
|
@@ -181,24 +198,6 @@ function patchInterpolationIndent(document, map, initialIndent, data) {
|
|
|
181
198
|
lineOffset += lines[i].length + 1;
|
|
182
199
|
}
|
|
183
200
|
}
|
|
184
|
-
if (firstLineIndent) {
|
|
185
|
-
indentTextEdits.push({
|
|
186
|
-
newText: firstLineIndent,
|
|
187
|
-
range: {
|
|
188
|
-
start: document.positionAt(mapping.sourceRange[0] + lineOffset),
|
|
189
|
-
end: document.positionAt(mapping.sourceRange[0] + lineOffset),
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
if (insertFinalNewline && i === map.mappings.length - 1 && !text.endsWith('\n')) {
|
|
194
|
-
indentTextEdits.push({
|
|
195
|
-
newText: '\n',
|
|
196
|
-
range: {
|
|
197
|
-
start: document.positionAt(mapping.sourceRange[1]),
|
|
198
|
-
end: document.positionAt(mapping.sourceRange[1]),
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
201
|
}
|
|
203
202
|
return indentTextEdits;
|
|
204
203
|
function getBaseIndent(pos) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-service",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.12",
|
|
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.
|
|
17
|
-
"@volar/shared": "1.2.0-alpha.
|
|
18
|
-
"@volar/source-map": "1.2.0-alpha.
|
|
19
|
-
"@volar/typescript-faster": "1.2.0-alpha.
|
|
16
|
+
"@volar/language-core": "1.2.0-alpha.12",
|
|
17
|
+
"@volar/shared": "1.2.0-alpha.12",
|
|
18
|
+
"@volar/source-map": "1.2.0-alpha.12",
|
|
19
|
+
"@volar/typescript-faster": "1.2.0-alpha.12",
|
|
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": "
|
|
26
|
+
"gitHead": "cac0a7e75c45bd217f98b8d2f66a03860cc89e0c"
|
|
27
27
|
}
|