@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.
Files changed (97) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/bin/browserServer.js +3 -0
  3. package/bin/nodeServer.js +3 -0
  4. package/dist/browser.d.ts +1 -0
  5. package/dist/browser.js +8 -0
  6. package/dist/check.js +2 -5
  7. package/dist/core/DiagnosticsManager.d.ts +3 -3
  8. package/dist/core/DiagnosticsManager.js +2 -2
  9. package/dist/core/config/ConfigManager.d.ts +19 -164
  10. package/dist/core/config/ConfigManager.js +62 -101
  11. package/dist/core/config/index.d.ts +1 -0
  12. package/dist/core/config/index.js +6 -1
  13. package/dist/core/config/interfaces.d.ts +123 -0
  14. package/dist/core/config/interfaces.js +2 -0
  15. package/dist/core/documents/AstroDocument.d.ts +18 -0
  16. package/dist/core/documents/AstroDocument.js +37 -0
  17. package/dist/core/documents/DocumentBase.d.ts +10 -2
  18. package/dist/core/documents/DocumentBase.js +15 -50
  19. package/dist/core/documents/DocumentManager.d.ts +12 -16
  20. package/dist/core/documents/DocumentManager.js +32 -26
  21. package/dist/core/documents/DocumentMapper.js +3 -1
  22. package/dist/core/documents/index.d.ts +1 -1
  23. package/dist/core/documents/index.js +6 -2
  24. package/dist/core/documents/parseAstro.d.ts +2 -2
  25. package/dist/core/documents/parseHtml.d.ts +2 -2
  26. package/dist/core/documents/parseHtml.js +4 -1
  27. package/dist/core/documents/utils.d.ts +22 -26
  28. package/dist/core/documents/utils.js +96 -134
  29. package/dist/index.d.ts +0 -1
  30. package/dist/index.js +1 -3
  31. package/dist/node.d.ts +1 -0
  32. package/dist/node.js +29 -0
  33. package/dist/plugins/PluginHost.d.ts +8 -9
  34. package/dist/plugins/PluginHost.js +22 -36
  35. package/dist/plugins/astro/AstroPlugin.d.ts +11 -12
  36. package/dist/plugins/astro/AstroPlugin.js +17 -38
  37. package/dist/plugins/astro/features/{CompletionProvider.d.ts → CompletionsProvider.d.ts} +5 -5
  38. package/dist/plugins/astro/features/{CompletionProvider.js → CompletionsProvider.js} +33 -54
  39. package/dist/plugins/css/CSSDocument.d.ts +3 -3
  40. package/dist/plugins/css/CSSDocument.js +7 -16
  41. package/dist/plugins/css/CSSPlugin.d.ts +19 -11
  42. package/dist/plugins/css/CSSPlugin.js +63 -41
  43. package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
  44. package/dist/plugins/css/StyleAttributeDocument.js +2 -2
  45. package/dist/plugins/css/features/astro-selectors.d.ts +2 -0
  46. package/dist/plugins/css/features/astro-selectors.js +16 -0
  47. package/dist/plugins/css/features/{getIdClassCompletion.d.ts → getIdClassCompletions.d.ts} +3 -3
  48. package/dist/plugins/css/features/{getIdClassCompletion.js → getIdClassCompletions.js} +10 -9
  49. package/dist/plugins/css/{service.d.ts → language-service.d.ts} +0 -0
  50. package/dist/plugins/css/{service.js → language-service.js} +2 -1
  51. package/dist/plugins/html/HTMLPlugin.d.ts +15 -17
  52. package/dist/plugins/html/HTMLPlugin.js +33 -41
  53. package/dist/plugins/index.d.ts +2 -2
  54. package/dist/plugins/index.js +7 -3
  55. package/dist/plugins/interfaces.d.ts +35 -48
  56. package/dist/plugins/typescript/LanguageServiceManager.d.ts +33 -14
  57. package/dist/plugins/typescript/LanguageServiceManager.js +57 -32
  58. package/dist/plugins/typescript/TypeScriptPlugin.d.ts +16 -23
  59. package/dist/plugins/typescript/TypeScriptPlugin.js +48 -56
  60. package/dist/plugins/typescript/astro-sys.d.ts +5 -3
  61. package/dist/plugins/typescript/astro-sys.js +24 -41
  62. package/dist/plugins/typescript/features/CompletionsProvider.d.ts +6 -6
  63. package/dist/plugins/typescript/features/CompletionsProvider.js +17 -33
  64. package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +4 -4
  65. package/dist/plugins/typescript/features/DiagnosticsProvider.js +22 -61
  66. package/dist/plugins/typescript/features/HoverProvider.d.ts +4 -5
  67. package/dist/plugins/typescript/features/HoverProvider.js +9 -10
  68. package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +4 -5
  69. package/dist/plugins/typescript/features/SignatureHelpProvider.js +15 -11
  70. package/dist/plugins/typescript/features/utils.d.ts +1 -12
  71. package/dist/plugins/typescript/features/utils.js +2 -22
  72. package/dist/plugins/typescript/language-service.d.ts +38 -0
  73. package/dist/plugins/typescript/language-service.js +227 -0
  74. package/dist/plugins/typescript/module-loader.d.ts +5 -8
  75. package/dist/plugins/typescript/module-loader.js +43 -23
  76. package/dist/plugins/typescript/{DocumentSnapshot.d.ts → snapshots/DocumentSnapshot.d.ts} +45 -42
  77. package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +135 -0
  78. package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +42 -0
  79. package/dist/plugins/typescript/snapshots/SnapshotManager.js +197 -0
  80. package/dist/plugins/typescript/snapshots/utils.d.ts +28 -0
  81. package/dist/plugins/typescript/snapshots/utils.js +84 -0
  82. package/dist/plugins/typescript/utils.d.ts +10 -11
  83. package/dist/plugins/typescript/utils.js +122 -151
  84. package/dist/server.d.ts +2 -4
  85. package/dist/server.js +88 -54
  86. package/dist/utils.d.ts +16 -8
  87. package/dist/utils.js +29 -14
  88. package/package.json +19 -13
  89. package/bin/server.js +0 -7
  90. package/dist/core/documents/Document.d.ts +0 -51
  91. package/dist/core/documents/Document.js +0 -135
  92. package/dist/plugins/typescript/DocumentSnapshot.js +0 -202
  93. package/dist/plugins/typescript/SnapshotManager.d.ts +0 -24
  94. package/dist/plugins/typescript/SnapshotManager.js +0 -97
  95. package/dist/plugins/typescript/languageService.d.ts +0 -17
  96. package/dist/plugins/typescript/languageService.js +0 -169
  97. 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.extractStyleTag = exports.walk = exports.offsetAt = exports.positionAt = exports.isInComponentStartTag = exports.isComponentTag = exports.isInTag = exports.isInsideFrontmatter = exports.isInsideExpression = exports.getFirstNonWhitespaceIndex = exports.getWordAt = exports.getWordRangeAt = void 0;
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('"')) || (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
- * Gets word range at position.
27
- * Delimiter is by default a whitespace, but can be adjusted.
81
+ * Return if a Node is a Component
28
82
  */
29
- function getWordRangeAt(str, pos, delimiterRegex = { left: /\S+$/, right: /\s/ }) {
30
- let start = str.slice(0, pos).search(delimiterRegex.left);
31
- if (start < 0) {
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
- return { start, end };
87
+ const firstChar = node.tag[0];
88
+ return /[A-Z]/.test(firstChar);
42
89
  }
43
- exports.getWordRangeAt = getWordRangeAt;
90
+ exports.isComponentTag = isComponentTag;
44
91
  /**
45
- * Gets word at position.
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 getWordAt(str, pos, delimiterRegex = { left: /\S+$/, right: /\s/ }) {
49
- const { start, end } = getWordRangeAt(str, pos, delimiterRegex);
50
- return str.slice(start, end);
94
+ function isInComponentStartTag(html, offset) {
95
+ const node = html.findNodeAt(offset);
96
+ return isComponentTag(node) && (!node.startTagEnd || offset < node.startTagEnd);
51
97
  }
52
- exports.getWordAt = getWordAt;
98
+ exports.isInComponentStartTag = isInComponentStartTag;
53
99
  /**
54
- * Gets index of first-non-whitespace character.
100
+ * Return if the current position is in a specific tag
55
101
  */
56
- function getFirstNonWhitespaceIndex(str) {
57
- return str.length - str.trimStart().length;
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.getFirstNonWhitespaceIndex = getFirstNonWhitespaceIndex;
60
- /** checks if a position is currently inside of an expression */
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 vscode_html_languageservice_1.Position.create(0, offset);
134
+ return vscode_languageserver_1.Position.create(0, offset);
104
135
  }
105
- while (low < high) {
136
+ while (low <= high) {
106
137
  const mid = Math.floor((low + high) / 2);
107
- if (lineOffsets[mid] > offset) {
108
- high = mid;
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 vscode_html_languageservice_1.Position.create(line, offset - lineOffsets[line]);
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
- function* walk(node) {
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
- * Extracts a tag (style or script) from the given text
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 extractTags(text, tag, html) {
197
- const rootNodes = (html === null || html === void 0 ? void 0 : html.roots) || (0, parseHtml_1.parseHtml)(text).roots;
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.extractStyleTag = extractStyleTag;
199
+ exports.getFirstNonWhitespaceIndex = getFirstNonWhitespaceIndex;
package/dist/index.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export { AstroCheck, DiagnosticSeverity } from './check';
2
- export { startServer } from './server';
package/dist/index.js CHANGED
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startServer = exports.DiagnosticSeverity = exports.AstroCheck = void 0;
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 type { CancellationToken, CompletionContext, CompletionItem, DefinitionLink, Diagnostic, Location, Position, SignatureHelp, SignatureHelpContext, TextDocumentIdentifier, WorkspaceEdit } from 'vscode-languageserver';
2
- import type { DocumentManager } from '../core/documents';
3
- import type * as d from './interfaces';
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 documentsManager;
9
+ private docManager;
12
10
  private plugins;
13
11
  private pluginHostConfig;
14
- constructor(documentsManager: DocumentManager);
12
+ constructor(docManager: DocumentManager);
15
13
  initialize(pluginHostConfig: PluginHostConfig): void;
16
- register(plugin: d.Plugin): void;
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(documentsManager) {
14
- this.documentsManager = documentsManager;
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
- register(plugin) {
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, utils_1.flatten)(completions.map((completion) => completion.items));
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
- if (!document) {
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
- if (!document) {
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
- return this.documentsManager.get(uri);
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 type { Document, DocumentManager } from '../../core/documents';
3
- import type { ConfigManager } from '../../core/config';
4
- import type { CompletionsProvider, AppCompletionList, FoldingRangeProvider } from '../interfaces';
5
- import { CompletionContext, Position, FoldingRange } from 'vscode-languageserver';
6
- export declare class AstroPlugin implements CompletionsProvider, FoldingRangeProvider {
7
- private readonly configManager;
8
- private readonly tsLanguageServiceManager;
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: Document, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList | null>;
13
- getFoldingRanges(document: Document): Promise<FoldingRange[]>;
14
- getDefinitions(document: Document, position: Position): Promise<DefinitionLink[]>;
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
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 utils_4 = require("../typescript/utils");
30
- const vscode_languageserver_types_1 = require("vscode-languageserver-types");
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.pluginName = 'Astro';
16
+ this.__name = 'astro';
35
17
  this.configManager = configManager;
36
- this.tsLanguageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(docManager, configManager, workspaceUris);
37
- this.completionProvider = new CompletionProvider_1.CompletionProvider(docManager, this.tsLanguageServiceManager);
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.astro;
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: vscode_languageserver_types_1.FoldingRangeKind.Imports,
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.tsLanguageServiceManager.getTypeScriptDoc(document);
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, utils_4.ensureRealFilePath)(def.fileName);
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, utils_3.isInsideFrontmatter)(document.getText(), document.offsetAt(position));
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
- ts.forEachChild(sourceFile, (tsNode) => {
115
- if (ts.isImportDeclaration(tsNode)) {
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 === ts.SyntaxKind.NamedImports) {
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
- }