@astrojs/language-server 1.0.5 → 2.0.0-next.6

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 (163) hide show
  1. package/LICENSE +3 -5
  2. package/bin/nodeServer.js +7 -3
  3. package/dist/core/astro2tsx.d.ts +6 -0
  4. package/dist/core/astro2tsx.js +119 -0
  5. package/dist/core/compilerUtils.d.ts +27 -0
  6. package/dist/core/compilerUtils.js +52 -0
  7. package/dist/core/index.d.ts +27 -0
  8. package/dist/core/index.js +119 -0
  9. package/dist/core/parseAstro.d.ts +27 -0
  10. package/dist/core/parseAstro.js +47 -0
  11. package/dist/core/parseCSS.d.ts +7 -0
  12. package/dist/core/parseCSS.js +116 -0
  13. package/dist/core/parseHTML.d.ts +7 -0
  14. package/dist/core/parseHTML.js +113 -0
  15. package/dist/core/parseJS.d.ts +7 -0
  16. package/dist/core/parseJS.js +236 -0
  17. package/dist/core/svelte.d.ts +18 -0
  18. package/dist/core/svelte.js +45 -0
  19. package/dist/core/utils.d.ts +14 -0
  20. package/dist/core/utils.js +138 -0
  21. package/dist/core/vue.d.ts +18 -0
  22. package/dist/core/vue.js +45 -0
  23. package/dist/importPackage.d.ts +1 -1
  24. package/dist/importPackage.js +4 -3
  25. package/dist/index.d.ts +1 -2
  26. package/dist/index.js +26 -6
  27. package/dist/languageServerPlugin.d.ts +2 -0
  28. package/dist/languageServerPlugin.js +76 -0
  29. package/dist/nodeServer.js +6 -0
  30. package/dist/plugins/astro.d.ts +3 -0
  31. package/dist/plugins/astro.js +123 -0
  32. package/dist/plugins/{html/features/astro-attributes.js → html-data.js} +1 -0
  33. package/dist/plugins/html.d.ts +3 -0
  34. package/dist/plugins/html.js +33 -0
  35. package/dist/plugins/typescript/codeActions.d.ts +4 -0
  36. package/dist/plugins/typescript/codeActions.js +49 -0
  37. package/dist/plugins/typescript/completions.d.ts +3 -0
  38. package/dist/plugins/typescript/completions.js +81 -0
  39. package/dist/plugins/typescript/diagnostics.d.ts +12 -0
  40. package/dist/plugins/typescript/diagnostics.js +99 -0
  41. package/dist/plugins/typescript/index.d.ts +3 -0
  42. package/dist/plugins/typescript/index.js +57 -0
  43. package/dist/utils.d.ts +19 -69
  44. package/dist/utils.js +66 -239
  45. package/package.json +39 -37
  46. package/types/astro-jsx.d.ts +49 -5
  47. package/bin/browserServer.js +0 -3
  48. package/dist/browser.js +0 -15
  49. package/dist/check.d.ts +0 -23
  50. package/dist/check.js +0 -60
  51. package/dist/core/DiagnosticsManager.d.ts +0 -13
  52. package/dist/core/DiagnosticsManager.js +0 -29
  53. package/dist/core/config/ConfigManager.d.ts +0 -43
  54. package/dist/core/config/ConfigManager.js +0 -226
  55. package/dist/core/config/index.d.ts +0 -2
  56. package/dist/core/config/index.js +0 -18
  57. package/dist/core/config/interfaces.d.ts +0 -77
  58. package/dist/core/config/interfaces.js +0 -2
  59. package/dist/core/documents/AstroDocument.d.ts +0 -19
  60. package/dist/core/documents/AstroDocument.js +0 -43
  61. package/dist/core/documents/DocumentBase.d.ts +0 -68
  62. package/dist/core/documents/DocumentBase.js +0 -75
  63. package/dist/core/documents/DocumentManager.d.ts +0 -23
  64. package/dist/core/documents/DocumentManager.js +0 -100
  65. package/dist/core/documents/DocumentMapper.d.ts +0 -94
  66. package/dist/core/documents/DocumentMapper.js +0 -264
  67. package/dist/core/documents/index.d.ts +0 -5
  68. package/dist/core/documents/index.js +0 -21
  69. package/dist/core/documents/parseAstro.d.ts +0 -15
  70. package/dist/core/documents/parseAstro.js +0 -63
  71. package/dist/core/documents/parseHtml.d.ts +0 -13
  72. package/dist/core/documents/parseHtml.js +0 -126
  73. package/dist/core/documents/utils.d.ts +0 -63
  74. package/dist/core/documents/utils.js +0 -223
  75. package/dist/node.d.ts +0 -1
  76. package/dist/node.js +0 -43
  77. package/dist/plugins/PluginHost.d.ts +0 -42
  78. package/dist/plugins/PluginHost.js +0 -206
  79. package/dist/plugins/astro/AstroPlugin.d.ts +0 -17
  80. package/dist/plugins/astro/AstroPlugin.js +0 -90
  81. package/dist/plugins/astro/features/CompletionsProvider.d.ts +0 -17
  82. package/dist/plugins/astro/features/CompletionsProvider.js +0 -242
  83. package/dist/plugins/astro/features/DiagnosticsProvider.d.ts +0 -10
  84. package/dist/plugins/astro/features/DiagnosticsProvider.js +0 -23
  85. package/dist/plugins/css/CSSDocument.d.ts +0 -45
  86. package/dist/plugins/css/CSSDocument.js +0 -68
  87. package/dist/plugins/css/CSSPlugin.d.ts +0 -39
  88. package/dist/plugins/css/CSSPlugin.js +0 -274
  89. package/dist/plugins/css/StyleAttributeDocument.d.ts +0 -40
  90. package/dist/plugins/css/StyleAttributeDocument.js +0 -64
  91. package/dist/plugins/css/features/astro-selectors.d.ts +0 -2
  92. package/dist/plugins/css/features/astro-selectors.js +0 -15
  93. package/dist/plugins/css/features/getIdClassCompletions.d.ts +0 -19
  94. package/dist/plugins/css/features/getIdClassCompletions.js +0 -57
  95. package/dist/plugins/css/language-service.d.ts +0 -3
  96. package/dist/plugins/css/language-service.js +0 -47
  97. package/dist/plugins/html/HTMLPlugin.d.ts +0 -33
  98. package/dist/plugins/html/HTMLPlugin.js +0 -198
  99. package/dist/plugins/html/utils.d.ts +0 -6
  100. package/dist/plugins/html/utils.js +0 -11
  101. package/dist/plugins/index.d.ts +0 -6
  102. package/dist/plugins/index.js +0 -22
  103. package/dist/plugins/interfaces.d.ts +0 -101
  104. package/dist/plugins/interfaces.js +0 -2
  105. package/dist/plugins/typescript/LanguageServiceManager.d.ts +0 -47
  106. package/dist/plugins/typescript/LanguageServiceManager.js +0 -97
  107. package/dist/plugins/typescript/TypeScriptPlugin.d.ts +0 -54
  108. package/dist/plugins/typescript/TypeScriptPlugin.js +0 -152
  109. package/dist/plugins/typescript/astro-sys.d.ts +0 -8
  110. package/dist/plugins/typescript/astro-sys.js +0 -46
  111. package/dist/plugins/typescript/astro2tsx.d.ts +0 -2
  112. package/dist/plugins/typescript/astro2tsx.js +0 -26
  113. package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +0 -17
  114. package/dist/plugins/typescript/features/CodeActionsProvider.js +0 -212
  115. package/dist/plugins/typescript/features/CompletionsProvider.d.ts +0 -31
  116. package/dist/plugins/typescript/features/CompletionsProvider.js +0 -294
  117. package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +0 -9
  118. package/dist/plugins/typescript/features/DefinitionsProvider.js +0 -58
  119. package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +0 -25
  120. package/dist/plugins/typescript/features/DiagnosticsProvider.js +0 -249
  121. package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +0 -11
  122. package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +0 -67
  123. package/dist/plugins/typescript/features/FileReferencesProvider.d.ts +0 -9
  124. package/dist/plugins/typescript/features/FileReferencesProvider.js +0 -27
  125. package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +0 -12
  126. package/dist/plugins/typescript/features/FoldingRangesProvider.js +0 -71
  127. package/dist/plugins/typescript/features/HoverProvider.d.ts +0 -10
  128. package/dist/plugins/typescript/features/HoverProvider.js +0 -50
  129. package/dist/plugins/typescript/features/ImplementationsProvider.d.ts +0 -9
  130. package/dist/plugins/typescript/features/ImplementationsProvider.js +0 -53
  131. package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +0 -13
  132. package/dist/plugins/typescript/features/InlayHintsProvider.js +0 -30
  133. package/dist/plugins/typescript/features/ReferencesProvider.d.ts +0 -9
  134. package/dist/plugins/typescript/features/ReferencesProvider.js +0 -55
  135. package/dist/plugins/typescript/features/RenameProvider.d.ts +0 -13
  136. package/dist/plugins/typescript/features/RenameProvider.js +0 -60
  137. package/dist/plugins/typescript/features/SemanticTokenProvider.d.ts +0 -16
  138. package/dist/plugins/typescript/features/SemanticTokenProvider.js +0 -75
  139. package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +0 -22
  140. package/dist/plugins/typescript/features/SignatureHelpProvider.js +0 -111
  141. package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +0 -9
  142. package/dist/plugins/typescript/features/TypeDefinitionsProvider.js +0 -54
  143. package/dist/plugins/typescript/features/utils.d.ts +0 -14
  144. package/dist/plugins/typescript/features/utils.js +0 -48
  145. package/dist/plugins/typescript/language-service.d.ts +0 -42
  146. package/dist/plugins/typescript/language-service.js +0 -278
  147. package/dist/plugins/typescript/module-loader.d.ts +0 -23
  148. package/dist/plugins/typescript/module-loader.js +0 -155
  149. package/dist/plugins/typescript/previewer.d.ts +0 -7
  150. package/dist/plugins/typescript/previewer.js +0 -108
  151. package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +0 -95
  152. package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +0 -187
  153. package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +0 -44
  154. package/dist/plugins/typescript/snapshots/SnapshotManager.js +0 -179
  155. package/dist/plugins/typescript/snapshots/utils.d.ts +0 -29
  156. package/dist/plugins/typescript/snapshots/utils.js +0 -106
  157. package/dist/plugins/typescript/utils.d.ts +0 -75
  158. package/dist/plugins/typescript/utils.js +0 -366
  159. package/dist/server.d.ts +0 -6
  160. package/dist/server.js +0 -275
  161. package/types/README.md +0 -5
  162. /package/dist/{browser.d.ts → nodeServer.d.ts} +0 -0
  163. /package/dist/plugins/{html/features/astro-attributes.d.ts → html-data.d.ts} +0 -0
package/dist/utils.d.ts CHANGED
@@ -1,82 +1,32 @@
1
- import type { Position, Range } from 'vscode-languageserver';
2
- /** Normalizes a document URI */
3
- export declare function normalizeUri(uri: string): string;
1
+ import type { Point } from '@astrojs/compiler/types';
2
+ import { HTMLDocument, Node, Position, Range, TextEdit } from 'vscode-html-languageservice';
3
+ import type { FrontmatterStatus } from './core/parseAstro.js';
4
+ export declare function isTsDocument(languageId: string): boolean;
4
5
  /**
5
- * Some paths (on windows) start with a upper case driver letter, some don't.
6
- * This is normalized here.
6
+ * Return true if a specific node could be a component.
7
+ * This is not a 100% sure test as it'll return false for any component that does not match the standard format for a component
7
8
  */
8
- export declare function normalizePath(path: string): string;
9
- /** Turns a URL into a normalized FS Path */
10
- export declare function urlToPath(stringUrl: string): string | null;
11
- /** Converts a path to a URL */
12
- export declare function pathToUrl(path: string): string;
9
+ export declare function isPossibleComponent(node: Node): boolean;
13
10
  /**
14
- * Given a path like foo/bar or foo/bar.astro , returns its last path
15
- * (bar or bar.astro in this example).
11
+ * Return if a given offset is inside the start tag of a component
16
12
  */
17
- export declare function getLastPartOfPath(path: string): string;
13
+ export declare function isInComponentStartTag(html: HTMLDocument, offset: number): boolean;
18
14
  /**
19
- * Return an element in an object using a path as a string (ex: `astro.typescript.format` will return astro['typescript']['format']).
20
- * From: https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get
15
+ * Return if a given position is inside a JSX expression
21
16
  */
22
- export declare function get<T>(obj: Record<string, any>, path: string): T | undefined;
17
+ export declare function isInsideExpression(html: string, tagStart: number, position: number): boolean;
23
18
  /**
24
- * Performs a deep merge of objects and returns new object. Does not modify
25
- * objects (immutable) and merges arrays via concatenation.
26
- * From: https://stackoverflow.com/a/48218209
19
+ * Return if a given offset is inside the frontmatter
27
20
  */
28
- export declare function mergeDeep(...objects: Record<string, any>[]): Record<string, any>;
21
+ export declare function isInsideFrontmatter(offset: number, frontmatter: FrontmatterStatus): boolean;
29
22
  /**
30
- * Transform a string into PascalCase
23
+ * Transform a Point from the Astro compiler to an LSP Position
31
24
  */
32
- export declare function toPascalCase(string: string): string;
25
+ export declare function PointToPosition(point: Point): Position;
33
26
  /**
34
- * Function to modify each line of a text, preserving the line break style (`\n` or `\r\n`)
27
+ * Force a range to be at the start of the frontmatter
35
28
  */
36
- export declare function modifyLines(text: string, replacementFn: (line: string, lineIdx: number) => string): string;
37
- /** Clamps a number between min and max */
38
- export declare function clamp(num: number, min: number, max: number): number;
39
- export declare function isNotNullOrUndefined<T>(val: T | undefined | null): val is T;
40
- export declare function isInRange(range: Range, positionToTest: Position): boolean;
41
- export declare function isBeforeOrEqualToPosition(position: Position, positionToTest: Position): boolean;
42
- /**
43
- * Like str.lastIndexOf, but for regular expressions. Note that you need to provide the g-flag to your RegExp!
44
- */
45
- export declare function regexLastIndexOf(text: string, regex: RegExp, endPos?: number): number;
46
- /**
47
- * Get all matches of a regexp.
48
- */
49
- export declare function getRegExpMatches(regex: RegExp, str: string): RegExpExecArray[];
50
- /**
51
- * Debounces a function but cancels previous invocation only if
52
- * a second function determines it should.
53
- *
54
- * @param fn The function with it's argument
55
- * @param determineIfSame The function which determines if the previous invocation should be canceld or not
56
- * @param milliseconds Number of miliseconds to debounce
57
- */
58
- export declare function debounceSameArg<T>(fn: (arg: T) => void, shouldCancelPrevious: (newArg: T, prevArg?: T) => boolean, milliseconds: number): (arg: T) => void;
59
- /**
60
- * Debounces a function but also waits at minimum the specified number of milliseconds until
61
- * the next invocation. This avoids needless calls when a synchronous call (like diagnostics)
62
- * took too long and the whole timeout of the next call was eaten up already.
63
- *
64
- * @param fn The function with it's argument
65
- * @param milliseconds Number of milliseconds to debounce/throttle
66
- */
67
- export declare function debounceThrottle<T extends (...args: any) => void>(fn: T, milliseconds: number): T;
68
- /**
69
- * Try to determine if a workspace could be an Astro project based on the content of `package.json`
70
- */
71
- export declare function isAstroWorkspace(workspacePath: string): boolean;
72
- export interface AstroInstall {
73
- path: string;
74
- version: {
75
- full: string;
76
- major: number;
77
- minor: number;
78
- patch: number;
79
- };
80
- }
81
- export declare function getAstroInstall(basePaths: string[]): AstroInstall | undefined;
29
+ export declare function ensureRangeIsInFrontmatter(range: Range, frontmatter: FrontmatterStatus): Range;
30
+ export declare function getNewFrontmatterEdit(edit: TextEdit, newLine: string): TextEdit;
31
+ export declare function getOpenFrontmatterEdit(edit: TextEdit, newLine: string): TextEdit;
82
32
  export declare function getWorkspacePnpPath(workspacePath: string): string | null;
package/dist/utils.js CHANGED
@@ -1,265 +1,91 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getWorkspacePnpPath = exports.getAstroInstall = exports.isAstroWorkspace = exports.debounceThrottle = exports.debounceSameArg = exports.getRegExpMatches = exports.regexLastIndexOf = exports.isBeforeOrEqualToPosition = exports.isInRange = exports.isNotNullOrUndefined = exports.clamp = exports.modifyLines = exports.toPascalCase = exports.mergeDeep = exports.get = exports.getLastPartOfPath = exports.pathToUrl = exports.urlToPath = exports.normalizePath = exports.normalizeUri = void 0;
4
- const path_1 = require("path");
5
- const vscode_uri_1 = require("vscode-uri");
6
- const importPackage_1 = require("./importPackage");
7
- /** Normalizes a document URI */
8
- function normalizeUri(uri) {
9
- return vscode_uri_1.URI.parse(uri).toString();
10
- }
11
- exports.normalizeUri = normalizeUri;
12
- /**
13
- * Some paths (on windows) start with a upper case driver letter, some don't.
14
- * This is normalized here.
15
- */
16
- function normalizePath(path) {
17
- return vscode_uri_1.URI.file(path).fsPath.replace(/\\/g, '/');
18
- }
19
- exports.normalizePath = normalizePath;
20
- /** Turns a URL into a normalized FS Path */
21
- function urlToPath(stringUrl) {
22
- const url = vscode_uri_1.URI.parse(stringUrl);
23
- if (url.scheme !== 'file') {
24
- return null;
25
- }
26
- return url.fsPath.replace(/\\/g, '/');
27
- }
28
- exports.urlToPath = urlToPath;
29
- /** Converts a path to a URL */
30
- function pathToUrl(path) {
31
- return vscode_uri_1.URI.file(path).toString();
32
- }
33
- exports.pathToUrl = pathToUrl;
6
+ exports.getWorkspacePnpPath = exports.getOpenFrontmatterEdit = exports.getNewFrontmatterEdit = exports.ensureRangeIsInFrontmatter = exports.PointToPosition = exports.isInsideFrontmatter = exports.isInsideExpression = exports.isInComponentStartTag = exports.isPossibleComponent = exports.isTsDocument = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const vscode_html_languageservice_1 = require("vscode-html-languageservice");
9
+ function isTsDocument(languageId) {
10
+ return (languageId === 'javascript' ||
11
+ languageId === 'typescript' ||
12
+ languageId === 'javascriptreact' ||
13
+ languageId === 'typescriptreact');
14
+ }
15
+ exports.isTsDocument = isTsDocument;
34
16
  /**
35
- * Given a path like foo/bar or foo/bar.astro , returns its last path
36
- * (bar or bar.astro in this example).
17
+ * Return true if a specific node could be a component.
18
+ * This is not a 100% sure test as it'll return false for any component that does not match the standard format for a component
37
19
  */
38
- function getLastPartOfPath(path) {
39
- return path.replace(/\\/g, '/').split('/').pop() || '';
20
+ function isPossibleComponent(node) {
21
+ return !!node.tag?.[0].match(/[A-Z]/) || !!node.tag?.match(/.+[.][A-Z]?/);
40
22
  }
41
- exports.getLastPartOfPath = getLastPartOfPath;
23
+ exports.isPossibleComponent = isPossibleComponent;
42
24
  /**
43
- * Return an element in an object using a path as a string (ex: `astro.typescript.format` will return astro['typescript']['format']).
44
- * From: https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get
25
+ * Return if a given offset is inside the start tag of a component
45
26
  */
46
- function get(obj, path) {
47
- const travel = (regexp) => String.prototype.split
48
- .call(path, regexp)
49
- .filter(Boolean)
50
- .reduce((res, key) => (res !== null && res !== undefined ? res[key] : res), obj);
51
- const result = travel(/[,[\]]+?/) || travel(/[,[\].]+?/);
52
- return result === undefined ? undefined : result;
27
+ function isInComponentStartTag(html, offset) {
28
+ const node = html.findNodeAt(offset);
29
+ return isPossibleComponent(node) && (!node.startTagEnd || offset < node.startTagEnd);
53
30
  }
54
- exports.get = get;
31
+ exports.isInComponentStartTag = isInComponentStartTag;
55
32
  /**
56
- * Performs a deep merge of objects and returns new object. Does not modify
57
- * objects (immutable) and merges arrays via concatenation.
58
- * From: https://stackoverflow.com/a/48218209
33
+ * Return if a given position is inside a JSX expression
59
34
  */
60
- function mergeDeep(...objects) {
61
- const isObject = (obj) => obj && typeof obj === 'object';
62
- return objects.reduce((prev, obj) => {
63
- Object.keys(obj).forEach((key) => {
64
- const pVal = prev[key];
65
- const oVal = obj[key];
66
- if (Array.isArray(pVal) && Array.isArray(oVal)) {
67
- prev[key] = pVal.concat(...oVal);
68
- }
69
- else if (isObject(pVal) && isObject(oVal)) {
70
- prev[key] = mergeDeep(pVal, oVal);
71
- }
72
- else {
73
- prev[key] = oVal;
74
- }
75
- });
76
- return prev;
77
- }, {});
35
+ function isInsideExpression(html, tagStart, position) {
36
+ const charactersInNode = html.substring(tagStart, position);
37
+ return charactersInNode.lastIndexOf('{') > charactersInNode.lastIndexOf('}');
78
38
  }
79
- exports.mergeDeep = mergeDeep;
39
+ exports.isInsideExpression = isInsideExpression;
80
40
  /**
81
- * Transform a string into PascalCase
41
+ * Return if a given offset is inside the frontmatter
82
42
  */
83
- function toPascalCase(string) {
84
- return `${string}`
85
- .replace(new RegExp(/[-_]+/, 'g'), ' ')
86
- .replace(new RegExp(/[^\w\s]/, 'g'), '')
87
- .replace(new RegExp(/\s+(.)(\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3.toLowerCase()}`)
88
- .replace(new RegExp(/\w/), (s) => s.toUpperCase());
89
- }
90
- exports.toPascalCase = toPascalCase;
91
- /**
92
- * Function to modify each line of a text, preserving the line break style (`\n` or `\r\n`)
93
- */
94
- function modifyLines(text, replacementFn) {
95
- let idx = 0;
96
- return text
97
- .split('\r\n')
98
- .map((l1) => l1
99
- .split('\n')
100
- .map((line) => replacementFn(line, idx++))
101
- .join('\n'))
102
- .join('\r\n');
103
- }
104
- exports.modifyLines = modifyLines;
105
- /** Clamps a number between min and max */
106
- function clamp(num, min, max) {
107
- return Math.max(min, Math.min(max, num));
108
- }
109
- exports.clamp = clamp;
110
- function isNotNullOrUndefined(val) {
111
- return val !== undefined && val !== null;
112
- }
113
- exports.isNotNullOrUndefined = isNotNullOrUndefined;
114
- function isInRange(range, positionToTest) {
115
- return isBeforeOrEqualToPosition(range.end, positionToTest) && isBeforeOrEqualToPosition(positionToTest, range.start);
116
- }
117
- exports.isInRange = isInRange;
118
- function isBeforeOrEqualToPosition(position, positionToTest) {
119
- return (positionToTest.line < position.line ||
120
- (positionToTest.line === position.line && positionToTest.character <= position.character));
121
- }
122
- exports.isBeforeOrEqualToPosition = isBeforeOrEqualToPosition;
123
- /**
124
- * Like str.lastIndexOf, but for regular expressions. Note that you need to provide the g-flag to your RegExp!
125
- */
126
- function regexLastIndexOf(text, regex, endPos) {
127
- if (endPos === undefined) {
128
- endPos = text.length;
129
- }
130
- else if (endPos < 0) {
131
- endPos = 0;
43
+ function isInsideFrontmatter(offset, frontmatter) {
44
+ switch (frontmatter.status) {
45
+ case 'closed':
46
+ return offset > frontmatter.position.start.offset && offset < frontmatter.position.end.offset;
47
+ case 'open':
48
+ return offset > frontmatter.position.start.offset;
49
+ case 'doesnt-exist':
50
+ return false;
132
51
  }
133
- const stringToWorkWith = text.substring(0, endPos + 1);
134
- let lastIndexOf = -1;
135
- let result = null;
136
- while ((result = regex.exec(stringToWorkWith)) !== null) {
137
- lastIndexOf = result.index;
138
- }
139
- return lastIndexOf;
140
- }
141
- exports.regexLastIndexOf = regexLastIndexOf;
142
- /**
143
- * Get all matches of a regexp.
144
- */
145
- function getRegExpMatches(regex, str) {
146
- const matches = [];
147
- let match;
148
- while ((match = regex.exec(str))) {
149
- matches.push(match);
150
- }
151
- return matches;
152
52
  }
153
- exports.getRegExpMatches = getRegExpMatches;
53
+ exports.isInsideFrontmatter = isInsideFrontmatter;
154
54
  /**
155
- * Debounces a function but cancels previous invocation only if
156
- * a second function determines it should.
157
- *
158
- * @param fn The function with it's argument
159
- * @param determineIfSame The function which determines if the previous invocation should be canceld or not
160
- * @param milliseconds Number of miliseconds to debounce
55
+ * Transform a Point from the Astro compiler to an LSP Position
161
56
  */
162
- function debounceSameArg(fn, shouldCancelPrevious, milliseconds) {
163
- let timeout;
164
- let prevArg;
165
- return (arg) => {
166
- if (shouldCancelPrevious(arg, prevArg)) {
167
- clearTimeout(timeout);
168
- }
169
- prevArg = arg;
170
- timeout = setTimeout(() => {
171
- fn(arg);
172
- prevArg = undefined;
173
- }, milliseconds);
174
- };
175
- }
176
- exports.debounceSameArg = debounceSameArg;
177
- /**
178
- * Debounces a function but also waits at minimum the specified number of milliseconds until
179
- * the next invocation. This avoids needless calls when a synchronous call (like diagnostics)
180
- * took too long and the whole timeout of the next call was eaten up already.
181
- *
182
- * @param fn The function with it's argument
183
- * @param milliseconds Number of milliseconds to debounce/throttle
184
- */
185
- function debounceThrottle(fn, milliseconds) {
186
- let timeout;
187
- let lastInvocation = Date.now() - milliseconds;
188
- function maybeCall(...args) {
189
- clearTimeout(timeout);
190
- timeout = setTimeout(() => {
191
- if (Date.now() - lastInvocation < milliseconds) {
192
- maybeCall(...args);
193
- return;
194
- }
195
- fn(...args);
196
- lastInvocation = Date.now();
197
- }, milliseconds);
198
- }
199
- return maybeCall;
57
+ function PointToPosition(point) {
58
+ return vscode_html_languageservice_1.Position.create(point.line, point.column);
200
59
  }
201
- exports.debounceThrottle = debounceThrottle;
60
+ exports.PointToPosition = PointToPosition;
202
61
  /**
203
- * Try to determine if a workspace could be an Astro project based on the content of `package.json`
62
+ * Force a range to be at the start of the frontmatter
204
63
  */
205
- function isAstroWorkspace(workspacePath) {
206
- try {
207
- const astroPackageJson = require.resolve('./package.json', { paths: [workspacePath] });
208
- const deps = Object.assign(require(astroPackageJson).dependencies ?? {}, require(astroPackageJson).devDependencies ?? {});
209
- if (Object.keys(deps).includes('astro')) {
210
- return true;
211
- }
212
- }
213
- catch (e) {
214
- return false;
215
- }
216
- return false;
217
- }
218
- exports.isAstroWorkspace = isAstroWorkspace;
219
- function getAstroInstall(basePaths) {
220
- let path;
221
- let version;
222
- try {
223
- path = (0, importPackage_1.getPackagePath)('astro', basePaths);
224
- if (!path) {
225
- throw Error;
226
- }
227
- version = require((0, path_1.resolve)(path, 'package.json')).version;
64
+ function ensureRangeIsInFrontmatter(range, frontmatter) {
65
+ if (frontmatter.status === 'open' || frontmatter.status === 'closed') {
66
+ const position = PointToPosition(frontmatter.position.start);
67
+ position.line += 1;
68
+ return vscode_html_languageservice_1.Range.create(position, position);
228
69
  }
229
- catch {
230
- // If we couldn't find it inside the workspace's node_modules, it might means we're in the monorepo
231
- try {
232
- path = (0, importPackage_1.getPackagePath)('./packages/astro', basePaths);
233
- if (!path) {
234
- throw Error;
235
- }
236
- version = require((0, path_1.resolve)(path, 'package.json')).version;
237
- }
238
- catch (e) {
239
- // If we still couldn't find it, it probably just doesn't exist
240
- console.error(`${basePaths[0]} seems to be an Astro project, but we couldn't find Astro or Astro is not installed`);
241
- return undefined;
242
- }
243
- }
244
- let [major, minor, patch] = version.split('.');
245
- if (patch.includes('-')) {
246
- const patchParts = patch.split('-');
247
- patch = patchParts[0];
248
- }
249
- return {
250
- path,
251
- version: {
252
- full: version,
253
- major: Number(major),
254
- minor: Number(minor),
255
- patch: Number(patch),
256
- },
257
- };
258
- }
259
- exports.getAstroInstall = getAstroInstall;
70
+ return range;
71
+ }
72
+ exports.ensureRangeIsInFrontmatter = ensureRangeIsInFrontmatter;
73
+ function getNewFrontmatterEdit(edit, newLine) {
74
+ edit.newText = `---${newLine}${edit.newText}---${newLine}${newLine}`;
75
+ edit.range = vscode_html_languageservice_1.Range.create(0, 0, 0, 0);
76
+ return edit;
77
+ }
78
+ exports.getNewFrontmatterEdit = getNewFrontmatterEdit;
79
+ function getOpenFrontmatterEdit(edit, newLine) {
80
+ edit.newText = edit.newText.startsWith(newLine)
81
+ ? `${edit.newText}---`
82
+ : `${newLine}${edit.newText}---`;
83
+ return edit;
84
+ }
85
+ exports.getOpenFrontmatterEdit = getOpenFrontmatterEdit;
260
86
  function getWorkspacePnpPath(workspacePath) {
261
87
  try {
262
- const possiblePath = (0, path_1.resolve)(workspacePath, '.pnp.cjs');
88
+ const possiblePath = node_path_1.default.resolve(workspacePath, '.pnp.cjs');
263
89
  require.resolve(possiblePath);
264
90
  return possiblePath;
265
91
  }
@@ -268,3 +94,4 @@ function getWorkspacePnpPath(workspacePath) {
268
94
  }
269
95
  }
270
96
  exports.getWorkspacePnpPath = getWorkspacePnpPath;
97
+ //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "1.0.5",
3
+ "version": "2.0.0-next.6",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -10,52 +10,54 @@
10
10
  },
11
11
  "type": "commonjs",
12
12
  "main": "dist/index.js",
13
- "bin": {
14
- "astro-ls": "./bin/nodeServer.js"
15
- },
16
13
  "files": [
17
- "dist",
18
14
  "bin",
19
- "types"
15
+ "dist/**/*.js",
16
+ "dist/**/*.d.ts",
17
+ "types/**/*.d.ts"
20
18
  ],
19
+ "bin": {
20
+ "astro-ls": "./bin/nodeServer.js"
21
+ },
21
22
  "dependencies": {
22
23
  "@astrojs/compiler": "^1.4.1",
23
- "@jridgewell/trace-mapping": "^0.3.14",
24
- "@vscode/emmet-helper": "^2.8.4",
25
- "events": "^3.3.0",
24
+ "@jridgewell/sourcemap-codec": "^1.4.15",
25
+ "@volar/language-core": "^1.6.2",
26
+ "@volar/language-server": "^1.6.2",
27
+ "@volar/language-service": "^1.6.2",
28
+ "@volar/source-map": "^1.6.2",
29
+ "fast-glob": "^3.2.12",
30
+ "muggle-string": "^0.3.1",
26
31
  "prettier": "^2.8.8",
27
- "prettier-plugin-astro": "^0.8.1",
28
- "vscode-css-languageservice": "^6.2.1",
29
- "vscode-html-languageservice": "^5.0.0",
30
- "vscode-languageserver": "^8.0.1",
31
- "vscode-languageserver-protocol": "^3.17.1",
32
- "vscode-languageserver-textdocument": "^1.0.4",
33
- "vscode-languageserver-types": "^3.17.1",
34
- "vscode-uri": "^3.0.3"
32
+ "prettier-plugin-astro": "^0.9.0",
33
+ "volar-service-css": "^0.0.2",
34
+ "volar-service-emmet": "^0.0.2",
35
+ "volar-service-html": "^0.0.2",
36
+ "volar-service-prettier": "^0.0.1",
37
+ "volar-service-typescript": "^0.0.2",
38
+ "volar-service-typescript-twoslash-queries": "^0.0.2",
39
+ "vscode-html-languageservice": "^5.0.5",
40
+ "vscode-uri": "^3.0.7"
35
41
  },
36
42
  "devDependencies": {
37
- "@astrojs/svelte": "^1.0.0",
38
- "@astrojs/vue": "^1.0.0",
39
- "@types/chai": "^4.3.0",
40
- "@types/mocha": "^9.1.0",
41
- "@types/node": "^16.11.58",
42
- "@types/prettier": "^2.7.0",
43
- "@types/sinon": "^10.0.11",
44
- "astro": "^1.6.2",
45
- "astro-scripts": "*",
46
- "chai": "^4.3.6",
47
- "cross-env": "^7.0.3",
48
- "mocha": "^9.2.2",
49
- "sinon": "^13.0.1",
50
- "svelte": "^3.49.0",
51
- "ts-node": "^10.7.0",
52
- "typescript": "~5.0.2",
53
- "vue": "^3.2.37"
43
+ "@astrojs/svelte": "^2.1.1",
44
+ "@astrojs/vue": "^2.1.1",
45
+ "@types/chai": "^4.3.5",
46
+ "@types/mocha": "^10.0.1",
47
+ "@types/node": "^16.18.26",
48
+ "@types/prettier": "^2.7.2",
49
+ "astro": "^2.4.4",
50
+ "chai": "^4.3.7",
51
+ "mocha": "^10.2.0",
52
+ "tsx": "^3.12.7",
53
+ "typescript": "~5.0.4",
54
+ "vscode-languageserver-protocol": "^3.17.3",
55
+ "vscode-languageserver-textdocument": "^1.0.8"
54
56
  },
55
57
  "scripts": {
56
- "build": "tsc --project tsconfig.build.json",
57
- "dev": "astro-scripts dev \"src/**/*.ts\"",
58
- "test": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --timeout 20000 --require ts-node/register \"test/**/*.ts\" --exclude \"test/**/*.d.ts\"",
58
+ "build": "tsc",
59
+ "dev": "tsc --watch",
60
+ "test": "mocha --require tsx --require test/takedown.ts test/misc/init.test.ts test/**/*.test.ts",
59
61
  "test:match": "pnpm run test -g"
60
62
  }
61
63
  }
@@ -32,7 +32,12 @@ declare namespace astroHTML.JSX {
32
32
  }
33
33
 
34
34
  interface AstroBuiltinAttributes {
35
- 'class:list'?: Record<string, boolean> | Record<any, any> | Iterable<string> | Iterable<any> | string;
35
+ 'class:list'?:
36
+ | Record<string, boolean>
37
+ | Record<any, any>
38
+ | Iterable<string>
39
+ | Iterable<any>
40
+ | string;
36
41
  'set:html'?: any;
37
42
  'set:text'?: any;
38
43
  'is:raw'?: boolean;
@@ -236,7 +241,17 @@ declare namespace astroHTML.JSX {
236
241
  */
237
242
  'aria-controls'?: string | undefined | null;
238
243
  /** Indicates the element that represents the current item within a container or set of related elements. */
239
- 'aria-current'?: boolean | 'false' | 'true' | 'page' | 'step' | 'location' | 'date' | 'time' | undefined | null;
244
+ 'aria-current'?:
245
+ | boolean
246
+ | 'false'
247
+ | 'true'
248
+ | 'page'
249
+ | 'step'
250
+ | 'location'
251
+ | 'date'
252
+ | 'time'
253
+ | undefined
254
+ | null;
240
255
  /**
241
256
  * Identifies the element (or elements) that describes the object.
242
257
  * @see aria-labelledby
@@ -275,7 +290,17 @@ declare namespace astroHTML.JSX {
275
290
  */
276
291
  'aria-grabbed'?: boolean | 'false' | 'true' | undefined | null;
277
292
  /** Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element. */
278
- 'aria-haspopup'?: boolean | 'false' | 'true' | 'menu' | 'listbox' | 'tree' | 'grid' | 'dialog' | undefined | null;
293
+ 'aria-haspopup'?:
294
+ | boolean
295
+ | 'false'
296
+ | 'true'
297
+ | 'menu'
298
+ | 'listbox'
299
+ | 'tree'
300
+ | 'grid'
301
+ | 'dialog'
302
+ | undefined
303
+ | null;
279
304
  /**
280
305
  * Indicates whether the element is exposed to an accessibility API.
281
306
  * @see aria-disabled.
@@ -478,11 +503,30 @@ declare namespace astroHTML.JSX {
478
503
  contenteditable?: 'true' | 'false' | boolean | 'inherit' | string | undefined | null;
479
504
  dir?: string | undefined | null;
480
505
  draggable?: 'true' | 'false' | boolean | undefined | null;
481
- enterkeyhint?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send' | undefined | null;
506
+ enterkeyhint?:
507
+ | 'enter'
508
+ | 'done'
509
+ | 'go'
510
+ | 'next'
511
+ | 'previous'
512
+ | 'search'
513
+ | 'send'
514
+ | undefined
515
+ | null;
482
516
  hidden?: boolean | string | undefined | null;
483
517
  id?: string | undefined | null;
484
518
  inert?: boolean | string | undefined | null;
485
- inputmode?: 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search' | undefined | null;
519
+ inputmode?:
520
+ | 'none'
521
+ | 'text'
522
+ | 'tel'
523
+ | 'url'
524
+ | 'email'
525
+ | 'numeric'
526
+ | 'decimal'
527
+ | 'search'
528
+ | undefined
529
+ | null;
486
530
  is?: string | undefined | null;
487
531
  itemid?: string | undefined | null;
488
532
  itemprop?: string | undefined | null;
@@ -1,3 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- require('../dist/browser.js');
package/dist/browser.js DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const browser_1 = require("vscode-languageserver/browser");
4
- const server_1 = require("./server");
5
- const messageReader = new browser_1.BrowserMessageReader(self);
6
- const messageWriter = new browser_1.BrowserMessageWriter(self);
7
- const connection = (0, browser_1.createConnection)(messageReader, messageWriter);
8
- (0, server_1.startLanguageServer)(connection, {
9
- loadTypescript(options) {
10
- return undefined; // TODO: Full browser support
11
- },
12
- loadTypescriptLocalized(options) {
13
- return undefined;
14
- },
15
- });