@astrojs/language-server 1.0.4 → 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.
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 +37 -38
  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 -277
  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
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WritableDocument = exports.ReadableDocument = void 0;
4
- const utils_1 = require("./utils");
5
- /**
6
- * Represents a textual document.
7
- */
8
- class ReadableDocument {
9
- constructor() {
10
- /**
11
- * Current version of the document.
12
- */
13
- this.version = 0;
14
- }
15
- /**
16
- * Get the length of the document's content
17
- */
18
- getTextLength() {
19
- return this.getText().length;
20
- }
21
- /**
22
- * Get the line and character based on the offset
23
- * @param offset The index of the position
24
- */
25
- positionAt(offset) {
26
- return (0, utils_1.positionAt)(offset, this.getText(), this.getLineOffsets());
27
- }
28
- /**
29
- * Get the index of the line and character position
30
- * @param position Line and character position
31
- */
32
- offsetAt(position) {
33
- return (0, utils_1.offsetAt)(position, this.getText(), this.getLineOffsets());
34
- }
35
- getLineUntilOffset(offset) {
36
- const { line, character } = this.positionAt(offset);
37
- return this.lines[line].slice(0, character);
38
- }
39
- getLineOffsets() {
40
- if (!this.lineOffsets) {
41
- this.lineOffsets = (0, utils_1.getLineOffsets)(this.getText());
42
- }
43
- return this.lineOffsets;
44
- }
45
- /**
46
- * Implements TextDocument
47
- */
48
- get uri() {
49
- return this.getURL();
50
- }
51
- get lines() {
52
- return this.getText().split(/\r?\n/);
53
- }
54
- get lineCount() {
55
- return this.lines.length;
56
- }
57
- }
58
- exports.ReadableDocument = ReadableDocument;
59
- /**
60
- * Represents a textual document that can be manipulated.
61
- */
62
- class WritableDocument extends ReadableDocument {
63
- /**
64
- * Update the text between two positions.
65
- * @param text The new text slice
66
- * @param start Start offset of the new text
67
- * @param end End offset of the new text
68
- */
69
- update(text, start, end) {
70
- this.lineOffsets = undefined;
71
- const content = this.getText();
72
- this.setText(content.slice(0, start) + text + content.slice(end));
73
- }
74
- }
75
- exports.WritableDocument = WritableDocument;
@@ -1,23 +0,0 @@
1
- import type { TextDocumentContentChangeEvent, TextDocumentItem, VersionedTextDocumentIdentifier } from 'vscode-languageserver';
2
- import { AstroDocument } from './AstroDocument';
3
- export type DocumentEvent = 'documentOpen' | 'documentChange' | 'documentClose';
4
- export declare class DocumentManager {
5
- private createDocument?;
6
- private emitter;
7
- private openedInClient;
8
- private documents;
9
- private locked;
10
- private deleteCandidates;
11
- constructor(createDocument?: ((textDocument: Pick<TextDocumentItem, 'text' | 'uri'>) => AstroDocument) | undefined);
12
- openDocument(textDocument: Pick<TextDocumentItem, 'text' | 'uri'>): AstroDocument;
13
- lockDocument(uri: string): void;
14
- markAsOpenedInClient(uri: string): void;
15
- getAllOpenedByClient(): [string, AstroDocument][];
16
- releaseDocument(uri: string): void;
17
- closeDocument(uri: string): void;
18
- updateDocument(textDocument: VersionedTextDocumentIdentifier, changes: TextDocumentContentChangeEvent[]): void;
19
- on(name: DocumentEvent, listener: (document: AstroDocument) => void): void;
20
- get(uri: string): AstroDocument | undefined;
21
- private notify;
22
- static newInstance(): DocumentManager;
23
- }
@@ -1,100 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentManager = void 0;
4
- const events_1 = require("events");
5
- const utils_1 = require("../../utils");
6
- const AstroDocument_1 = require("./AstroDocument");
7
- class DocumentManager {
8
- constructor(createDocument) {
9
- this.createDocument = createDocument;
10
- this.emitter = new events_1.EventEmitter();
11
- this.openedInClient = new Set();
12
- this.documents = new Map();
13
- this.locked = new Set();
14
- this.deleteCandidates = new Set();
15
- if (!createDocument) {
16
- this.createDocument = (textDocument) => new AstroDocument_1.AstroDocument(textDocument.uri, textDocument.text);
17
- }
18
- }
19
- openDocument(textDocument) {
20
- textDocument = { ...textDocument, uri: (0, utils_1.normalizeUri)(textDocument.uri) };
21
- let document;
22
- if (this.documents.has(textDocument.uri)) {
23
- document = this.documents.get(textDocument.uri);
24
- document.setText(textDocument.text);
25
- }
26
- else {
27
- document = this.createDocument(textDocument);
28
- this.documents.set(textDocument.uri, document);
29
- this.notify('documentOpen', document);
30
- }
31
- this.notify('documentChange', document);
32
- return document;
33
- }
34
- lockDocument(uri) {
35
- this.locked.add((0, utils_1.normalizeUri)(uri));
36
- }
37
- markAsOpenedInClient(uri) {
38
- this.openedInClient.add((0, utils_1.normalizeUri)(uri));
39
- }
40
- getAllOpenedByClient() {
41
- return Array.from(this.documents.entries()).filter((doc) => this.openedInClient.has(doc[0]));
42
- }
43
- releaseDocument(uri) {
44
- uri = (0, utils_1.normalizeUri)(uri);
45
- this.locked.delete(uri);
46
- this.openedInClient.delete(uri);
47
- if (this.deleteCandidates.has(uri)) {
48
- this.deleteCandidates.delete(uri);
49
- this.closeDocument(uri);
50
- }
51
- }
52
- closeDocument(uri) {
53
- uri = (0, utils_1.normalizeUri)(uri);
54
- const document = this.documents.get(uri);
55
- if (!document) {
56
- throw new Error('Cannot call methods on an unopened document');
57
- }
58
- this.notify('documentClose', document);
59
- // Some plugin may prevent a document from actually being closed.
60
- if (!this.locked.has(uri)) {
61
- this.documents.delete(uri);
62
- }
63
- else {
64
- this.deleteCandidates.add(uri);
65
- }
66
- this.openedInClient.delete(uri);
67
- }
68
- updateDocument(textDocument, changes) {
69
- const document = this.documents.get((0, utils_1.normalizeUri)(textDocument.uri));
70
- if (!document) {
71
- throw new Error('Cannot call methods on an unopened document');
72
- }
73
- for (const change of changes) {
74
- let start = 0;
75
- let end = 0;
76
- if ('range' in change) {
77
- start = document.offsetAt(change.range.start);
78
- end = document.offsetAt(change.range.end);
79
- }
80
- else {
81
- end = document.getTextLength();
82
- }
83
- document.update(change.text, start, end);
84
- }
85
- this.notify('documentChange', document);
86
- }
87
- on(name, listener) {
88
- this.emitter.on(name, listener);
89
- }
90
- get(uri) {
91
- return this.documents.get((0, utils_1.normalizeUri)(uri));
92
- }
93
- notify(name, document) {
94
- this.emitter.emit(name, document);
95
- }
96
- static newInstance() {
97
- return new DocumentManager(({ uri, text }) => new AstroDocument_1.AstroDocument(uri, text));
98
- }
99
- }
100
- exports.DocumentManager = DocumentManager;
@@ -1,94 +0,0 @@
1
- import { TraceMap } from '@jridgewell/trace-mapping';
2
- import type ts from 'typescript';
3
- import { CodeAction, ColorPresentation, CompletionItem, Diagnostic, FoldingRange, Hover, InsertReplaceEdit, LocationLink, Position, Range, SelectionRange, SymbolInformation, TextDocumentEdit, TextEdit } from 'vscode-languageserver';
4
- import { DocumentSnapshot, ScriptTagDocumentSnapshot } from '../../plugins/typescript/snapshots/DocumentSnapshot';
5
- import { TagInformation } from './utils';
6
- export interface DocumentMapper {
7
- /**
8
- * Map the generated position to the original position
9
- * @param generatedPosition Position in fragment
10
- */
11
- getOriginalPosition(generatedPosition: Position): Position;
12
- /**
13
- * Map the original position to the generated position
14
- * @param originalPosition Position in parent
15
- */
16
- getGeneratedPosition(originalPosition: Position): Position;
17
- /**
18
- * Returns true if the given original position is inside of the generated map
19
- * @param pos Position in original
20
- */
21
- isInGenerated(pos: Position): boolean;
22
- /**
23
- * Get document URL
24
- */
25
- getURL(): string;
26
- /**
27
- * Implement this if you need teardown logic before this mapper gets cleaned up.
28
- */
29
- destroy?(): void;
30
- }
31
- /**
32
- * Does not map, returns positions as is.
33
- */
34
- export declare class IdentityMapper implements DocumentMapper {
35
- private url;
36
- private parent?;
37
- constructor(url: string, parent?: DocumentMapper | undefined);
38
- getOriginalPosition(generatedPosition: Position): Position;
39
- getGeneratedPosition(originalPosition: Position): Position;
40
- isInGenerated(position: Position): boolean;
41
- getURL(): string;
42
- destroy(): void;
43
- }
44
- /**
45
- * Maps positions in a fragment relative to a parent.
46
- */
47
- export declare class FragmentMapper implements DocumentMapper {
48
- private originalText;
49
- private tagInfo;
50
- private url;
51
- private lineOffsetsOriginal;
52
- private lineOffsetsGenerated;
53
- constructor(originalText: string, tagInfo: TagInformation, url: string);
54
- getOriginalPosition(generatedPosition: Position): Position;
55
- private offsetInParent;
56
- getGeneratedPosition(originalPosition: Position): Position;
57
- isInGenerated(pos: Position): boolean;
58
- getURL(): string;
59
- }
60
- export declare class SourceMapDocumentMapper implements DocumentMapper {
61
- protected traceMap: TraceMap;
62
- protected sourceUri: string;
63
- private parent?;
64
- constructor(traceMap: TraceMap, sourceUri: string, parent?: DocumentMapper | undefined);
65
- getOriginalPosition(generatedPosition: Position): Position;
66
- getGeneratedPosition(originalPosition: Position): Position;
67
- isInGenerated(position: Position): boolean;
68
- getURL(): string;
69
- }
70
- export declare class ConsumerDocumentMapper extends SourceMapDocumentMapper {
71
- private nrPrependesLines;
72
- constructor(traceMap: TraceMap, sourceUri: string, nrPrependesLines: number);
73
- getOriginalPosition(generatedPosition: Position): Position;
74
- getGeneratedPosition(originalPosition: Position): Position;
75
- isInGenerated(): boolean;
76
- }
77
- export declare function mapRangeToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, range: Range): Range;
78
- export declare function mapRangeToGenerated(fragment: DocumentMapper, range: Range): Range;
79
- export declare function mapCompletionItemToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, item: CompletionItem): CompletionItem;
80
- export declare function mapHoverToParent(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, hover: Hover): Hover;
81
- export declare function mapObjWithRangeToOriginal<T extends {
82
- range: Range;
83
- }>(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, objWithRange: T): T;
84
- export declare function mapInsertReplaceEditToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, edit: InsertReplaceEdit): InsertReplaceEdit;
85
- export declare function mapEditToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, edit: TextEdit | InsertReplaceEdit): TextEdit | InsertReplaceEdit;
86
- export declare function mapDiagnosticToGenerated(fragment: DocumentMapper, diagnostic: Diagnostic): Diagnostic;
87
- export declare function mapColorPresentationToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, presentation: ColorPresentation): ColorPresentation;
88
- export declare function mapSymbolInformationToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, info: SymbolInformation): SymbolInformation;
89
- export declare function mapLocationLinkToOriginal(fragment: DocumentMapper, def: LocationLink): LocationLink;
90
- export declare function mapTextDocumentEditToOriginal(fragment: DocumentMapper, edit: TextDocumentEdit): TextDocumentEdit;
91
- export declare function mapCodeActionToOriginal(fragment: DocumentMapper, codeAction: CodeAction): CodeAction;
92
- export declare function mapScriptSpanStartToSnapshot(span: ts.TextSpan, scriptTagSnapshot: ScriptTagDocumentSnapshot, tsSnapshot: DocumentSnapshot): number;
93
- export declare function mapFoldingRangeToParent(fragment: DocumentMapper, foldingRange: FoldingRange): FoldingRange;
94
- export declare function mapSelectionRangeToParent(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, selectionRange: SelectionRange): SelectionRange;
@@ -1,264 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapSelectionRangeToParent = exports.mapFoldingRangeToParent = exports.mapScriptSpanStartToSnapshot = exports.mapCodeActionToOriginal = exports.mapTextDocumentEditToOriginal = exports.mapLocationLinkToOriginal = exports.mapSymbolInformationToOriginal = exports.mapColorPresentationToOriginal = exports.mapDiagnosticToGenerated = exports.mapEditToOriginal = exports.mapInsertReplaceEditToOriginal = exports.mapObjWithRangeToOriginal = exports.mapHoverToParent = exports.mapCompletionItemToOriginal = exports.mapRangeToGenerated = exports.mapRangeToOriginal = exports.ConsumerDocumentMapper = exports.SourceMapDocumentMapper = exports.FragmentMapper = exports.IdentityMapper = void 0;
4
- const trace_mapping_1 = require("@jridgewell/trace-mapping");
5
- const vscode_languageserver_1 = require("vscode-languageserver");
6
- const utils_1 = require("./utils");
7
- /**
8
- * Does not map, returns positions as is.
9
- */
10
- class IdentityMapper {
11
- constructor(url, parent) {
12
- this.url = url;
13
- this.parent = parent;
14
- }
15
- getOriginalPosition(generatedPosition) {
16
- if (this.parent) {
17
- generatedPosition = this.getOriginalPosition(generatedPosition);
18
- }
19
- return generatedPosition;
20
- }
21
- getGeneratedPosition(originalPosition) {
22
- if (this.parent) {
23
- originalPosition = this.getGeneratedPosition(originalPosition);
24
- }
25
- return originalPosition;
26
- }
27
- isInGenerated(position) {
28
- if (this.parent && !this.parent.isInGenerated(position)) {
29
- return false;
30
- }
31
- return true;
32
- }
33
- getURL() {
34
- return this.url;
35
- }
36
- destroy() {
37
- this.parent?.destroy?.();
38
- }
39
- }
40
- exports.IdentityMapper = IdentityMapper;
41
- /**
42
- * Maps positions in a fragment relative to a parent.
43
- */
44
- class FragmentMapper {
45
- constructor(originalText, tagInfo, url) {
46
- this.originalText = originalText;
47
- this.tagInfo = tagInfo;
48
- this.url = url;
49
- this.lineOffsetsOriginal = (0, utils_1.getLineOffsets)(this.originalText);
50
- this.lineOffsetsGenerated = (0, utils_1.getLineOffsets)(this.tagInfo.content);
51
- }
52
- getOriginalPosition(generatedPosition) {
53
- const parentOffset = this.offsetInParent((0, utils_1.offsetAt)(generatedPosition, this.tagInfo.content, this.lineOffsetsGenerated));
54
- return (0, utils_1.positionAt)(parentOffset, this.originalText, this.lineOffsetsOriginal);
55
- }
56
- offsetInParent(offset) {
57
- return this.tagInfo.start + offset;
58
- }
59
- getGeneratedPosition(originalPosition) {
60
- const fragmentOffset = (0, utils_1.offsetAt)(originalPosition, this.originalText, this.lineOffsetsOriginal) - this.tagInfo.start;
61
- return (0, utils_1.positionAt)(fragmentOffset, this.tagInfo.content, this.lineOffsetsGenerated);
62
- }
63
- isInGenerated(pos) {
64
- const offset = (0, utils_1.offsetAt)(pos, this.originalText, this.lineOffsetsOriginal);
65
- return offset >= this.tagInfo.start && offset <= this.tagInfo.end;
66
- }
67
- getURL() {
68
- return this.url;
69
- }
70
- }
71
- exports.FragmentMapper = FragmentMapper;
72
- class SourceMapDocumentMapper {
73
- constructor(traceMap, sourceUri, parent) {
74
- this.traceMap = traceMap;
75
- this.sourceUri = sourceUri;
76
- this.parent = parent;
77
- }
78
- getOriginalPosition(generatedPosition) {
79
- if (this.parent) {
80
- generatedPosition = this.parent.getOriginalPosition(generatedPosition);
81
- }
82
- if (generatedPosition.line < 0) {
83
- return { line: -1, character: -1 };
84
- }
85
- const mapped = (0, trace_mapping_1.originalPositionFor)(this.traceMap, {
86
- line: generatedPosition.line + 1,
87
- column: generatedPosition.character,
88
- });
89
- if (!mapped) {
90
- return { line: -1, character: -1 };
91
- }
92
- if (mapped.line === 0) {
93
- // eslint-disable-next-line no-console
94
- console.log('Got 0 mapped line from', generatedPosition, 'col was', mapped.column);
95
- }
96
- return {
97
- line: (mapped.line || 0) - 1,
98
- character: mapped.column || 0,
99
- };
100
- }
101
- getGeneratedPosition(originalPosition) {
102
- if (this.parent) {
103
- originalPosition = this.parent.getGeneratedPosition(originalPosition);
104
- }
105
- const mapped = (0, trace_mapping_1.generatedPositionFor)(this.traceMap, {
106
- line: originalPosition.line + 1,
107
- column: originalPosition.character,
108
- source: this.sourceUri,
109
- });
110
- if (!mapped) {
111
- return { line: -1, character: -1 };
112
- }
113
- const result = {
114
- line: (mapped.line || 0) - 1,
115
- character: mapped.column || 0,
116
- };
117
- if (result.line < 0) {
118
- return result;
119
- }
120
- return result;
121
- }
122
- isInGenerated(position) {
123
- if (this.parent && !this.isInGenerated(position)) {
124
- return false;
125
- }
126
- const generated = this.getGeneratedPosition(position);
127
- return generated.line >= 0;
128
- }
129
- getURL() {
130
- return this.sourceUri;
131
- }
132
- }
133
- exports.SourceMapDocumentMapper = SourceMapDocumentMapper;
134
- class ConsumerDocumentMapper extends SourceMapDocumentMapper {
135
- constructor(traceMap, sourceUri, nrPrependesLines) {
136
- super(traceMap, sourceUri);
137
- this.nrPrependesLines = nrPrependesLines;
138
- }
139
- getOriginalPosition(generatedPosition) {
140
- return super.getOriginalPosition(vscode_languageserver_1.Position.create(generatedPosition.line - this.nrPrependesLines, generatedPosition.character));
141
- }
142
- getGeneratedPosition(originalPosition) {
143
- const result = super.getGeneratedPosition(originalPosition);
144
- result.line += this.nrPrependesLines;
145
- return result;
146
- }
147
- isInGenerated() {
148
- // always return true and map outliers case by case
149
- return true;
150
- }
151
- }
152
- exports.ConsumerDocumentMapper = ConsumerDocumentMapper;
153
- function mapRangeToOriginal(fragment, range) {
154
- // DON'T use Range.create here! Positions might not be mapped
155
- // and therefore return negative numbers, which makes Range.create throw.
156
- // These invalid position need to be handled
157
- // on a case-by-case basis in the calling functions.
158
- const originalRange = {
159
- start: fragment.getOriginalPosition(range.start),
160
- end: fragment.getOriginalPosition(range.end),
161
- };
162
- // Range may be mapped one character short - reverse that for "in the same line" cases
163
- if (originalRange.start.line === originalRange.end.line &&
164
- range.start.line === range.end.line &&
165
- originalRange.end.character - originalRange.start.character === range.end.character - range.start.character - 1) {
166
- originalRange.end.character += 1;
167
- }
168
- return originalRange;
169
- }
170
- exports.mapRangeToOriginal = mapRangeToOriginal;
171
- function mapRangeToGenerated(fragment, range) {
172
- return vscode_languageserver_1.Range.create(fragment.getGeneratedPosition(range.start), fragment.getGeneratedPosition(range.end));
173
- }
174
- exports.mapRangeToGenerated = mapRangeToGenerated;
175
- function mapCompletionItemToOriginal(fragment, item) {
176
- if (!item.textEdit) {
177
- return item;
178
- }
179
- return {
180
- ...item,
181
- textEdit: mapEditToOriginal(fragment, item.textEdit),
182
- };
183
- }
184
- exports.mapCompletionItemToOriginal = mapCompletionItemToOriginal;
185
- function mapHoverToParent(fragment, hover) {
186
- if (!hover.range) {
187
- return hover;
188
- }
189
- return { ...hover, range: mapRangeToOriginal(fragment, hover.range) };
190
- }
191
- exports.mapHoverToParent = mapHoverToParent;
192
- function mapObjWithRangeToOriginal(fragment, objWithRange) {
193
- return { ...objWithRange, range: mapRangeToOriginal(fragment, objWithRange.range) };
194
- }
195
- exports.mapObjWithRangeToOriginal = mapObjWithRangeToOriginal;
196
- function mapInsertReplaceEditToOriginal(fragment, edit) {
197
- return {
198
- ...edit,
199
- insert: mapRangeToOriginal(fragment, edit.insert),
200
- replace: mapRangeToOriginal(fragment, edit.replace),
201
- };
202
- }
203
- exports.mapInsertReplaceEditToOriginal = mapInsertReplaceEditToOriginal;
204
- function mapEditToOriginal(fragment, edit) {
205
- return vscode_languageserver_1.TextEdit.is(edit) ? mapObjWithRangeToOriginal(fragment, edit) : mapInsertReplaceEditToOriginal(fragment, edit);
206
- }
207
- exports.mapEditToOriginal = mapEditToOriginal;
208
- function mapDiagnosticToGenerated(fragment, diagnostic) {
209
- return { ...diagnostic, range: mapRangeToGenerated(fragment, diagnostic.range) };
210
- }
211
- exports.mapDiagnosticToGenerated = mapDiagnosticToGenerated;
212
- function mapColorPresentationToOriginal(fragment, presentation) {
213
- const item = {
214
- ...presentation,
215
- };
216
- if (item.textEdit) {
217
- item.textEdit = mapObjWithRangeToOriginal(fragment, item.textEdit);
218
- }
219
- if (item.additionalTextEdits) {
220
- item.additionalTextEdits = item.additionalTextEdits.map((edit) => mapObjWithRangeToOriginal(fragment, edit));
221
- }
222
- return item;
223
- }
224
- exports.mapColorPresentationToOriginal = mapColorPresentationToOriginal;
225
- function mapSymbolInformationToOriginal(fragment, info) {
226
- return { ...info, location: mapObjWithRangeToOriginal(fragment, info.location) };
227
- }
228
- exports.mapSymbolInformationToOriginal = mapSymbolInformationToOriginal;
229
- function mapLocationLinkToOriginal(fragment, def) {
230
- return vscode_languageserver_1.LocationLink.create(def.targetUri, fragment.getURL() === def.targetUri ? mapRangeToOriginal(fragment, def.targetRange) : def.targetRange, fragment.getURL() === def.targetUri
231
- ? mapRangeToOriginal(fragment, def.targetSelectionRange)
232
- : def.targetSelectionRange, def.originSelectionRange ? mapRangeToOriginal(fragment, def.originSelectionRange) : undefined);
233
- }
234
- exports.mapLocationLinkToOriginal = mapLocationLinkToOriginal;
235
- function mapTextDocumentEditToOriginal(fragment, edit) {
236
- if (edit.textDocument.uri !== fragment.getURL()) {
237
- return edit;
238
- }
239
- return vscode_languageserver_1.TextDocumentEdit.create(edit.textDocument, edit.edits.map((textEdit) => mapObjWithRangeToOriginal(fragment, textEdit)));
240
- }
241
- exports.mapTextDocumentEditToOriginal = mapTextDocumentEditToOriginal;
242
- function mapCodeActionToOriginal(fragment, codeAction) {
243
- return vscode_languageserver_1.CodeAction.create(codeAction.title, {
244
- documentChanges: codeAction.edit.documentChanges.map((edit) => mapTextDocumentEditToOriginal(fragment, edit)),
245
- }, codeAction.kind);
246
- }
247
- exports.mapCodeActionToOriginal = mapCodeActionToOriginal;
248
- function mapScriptSpanStartToSnapshot(span, scriptTagSnapshot, tsSnapshot) {
249
- const originalPosition = scriptTagSnapshot.getOriginalPosition(scriptTagSnapshot.positionAt(span.start));
250
- return tsSnapshot.offsetAt(tsSnapshot.getGeneratedPosition(originalPosition));
251
- }
252
- exports.mapScriptSpanStartToSnapshot = mapScriptSpanStartToSnapshot;
253
- function mapFoldingRangeToParent(fragment, foldingRange) {
254
- // Despite FoldingRange asking for a start and end line and a start and end character, FoldingRanges
255
- // don't use the Range type, instead asking for 4 number. Not sure why, but it's not convenient
256
- const range = mapRangeToOriginal(fragment, vscode_languageserver_1.Range.create(foldingRange.startLine, foldingRange.startCharacter || 0, foldingRange.endLine, foldingRange.endCharacter || 0));
257
- return vscode_languageserver_1.FoldingRange.create(range.start.line, range.end.line, foldingRange.startCharacter ? range.start.character : undefined, foldingRange.endCharacter ? range.end.character : undefined, foldingRange.kind);
258
- }
259
- exports.mapFoldingRangeToParent = mapFoldingRangeToParent;
260
- function mapSelectionRangeToParent(fragment, selectionRange) {
261
- const { range, parent } = selectionRange;
262
- return vscode_languageserver_1.SelectionRange.create(mapRangeToOriginal(fragment, range), parent && mapSelectionRangeToParent(fragment, parent));
263
- }
264
- exports.mapSelectionRangeToParent = mapSelectionRangeToParent;
@@ -1,5 +0,0 @@
1
- export * from './AstroDocument';
2
- export * from './DocumentBase';
3
- export * from './DocumentManager';
4
- export * from './DocumentMapper';
5
- export * from './utils';
@@ -1,21 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./AstroDocument"), exports);
18
- __exportStar(require("./DocumentBase"), exports);
19
- __exportStar(require("./DocumentManager"), exports);
20
- __exportStar(require("./DocumentMapper"), exports);
21
- __exportStar(require("./utils"), exports);
@@ -1,15 +0,0 @@
1
- interface Frontmatter {
2
- state: null | 'open' | 'closed';
3
- startOffset: null | number;
4
- endOffset: null | number;
5
- }
6
- interface Content {
7
- firstNonWhitespaceOffset: null | number;
8
- }
9
- export interface AstroMetadata {
10
- frontmatter: Frontmatter;
11
- content: Content;
12
- }
13
- /** Parses a document to collect metadata about Astro features */
14
- export declare function parseAstro(content: string): AstroMetadata;
15
- export {};
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseAstro = void 0;
4
- const utils_1 = require("./utils");
5
- /** Parses a document to collect metadata about Astro features */
6
- function parseAstro(content) {
7
- const frontmatter = getFrontmatter(content);
8
- return {
9
- frontmatter,
10
- content: getContent(content, frontmatter),
11
- };
12
- }
13
- exports.parseAstro = parseAstro;
14
- /** Get frontmatter metadata */
15
- function getFrontmatter(content) {
16
- /** Quickly check how many `---` blocks are in the document */
17
- function getFrontmatterState() {
18
- const parts = content.trim().split('---').length;
19
- switch (parts) {
20
- case 1:
21
- return null;
22
- case 2:
23
- return 'open';
24
- default:
25
- return 'closed';
26
- }
27
- }
28
- const state = getFrontmatterState();
29
- /** Construct a range containing the document's frontmatter */
30
- function getFrontmatterOffsets() {
31
- const startOffset = content.indexOf('---');
32
- if (startOffset === -1)
33
- return [null, null];
34
- const endOffset = content.slice(startOffset + 3).indexOf('---') + 3;
35
- if (endOffset === -1)
36
- return [startOffset, null];
37
- return [startOffset, endOffset];
38
- }
39
- const [startOffset, endOffset] = getFrontmatterOffsets();
40
- return {
41
- state,
42
- startOffset,
43
- endOffset,
44
- };
45
- }
46
- /** Get content metadata */
47
- function getContent(content, frontmatter) {
48
- switch (frontmatter.state) {
49
- case null: {
50
- const offset = (0, utils_1.getFirstNonWhitespaceIndex)(content);
51
- return { firstNonWhitespaceOffset: offset === -1 ? null : offset };
52
- }
53
- case 'open': {
54
- return { firstNonWhitespaceOffset: null };
55
- }
56
- case 'closed': {
57
- const { endOffset } = frontmatter;
58
- const end = (endOffset ?? 0) + 3;
59
- const offset = (0, utils_1.getFirstNonWhitespaceIndex)(content.slice(end));
60
- return { firstNonWhitespaceOffset: end + offset };
61
- }
62
- }
63
- }
@@ -1,13 +0,0 @@
1
- import { HTMLDocument, Position } from 'vscode-html-languageservice';
2
- import type { AstroDocument } from './AstroDocument';
3
- import { AstroMetadata } from './parseAstro';
4
- /**
5
- * Parses text as HTML
6
- */
7
- export declare function parseHtml(text: string, frontmatter: AstroMetadata): HTMLDocument;
8
- export interface AttributeContext {
9
- name: string;
10
- inValue: boolean;
11
- valueRange?: [number, number];
12
- }
13
- export declare function getAttributeContextAtPosition(document: AstroDocument, position: Position): AttributeContext | null;