@astrojs/language-server 0.9.2 → 0.12.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.
- package/CHANGELOG.md +22 -0
- package/bin/browserServer.js +3 -0
- package/bin/nodeServer.js +3 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +8 -0
- package/dist/check.js +2 -5
- package/dist/core/DiagnosticsManager.d.ts +3 -3
- package/dist/core/DiagnosticsManager.js +2 -2
- package/dist/core/config/ConfigManager.d.ts +19 -164
- package/dist/core/config/ConfigManager.js +62 -101
- package/dist/core/config/index.d.ts +1 -0
- package/dist/core/config/index.js +6 -1
- package/dist/core/config/interfaces.d.ts +123 -0
- package/dist/core/config/interfaces.js +2 -0
- package/dist/core/documents/AstroDocument.d.ts +18 -0
- package/dist/core/documents/AstroDocument.js +37 -0
- package/dist/core/documents/DocumentBase.d.ts +10 -2
- package/dist/core/documents/DocumentBase.js +15 -50
- package/dist/core/documents/DocumentManager.d.ts +12 -16
- package/dist/core/documents/DocumentManager.js +32 -26
- package/dist/core/documents/DocumentMapper.js +3 -1
- package/dist/core/documents/index.d.ts +1 -1
- package/dist/core/documents/index.js +6 -2
- package/dist/core/documents/parseAstro.d.ts +2 -2
- package/dist/core/documents/parseHtml.d.ts +2 -2
- package/dist/core/documents/parseHtml.js +4 -1
- package/dist/core/documents/utils.d.ts +22 -26
- package/dist/core/documents/utils.js +96 -134
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -3
- package/dist/node.d.ts +1 -0
- package/dist/node.js +29 -0
- package/dist/plugins/PluginHost.d.ts +8 -9
- package/dist/plugins/PluginHost.js +22 -36
- package/dist/plugins/astro/AstroPlugin.d.ts +11 -12
- package/dist/plugins/astro/AstroPlugin.js +17 -38
- package/dist/plugins/astro/features/{CompletionProvider.d.ts → CompletionsProvider.d.ts} +5 -5
- package/dist/plugins/astro/features/{CompletionProvider.js → CompletionsProvider.js} +33 -54
- package/dist/plugins/css/CSSDocument.d.ts +3 -3
- package/dist/plugins/css/CSSDocument.js +7 -16
- package/dist/plugins/css/CSSPlugin.d.ts +19 -11
- package/dist/plugins/css/CSSPlugin.js +63 -41
- package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
- package/dist/plugins/css/StyleAttributeDocument.js +2 -2
- package/dist/plugins/css/features/astro-selectors.d.ts +2 -0
- package/dist/plugins/css/features/astro-selectors.js +16 -0
- package/dist/plugins/css/features/{getIdClassCompletion.d.ts → getIdClassCompletions.d.ts} +3 -3
- package/dist/plugins/css/features/{getIdClassCompletion.js → getIdClassCompletions.js} +10 -9
- package/dist/plugins/css/{service.d.ts → language-service.d.ts} +0 -0
- package/dist/plugins/css/{service.js → language-service.js} +2 -1
- package/dist/plugins/html/HTMLPlugin.d.ts +15 -17
- package/dist/plugins/html/HTMLPlugin.js +33 -41
- package/dist/plugins/index.d.ts +2 -2
- package/dist/plugins/index.js +7 -3
- package/dist/plugins/interfaces.d.ts +35 -48
- package/dist/plugins/typescript/LanguageServiceManager.d.ts +33 -14
- package/dist/plugins/typescript/LanguageServiceManager.js +57 -32
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +16 -23
- package/dist/plugins/typescript/TypeScriptPlugin.js +48 -56
- package/dist/plugins/typescript/astro-sys.d.ts +5 -3
- package/dist/plugins/typescript/astro-sys.js +24 -41
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +6 -6
- package/dist/plugins/typescript/features/CompletionsProvider.js +17 -33
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +4 -4
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +22 -61
- package/dist/plugins/typescript/features/HoverProvider.d.ts +4 -5
- package/dist/plugins/typescript/features/HoverProvider.js +9 -10
- package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +4 -5
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +15 -11
- package/dist/plugins/typescript/features/utils.d.ts +1 -12
- package/dist/plugins/typescript/features/utils.js +2 -22
- package/dist/plugins/typescript/language-service.d.ts +38 -0
- package/dist/plugins/typescript/language-service.js +227 -0
- package/dist/plugins/typescript/module-loader.d.ts +5 -8
- package/dist/plugins/typescript/module-loader.js +43 -23
- package/dist/plugins/typescript/{DocumentSnapshot.d.ts → snapshots/DocumentSnapshot.d.ts} +45 -42
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +135 -0
- package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +42 -0
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +197 -0
- package/dist/plugins/typescript/snapshots/utils.d.ts +28 -0
- package/dist/plugins/typescript/snapshots/utils.js +84 -0
- package/dist/plugins/typescript/utils.d.ts +10 -11
- package/dist/plugins/typescript/utils.js +122 -151
- package/dist/server.d.ts +2 -4
- package/dist/server.js +88 -54
- package/dist/utils.d.ts +16 -8
- package/dist/utils.js +29 -14
- package/package.json +19 -13
- package/bin/server.js +0 -7
- package/dist/core/documents/Document.d.ts +0 -51
- package/dist/core/documents/Document.js +0 -135
- package/dist/plugins/typescript/DocumentSnapshot.js +0 -202
- package/dist/plugins/typescript/SnapshotManager.d.ts +0 -24
- package/dist/plugins/typescript/SnapshotManager.js +0 -97
- package/dist/plugins/typescript/languageService.d.ts +0 -17
- package/dist/plugins/typescript/languageService.js +0 -169
- package/types/index.d.ts +0 -4
|
@@ -1,10 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
3
|
+
exports.getFirstNonWhitespaceIndex = exports.getLineOffsets = exports.offsetAt = exports.positionAt = exports.isInsideFrontmatter = exports.isInsideExpression = exports.isInTag = exports.isInComponentStartTag = exports.isComponentTag = exports.extractStyleTags = exports.walk = void 0;
|
|
5
4
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
6
5
|
const utils_1 = require("../../utils");
|
|
7
6
|
const parseHtml_1 = require("./parseHtml");
|
|
7
|
+
function* walk(node) {
|
|
8
|
+
for (let child of node.children) {
|
|
9
|
+
yield* walk(child);
|
|
10
|
+
}
|
|
11
|
+
yield node;
|
|
12
|
+
}
|
|
13
|
+
exports.walk = walk;
|
|
14
|
+
/**
|
|
15
|
+
* Extracts a tag (style or script) from the given text
|
|
16
|
+
* and returns its start, end and the attributes on that tag.
|
|
17
|
+
*
|
|
18
|
+
* @param source text content to extract tag from
|
|
19
|
+
* @param tag the tag to extract
|
|
20
|
+
*/
|
|
21
|
+
function extractTags(text, tag, html) {
|
|
22
|
+
const rootNodes = (html === null || html === void 0 ? void 0 : html.roots) || (0, parseHtml_1.parseHtml)(text).roots;
|
|
23
|
+
const matchedNodes = rootNodes.filter((node) => node.tag === tag);
|
|
24
|
+
if (tag === 'style' && !matchedNodes.length && rootNodes.length) {
|
|
25
|
+
for (let child of walk(rootNodes[0])) {
|
|
26
|
+
if (child.tag === 'style') {
|
|
27
|
+
matchedNodes.push(child);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return matchedNodes.map(transformToTagInfo);
|
|
32
|
+
function transformToTagInfo(matchedNode) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const start = (_a = matchedNode.startTagEnd) !== null && _a !== void 0 ? _a : matchedNode.start;
|
|
35
|
+
const end = (_b = matchedNode.endTagStart) !== null && _b !== void 0 ? _b : matchedNode.end;
|
|
36
|
+
const startPos = positionAt(start, text);
|
|
37
|
+
const endPos = positionAt(end, text);
|
|
38
|
+
const container = {
|
|
39
|
+
start: matchedNode.start,
|
|
40
|
+
end: matchedNode.end,
|
|
41
|
+
};
|
|
42
|
+
const content = text.substring(start, end);
|
|
43
|
+
return {
|
|
44
|
+
content,
|
|
45
|
+
attributes: parseAttributes(matchedNode.attributes),
|
|
46
|
+
start,
|
|
47
|
+
end,
|
|
48
|
+
startPos,
|
|
49
|
+
endPos,
|
|
50
|
+
container,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function extractStyleTags(source, html) {
|
|
55
|
+
const styles = extractTags(source, 'style', html);
|
|
56
|
+
if (!styles.length) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
return styles;
|
|
60
|
+
}
|
|
61
|
+
exports.extractStyleTags = extractStyleTags;
|
|
8
62
|
function parseAttributes(rawAttrs) {
|
|
9
63
|
const attrs = {};
|
|
10
64
|
if (!rawAttrs) {
|
|
@@ -16,48 +70,42 @@ function parseAttributes(rawAttrs) {
|
|
|
16
70
|
});
|
|
17
71
|
return attrs;
|
|
18
72
|
function removeOuterQuotes(attrValue) {
|
|
19
|
-
if ((attrValue.startsWith('"') && attrValue.endsWith('"')) ||
|
|
73
|
+
if ((attrValue.startsWith('"') && attrValue.endsWith('"')) ||
|
|
74
|
+
(attrValue.startsWith("'") && attrValue.endsWith("'"))) {
|
|
20
75
|
return attrValue.slice(1, attrValue.length - 1);
|
|
21
76
|
}
|
|
22
77
|
return attrValue;
|
|
23
78
|
}
|
|
24
79
|
}
|
|
25
80
|
/**
|
|
26
|
-
*
|
|
27
|
-
* Delimiter is by default a whitespace, but can be adjusted.
|
|
81
|
+
* Return if a Node is a Component
|
|
28
82
|
*/
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
start = pos;
|
|
33
|
-
}
|
|
34
|
-
let end = str.slice(pos).search(delimiterRegex.right);
|
|
35
|
-
if (end < 0) {
|
|
36
|
-
end = str.length;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
end = end + pos;
|
|
83
|
+
function isComponentTag(node) {
|
|
84
|
+
if (!node.tag) {
|
|
85
|
+
return false;
|
|
40
86
|
}
|
|
41
|
-
|
|
87
|
+
const firstChar = node.tag[0];
|
|
88
|
+
return /[A-Z]/.test(firstChar);
|
|
42
89
|
}
|
|
43
|
-
exports.
|
|
90
|
+
exports.isComponentTag = isComponentTag;
|
|
44
91
|
/**
|
|
45
|
-
*
|
|
46
|
-
* Delimiter is by default a whitespace, but can be adjusted.
|
|
92
|
+
* Return if a given offset is inside the start tag of a component
|
|
47
93
|
*/
|
|
48
|
-
function
|
|
49
|
-
const
|
|
50
|
-
return
|
|
94
|
+
function isInComponentStartTag(html, offset) {
|
|
95
|
+
const node = html.findNodeAt(offset);
|
|
96
|
+
return isComponentTag(node) && (!node.startTagEnd || offset < node.startTagEnd);
|
|
51
97
|
}
|
|
52
|
-
exports.
|
|
98
|
+
exports.isInComponentStartTag = isInComponentStartTag;
|
|
53
99
|
/**
|
|
54
|
-
*
|
|
100
|
+
* Return if the current position is in a specific tag
|
|
55
101
|
*/
|
|
56
|
-
function
|
|
57
|
-
return
|
|
102
|
+
function isInTag(position, tagInfo) {
|
|
103
|
+
return !!tagInfo && (0, utils_1.isInRange)(vscode_languageserver_1.Range.create(tagInfo.startPos, tagInfo.endPos), position);
|
|
58
104
|
}
|
|
59
|
-
exports.
|
|
60
|
-
/**
|
|
105
|
+
exports.isInTag = isInTag;
|
|
106
|
+
/**
|
|
107
|
+
* Return if a given position is inside a JSX expression
|
|
108
|
+
*/
|
|
61
109
|
function isInsideExpression(html, tagStart, position) {
|
|
62
110
|
const charactersInNode = html.substring(tagStart, position);
|
|
63
111
|
return charactersInNode.lastIndexOf('{') > charactersInNode.lastIndexOf('}');
|
|
@@ -72,58 +120,45 @@ function isInsideFrontmatter(text, offset) {
|
|
|
72
120
|
return start > 1 && start < 3 && end >= 1;
|
|
73
121
|
}
|
|
74
122
|
exports.isInsideFrontmatter = isInsideFrontmatter;
|
|
75
|
-
function isInTag(position, tagInfo) {
|
|
76
|
-
return !!tagInfo && (0, utils_1.isInRange)(position, vscode_languageserver_1.Range.create(tagInfo.startPos, tagInfo.endPos));
|
|
77
|
-
}
|
|
78
|
-
exports.isInTag = isInTag;
|
|
79
|
-
function isComponentTag(node) {
|
|
80
|
-
if (!node.tag) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
const firstChar = node.tag[0];
|
|
84
|
-
return /[A-Z]/.test(firstChar);
|
|
85
|
-
}
|
|
86
|
-
exports.isComponentTag = isComponentTag;
|
|
87
|
-
function isInComponentStartTag(html, offset) {
|
|
88
|
-
const node = html.findNodeAt(offset);
|
|
89
|
-
return (isComponentTag(node) && (!node.startTagEnd || offset < node.startTagEnd));
|
|
90
|
-
}
|
|
91
|
-
exports.isInComponentStartTag = isInComponentStartTag;
|
|
92
123
|
/**
|
|
93
124
|
* Get the line and character based on the offset
|
|
94
125
|
* @param offset The index of the position
|
|
95
126
|
* @param text The text for which the position should be retrived
|
|
127
|
+
* @param lineOffsets number Array with offsets for each line. Computed if not given
|
|
96
128
|
*/
|
|
97
|
-
function positionAt(offset, text) {
|
|
129
|
+
function positionAt(offset, text, lineOffsets = getLineOffsets(text)) {
|
|
98
130
|
offset = (0, utils_1.clamp)(offset, 0, text.length);
|
|
99
|
-
const lineOffsets = getLineOffsets(text);
|
|
100
131
|
let low = 0;
|
|
101
132
|
let high = lineOffsets.length;
|
|
102
133
|
if (high === 0) {
|
|
103
|
-
return
|
|
134
|
+
return vscode_languageserver_1.Position.create(0, offset);
|
|
104
135
|
}
|
|
105
|
-
while (low
|
|
136
|
+
while (low <= high) {
|
|
106
137
|
const mid = Math.floor((low + high) / 2);
|
|
107
|
-
|
|
108
|
-
|
|
138
|
+
const lineOffset = lineOffsets[mid];
|
|
139
|
+
if (lineOffset === offset) {
|
|
140
|
+
return vscode_languageserver_1.Position.create(mid, 0);
|
|
109
141
|
}
|
|
110
|
-
else {
|
|
142
|
+
else if (offset > lineOffset) {
|
|
111
143
|
low = mid + 1;
|
|
112
144
|
}
|
|
145
|
+
else {
|
|
146
|
+
high = mid - 1;
|
|
147
|
+
}
|
|
113
148
|
}
|
|
114
149
|
// low is the least x for which the line offset is larger than the current offset
|
|
115
150
|
// or array.length if no line offset is larger than the current offset
|
|
116
151
|
const line = low - 1;
|
|
117
|
-
return
|
|
152
|
+
return vscode_languageserver_1.Position.create(line, offset - lineOffsets[line]);
|
|
118
153
|
}
|
|
119
154
|
exports.positionAt = positionAt;
|
|
120
155
|
/**
|
|
121
156
|
* Get the offset of the line and character position
|
|
122
157
|
* @param position Line and character position
|
|
123
158
|
* @param text The text for which the offset should be retrived
|
|
159
|
+
* @param lineOffsets number Array with offsets for each line. Computed if not given
|
|
124
160
|
*/
|
|
125
|
-
function offsetAt(position, text) {
|
|
126
|
-
const lineOffsets = getLineOffsets(text);
|
|
161
|
+
function offsetAt(position, text, lineOffsets = getLineOffsets(text)) {
|
|
127
162
|
if (position.line >= lineOffsets.length) {
|
|
128
163
|
return text.length;
|
|
129
164
|
}
|
|
@@ -154,84 +189,11 @@ function getLineOffsets(text) {
|
|
|
154
189
|
}
|
|
155
190
|
return lineOffsets;
|
|
156
191
|
}
|
|
157
|
-
|
|
158
|
-
for (let child of node.children) {
|
|
159
|
-
yield* walk(child);
|
|
160
|
-
}
|
|
161
|
-
yield node;
|
|
162
|
-
}
|
|
163
|
-
exports.walk = walk;
|
|
164
|
-
/*
|
|
165
|
-
export function* walk(node: Node, startIndex = 0) {
|
|
166
|
-
let skip, tmp;
|
|
167
|
-
let depth = 0;
|
|
168
|
-
let index = startIndex;
|
|
169
|
-
|
|
170
|
-
// Always start with the initial element.
|
|
171
|
-
do {
|
|
172
|
-
if ( !skip && (tmp = node.firstChild) ) {
|
|
173
|
-
depth++;
|
|
174
|
-
callback('child', node, tmp, index);
|
|
175
|
-
index++;
|
|
176
|
-
} else if ( tmp = node.nextSibling ) {
|
|
177
|
-
skip = false;
|
|
178
|
-
callback('sibling', node, tmp, index);
|
|
179
|
-
index++;
|
|
180
|
-
} else {
|
|
181
|
-
tmp = node.parentNode;
|
|
182
|
-
depth--;
|
|
183
|
-
skip = true;
|
|
184
|
-
}
|
|
185
|
-
node = tmp;
|
|
186
|
-
} while ( depth > 0 );
|
|
187
|
-
};
|
|
188
|
-
*/
|
|
192
|
+
exports.getLineOffsets = getLineOffsets;
|
|
189
193
|
/**
|
|
190
|
-
*
|
|
191
|
-
* and returns its start, end and the attributes on that tag.
|
|
192
|
-
*
|
|
193
|
-
* @param source text content to extract tag from
|
|
194
|
-
* @param tag the tag to extract
|
|
194
|
+
* Gets index of first-non-whitespace character.
|
|
195
195
|
*/
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
const matchedNodes = rootNodes.filter((node) => node.tag === tag);
|
|
199
|
-
if (tag === 'style' && !matchedNodes.length && rootNodes.length && rootNodes[0].tag === 'html') {
|
|
200
|
-
for (let child of walk(rootNodes[0])) {
|
|
201
|
-
if (child.tag === 'style') {
|
|
202
|
-
matchedNodes.push(child);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return matchedNodes.map(transformToTagInfo);
|
|
207
|
-
function transformToTagInfo(matchedNode) {
|
|
208
|
-
var _a, _b;
|
|
209
|
-
const start = (_a = matchedNode.startTagEnd) !== null && _a !== void 0 ? _a : matchedNode.start;
|
|
210
|
-
const end = (_b = matchedNode.endTagStart) !== null && _b !== void 0 ? _b : matchedNode.end;
|
|
211
|
-
const startPos = positionAt(start, text);
|
|
212
|
-
const endPos = positionAt(end, text);
|
|
213
|
-
const container = {
|
|
214
|
-
start: matchedNode.start,
|
|
215
|
-
end: matchedNode.end,
|
|
216
|
-
};
|
|
217
|
-
const content = text.substring(start, end);
|
|
218
|
-
return {
|
|
219
|
-
content,
|
|
220
|
-
attributes: parseAttributes(matchedNode.attributes),
|
|
221
|
-
start,
|
|
222
|
-
end,
|
|
223
|
-
startPos,
|
|
224
|
-
endPos,
|
|
225
|
-
container,
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
function extractStyleTag(source, html) {
|
|
230
|
-
const styles = extractTags(source, 'style', html);
|
|
231
|
-
if (!styles.length) {
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
// There can only be one style tag
|
|
235
|
-
return styles[0];
|
|
196
|
+
function getFirstNonWhitespaceIndex(str) {
|
|
197
|
+
return str.length - str.trimStart().length;
|
|
236
198
|
}
|
|
237
|
-
exports.
|
|
199
|
+
exports.getFirstNonWhitespaceIndex = getFirstNonWhitespaceIndex;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DiagnosticSeverity = exports.AstroCheck = void 0;
|
|
4
4
|
var check_1 = require("./check");
|
|
5
5
|
Object.defineProperty(exports, "AstroCheck", { enumerable: true, get: function () { return check_1.AstroCheck; } });
|
|
6
6
|
Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return check_1.DiagnosticSeverity; } });
|
|
7
|
-
var server_1 = require("./server");
|
|
8
|
-
Object.defineProperty(exports, "startServer", { enumerable: true, get: function () { return server_1.startServer; } });
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
const vscode = __importStar(require("vscode-languageserver/node"));
|
|
27
|
+
const server_1 = require("./server");
|
|
28
|
+
const connection = vscode.createConnection(vscode.ProposedFeatures.all);
|
|
29
|
+
(0, server_1.startLanguageServer)(connection);
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
4
|
-
import { CompletionList } from 'vscode-languageserver';
|
|
5
|
-
import { Hover, FoldingRange } from 'vscode-languageserver-types';
|
|
1
|
+
import { CancellationToken, CompletionContext, CompletionItem, CompletionList, DefinitionLink, Diagnostic, FoldingRange, Hover, Position, Location, SignatureHelp, SignatureHelpContext, TextDocumentContentChangeEvent, TextDocumentIdentifier, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
|
+
import type { AppCompletionItem, Plugin } from './interfaces';
|
|
3
|
+
import { DocumentManager } from '../core/documents/DocumentManager';
|
|
6
4
|
interface PluginHostConfig {
|
|
7
5
|
filterIncompleteCompletions: boolean;
|
|
8
6
|
definitionLinkSupport: boolean;
|
|
9
7
|
}
|
|
10
8
|
export declare class PluginHost {
|
|
11
|
-
private
|
|
9
|
+
private docManager;
|
|
12
10
|
private plugins;
|
|
13
11
|
private pluginHostConfig;
|
|
14
|
-
constructor(
|
|
12
|
+
constructor(docManager: DocumentManager);
|
|
15
13
|
initialize(pluginHostConfig: PluginHostConfig): void;
|
|
16
|
-
|
|
14
|
+
registerPlugin(plugin: Plugin): void;
|
|
17
15
|
getCompletions(textDocument: TextDocumentIdentifier, position: Position, completionContext?: CompletionContext): Promise<CompletionList>;
|
|
16
|
+
resolveCompletion(textDocument: TextDocumentIdentifier, completionItem: AppCompletionItem): Promise<CompletionItem>;
|
|
18
17
|
getDiagnostics(textDocument: TextDocumentIdentifier): Promise<Diagnostic[]>;
|
|
19
|
-
resolveCompletion(textDocument: TextDocumentIdentifier, completionItem: d.AppCompletionItem): Promise<CompletionItem>;
|
|
20
18
|
doHover(textDocument: TextDocumentIdentifier, position: Position): Promise<Hover | null>;
|
|
21
19
|
doTagComplete(textDocument: TextDocumentIdentifier, position: Position): Promise<string | null>;
|
|
22
20
|
getFoldingRanges(textDocument: TextDocumentIdentifier): Promise<FoldingRange[] | null>;
|
|
@@ -24,6 +22,7 @@ export declare class PluginHost {
|
|
|
24
22
|
rename(textDocument: TextDocumentIdentifier, position: Position, newName: string): Promise<WorkspaceEdit | null>;
|
|
25
23
|
getSignatureHelp(textDocument: TextDocumentIdentifier, position: Position, context: SignatureHelpContext | undefined, cancellationToken: CancellationToken): Promise<SignatureHelp | null>;
|
|
26
24
|
onWatchFileChanges(onWatchFileChangesParams: any[]): void;
|
|
25
|
+
updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): void;
|
|
27
26
|
private getDocument;
|
|
28
27
|
private execute;
|
|
29
28
|
private tryExecutePlugin;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PluginHost = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
4
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
6
|
var ExecuteMode;
|
|
7
7
|
(function (ExecuteMode) {
|
|
8
8
|
ExecuteMode[ExecuteMode["None"] = 0] = "None";
|
|
@@ -10,8 +10,8 @@ var ExecuteMode;
|
|
|
10
10
|
ExecuteMode[ExecuteMode["Collect"] = 2] = "Collect";
|
|
11
11
|
})(ExecuteMode || (ExecuteMode = {}));
|
|
12
12
|
class PluginHost {
|
|
13
|
-
constructor(
|
|
14
|
-
this.
|
|
13
|
+
constructor(docManager) {
|
|
14
|
+
this.docManager = docManager;
|
|
15
15
|
this.plugins = [];
|
|
16
16
|
this.pluginHostConfig = {
|
|
17
17
|
filterIncompleteCompletions: true,
|
|
@@ -21,62 +21,41 @@ class PluginHost {
|
|
|
21
21
|
initialize(pluginHostConfig) {
|
|
22
22
|
this.pluginHostConfig = pluginHostConfig;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
registerPlugin(plugin) {
|
|
25
25
|
this.plugins.push(plugin);
|
|
26
26
|
}
|
|
27
27
|
async getCompletions(textDocument, position, completionContext) {
|
|
28
28
|
const document = this.getDocument(textDocument.uri);
|
|
29
|
-
if (!document) {
|
|
30
|
-
throw new Error('Cannot call methods on an unopened document');
|
|
31
|
-
}
|
|
32
29
|
const completions = (await this.execute('getCompletions', [document, position, completionContext], ExecuteMode.Collect)).filter((completion) => completion != null);
|
|
33
|
-
let flattenedCompletions = (0,
|
|
30
|
+
let flattenedCompletions = (0, lodash_1.flatten)(completions.map((completion) => completion.items));
|
|
34
31
|
const isIncomplete = completions.reduce((incomplete, completion) => incomplete || completion.isIncomplete, false);
|
|
35
32
|
return vscode_languageserver_1.CompletionList.create(flattenedCompletions, isIncomplete);
|
|
36
33
|
}
|
|
37
|
-
async getDiagnostics(textDocument) {
|
|
38
|
-
const document = this.getDocument(textDocument.uri);
|
|
39
|
-
if (!document) {
|
|
40
|
-
throw new Error('Cannot call methods on an unopened document');
|
|
41
|
-
}
|
|
42
|
-
return (0, utils_1.flatten)(await this.execute('getDiagnostics', [document], ExecuteMode.Collect));
|
|
43
|
-
}
|
|
44
34
|
async resolveCompletion(textDocument, completionItem) {
|
|
45
35
|
const document = this.getDocument(textDocument.uri);
|
|
46
|
-
if (!document) {
|
|
47
|
-
throw new Error('Cannot call methods on an unopened document');
|
|
48
|
-
}
|
|
49
36
|
const result = await this.execute('resolveCompletion', [document, completionItem], ExecuteMode.FirstNonNull);
|
|
50
37
|
return result !== null && result !== void 0 ? result : completionItem;
|
|
51
38
|
}
|
|
39
|
+
async getDiagnostics(textDocument) {
|
|
40
|
+
const document = this.getDocument(textDocument.uri);
|
|
41
|
+
return (0, lodash_1.flatten)(await this.execute('getDiagnostics', [document], ExecuteMode.Collect));
|
|
42
|
+
}
|
|
52
43
|
async doHover(textDocument, position) {
|
|
53
44
|
const document = this.getDocument(textDocument.uri);
|
|
54
|
-
if (!document) {
|
|
55
|
-
throw new Error('Cannot call methods on an unopened document');
|
|
56
|
-
}
|
|
57
45
|
return this.execute('doHover', [document, position], ExecuteMode.FirstNonNull);
|
|
58
46
|
}
|
|
59
47
|
async doTagComplete(textDocument, position) {
|
|
60
48
|
const document = this.getDocument(textDocument.uri);
|
|
61
|
-
if (!document) {
|
|
62
|
-
throw new Error('Cannot call methods on an unopened document');
|
|
63
|
-
}
|
|
64
49
|
return this.execute('doTagComplete', [document, position], ExecuteMode.FirstNonNull);
|
|
65
50
|
}
|
|
66
51
|
async getFoldingRanges(textDocument) {
|
|
67
52
|
const document = this.getDocument(textDocument.uri);
|
|
68
|
-
|
|
69
|
-
throw new Error('Cannot call methods on an unopened document');
|
|
70
|
-
}
|
|
71
|
-
const foldingRanges = (0, utils_1.flatten)(await this.execute('getFoldingRanges', [document], ExecuteMode.Collect)).filter((completion) => completion != null);
|
|
53
|
+
const foldingRanges = (0, lodash_1.flatten)(await this.execute('getFoldingRanges', [document], ExecuteMode.Collect)).filter((completion) => completion != null);
|
|
72
54
|
return foldingRanges;
|
|
73
55
|
}
|
|
74
56
|
async getDefinitions(textDocument, position) {
|
|
75
57
|
const document = this.getDocument(textDocument.uri);
|
|
76
|
-
|
|
77
|
-
throw new Error('Cannot call methods on an unopened document');
|
|
78
|
-
}
|
|
79
|
-
const definitions = (0, utils_1.flatten)(await this.execute('getDefinitions', [document, position], ExecuteMode.Collect));
|
|
58
|
+
const definitions = (0, lodash_1.flatten)(await this.execute('getDefinitions', [document, position], ExecuteMode.Collect));
|
|
80
59
|
if (this.pluginHostConfig.definitionLinkSupport) {
|
|
81
60
|
return definitions;
|
|
82
61
|
}
|
|
@@ -86,9 +65,6 @@ class PluginHost {
|
|
|
86
65
|
}
|
|
87
66
|
async rename(textDocument, position, newName) {
|
|
88
67
|
const document = this.getDocument(textDocument.uri);
|
|
89
|
-
if (!document) {
|
|
90
|
-
throw new Error('Cannot call methods on an unopened document');
|
|
91
|
-
}
|
|
92
68
|
return this.execute('rename', [document, position, newName], ExecuteMode.FirstNonNull);
|
|
93
69
|
}
|
|
94
70
|
async getSignatureHelp(textDocument, position, context, cancellationToken) {
|
|
@@ -104,8 +80,18 @@ class PluginHost {
|
|
|
104
80
|
(_a = support.onWatchFileChanges) === null || _a === void 0 ? void 0 : _a.call(support, onWatchFileChangesParams);
|
|
105
81
|
}
|
|
106
82
|
}
|
|
83
|
+
updateNonAstroFile(fileName, changes) {
|
|
84
|
+
var _a;
|
|
85
|
+
for (const support of this.plugins) {
|
|
86
|
+
(_a = support.updateNonAstroFile) === null || _a === void 0 ? void 0 : _a.call(support, fileName, changes);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
107
89
|
getDocument(uri) {
|
|
108
|
-
|
|
90
|
+
const document = this.docManager.get(uri);
|
|
91
|
+
if (!document) {
|
|
92
|
+
throw new Error('Cannot call methods on an unopened document');
|
|
93
|
+
}
|
|
94
|
+
return document;
|
|
109
95
|
}
|
|
110
96
|
async execute(name, args, mode) {
|
|
111
97
|
const plugins = this.plugins.filter((plugin) => typeof plugin[name] === 'function');
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { DefinitionLink } from 'vscode-languageserver';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
private
|
|
8
|
-
private readonly
|
|
1
|
+
import { CompletionContext, DefinitionLink, FoldingRange, Position } from 'vscode-languageserver';
|
|
2
|
+
import { ConfigManager } from '../../core/config';
|
|
3
|
+
import { AstroDocument, DocumentManager } from '../../core/documents';
|
|
4
|
+
import { AppCompletionList, Plugin } from '../interfaces';
|
|
5
|
+
export declare class AstroPlugin implements Plugin {
|
|
6
|
+
__name: string;
|
|
7
|
+
private configManager;
|
|
8
|
+
private readonly languageServiceManager;
|
|
9
9
|
private readonly completionProvider;
|
|
10
|
-
pluginName: string;
|
|
11
10
|
constructor(docManager: DocumentManager, configManager: ConfigManager, workspaceUris: string[]);
|
|
12
|
-
getCompletions(document:
|
|
13
|
-
getFoldingRanges(document:
|
|
14
|
-
getDefinitions(document:
|
|
11
|
+
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList | null>;
|
|
12
|
+
getFoldingRanges(document: AstroDocument): Promise<FoldingRange[]>;
|
|
13
|
+
getDefinitions(document: AstroDocument, position: Position): Promise<DefinitionLink[]>;
|
|
15
14
|
private isInsideFrontmatter;
|
|
16
15
|
private isComponentTag;
|
|
17
16
|
private getDefinitionsForComponentName;
|
|
@@ -1,40 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
4
|
};
|
|
21
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
6
|
exports.AstroPlugin = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
23
8
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
9
|
+
const documents_1 = require("../../core/documents");
|
|
24
10
|
const utils_1 = require("../../utils");
|
|
25
|
-
const utils_2 = require("../typescript/utils");
|
|
26
|
-
const utils_3 = require("../../core/documents/utils");
|
|
27
|
-
const ts = __importStar(require("typescript"));
|
|
28
11
|
const LanguageServiceManager_1 = require("../typescript/LanguageServiceManager");
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const CompletionProvider_1 = require("./features/CompletionProvider");
|
|
12
|
+
const utils_2 = require("../typescript/utils");
|
|
13
|
+
const CompletionsProvider_1 = require("./features/CompletionsProvider");
|
|
32
14
|
class AstroPlugin {
|
|
33
15
|
constructor(docManager, configManager, workspaceUris) {
|
|
34
|
-
this.
|
|
16
|
+
this.__name = 'astro';
|
|
35
17
|
this.configManager = configManager;
|
|
36
|
-
this.
|
|
37
|
-
this.completionProvider = new
|
|
18
|
+
this.languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(docManager, workspaceUris, configManager);
|
|
19
|
+
this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(docManager, this.languageServiceManager);
|
|
38
20
|
}
|
|
39
21
|
async getCompletions(document, position, completionContext) {
|
|
40
22
|
const completions = this.completionProvider.getCompletions(document, position, completionContext);
|
|
@@ -42,7 +24,7 @@ class AstroPlugin {
|
|
|
42
24
|
}
|
|
43
25
|
async getFoldingRanges(document) {
|
|
44
26
|
const foldingRanges = [];
|
|
45
|
-
const { frontmatter } = document.
|
|
27
|
+
const { frontmatter } = document.astroMeta;
|
|
46
28
|
// Currently editing frontmatter, don't fold
|
|
47
29
|
if (frontmatter.state !== 'closed')
|
|
48
30
|
return foldingRanges;
|
|
@@ -54,7 +36,7 @@ class AstroPlugin {
|
|
|
54
36
|
startCharacter: start.character,
|
|
55
37
|
endLine: end.line,
|
|
56
38
|
endCharacter: end.character,
|
|
57
|
-
kind:
|
|
39
|
+
kind: vscode_languageserver_1.FoldingRangeKind.Imports,
|
|
58
40
|
},
|
|
59
41
|
];
|
|
60
42
|
}
|
|
@@ -69,20 +51,20 @@ class AstroPlugin {
|
|
|
69
51
|
return [];
|
|
70
52
|
}
|
|
71
53
|
const [componentName] = node.tag.split(':');
|
|
72
|
-
const { lang } = await this.
|
|
54
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
73
55
|
const defs = this.getDefinitionsForComponentName(document, lang, componentName);
|
|
74
56
|
if (!defs || !defs.length) {
|
|
75
57
|
return [];
|
|
76
58
|
}
|
|
77
59
|
const startRange = vscode_languageserver_1.Range.create(vscode_languageserver_1.Position.create(0, 0), vscode_languageserver_1.Position.create(0, 0));
|
|
78
60
|
const links = defs.map((def) => {
|
|
79
|
-
const defFilePath = (0,
|
|
61
|
+
const defFilePath = (0, utils_2.ensureRealFilePath)(def.fileName);
|
|
80
62
|
return vscode_languageserver_1.LocationLink.create((0, utils_1.pathToUrl)(defFilePath), startRange, startRange);
|
|
81
63
|
});
|
|
82
64
|
return links;
|
|
83
65
|
}
|
|
84
66
|
isInsideFrontmatter(document, position) {
|
|
85
|
-
return (0,
|
|
67
|
+
return (0, documents_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position));
|
|
86
68
|
}
|
|
87
69
|
isComponentTag(node) {
|
|
88
70
|
if (!node.tag) {
|
|
@@ -111,15 +93,15 @@ class AstroPlugin {
|
|
|
111
93
|
}
|
|
112
94
|
getImportSpecifierForIdentifier(sourceFile, identifier) {
|
|
113
95
|
let importSpecifier = undefined;
|
|
114
|
-
|
|
115
|
-
if (
|
|
96
|
+
typescript_1.default.forEachChild(sourceFile, (tsNode) => {
|
|
97
|
+
if (typescript_1.default.isImportDeclaration(tsNode)) {
|
|
116
98
|
if (tsNode.importClause) {
|
|
117
99
|
const { name, namedBindings } = tsNode.importClause;
|
|
118
100
|
if (name && name.getText() === identifier) {
|
|
119
101
|
importSpecifier = tsNode.moduleSpecifier;
|
|
120
102
|
return true;
|
|
121
103
|
}
|
|
122
|
-
else if (namedBindings && namedBindings.kind ===
|
|
104
|
+
else if (namedBindings && namedBindings.kind === typescript_1.default.SyntaxKind.NamedImports) {
|
|
123
105
|
const elements = namedBindings.elements;
|
|
124
106
|
for (let elem of elements) {
|
|
125
107
|
if (elem.name.getText() === identifier) {
|
|
@@ -135,6 +117,3 @@ class AstroPlugin {
|
|
|
135
117
|
}
|
|
136
118
|
}
|
|
137
119
|
exports.AstroPlugin = AstroPlugin;
|
|
138
|
-
function isNodeExported(node) {
|
|
139
|
-
return (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Export) !== 0 || (!!node.parent && node.parent.kind === ts.SyntaxKind.SourceFile);
|
|
140
|
-
}
|