@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.
- package/LICENSE +3 -5
- package/bin/nodeServer.js +7 -3
- package/dist/core/astro2tsx.d.ts +6 -0
- package/dist/core/astro2tsx.js +119 -0
- package/dist/core/compilerUtils.d.ts +27 -0
- package/dist/core/compilerUtils.js +52 -0
- package/dist/core/index.d.ts +27 -0
- package/dist/core/index.js +119 -0
- package/dist/core/parseAstro.d.ts +27 -0
- package/dist/core/parseAstro.js +47 -0
- package/dist/core/parseCSS.d.ts +7 -0
- package/dist/core/parseCSS.js +116 -0
- package/dist/core/parseHTML.d.ts +7 -0
- package/dist/core/parseHTML.js +113 -0
- package/dist/core/parseJS.d.ts +7 -0
- package/dist/core/parseJS.js +236 -0
- package/dist/core/svelte.d.ts +18 -0
- package/dist/core/svelte.js +45 -0
- package/dist/core/utils.d.ts +14 -0
- package/dist/core/utils.js +138 -0
- package/dist/core/vue.d.ts +18 -0
- package/dist/core/vue.js +45 -0
- package/dist/importPackage.d.ts +1 -1
- package/dist/importPackage.js +4 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +26 -6
- package/dist/languageServerPlugin.d.ts +2 -0
- package/dist/languageServerPlugin.js +76 -0
- package/dist/nodeServer.js +6 -0
- package/dist/plugins/astro.d.ts +3 -0
- package/dist/plugins/astro.js +123 -0
- package/dist/plugins/{html/features/astro-attributes.js → html-data.js} +1 -0
- package/dist/plugins/html.d.ts +3 -0
- package/dist/plugins/html.js +33 -0
- package/dist/plugins/typescript/codeActions.d.ts +4 -0
- package/dist/plugins/typescript/codeActions.js +49 -0
- package/dist/plugins/typescript/completions.d.ts +3 -0
- package/dist/plugins/typescript/completions.js +81 -0
- package/dist/plugins/typescript/diagnostics.d.ts +12 -0
- package/dist/plugins/typescript/diagnostics.js +99 -0
- package/dist/plugins/typescript/index.d.ts +3 -0
- package/dist/plugins/typescript/index.js +57 -0
- package/dist/utils.d.ts +19 -69
- package/dist/utils.js +66 -239
- package/package.json +39 -37
- package/types/astro-jsx.d.ts +49 -5
- package/bin/browserServer.js +0 -3
- package/dist/browser.js +0 -15
- package/dist/check.d.ts +0 -23
- package/dist/check.js +0 -60
- package/dist/core/DiagnosticsManager.d.ts +0 -13
- package/dist/core/DiagnosticsManager.js +0 -29
- package/dist/core/config/ConfigManager.d.ts +0 -43
- package/dist/core/config/ConfigManager.js +0 -226
- package/dist/core/config/index.d.ts +0 -2
- package/dist/core/config/index.js +0 -18
- package/dist/core/config/interfaces.d.ts +0 -77
- package/dist/core/config/interfaces.js +0 -2
- package/dist/core/documents/AstroDocument.d.ts +0 -19
- package/dist/core/documents/AstroDocument.js +0 -43
- package/dist/core/documents/DocumentBase.d.ts +0 -68
- package/dist/core/documents/DocumentBase.js +0 -75
- package/dist/core/documents/DocumentManager.d.ts +0 -23
- package/dist/core/documents/DocumentManager.js +0 -100
- package/dist/core/documents/DocumentMapper.d.ts +0 -94
- package/dist/core/documents/DocumentMapper.js +0 -264
- package/dist/core/documents/index.d.ts +0 -5
- package/dist/core/documents/index.js +0 -21
- package/dist/core/documents/parseAstro.d.ts +0 -15
- package/dist/core/documents/parseAstro.js +0 -63
- package/dist/core/documents/parseHtml.d.ts +0 -13
- package/dist/core/documents/parseHtml.js +0 -126
- package/dist/core/documents/utils.d.ts +0 -63
- package/dist/core/documents/utils.js +0 -223
- package/dist/node.d.ts +0 -1
- package/dist/node.js +0 -43
- package/dist/plugins/PluginHost.d.ts +0 -42
- package/dist/plugins/PluginHost.js +0 -206
- package/dist/plugins/astro/AstroPlugin.d.ts +0 -17
- package/dist/plugins/astro/AstroPlugin.js +0 -90
- package/dist/plugins/astro/features/CompletionsProvider.d.ts +0 -17
- package/dist/plugins/astro/features/CompletionsProvider.js +0 -242
- package/dist/plugins/astro/features/DiagnosticsProvider.d.ts +0 -10
- package/dist/plugins/astro/features/DiagnosticsProvider.js +0 -23
- package/dist/plugins/css/CSSDocument.d.ts +0 -45
- package/dist/plugins/css/CSSDocument.js +0 -68
- package/dist/plugins/css/CSSPlugin.d.ts +0 -39
- package/dist/plugins/css/CSSPlugin.js +0 -274
- package/dist/plugins/css/StyleAttributeDocument.d.ts +0 -40
- package/dist/plugins/css/StyleAttributeDocument.js +0 -64
- package/dist/plugins/css/features/astro-selectors.d.ts +0 -2
- package/dist/plugins/css/features/astro-selectors.js +0 -15
- package/dist/plugins/css/features/getIdClassCompletions.d.ts +0 -19
- package/dist/plugins/css/features/getIdClassCompletions.js +0 -57
- package/dist/plugins/css/language-service.d.ts +0 -3
- package/dist/plugins/css/language-service.js +0 -47
- package/dist/plugins/html/HTMLPlugin.d.ts +0 -33
- package/dist/plugins/html/HTMLPlugin.js +0 -198
- package/dist/plugins/html/utils.d.ts +0 -6
- package/dist/plugins/html/utils.js +0 -11
- package/dist/plugins/index.d.ts +0 -6
- package/dist/plugins/index.js +0 -22
- package/dist/plugins/interfaces.d.ts +0 -101
- package/dist/plugins/interfaces.js +0 -2
- package/dist/plugins/typescript/LanguageServiceManager.d.ts +0 -47
- package/dist/plugins/typescript/LanguageServiceManager.js +0 -97
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +0 -54
- package/dist/plugins/typescript/TypeScriptPlugin.js +0 -152
- package/dist/plugins/typescript/astro-sys.d.ts +0 -8
- package/dist/plugins/typescript/astro-sys.js +0 -46
- package/dist/plugins/typescript/astro2tsx.d.ts +0 -2
- package/dist/plugins/typescript/astro2tsx.js +0 -26
- package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +0 -17
- package/dist/plugins/typescript/features/CodeActionsProvider.js +0 -212
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +0 -31
- package/dist/plugins/typescript/features/CompletionsProvider.js +0 -294
- package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/DefinitionsProvider.js +0 -58
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +0 -25
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +0 -249
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +0 -11
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +0 -67
- package/dist/plugins/typescript/features/FileReferencesProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/FileReferencesProvider.js +0 -27
- package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +0 -12
- package/dist/plugins/typescript/features/FoldingRangesProvider.js +0 -71
- package/dist/plugins/typescript/features/HoverProvider.d.ts +0 -10
- package/dist/plugins/typescript/features/HoverProvider.js +0 -50
- package/dist/plugins/typescript/features/ImplementationsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/ImplementationsProvider.js +0 -53
- package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +0 -13
- package/dist/plugins/typescript/features/InlayHintsProvider.js +0 -30
- package/dist/plugins/typescript/features/ReferencesProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/ReferencesProvider.js +0 -55
- package/dist/plugins/typescript/features/RenameProvider.d.ts +0 -13
- package/dist/plugins/typescript/features/RenameProvider.js +0 -60
- package/dist/plugins/typescript/features/SemanticTokenProvider.d.ts +0 -16
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +0 -75
- package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +0 -22
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +0 -111
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.js +0 -54
- package/dist/plugins/typescript/features/utils.d.ts +0 -14
- package/dist/plugins/typescript/features/utils.js +0 -48
- package/dist/plugins/typescript/language-service.d.ts +0 -42
- package/dist/plugins/typescript/language-service.js +0 -278
- package/dist/plugins/typescript/module-loader.d.ts +0 -23
- package/dist/plugins/typescript/module-loader.js +0 -155
- package/dist/plugins/typescript/previewer.d.ts +0 -7
- package/dist/plugins/typescript/previewer.js +0 -108
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +0 -95
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +0 -187
- package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +0 -44
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +0 -179
- package/dist/plugins/typescript/snapshots/utils.d.ts +0 -29
- package/dist/plugins/typescript/snapshots/utils.js +0 -106
- package/dist/plugins/typescript/utils.d.ts +0 -75
- package/dist/plugins/typescript/utils.js +0 -366
- package/dist/server.d.ts +0 -6
- package/dist/server.js +0 -275
- package/types/README.md +0 -5
- /package/dist/{browser.d.ts → nodeServer.d.ts} +0 -0
- /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 {
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
*
|
|
6
|
-
* This is
|
|
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
|
|
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
|
-
*
|
|
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
|
|
13
|
+
export declare function isInComponentStartTag(html: HTMLDocument, offset: number): boolean;
|
|
18
14
|
/**
|
|
19
|
-
* Return
|
|
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
|
|
17
|
+
export declare function isInsideExpression(html: string, tagStart: number, position: number): boolean;
|
|
23
18
|
/**
|
|
24
|
-
*
|
|
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
|
|
21
|
+
export declare function isInsideFrontmatter(offset: number, frontmatter: FrontmatterStatus): boolean;
|
|
29
22
|
/**
|
|
30
|
-
* Transform a
|
|
23
|
+
* Transform a Point from the Astro compiler to an LSP Position
|
|
31
24
|
*/
|
|
32
|
-
export declare function
|
|
25
|
+
export declare function PointToPosition(point: Point): Position;
|
|
33
26
|
/**
|
|
34
|
-
*
|
|
27
|
+
* Force a range to be at the start of the frontmatter
|
|
35
28
|
*/
|
|
36
|
-
export declare function
|
|
37
|
-
|
|
38
|
-
export declare function
|
|
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.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
*
|
|
36
|
-
*
|
|
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
|
|
39
|
-
return
|
|
20
|
+
function isPossibleComponent(node) {
|
|
21
|
+
return !!node.tag?.[0].match(/[A-Z]/) || !!node.tag?.match(/.+[.][A-Z]?/);
|
|
40
22
|
}
|
|
41
|
-
exports.
|
|
23
|
+
exports.isPossibleComponent = isPossibleComponent;
|
|
42
24
|
/**
|
|
43
|
-
* Return
|
|
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
|
|
47
|
-
const
|
|
48
|
-
|
|
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.
|
|
31
|
+
exports.isInComponentStartTag = isInComponentStartTag;
|
|
55
32
|
/**
|
|
56
|
-
*
|
|
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
|
|
61
|
-
const
|
|
62
|
-
return
|
|
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.
|
|
39
|
+
exports.isInsideExpression = isInsideExpression;
|
|
80
40
|
/**
|
|
81
|
-
*
|
|
41
|
+
* Return if a given offset is inside the frontmatter
|
|
82
42
|
*/
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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.
|
|
53
|
+
exports.isInsideFrontmatter = isInsideFrontmatter;
|
|
154
54
|
/**
|
|
155
|
-
*
|
|
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
|
|
163
|
-
|
|
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.
|
|
60
|
+
exports.PointToPosition = PointToPosition;
|
|
202
61
|
/**
|
|
203
|
-
*
|
|
62
|
+
* Force a range to be at the start of the frontmatter
|
|
204
63
|
*/
|
|
205
|
-
function
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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 =
|
|
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": "
|
|
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
|
-
"
|
|
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/
|
|
24
|
-
"@
|
|
25
|
-
"
|
|
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.
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"vscode-
|
|
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.
|
|
38
|
-
"@astrojs/vue": "^1.
|
|
39
|
-
"@types/chai": "^4.3.
|
|
40
|
-
"@types/mocha": "^
|
|
41
|
-
"@types/node": "^16.
|
|
42
|
-
"@types/prettier": "^2.7.
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
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
|
|
57
|
-
"dev": "
|
|
58
|
-
"test": "
|
|
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
|
}
|
package/types/astro-jsx.d.ts
CHANGED
|
@@ -32,7 +32,12 @@ declare namespace astroHTML.JSX {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
interface AstroBuiltinAttributes {
|
|
35
|
-
'class:list'?:
|
|
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'?:
|
|
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'?:
|
|
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?:
|
|
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?:
|
|
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;
|
package/bin/browserServer.js
DELETED
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
|
-
});
|