@astrojs/language-server 0.11.0 → 0.13.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/CHANGELOG.md +23 -0
- package/bin/browserServer.js +3 -0
- package/bin/nodeServer.js +3 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +8 -0
- package/dist/check.js +2 -5
- package/dist/core/DiagnosticsManager.d.ts +3 -3
- package/dist/core/DiagnosticsManager.js +2 -2
- package/dist/core/config/ConfigManager.d.ts +19 -164
- package/dist/core/config/ConfigManager.js +62 -101
- package/dist/core/config/index.d.ts +1 -0
- package/dist/core/config/index.js +1 -0
- package/dist/core/config/interfaces.d.ts +123 -0
- package/dist/core/config/interfaces.js +2 -0
- package/dist/core/documents/AstroDocument.d.ts +18 -0
- package/dist/core/documents/AstroDocument.js +42 -0
- package/dist/core/documents/DocumentBase.d.ts +10 -2
- package/dist/core/documents/DocumentBase.js +15 -50
- package/dist/core/documents/DocumentManager.d.ts +12 -16
- package/dist/core/documents/DocumentManager.js +32 -26
- package/dist/core/documents/DocumentMapper.js +3 -1
- package/dist/core/documents/index.d.ts +1 -1
- package/dist/core/documents/index.js +1 -1
- package/dist/core/documents/parseAstro.d.ts +2 -2
- package/dist/core/documents/parseHtml.d.ts +2 -2
- package/dist/core/documents/parseHtml.js +4 -1
- package/dist/core/documents/utils.d.ts +22 -26
- package/dist/core/documents/utils.js +96 -134
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -3
- package/dist/node.d.ts +1 -0
- package/dist/node.js +29 -0
- package/dist/plugins/PluginHost.d.ts +11 -9
- package/dist/plugins/PluginHost.js +34 -36
- package/dist/plugins/astro/AstroPlugin.d.ts +11 -12
- package/dist/plugins/astro/AstroPlugin.js +17 -42
- package/dist/plugins/astro/features/{CompletionProvider.d.ts → CompletionsProvider.d.ts} +5 -5
- package/dist/plugins/astro/features/{CompletionProvider.js → CompletionsProvider.js} +33 -58
- package/dist/plugins/css/CSSDocument.d.ts +3 -3
- package/dist/plugins/css/CSSDocument.js +7 -16
- package/dist/plugins/css/CSSPlugin.d.ts +31 -12
- package/dist/plugins/css/CSSPlugin.js +174 -41
- package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
- package/dist/plugins/css/StyleAttributeDocument.js +2 -2
- package/dist/plugins/css/features/astro-selectors.d.ts +2 -0
- package/dist/plugins/css/features/astro-selectors.js +16 -0
- package/dist/plugins/css/features/{getIdClassCompletion.d.ts → getIdClassCompletions.d.ts} +3 -3
- package/dist/plugins/css/features/{getIdClassCompletion.js → getIdClassCompletions.js} +10 -9
- package/dist/plugins/css/{service.d.ts → language-service.d.ts} +0 -0
- package/dist/plugins/css/{service.js → language-service.js} +2 -1
- package/dist/plugins/html/HTMLPlugin.d.ts +18 -17
- package/dist/plugins/html/HTMLPlugin.js +69 -41
- package/dist/plugins/html/features/astro-attributes.d.ts +2 -0
- package/dist/plugins/html/features/astro-attributes.js +126 -0
- package/dist/plugins/index.d.ts +2 -2
- package/dist/plugins/index.js +2 -2
- package/dist/plugins/interfaces.d.ts +35 -48
- package/dist/plugins/typescript/LanguageServiceManager.d.ts +33 -14
- package/dist/plugins/typescript/LanguageServiceManager.js +57 -32
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +18 -23
- package/dist/plugins/typescript/TypeScriptPlugin.js +58 -55
- package/dist/plugins/typescript/astro-sys.d.ts +5 -3
- package/dist/plugins/typescript/astro-sys.js +24 -45
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +6 -6
- package/dist/plugins/typescript/features/CompletionsProvider.js +18 -38
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +4 -4
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +27 -87
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +10 -0
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +69 -0
- package/dist/plugins/typescript/features/HoverProvider.d.ts +4 -5
- package/dist/plugins/typescript/features/HoverProvider.js +9 -10
- package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +4 -5
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +15 -11
- package/dist/plugins/typescript/features/utils.d.ts +1 -12
- package/dist/plugins/typescript/features/utils.js +2 -22
- package/dist/plugins/typescript/language-service.d.ts +38 -0
- package/dist/plugins/typescript/language-service.js +230 -0
- package/dist/plugins/typescript/module-loader.d.ts +5 -8
- package/dist/plugins/typescript/module-loader.js +43 -23
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +90 -0
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +135 -0
- package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +42 -0
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +197 -0
- package/dist/plugins/typescript/snapshots/utils.d.ts +28 -0
- package/dist/plugins/typescript/snapshots/utils.js +84 -0
- package/dist/plugins/typescript/utils.d.ts +10 -13
- package/dist/plugins/typescript/utils.js +154 -158
- package/dist/server.d.ts +2 -4
- package/dist/server.js +93 -54
- package/dist/utils.d.ts +20 -16
- package/dist/utils.js +35 -24
- package/package.json +18 -12
- package/types/astro-jsx.d.ts +1077 -0
- package/bin/server.js +0 -7
- package/dist/core/documents/Document.d.ts +0 -51
- package/dist/core/documents/Document.js +0 -135
- package/dist/plugins/typescript/DocumentSnapshot.d.ts +0 -99
- package/dist/plugins/typescript/DocumentSnapshot.js +0 -259
- package/dist/plugins/typescript/SnapshotManager.d.ts +0 -24
- package/dist/plugins/typescript/SnapshotManager.js +0 -103
- package/dist/plugins/typescript/languageService.d.ts +0 -17
- package/dist/plugins/typescript/languageService.js +0 -173
- package/types/index.d.ts +0 -4
package/bin/server.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { TagInformation } from './utils';
|
|
2
|
-
import { Position } from 'vscode-languageserver';
|
|
3
|
-
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
|
-
import { HTMLDocument } from 'vscode-html-languageservice';
|
|
5
|
-
import { AstroDocument } from './parseAstro';
|
|
6
|
-
export declare class Document implements TextDocument {
|
|
7
|
-
uri: string;
|
|
8
|
-
private content;
|
|
9
|
-
languageId: string;
|
|
10
|
-
version: number;
|
|
11
|
-
html: HTMLDocument;
|
|
12
|
-
astro: AstroDocument;
|
|
13
|
-
styleInfo: TagInformation | null;
|
|
14
|
-
constructor(uri: string, text: string);
|
|
15
|
-
private updateDocInfo;
|
|
16
|
-
setText(text: string): void;
|
|
17
|
-
/**
|
|
18
|
-
* Update the text between two positions.
|
|
19
|
-
* @param text The new text slice
|
|
20
|
-
* @param start Start offset of the new text
|
|
21
|
-
* @param end End offset of the new text
|
|
22
|
-
*/
|
|
23
|
-
update(text: string, start: number, end: number): void;
|
|
24
|
-
getText(): string;
|
|
25
|
-
/**
|
|
26
|
-
* Get the line and character based on the offset
|
|
27
|
-
* @param offset The index of the position
|
|
28
|
-
*/
|
|
29
|
-
positionAt(offset: number): Position;
|
|
30
|
-
/**
|
|
31
|
-
* Get the index of the line and character position
|
|
32
|
-
* @param position Line and character position
|
|
33
|
-
*/
|
|
34
|
-
offsetAt(position: Position): number;
|
|
35
|
-
getLineUntilOffset(offset: number): string;
|
|
36
|
-
private getLineOffsets;
|
|
37
|
-
/**
|
|
38
|
-
* Get the length of the document's content
|
|
39
|
-
*/
|
|
40
|
-
getTextLength(): number;
|
|
41
|
-
/**
|
|
42
|
-
* Returns the file path if the url scheme is file
|
|
43
|
-
*/
|
|
44
|
-
getFilePath(): string | null;
|
|
45
|
-
/**
|
|
46
|
-
* Get URL file path.
|
|
47
|
-
*/
|
|
48
|
-
getURL(): string;
|
|
49
|
-
get lines(): string[];
|
|
50
|
-
get lineCount(): number;
|
|
51
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Document = void 0;
|
|
4
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
5
|
-
const utils_1 = require("../../utils");
|
|
6
|
-
const parseHtml_1 = require("./parseHtml");
|
|
7
|
-
const parseAstro_1 = require("./parseAstro");
|
|
8
|
-
const utils_2 = require("./utils");
|
|
9
|
-
class Document {
|
|
10
|
-
constructor(uri, text) {
|
|
11
|
-
this.uri = uri;
|
|
12
|
-
this.languageId = 'astro';
|
|
13
|
-
this.version = 0;
|
|
14
|
-
this.styleInfo = null;
|
|
15
|
-
this.content = text;
|
|
16
|
-
this.updateDocInfo();
|
|
17
|
-
}
|
|
18
|
-
updateDocInfo() {
|
|
19
|
-
this.html = (0, parseHtml_1.parseHtml)(this.content);
|
|
20
|
-
this.astro = (0, parseAstro_1.parseAstro)(this.content);
|
|
21
|
-
this.styleInfo = (0, utils_2.extractStyleTag)(this.content, this.html);
|
|
22
|
-
if (this.styleInfo) {
|
|
23
|
-
this.styleInfo.attributes.lang = 'css';
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
setText(text) {
|
|
27
|
-
this.content = text;
|
|
28
|
-
this.version++;
|
|
29
|
-
this.updateDocInfo();
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Update the text between two positions.
|
|
33
|
-
* @param text The new text slice
|
|
34
|
-
* @param start Start offset of the new text
|
|
35
|
-
* @param end End offset of the new text
|
|
36
|
-
*/
|
|
37
|
-
update(text, start, end) {
|
|
38
|
-
const content = this.getText();
|
|
39
|
-
this.setText(content.slice(0, start) + text + content.slice(end));
|
|
40
|
-
}
|
|
41
|
-
getText() {
|
|
42
|
-
return this.content;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Get the line and character based on the offset
|
|
46
|
-
* @param offset The index of the position
|
|
47
|
-
*/
|
|
48
|
-
positionAt(offset) {
|
|
49
|
-
offset = (0, utils_1.clamp)(offset, 0, this.getTextLength());
|
|
50
|
-
const lineOffsets = this.getLineOffsets();
|
|
51
|
-
let low = 0;
|
|
52
|
-
let high = lineOffsets.length;
|
|
53
|
-
if (high === 0) {
|
|
54
|
-
return vscode_languageserver_1.Position.create(0, offset);
|
|
55
|
-
}
|
|
56
|
-
while (low < high) {
|
|
57
|
-
const mid = Math.floor((low + high) / 2);
|
|
58
|
-
if (lineOffsets[mid] > offset) {
|
|
59
|
-
high = mid;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
low = mid + 1;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// low is the least x for which the line offset is larger than the current offset
|
|
66
|
-
// or array.length if no line offset is larger than the current offset
|
|
67
|
-
const line = low - 1;
|
|
68
|
-
return vscode_languageserver_1.Position.create(line, offset - lineOffsets[line]);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Get the index of the line and character position
|
|
72
|
-
* @param position Line and character position
|
|
73
|
-
*/
|
|
74
|
-
offsetAt(position) {
|
|
75
|
-
const lineOffsets = this.getLineOffsets();
|
|
76
|
-
if (position.line >= lineOffsets.length) {
|
|
77
|
-
return this.getTextLength();
|
|
78
|
-
}
|
|
79
|
-
else if (position.line < 0) {
|
|
80
|
-
return 0;
|
|
81
|
-
}
|
|
82
|
-
const lineOffset = lineOffsets[position.line];
|
|
83
|
-
const nextLineOffset = position.line + 1 < lineOffsets.length ? lineOffsets[position.line + 1] : this.getTextLength();
|
|
84
|
-
return (0, utils_1.clamp)(nextLineOffset, lineOffset, lineOffset + position.character);
|
|
85
|
-
}
|
|
86
|
-
getLineUntilOffset(offset) {
|
|
87
|
-
const { line, character } = this.positionAt(offset);
|
|
88
|
-
return this.lines[line].slice(0, character);
|
|
89
|
-
}
|
|
90
|
-
getLineOffsets() {
|
|
91
|
-
const lineOffsets = [];
|
|
92
|
-
const text = this.getText();
|
|
93
|
-
let isLineStart = true;
|
|
94
|
-
for (let i = 0; i < text.length; i++) {
|
|
95
|
-
if (isLineStart) {
|
|
96
|
-
lineOffsets.push(i);
|
|
97
|
-
isLineStart = false;
|
|
98
|
-
}
|
|
99
|
-
const ch = text.charAt(i);
|
|
100
|
-
isLineStart = ch === '\r' || ch === '\n';
|
|
101
|
-
if (ch === '\r' && i + 1 < text.length && text.charAt(i + 1) === '\n') {
|
|
102
|
-
i++;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (isLineStart && text.length > 0) {
|
|
106
|
-
lineOffsets.push(text.length);
|
|
107
|
-
}
|
|
108
|
-
return lineOffsets;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Get the length of the document's content
|
|
112
|
-
*/
|
|
113
|
-
getTextLength() {
|
|
114
|
-
return this.getText().length;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Returns the file path if the url scheme is file
|
|
118
|
-
*/
|
|
119
|
-
getFilePath() {
|
|
120
|
-
return (0, utils_1.urlToPath)(this.uri);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Get URL file path.
|
|
124
|
-
*/
|
|
125
|
-
getURL() {
|
|
126
|
-
return this.uri;
|
|
127
|
-
}
|
|
128
|
-
get lines() {
|
|
129
|
-
return this.getText().split(/\r?\n/);
|
|
130
|
-
}
|
|
131
|
-
get lineCount() {
|
|
132
|
-
return this.lines.length;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.Document = Document;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
import { TextDocumentContentChangeEvent, Position, Range } from 'vscode-languageserver';
|
|
3
|
-
import { Document, DocumentMapper, IdentityMapper } from '../../core/documents';
|
|
4
|
-
/**
|
|
5
|
-
* The mapper to get from original snapshot positions to generated and vice versa.
|
|
6
|
-
*/
|
|
7
|
-
export interface SnapshotFragment extends DocumentMapper {
|
|
8
|
-
positionAt(offset: number): Position;
|
|
9
|
-
offsetAt(position: Position): number;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* An error which occured while trying to parse/preprocess the Astro file contents.
|
|
13
|
-
*/
|
|
14
|
-
export interface ParserError {
|
|
15
|
-
message: string;
|
|
16
|
-
range: Range;
|
|
17
|
-
code: number;
|
|
18
|
-
}
|
|
19
|
-
export interface DocumentSnapshot extends ts.IScriptSnapshot {
|
|
20
|
-
version: number;
|
|
21
|
-
filePath: string;
|
|
22
|
-
scriptKind: ts.ScriptKind;
|
|
23
|
-
parserError: ParserError | null;
|
|
24
|
-
positionAt(offset: number): Position;
|
|
25
|
-
/**
|
|
26
|
-
* Instantiates a source mapper.
|
|
27
|
-
* `destroyFragment` needs to be called when
|
|
28
|
-
* it's no longer needed / the class should be cleaned up
|
|
29
|
-
* in order to prevent memory leaks.
|
|
30
|
-
*/
|
|
31
|
-
getFragment(): Promise<DocumentFragmentSnapshot>;
|
|
32
|
-
/**
|
|
33
|
-
* Needs to be called when source mapper
|
|
34
|
-
* is no longer needed / the class should be cleaned up
|
|
35
|
-
* in order to prevent memory leaks.
|
|
36
|
-
*/
|
|
37
|
-
destroyFragment(): void;
|
|
38
|
-
/**
|
|
39
|
-
* Convenience function for getText(0, getLength())
|
|
40
|
-
*/
|
|
41
|
-
getFullText(): string;
|
|
42
|
-
createFragment(mapper: IdentityMapper): DocumentFragmentSnapshot;
|
|
43
|
-
toTSX(code: string, filePath: string): string;
|
|
44
|
-
}
|
|
45
|
-
export declare abstract class DocumentFragmentSnapshot implements Omit<DocumentSnapshot, 'createFragment' | 'getFragment' | 'destroyFragment' | 'toTSX'>, SnapshotFragment {
|
|
46
|
-
private mapper;
|
|
47
|
-
private parent;
|
|
48
|
-
version: number;
|
|
49
|
-
filePath: string;
|
|
50
|
-
url: string;
|
|
51
|
-
text: string;
|
|
52
|
-
parserError: null;
|
|
53
|
-
scriptKind: ts.ScriptKind;
|
|
54
|
-
scriptInfo: null;
|
|
55
|
-
constructor(mapper: any, parent: Document, toTSX: (code: string, filePath: string) => string);
|
|
56
|
-
abstract toVirtualFilePath(filePath: string): string;
|
|
57
|
-
getText(start: number, end: number): string;
|
|
58
|
-
getLength(): number;
|
|
59
|
-
getFullText(): string;
|
|
60
|
-
getChangeRange(): undefined;
|
|
61
|
-
positionAt(offset: number): import("vscode-html-languageservice").Position;
|
|
62
|
-
getLineContainingOffset(offset: number): string;
|
|
63
|
-
offsetAt(position: Position): number;
|
|
64
|
-
getOriginalPosition(pos: Position): Position;
|
|
65
|
-
getGeneratedPosition(pos: Position): Position;
|
|
66
|
-
isInGenerated(pos: Position): boolean;
|
|
67
|
-
getURL(): string;
|
|
68
|
-
}
|
|
69
|
-
declare class FrameworkDocumentFragmentSnapshot extends DocumentFragmentSnapshot {
|
|
70
|
-
toVirtualFilePath(filePath: string): string;
|
|
71
|
-
}
|
|
72
|
-
export declare class AstroDocumentFragmentSnapshot extends DocumentFragmentSnapshot {
|
|
73
|
-
toVirtualFilePath(filePath: string): string;
|
|
74
|
-
}
|
|
75
|
-
export declare class TypeScriptDocumentSnapshot implements DocumentSnapshot {
|
|
76
|
-
version: number;
|
|
77
|
-
readonly filePath: string;
|
|
78
|
-
private text;
|
|
79
|
-
scriptKind: ts.ScriptKind;
|
|
80
|
-
scriptInfo: null;
|
|
81
|
-
parserError: null;
|
|
82
|
-
url: string;
|
|
83
|
-
constructor(version: number, filePath: string, text: string);
|
|
84
|
-
toTSX(): any;
|
|
85
|
-
createFragment(): any;
|
|
86
|
-
destroyFragment(): void;
|
|
87
|
-
getText(start: number, end: number): string;
|
|
88
|
-
getLength(): number;
|
|
89
|
-
getFullText(): string;
|
|
90
|
-
getChangeRange(): undefined;
|
|
91
|
-
positionAt(offset: number): import("vscode-html-languageservice").Position;
|
|
92
|
-
offsetAt(position: Position): number;
|
|
93
|
-
getFragment(): Promise<FrameworkDocumentFragmentSnapshot>;
|
|
94
|
-
getOriginalPosition(pos: Position): Position;
|
|
95
|
-
getLineContainingOffset(offset: number): string;
|
|
96
|
-
update(changes: TextDocumentContentChangeEvent[]): void;
|
|
97
|
-
}
|
|
98
|
-
export declare const createDocumentSnapshot: (filePath: string, currentText: string | null, createDocument?: ((_filePath: string, text: string, overrideText: boolean) => Document) | undefined) => DocumentSnapshot;
|
|
99
|
-
export {};
|
|
@@ -1,259 +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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.createDocumentSnapshot = exports.TypeScriptDocumentSnapshot = exports.AstroDocumentFragmentSnapshot = exports.DocumentFragmentSnapshot = void 0;
|
|
30
|
-
const ts = __importStar(require("typescript"));
|
|
31
|
-
const documents_1 = require("../../core/documents");
|
|
32
|
-
const utils_1 = require("../../core/documents/utils");
|
|
33
|
-
const utils_2 = require("../../utils");
|
|
34
|
-
const utils_3 = require("./utils");
|
|
35
|
-
const os_1 = require("os");
|
|
36
|
-
const astro2tsx_1 = __importDefault(require("./astro2tsx"));
|
|
37
|
-
const svelte_language_integration_1 = require("@astrojs/svelte-language-integration");
|
|
38
|
-
class DocumentFragmentSnapshot {
|
|
39
|
-
constructor(mapper, parent, toTSX) {
|
|
40
|
-
this.mapper = mapper;
|
|
41
|
-
this.parent = parent;
|
|
42
|
-
this.parserError = null;
|
|
43
|
-
this.scriptKind = ts.ScriptKind.TSX;
|
|
44
|
-
this.scriptInfo = null;
|
|
45
|
-
const filePath = parent.getFilePath();
|
|
46
|
-
if (!filePath)
|
|
47
|
-
throw new Error('Cannot create a document fragment from a non-local document');
|
|
48
|
-
const text = parent.getText();
|
|
49
|
-
this.version = parent.version;
|
|
50
|
-
this.filePath = this.toVirtualFilePath(filePath);
|
|
51
|
-
this.url = this.toVirtualFilePath(filePath);
|
|
52
|
-
this.text = toTSX(text, this.filePath);
|
|
53
|
-
}
|
|
54
|
-
getText(start, end) {
|
|
55
|
-
return this.text.substring(start, end);
|
|
56
|
-
}
|
|
57
|
-
getLength() {
|
|
58
|
-
return this.text.length;
|
|
59
|
-
}
|
|
60
|
-
getFullText() {
|
|
61
|
-
return this.text;
|
|
62
|
-
}
|
|
63
|
-
getChangeRange() {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
positionAt(offset) {
|
|
67
|
-
return (0, utils_1.positionAt)(offset, this.text);
|
|
68
|
-
}
|
|
69
|
-
getLineContainingOffset(offset) {
|
|
70
|
-
const chunks = this.getText(0, offset).split(os_1.EOL);
|
|
71
|
-
return chunks[chunks.length - 1];
|
|
72
|
-
}
|
|
73
|
-
offsetAt(position) {
|
|
74
|
-
return (0, utils_1.offsetAt)(position, this.text);
|
|
75
|
-
}
|
|
76
|
-
getOriginalPosition(pos) {
|
|
77
|
-
return this.mapper.getOriginalPosition(pos);
|
|
78
|
-
}
|
|
79
|
-
getGeneratedPosition(pos) {
|
|
80
|
-
return this.mapper.getGeneratedPosition(pos);
|
|
81
|
-
}
|
|
82
|
-
isInGenerated(pos) {
|
|
83
|
-
return !(0, utils_1.isInTag)(pos, this.parent.styleInfo);
|
|
84
|
-
}
|
|
85
|
-
getURL() {
|
|
86
|
-
return this.url;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.DocumentFragmentSnapshot = DocumentFragmentSnapshot;
|
|
90
|
-
class DocumentSnapshotBase {
|
|
91
|
-
constructor(doc) {
|
|
92
|
-
this.doc = doc;
|
|
93
|
-
this.version = this.doc.version;
|
|
94
|
-
this.scriptKind = ts.ScriptKind.TSX;
|
|
95
|
-
this.parserError = null;
|
|
96
|
-
}
|
|
97
|
-
get text() {
|
|
98
|
-
let raw = this.doc.getText();
|
|
99
|
-
return this.toTSX(raw, this.filePath);
|
|
100
|
-
}
|
|
101
|
-
get filePath() {
|
|
102
|
-
return this.doc.getFilePath() || '';
|
|
103
|
-
}
|
|
104
|
-
getText(start, end) {
|
|
105
|
-
return this.text.substring(start, end);
|
|
106
|
-
}
|
|
107
|
-
getLength() {
|
|
108
|
-
return this.text.length;
|
|
109
|
-
}
|
|
110
|
-
getFullText() {
|
|
111
|
-
return this.text;
|
|
112
|
-
}
|
|
113
|
-
getChangeRange() {
|
|
114
|
-
return undefined;
|
|
115
|
-
}
|
|
116
|
-
positionAt(offset) {
|
|
117
|
-
return (0, utils_1.positionAt)(offset, this.text);
|
|
118
|
-
}
|
|
119
|
-
getLineContainingOffset(offset) {
|
|
120
|
-
const chunks = this.getText(0, offset).split(os_1.EOL);
|
|
121
|
-
return chunks[chunks.length - 1];
|
|
122
|
-
}
|
|
123
|
-
offsetAt(position) {
|
|
124
|
-
return (0, utils_1.offsetAt)(position, this.text);
|
|
125
|
-
}
|
|
126
|
-
getMapper(uri) {
|
|
127
|
-
return new documents_1.IdentityMapper(uri);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
class FrameworkDocumentSnapshot extends DocumentSnapshotBase {
|
|
131
|
-
toTSX(code, filePath) {
|
|
132
|
-
if ((0, utils_3.isVirtualSvelteFilePath)(filePath)) {
|
|
133
|
-
return (0, svelte_language_integration_1.toTSX)(code);
|
|
134
|
-
}
|
|
135
|
-
return 'export default function() {}';
|
|
136
|
-
}
|
|
137
|
-
createFragment(mapper) {
|
|
138
|
-
return new FrameworkDocumentFragmentSnapshot(mapper, this.doc, this.toTSX);
|
|
139
|
-
}
|
|
140
|
-
async getFragment() {
|
|
141
|
-
const uri = (0, utils_2.pathToUrl)(this.filePath);
|
|
142
|
-
const mapper = await this.getMapper(uri);
|
|
143
|
-
return this.createFragment(mapper);
|
|
144
|
-
}
|
|
145
|
-
async destroyFragment() {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
class FrameworkDocumentFragmentSnapshot extends DocumentFragmentSnapshot {
|
|
150
|
-
toVirtualFilePath(filePath) {
|
|
151
|
-
return filePath;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
class AstroDocumentSnapshot extends DocumentSnapshotBase {
|
|
155
|
-
createFragment(mapper) {
|
|
156
|
-
return new AstroDocumentFragmentSnapshot(mapper, this.doc, this.toTSX);
|
|
157
|
-
}
|
|
158
|
-
async getFragment() {
|
|
159
|
-
const uri = (0, utils_2.pathToUrl)(this.filePath);
|
|
160
|
-
const mapper = await this.getMapper(uri);
|
|
161
|
-
return new AstroDocumentFragmentSnapshot(mapper, this.doc, this.toTSX);
|
|
162
|
-
}
|
|
163
|
-
async destroyFragment() {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
toTSX(code, filePath) {
|
|
167
|
-
return (0, astro2tsx_1.default)(code).code;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
class AstroDocumentFragmentSnapshot extends DocumentFragmentSnapshot {
|
|
171
|
-
toVirtualFilePath(filePath) {
|
|
172
|
-
return (0, utils_3.toVirtualAstroFilePath)(filePath);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
exports.AstroDocumentFragmentSnapshot = AstroDocumentFragmentSnapshot;
|
|
176
|
-
class TypeScriptDocumentSnapshot {
|
|
177
|
-
constructor(version, filePath, text) {
|
|
178
|
-
this.version = version;
|
|
179
|
-
this.filePath = filePath;
|
|
180
|
-
this.text = text;
|
|
181
|
-
this.scriptKind = (0, utils_3.getScriptKindFromFileName)(this.filePath);
|
|
182
|
-
this.scriptInfo = null;
|
|
183
|
-
this.parserError = null;
|
|
184
|
-
this.url = (0, utils_2.pathToUrl)(filePath);
|
|
185
|
-
}
|
|
186
|
-
// We don't create Fragments for TypescriptDocument, nor do we convert them to TSX so those three methods are not
|
|
187
|
-
// necessary, though they're required to be implemented for DocumentSnapshot
|
|
188
|
-
toTSX() {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
createFragment() {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
destroyFragment() {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
getText(start, end) {
|
|
198
|
-
return this.text.substring(start, end);
|
|
199
|
-
}
|
|
200
|
-
getLength() {
|
|
201
|
-
return this.text.length;
|
|
202
|
-
}
|
|
203
|
-
getFullText() {
|
|
204
|
-
return this.text;
|
|
205
|
-
}
|
|
206
|
-
getChangeRange() {
|
|
207
|
-
return undefined;
|
|
208
|
-
}
|
|
209
|
-
positionAt(offset) {
|
|
210
|
-
return (0, utils_1.positionAt)(offset, this.text);
|
|
211
|
-
}
|
|
212
|
-
offsetAt(position) {
|
|
213
|
-
return (0, utils_1.offsetAt)(position, this.text);
|
|
214
|
-
}
|
|
215
|
-
async getFragment() {
|
|
216
|
-
return this;
|
|
217
|
-
}
|
|
218
|
-
getOriginalPosition(pos) {
|
|
219
|
-
return pos;
|
|
220
|
-
}
|
|
221
|
-
getLineContainingOffset(offset) {
|
|
222
|
-
const chunks = this.getText(0, offset).split('\n');
|
|
223
|
-
return chunks[chunks.length - 1];
|
|
224
|
-
}
|
|
225
|
-
update(changes) {
|
|
226
|
-
for (const change of changes) {
|
|
227
|
-
let start = 0;
|
|
228
|
-
let end = 0;
|
|
229
|
-
if ('range' in change) {
|
|
230
|
-
start = this.offsetAt(change.range.start);
|
|
231
|
-
end = this.offsetAt(change.range.end);
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
end = this.getLength();
|
|
235
|
-
}
|
|
236
|
-
this.text = this.text.slice(0, start) + change.text + this.text.slice(end);
|
|
237
|
-
}
|
|
238
|
-
this.version++;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
exports.TypeScriptDocumentSnapshot = TypeScriptDocumentSnapshot;
|
|
242
|
-
const createDocumentSnapshot = (filePath, currentText, createDocument) => {
|
|
243
|
-
var _a;
|
|
244
|
-
let text = currentText || ((_a = ts.sys.readFile(filePath.replace(".tsx", ""))) !== null && _a !== void 0 ? _a : '');
|
|
245
|
-
if ((0, utils_3.isVirtualFrameworkFilePath)('vue', 'tsx', filePath) || (0, utils_3.isVirtualFrameworkFilePath)('svelte', 'tsx', filePath)) {
|
|
246
|
-
if (!createDocument)
|
|
247
|
-
throw new Error('Framework documents require the "createDocument" utility to be provided');
|
|
248
|
-
const snapshot = new FrameworkDocumentSnapshot(createDocument(filePath, text, currentText !== null));
|
|
249
|
-
return snapshot;
|
|
250
|
-
}
|
|
251
|
-
if ((0, utils_3.isAstroFilePath)(filePath)) {
|
|
252
|
-
if (!createDocument)
|
|
253
|
-
throw new Error('Astro documents require the "createDocument" utility to be provided');
|
|
254
|
-
const snapshot = new AstroDocumentSnapshot(createDocument(filePath, text, currentText !== null));
|
|
255
|
-
return snapshot;
|
|
256
|
-
}
|
|
257
|
-
return new TypeScriptDocumentSnapshot(0, filePath, text);
|
|
258
|
-
};
|
|
259
|
-
exports.createDocumentSnapshot = createDocumentSnapshot;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { TextDocumentContentChangeEvent } from 'vscode-languageserver';
|
|
2
|
-
import { DocumentSnapshot } from './DocumentSnapshot';
|
|
3
|
-
export interface TsFilesSpec {
|
|
4
|
-
include?: readonly string[];
|
|
5
|
-
exclude?: readonly string[];
|
|
6
|
-
}
|
|
7
|
-
export declare class SnapshotManager {
|
|
8
|
-
private projectFiles;
|
|
9
|
-
private fileSpec;
|
|
10
|
-
private workspaceRoot;
|
|
11
|
-
private documents;
|
|
12
|
-
private lastLogged;
|
|
13
|
-
private readonly watchExtensions;
|
|
14
|
-
constructor(projectFiles: string[], fileSpec: TsFilesSpec, workspaceRoot: string);
|
|
15
|
-
updateProjectFiles(): void;
|
|
16
|
-
updateProjectFile(fileName: string, changes?: TextDocumentContentChangeEvent[]): void;
|
|
17
|
-
has(fileName: string): boolean;
|
|
18
|
-
get(fileName: string): DocumentSnapshot | undefined;
|
|
19
|
-
set(fileName: string, snapshot: DocumentSnapshot): Map<string, DocumentSnapshot>;
|
|
20
|
-
delete(fileName: string): boolean;
|
|
21
|
-
getFileNames(): string[];
|
|
22
|
-
getProjectFileNames(): string[];
|
|
23
|
-
private logStatistics;
|
|
24
|
-
}
|
|
@@ -1,103 +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
|
-
exports.SnapshotManager = void 0;
|
|
27
|
-
const ts = __importStar(require("typescript"));
|
|
28
|
-
const utils_1 = require("./utils");
|
|
29
|
-
const DocumentSnapshot_1 = require("./DocumentSnapshot");
|
|
30
|
-
class SnapshotManager {
|
|
31
|
-
constructor(projectFiles, fileSpec, workspaceRoot) {
|
|
32
|
-
this.projectFiles = projectFiles;
|
|
33
|
-
this.fileSpec = fileSpec;
|
|
34
|
-
this.workspaceRoot = workspaceRoot;
|
|
35
|
-
this.documents = new Map();
|
|
36
|
-
this.lastLogged = new Date(new Date().getTime() - 60001);
|
|
37
|
-
this.watchExtensions = [ts.Extension.Dts, ts.Extension.Js, ts.Extension.Jsx, ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Json];
|
|
38
|
-
}
|
|
39
|
-
updateProjectFiles() {
|
|
40
|
-
const { include, exclude } = this.fileSpec;
|
|
41
|
-
if ((include === null || include === void 0 ? void 0 : include.length) === 0)
|
|
42
|
-
return;
|
|
43
|
-
const projectFiles = ts.sys.readDirectory(this.workspaceRoot, this.watchExtensions, exclude, include);
|
|
44
|
-
this.projectFiles = Array.from(new Set([...this.projectFiles, ...projectFiles]));
|
|
45
|
-
}
|
|
46
|
-
updateProjectFile(fileName, changes) {
|
|
47
|
-
const previousSnapshot = this.get(fileName);
|
|
48
|
-
if (changes) {
|
|
49
|
-
if (!(previousSnapshot instanceof DocumentSnapshot_1.TypeScriptDocumentSnapshot)) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
previousSnapshot.update(changes);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
const newSnapshot = (0, DocumentSnapshot_1.createDocumentSnapshot)(fileName, null);
|
|
56
|
-
if (previousSnapshot) {
|
|
57
|
-
newSnapshot.version = previousSnapshot.version + 1;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
// ensure it's greater than initial version
|
|
61
|
-
// so that ts server picks up the change
|
|
62
|
-
newSnapshot.version += 1;
|
|
63
|
-
}
|
|
64
|
-
this.set(fileName, newSnapshot);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
has(fileName) {
|
|
68
|
-
return this.projectFiles.includes(fileName) || this.getFileNames().includes(fileName);
|
|
69
|
-
}
|
|
70
|
-
get(fileName) {
|
|
71
|
-
return this.documents.get(fileName);
|
|
72
|
-
}
|
|
73
|
-
set(fileName, snapshot) {
|
|
74
|
-
return this.documents.set(fileName, snapshot);
|
|
75
|
-
}
|
|
76
|
-
delete(fileName) {
|
|
77
|
-
this.projectFiles = this.projectFiles.filter((s) => s !== fileName);
|
|
78
|
-
return this.documents.delete(fileName);
|
|
79
|
-
}
|
|
80
|
-
getFileNames() {
|
|
81
|
-
return Array.from(this.documents.keys()).map((fileName) => (0, utils_1.toVirtualFilePath)(fileName));
|
|
82
|
-
}
|
|
83
|
-
getProjectFileNames() {
|
|
84
|
-
return this.projectFiles.map((file) => {
|
|
85
|
-
return (0, utils_1.toVirtualFilePath)(file);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
logStatistics() {
|
|
89
|
-
const date = new Date();
|
|
90
|
-
// Don't use setInterval because that will keep tests running forever
|
|
91
|
-
if (date.getTime() - this.lastLogged.getTime() > 60000) {
|
|
92
|
-
this.lastLogged = date;
|
|
93
|
-
const projectFiles = this.getProjectFileNames();
|
|
94
|
-
const allFiles = Array.from(new Set([...projectFiles, ...this.getFileNames()]));
|
|
95
|
-
console.log('SnapshotManager File Statistics:\n' +
|
|
96
|
-
`Project files: ${projectFiles.length}\n` +
|
|
97
|
-
`Astro files: ${allFiles.filter((name) => name.endsWith('.astro')).length}\n` +
|
|
98
|
-
`From node_modules: ${allFiles.filter((name) => name.includes('node_modules')).length}\n` +
|
|
99
|
-
`Total: ${allFiles.length}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
exports.SnapshotManager = SnapshotManager;
|