@astrojs/language-server 1.0.5 → 2.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +37 -38
- 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
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAttributeContextAtPosition = exports.parseHtml = void 0;
|
|
4
|
-
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
const parser = (0, vscode_html_languageservice_1.getLanguageService)();
|
|
7
|
-
/**
|
|
8
|
-
* Parses text as HTML
|
|
9
|
-
*/
|
|
10
|
-
function parseHtml(text, frontmatter) {
|
|
11
|
-
const preprocessed = preprocess(text, frontmatter);
|
|
12
|
-
// We can safely only set getText because only this is used for parsing
|
|
13
|
-
const parsedDoc = parser.parseHTMLDocument({ getText: () => preprocessed });
|
|
14
|
-
return parsedDoc;
|
|
15
|
-
}
|
|
16
|
-
exports.parseHtml = parseHtml;
|
|
17
|
-
const createScanner = parser.createScanner;
|
|
18
|
-
/**
|
|
19
|
-
* scan the text and remove any `>` or `<` that cause the tag to end short,
|
|
20
|
-
*/
|
|
21
|
-
function preprocess(text, frontmatter) {
|
|
22
|
-
let scanner = createScanner(text);
|
|
23
|
-
let token = scanner.scan();
|
|
24
|
-
let currentStartTagStart = null;
|
|
25
|
-
const hasFrontmatter = frontmatter !== undefined;
|
|
26
|
-
while (token !== vscode_html_languageservice_1.TokenType.EOS) {
|
|
27
|
-
const offset = scanner.getTokenOffset();
|
|
28
|
-
if (hasFrontmatter &&
|
|
29
|
-
(scanner.getTokenText() === '>' || scanner.getTokenText() === '<') &&
|
|
30
|
-
offset < (frontmatter.content.firstNonWhitespaceOffset ?? 0)) {
|
|
31
|
-
blankStartOrEndTagLike(offset, vscode_html_languageservice_1.ScannerState.WithinContent);
|
|
32
|
-
}
|
|
33
|
-
if (token === vscode_html_languageservice_1.TokenType.StartTagOpen) {
|
|
34
|
-
currentStartTagStart = offset;
|
|
35
|
-
}
|
|
36
|
-
if (token === vscode_html_languageservice_1.TokenType.StartTagClose) {
|
|
37
|
-
if (shouldBlankStartOrEndTagLike(offset)) {
|
|
38
|
-
blankStartOrEndTagLike(offset);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
currentStartTagStart = null;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (token === vscode_html_languageservice_1.TokenType.StartTagSelfClose) {
|
|
45
|
-
currentStartTagStart = null;
|
|
46
|
-
}
|
|
47
|
-
// <Foo checked={a < 1}>
|
|
48
|
-
// https://github.com/microsoft/vscode-html-languageservice/blob/71806ef57be07e1068ee40900ef8b0899c80e68a/src/parser/htmlScanner.ts#L327
|
|
49
|
-
if (token === vscode_html_languageservice_1.TokenType.Unknown &&
|
|
50
|
-
scanner.getScannerState() === vscode_html_languageservice_1.ScannerState.WithinTag &&
|
|
51
|
-
scanner.getTokenText() === '<' &&
|
|
52
|
-
shouldBlankStartOrEndTagLike(offset)) {
|
|
53
|
-
blankStartOrEndTagLike(offset);
|
|
54
|
-
}
|
|
55
|
-
// TODO: Handle TypeScript generics inside expressions / Use the compiler to parse HTML instead?
|
|
56
|
-
token = scanner.scan();
|
|
57
|
-
}
|
|
58
|
-
return text;
|
|
59
|
-
function shouldBlankStartOrEndTagLike(offset) {
|
|
60
|
-
// not null rather than falsy, otherwise it won't work on first tag(0)
|
|
61
|
-
return currentStartTagStart !== null && (0, utils_1.isInsideExpression)(text, currentStartTagStart, offset);
|
|
62
|
-
}
|
|
63
|
-
function blankStartOrEndTagLike(offset, state) {
|
|
64
|
-
text = text.substring(0, offset) + ' ' + text.substring(offset + 1);
|
|
65
|
-
scanner = createScanner(text, offset, state ?? vscode_html_languageservice_1.ScannerState.WithinTag);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function getAttributeContextAtPosition(document, position) {
|
|
69
|
-
const offset = document.offsetAt(position);
|
|
70
|
-
const { html } = document;
|
|
71
|
-
const tag = html.findNodeAt(offset);
|
|
72
|
-
if (!inStartTag(offset, tag) || !tag.attributes) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
const text = document.getText();
|
|
76
|
-
const beforeStartTagEnd = text.substring(0, tag.start) + preprocess(text.substring(tag.start, tag.startTagEnd));
|
|
77
|
-
const scanner = createScanner(beforeStartTagEnd, tag.start);
|
|
78
|
-
let token = scanner.scan();
|
|
79
|
-
let currentAttributeName;
|
|
80
|
-
const inTokenRange = () => scanner.getTokenOffset() <= offset && offset <= scanner.getTokenEnd();
|
|
81
|
-
while (token != vscode_html_languageservice_1.TokenType.EOS) {
|
|
82
|
-
// adopted from https://github.com/microsoft/vscode-html-languageservice/blob/2f7ae4df298ac2c299a40e9024d118f4a9dc0c68/src/services/htmlCompletion.ts#L402
|
|
83
|
-
if (token === vscode_html_languageservice_1.TokenType.AttributeName) {
|
|
84
|
-
currentAttributeName = scanner.getTokenText();
|
|
85
|
-
if (inTokenRange()) {
|
|
86
|
-
return {
|
|
87
|
-
name: currentAttributeName,
|
|
88
|
-
inValue: false,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else if (token === vscode_html_languageservice_1.TokenType.DelimiterAssign) {
|
|
93
|
-
if (scanner.getTokenEnd() === offset && currentAttributeName) {
|
|
94
|
-
const nextToken = scanner.scan();
|
|
95
|
-
return {
|
|
96
|
-
name: currentAttributeName,
|
|
97
|
-
inValue: true,
|
|
98
|
-
valueRange: [offset, nextToken === vscode_html_languageservice_1.TokenType.AttributeValue ? scanner.getTokenEnd() : offset],
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else if (token === vscode_html_languageservice_1.TokenType.AttributeValue) {
|
|
103
|
-
if (inTokenRange() && currentAttributeName) {
|
|
104
|
-
let start = scanner.getTokenOffset();
|
|
105
|
-
let end = scanner.getTokenEnd();
|
|
106
|
-
const char = text[start];
|
|
107
|
-
if (char === '"' || char === "'") {
|
|
108
|
-
start++;
|
|
109
|
-
end--;
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
name: currentAttributeName,
|
|
113
|
-
inValue: true,
|
|
114
|
-
valueRange: [start, end],
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
currentAttributeName = undefined;
|
|
118
|
-
}
|
|
119
|
-
token = scanner.scan();
|
|
120
|
-
}
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
exports.getAttributeContextAtPosition = getAttributeContextAtPosition;
|
|
124
|
-
function inStartTag(offset, node) {
|
|
125
|
-
return offset > node.start && node.startTagEnd != undefined && offset < node.startTagEnd;
|
|
126
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { HTMLDocument, Node } from 'vscode-html-languageservice';
|
|
2
|
-
import { Position } from 'vscode-languageserver';
|
|
3
|
-
export interface TagInformation {
|
|
4
|
-
content: string;
|
|
5
|
-
attributes: Record<string, string>;
|
|
6
|
-
start: number;
|
|
7
|
-
end: number;
|
|
8
|
-
startPos: Position;
|
|
9
|
-
endPos: Position;
|
|
10
|
-
container: {
|
|
11
|
-
start: number;
|
|
12
|
-
end: number;
|
|
13
|
-
};
|
|
14
|
-
closed: boolean;
|
|
15
|
-
}
|
|
16
|
-
export declare function walk(node: Node): Generator<Node, void, unknown>;
|
|
17
|
-
export declare function extractStyleTags(source: string, html: HTMLDocument): TagInformation[];
|
|
18
|
-
export declare function extractScriptTags(source: string, html: HTMLDocument): TagInformation[];
|
|
19
|
-
export declare function getLineAtPosition(position: Position, text: string): string;
|
|
20
|
-
/**
|
|
21
|
-
* Return if a given offset is inside the start tag of a component
|
|
22
|
-
*/
|
|
23
|
-
export declare function isInComponentStartTag(html: HTMLDocument, offset: number): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Return if a given offset is inside the name of a tag
|
|
26
|
-
*/
|
|
27
|
-
export declare function isInTagName(html: HTMLDocument, offset: number): boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Return true if a specific node could be a component.
|
|
30
|
-
* 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
|
|
31
|
-
*/
|
|
32
|
-
export declare function isPossibleComponent(node: Node): boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Return if the current position is in a specific tag
|
|
35
|
-
*/
|
|
36
|
-
export declare function isInTag(position: Position, tagInfo: TagInformation | null): tagInfo is TagInformation;
|
|
37
|
-
/**
|
|
38
|
-
* Return if a given position is inside a JSX expression
|
|
39
|
-
*/
|
|
40
|
-
export declare function isInsideExpression(html: string, tagStart: number, position: number): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Returns if a given offset is inside of the document frontmatter
|
|
43
|
-
*/
|
|
44
|
-
export declare function isInsideFrontmatter(text: string, offset: number): boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Get the line and character based on the offset
|
|
47
|
-
* @param offset The index of the position
|
|
48
|
-
* @param text The text for which the position should be retrived
|
|
49
|
-
* @param lineOffsets number Array with offsets for each line. Computed if not given
|
|
50
|
-
*/
|
|
51
|
-
export declare function positionAt(offset: number, text: string, lineOffsets?: number[]): Position;
|
|
52
|
-
/**
|
|
53
|
-
* Get the offset of the line and character position
|
|
54
|
-
* @param position Line and character position
|
|
55
|
-
* @param text The text for which the offset should be retrived
|
|
56
|
-
* @param lineOffsets number Array with offsets for each line. Computed if not given
|
|
57
|
-
*/
|
|
58
|
-
export declare function offsetAt(position: Position, text: string, lineOffsets?: number[]): number;
|
|
59
|
-
export declare function getLineOffsets(text: string): number[];
|
|
60
|
-
/**
|
|
61
|
-
* Gets index of first-non-whitespace character.
|
|
62
|
-
*/
|
|
63
|
-
export declare function getFirstNonWhitespaceIndex(str: string): number;
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFirstNonWhitespaceIndex = exports.getLineOffsets = exports.offsetAt = exports.positionAt = exports.isInsideFrontmatter = exports.isInsideExpression = exports.isInTag = exports.isPossibleComponent = exports.isInTagName = exports.isInComponentStartTag = exports.getLineAtPosition = exports.extractScriptTags = exports.extractStyleTags = exports.walk = void 0;
|
|
4
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
5
|
-
const utils_1 = require("../../utils");
|
|
6
|
-
function* walk(node) {
|
|
7
|
-
for (let child of node.children) {
|
|
8
|
-
yield* walk(child);
|
|
9
|
-
}
|
|
10
|
-
yield node;
|
|
11
|
-
}
|
|
12
|
-
exports.walk = walk;
|
|
13
|
-
/**
|
|
14
|
-
* Extracts a tag (style or script) from the given text
|
|
15
|
-
* and returns its start, end and the attributes on that tag.
|
|
16
|
-
*
|
|
17
|
-
* @param source text content to extract tag from
|
|
18
|
-
* @param tag the tag to extract
|
|
19
|
-
*/
|
|
20
|
-
function extractTags(text, tag, html) {
|
|
21
|
-
const rootNodes = html.roots;
|
|
22
|
-
const matchedNodes = rootNodes.filter((node) => node.tag === tag);
|
|
23
|
-
if (tag === 'style' && !matchedNodes.length && rootNodes.length) {
|
|
24
|
-
for (let child of walk(rootNodes[0])) {
|
|
25
|
-
if (child.tag === 'style') {
|
|
26
|
-
matchedNodes.push(child);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (tag === 'script' && !matchedNodes.length && rootNodes.length) {
|
|
31
|
-
for (let child of walk(rootNodes[0])) {
|
|
32
|
-
if (child.tag === 'script') {
|
|
33
|
-
matchedNodes.push(child);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return matchedNodes.map(transformToTagInfo);
|
|
38
|
-
function transformToTagInfo(matchedNode) {
|
|
39
|
-
const start = matchedNode.startTagEnd ?? matchedNode.start;
|
|
40
|
-
const end = matchedNode.endTagStart ?? matchedNode.end;
|
|
41
|
-
const startPos = positionAt(start, text);
|
|
42
|
-
const endPos = positionAt(end, text);
|
|
43
|
-
const container = {
|
|
44
|
-
start: matchedNode.start,
|
|
45
|
-
end: matchedNode.end,
|
|
46
|
-
};
|
|
47
|
-
const content = text.substring(start, end);
|
|
48
|
-
return {
|
|
49
|
-
content,
|
|
50
|
-
attributes: parseAttributes(matchedNode.attributes),
|
|
51
|
-
start,
|
|
52
|
-
end,
|
|
53
|
-
startPos,
|
|
54
|
-
endPos,
|
|
55
|
-
container,
|
|
56
|
-
// vscode-html-languageservice types does not contain this, despite it existing. Annoying
|
|
57
|
-
closed: matchedNode.closed,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function extractStyleTags(source, html) {
|
|
62
|
-
const styles = extractTags(source, 'style', html);
|
|
63
|
-
if (!styles.length) {
|
|
64
|
-
return [];
|
|
65
|
-
}
|
|
66
|
-
return styles;
|
|
67
|
-
}
|
|
68
|
-
exports.extractStyleTags = extractStyleTags;
|
|
69
|
-
function extractScriptTags(source, html) {
|
|
70
|
-
const scripts = extractTags(source, 'script', html);
|
|
71
|
-
if (!scripts.length) {
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
return scripts;
|
|
75
|
-
}
|
|
76
|
-
exports.extractScriptTags = extractScriptTags;
|
|
77
|
-
function parseAttributes(rawAttrs) {
|
|
78
|
-
const attrs = {};
|
|
79
|
-
if (!rawAttrs) {
|
|
80
|
-
return attrs;
|
|
81
|
-
}
|
|
82
|
-
Object.keys(rawAttrs).forEach((attrName) => {
|
|
83
|
-
const attrValue = rawAttrs[attrName];
|
|
84
|
-
attrs[attrName] = attrValue === null ? attrName : removeOuterQuotes(attrValue);
|
|
85
|
-
});
|
|
86
|
-
return attrs;
|
|
87
|
-
function removeOuterQuotes(attrValue) {
|
|
88
|
-
if ((attrValue.startsWith('"') && attrValue.endsWith('"')) ||
|
|
89
|
-
(attrValue.startsWith("'") && attrValue.endsWith("'"))) {
|
|
90
|
-
return attrValue.slice(1, attrValue.length - 1);
|
|
91
|
-
}
|
|
92
|
-
return attrValue;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function getLineAtPosition(position, text) {
|
|
96
|
-
return text.substring(offsetAt({ line: position.line, character: 0 }, text), offsetAt({ line: position.line, character: Number.MAX_VALUE }, text));
|
|
97
|
-
}
|
|
98
|
-
exports.getLineAtPosition = getLineAtPosition;
|
|
99
|
-
/**
|
|
100
|
-
* Return if a given offset is inside the start tag of a component
|
|
101
|
-
*/
|
|
102
|
-
function isInComponentStartTag(html, offset) {
|
|
103
|
-
const node = html.findNodeAt(offset);
|
|
104
|
-
return isPossibleComponent(node) && (!node.startTagEnd || offset < node.startTagEnd);
|
|
105
|
-
}
|
|
106
|
-
exports.isInComponentStartTag = isInComponentStartTag;
|
|
107
|
-
/**
|
|
108
|
-
* Return if a given offset is inside the name of a tag
|
|
109
|
-
*/
|
|
110
|
-
function isInTagName(html, offset) {
|
|
111
|
-
const node = html.findNodeAt(offset);
|
|
112
|
-
return offset > node.start && offset < node.start + (node.tag?.length ?? 0);
|
|
113
|
-
}
|
|
114
|
-
exports.isInTagName = isInTagName;
|
|
115
|
-
/**
|
|
116
|
-
* Return true if a specific node could be a component.
|
|
117
|
-
* 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
|
|
118
|
-
*/
|
|
119
|
-
function isPossibleComponent(node) {
|
|
120
|
-
return !!node.tag?.[0].match(/[A-Z]/) || !!node.tag?.match(/.+[.][A-Z]?/);
|
|
121
|
-
}
|
|
122
|
-
exports.isPossibleComponent = isPossibleComponent;
|
|
123
|
-
/**
|
|
124
|
-
* Return if the current position is in a specific tag
|
|
125
|
-
*/
|
|
126
|
-
function isInTag(position, tagInfo) {
|
|
127
|
-
return !!tagInfo && (0, utils_1.isInRange)(vscode_languageserver_1.Range.create(tagInfo.startPos, tagInfo.endPos), position);
|
|
128
|
-
}
|
|
129
|
-
exports.isInTag = isInTag;
|
|
130
|
-
/**
|
|
131
|
-
* Return if a given position is inside a JSX expression
|
|
132
|
-
*/
|
|
133
|
-
function isInsideExpression(html, tagStart, position) {
|
|
134
|
-
const charactersInNode = html.substring(tagStart, position);
|
|
135
|
-
return charactersInNode.lastIndexOf('{') > charactersInNode.lastIndexOf('}');
|
|
136
|
-
}
|
|
137
|
-
exports.isInsideExpression = isInsideExpression;
|
|
138
|
-
/**
|
|
139
|
-
* Returns if a given offset is inside of the document frontmatter
|
|
140
|
-
*/
|
|
141
|
-
function isInsideFrontmatter(text, offset) {
|
|
142
|
-
let start = text.slice(0, offset).trim().split('---').length;
|
|
143
|
-
let end = text.slice(offset).trim().split('---').length;
|
|
144
|
-
return start > 1 && start < 3 && end >= 1;
|
|
145
|
-
}
|
|
146
|
-
exports.isInsideFrontmatter = isInsideFrontmatter;
|
|
147
|
-
/**
|
|
148
|
-
* Get the line and character based on the offset
|
|
149
|
-
* @param offset The index of the position
|
|
150
|
-
* @param text The text for which the position should be retrived
|
|
151
|
-
* @param lineOffsets number Array with offsets for each line. Computed if not given
|
|
152
|
-
*/
|
|
153
|
-
function positionAt(offset, text, lineOffsets = getLineOffsets(text)) {
|
|
154
|
-
offset = (0, utils_1.clamp)(offset, 0, text.length);
|
|
155
|
-
let low = 0;
|
|
156
|
-
let high = lineOffsets.length;
|
|
157
|
-
if (high === 0) {
|
|
158
|
-
return vscode_languageserver_1.Position.create(0, offset);
|
|
159
|
-
}
|
|
160
|
-
while (low <= high) {
|
|
161
|
-
const mid = Math.floor((low + high) / 2);
|
|
162
|
-
const lineOffset = lineOffsets[mid];
|
|
163
|
-
if (lineOffset === offset) {
|
|
164
|
-
return vscode_languageserver_1.Position.create(mid, 0);
|
|
165
|
-
}
|
|
166
|
-
else if (offset > lineOffset) {
|
|
167
|
-
low = mid + 1;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
high = mid - 1;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// low is the least x for which the line offset is larger than the current offset
|
|
174
|
-
// or array.length if no line offset is larger than the current offset
|
|
175
|
-
const line = low - 1;
|
|
176
|
-
return vscode_languageserver_1.Position.create(line, offset - lineOffsets[line]);
|
|
177
|
-
}
|
|
178
|
-
exports.positionAt = positionAt;
|
|
179
|
-
/**
|
|
180
|
-
* Get the offset of the line and character position
|
|
181
|
-
* @param position Line and character position
|
|
182
|
-
* @param text The text for which the offset should be retrived
|
|
183
|
-
* @param lineOffsets number Array with offsets for each line. Computed if not given
|
|
184
|
-
*/
|
|
185
|
-
function offsetAt(position, text, lineOffsets = getLineOffsets(text)) {
|
|
186
|
-
if (position.line >= lineOffsets.length) {
|
|
187
|
-
return text.length;
|
|
188
|
-
}
|
|
189
|
-
else if (position.line < 0) {
|
|
190
|
-
return 0;
|
|
191
|
-
}
|
|
192
|
-
const lineOffset = lineOffsets[position.line];
|
|
193
|
-
const nextLineOffset = position.line + 1 < lineOffsets.length ? lineOffsets[position.line + 1] : text.length;
|
|
194
|
-
return (0, utils_1.clamp)(nextLineOffset, lineOffset, lineOffset + position.character);
|
|
195
|
-
}
|
|
196
|
-
exports.offsetAt = offsetAt;
|
|
197
|
-
function getLineOffsets(text) {
|
|
198
|
-
const lineOffsets = [];
|
|
199
|
-
let isLineStart = true;
|
|
200
|
-
for (let i = 0; i < text.length; i++) {
|
|
201
|
-
if (isLineStart) {
|
|
202
|
-
lineOffsets.push(i);
|
|
203
|
-
isLineStart = false;
|
|
204
|
-
}
|
|
205
|
-
const ch = text.charAt(i);
|
|
206
|
-
isLineStart = ch === '\r' || ch === '\n';
|
|
207
|
-
if (ch === '\r' && i + 1 < text.length && text.charAt(i + 1) === '\n') {
|
|
208
|
-
i++;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
if (isLineStart && text.length > 0) {
|
|
212
|
-
lineOffsets.push(text.length);
|
|
213
|
-
}
|
|
214
|
-
return lineOffsets;
|
|
215
|
-
}
|
|
216
|
-
exports.getLineOffsets = getLineOffsets;
|
|
217
|
-
/**
|
|
218
|
-
* Gets index of first-non-whitespace character.
|
|
219
|
-
*/
|
|
220
|
-
function getFirstNonWhitespaceIndex(str) {
|
|
221
|
-
return str.length - str.trimStart().length;
|
|
222
|
-
}
|
|
223
|
-
exports.getFirstNonWhitespaceIndex = getFirstNonWhitespaceIndex;
|
package/dist/node.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/node.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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, {
|
|
30
|
-
loadTypescript(options) {
|
|
31
|
-
if (options?.typescript?.serverPath) {
|
|
32
|
-
return require(options?.typescript?.serverPath);
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
loadTypescriptLocalized(options) {
|
|
36
|
-
if (options?.typescript?.localizedPath) {
|
|
37
|
-
try {
|
|
38
|
-
return require(options?.typescript?.localizedPath);
|
|
39
|
-
}
|
|
40
|
-
catch { }
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { CancellationToken, CodeAction, CodeActionContext, Color, ColorInformation, ColorPresentation, CompletionContext, CompletionItem, CompletionList, DefinitionLink, Diagnostic, FoldingRange, FormattingOptions, Hover, InlayHint, LinkedEditingRanges, Location, Position, Range, ReferenceContext, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, TextDocumentIdentifier, TextEdit, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
|
-
import type { DocumentManager } from '../core/documents/DocumentManager';
|
|
3
|
-
import type { AppCompletionItem, Plugin } from './interfaces';
|
|
4
|
-
export interface PluginHostConfig {
|
|
5
|
-
filterIncompleteCompletions: boolean;
|
|
6
|
-
definitionLinkSupport: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare class PluginHost {
|
|
9
|
-
private docManager;
|
|
10
|
-
private plugins;
|
|
11
|
-
private pluginHostConfig;
|
|
12
|
-
constructor(docManager: DocumentManager);
|
|
13
|
-
initialize(pluginHostConfig: PluginHostConfig): void;
|
|
14
|
-
registerPlugin(plugin: Plugin): void;
|
|
15
|
-
getCompletions(textDocument: TextDocumentIdentifier, position: Position, completionContext?: CompletionContext, cancellationToken?: CancellationToken): Promise<CompletionList>;
|
|
16
|
-
resolveCompletion(textDocument: TextDocumentIdentifier, completionItem: AppCompletionItem): Promise<CompletionItem>;
|
|
17
|
-
getDiagnostics(textDocument: TextDocumentIdentifier): Promise<Diagnostic[]>;
|
|
18
|
-
doHover(textDocument: TextDocumentIdentifier, position: Position): Promise<Hover | null>;
|
|
19
|
-
formatDocument(textDocument: TextDocumentIdentifier, options: FormattingOptions): Promise<TextEdit[]>;
|
|
20
|
-
getCodeActions(textDocument: TextDocumentIdentifier, range: Range, context: CodeActionContext, cancellationToken?: CancellationToken): Promise<CodeAction[]>;
|
|
21
|
-
doTagComplete(textDocument: TextDocumentIdentifier, position: Position): Promise<string | null>;
|
|
22
|
-
getFoldingRanges(textDocument: TextDocumentIdentifier): Promise<FoldingRange[] | null>;
|
|
23
|
-
getDocumentSymbols(textDocument: TextDocumentIdentifier, cancellationToken?: CancellationToken): Promise<SymbolInformation[]>;
|
|
24
|
-
getSemanticTokens(textDocument: TextDocumentIdentifier, range?: Range, cancellationToken?: CancellationToken): Promise<SemanticTokens | null>;
|
|
25
|
-
getLinkedEditingRanges(textDocument: TextDocumentIdentifier, position: Position): Promise<LinkedEditingRanges | null>;
|
|
26
|
-
fileReferences(textDocument: TextDocumentIdentifier): Promise<Location[] | null>;
|
|
27
|
-
getDefinitions(textDocument: TextDocumentIdentifier, position: Position): Promise<DefinitionLink[] | Location[]>;
|
|
28
|
-
getTypeDefinitions(textDocument: TextDocumentIdentifier, position: Position): Promise<Location[] | null>;
|
|
29
|
-
getImplementations(textDocument: TextDocumentIdentifier, position: Position): Promise<Location[] | null>;
|
|
30
|
-
getReferences(textdocument: TextDocumentIdentifier, position: Position, context: ReferenceContext): Promise<Location[] | null>;
|
|
31
|
-
prepareRename(textDocument: TextDocumentIdentifier, position: Position): Promise<Range | null>;
|
|
32
|
-
rename(textDocument: TextDocumentIdentifier, position: Position, newName: string): Promise<WorkspaceEdit | null>;
|
|
33
|
-
getDocumentColors(textDocument: TextDocumentIdentifier): Promise<ColorInformation[]>;
|
|
34
|
-
getColorPresentations(textDocument: TextDocumentIdentifier, range: Range, color: Color): Promise<ColorPresentation[]>;
|
|
35
|
-
getInlayHints(textDocument: TextDocumentIdentifier, range: Range, cancellationToken?: CancellationToken): Promise<InlayHint[]>;
|
|
36
|
-
getSignatureHelp(textDocument: TextDocumentIdentifier, position: Position, context: SignatureHelpContext | undefined, cancellationToken?: CancellationToken): Promise<SignatureHelp | null>;
|
|
37
|
-
onWatchFileChanges(onWatchFileChangesParams: any[]): Promise<void>;
|
|
38
|
-
updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[], text?: string): void;
|
|
39
|
-
private getDocument;
|
|
40
|
-
private execute;
|
|
41
|
-
private tryExecutePlugin;
|
|
42
|
-
}
|