@astrojs/language-server 0.9.2 → 0.12.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 +22 -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 +6 -1
- 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 +37 -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 +6 -2
- 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 +8 -9
- package/dist/plugins/PluginHost.js +22 -36
- package/dist/plugins/astro/AstroPlugin.d.ts +11 -12
- package/dist/plugins/astro/AstroPlugin.js +17 -38
- package/dist/plugins/astro/features/{CompletionProvider.d.ts → CompletionsProvider.d.ts} +5 -5
- package/dist/plugins/astro/features/{CompletionProvider.js → CompletionsProvider.js} +33 -54
- package/dist/plugins/css/CSSDocument.d.ts +3 -3
- package/dist/plugins/css/CSSDocument.js +7 -16
- package/dist/plugins/css/CSSPlugin.d.ts +19 -11
- package/dist/plugins/css/CSSPlugin.js +63 -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 +15 -17
- package/dist/plugins/html/HTMLPlugin.js +33 -41
- package/dist/plugins/index.d.ts +2 -2
- package/dist/plugins/index.js +7 -3
- 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 +16 -23
- package/dist/plugins/typescript/TypeScriptPlugin.js +48 -56
- package/dist/plugins/typescript/astro-sys.d.ts +5 -3
- package/dist/plugins/typescript/astro-sys.js +24 -41
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +6 -6
- package/dist/plugins/typescript/features/CompletionsProvider.js +17 -33
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +4 -4
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +22 -61
- 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 +227 -0
- package/dist/plugins/typescript/module-loader.d.ts +5 -8
- package/dist/plugins/typescript/module-loader.js +43 -23
- package/dist/plugins/typescript/{DocumentSnapshot.d.ts → snapshots/DocumentSnapshot.d.ts} +45 -42
- 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 -11
- package/dist/plugins/typescript/utils.js +122 -151
- package/dist/server.d.ts +2 -4
- package/dist/server.js +88 -54
- package/dist/utils.d.ts +16 -8
- package/dist/utils.js +29 -14
- package/package.json +19 -13
- 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.js +0 -202
- package/dist/plugins/typescript/SnapshotManager.d.ts +0 -24
- package/dist/plugins/typescript/SnapshotManager.js +0 -97
- package/dist/plugins/typescript/languageService.d.ts +0 -17
- package/dist/plugins/typescript/languageService.js +0 -169
- package/types/index.d.ts +0 -4
package/dist/utils.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.debounceThrottle = exports.debounceSameArg = exports.isBeforeOrEqualToPosition = exports.isInRange = exports.isNotNullOrUndefined = exports.clamp = exports.flatten = exports.isPossibleClientComponent = exports.isPossibleComponent = exports.pathToUrl = exports.urlToPath = exports.normalizeUri = void 0;
|
|
3
|
+
exports.debounceThrottle = exports.debounceSameArg = exports.isBeforeOrEqualToPosition = exports.isInRange = exports.isNotNullOrUndefined = exports.clamp = exports.flatten = exports.isPossibleClientComponent = exports.isPossibleComponent = exports.getLastPartOfPath = exports.pathToUrl = exports.urlToPath = exports.normalizePath = exports.normalizeUri = void 0;
|
|
4
4
|
const vscode_uri_1 = require("vscode-uri");
|
|
5
5
|
/** Normalizes a document URI */
|
|
6
6
|
function normalizeUri(uri) {
|
|
7
7
|
return vscode_uri_1.URI.parse(uri).toString();
|
|
8
8
|
}
|
|
9
9
|
exports.normalizeUri = normalizeUri;
|
|
10
|
+
/**
|
|
11
|
+
* Some paths (on windows) start with a upper case driver letter, some don't.
|
|
12
|
+
* This is normalized here.
|
|
13
|
+
*/
|
|
14
|
+
function normalizePath(path) {
|
|
15
|
+
return vscode_uri_1.URI.file(path).fsPath.replace(/\\/g, '/');
|
|
16
|
+
}
|
|
17
|
+
exports.normalizePath = normalizePath;
|
|
10
18
|
/** Turns a URL into a normalized FS Path */
|
|
11
19
|
function urlToPath(stringUrl) {
|
|
12
20
|
const url = vscode_uri_1.URI.parse(stringUrl);
|
|
@@ -21,6 +29,14 @@ function pathToUrl(path) {
|
|
|
21
29
|
return vscode_uri_1.URI.file(path).toString();
|
|
22
30
|
}
|
|
23
31
|
exports.pathToUrl = pathToUrl;
|
|
32
|
+
/**
|
|
33
|
+
* Given a path like foo/bar or foo/bar.astro , returns its last path
|
|
34
|
+
* (bar or bar.astro in this example).
|
|
35
|
+
*/
|
|
36
|
+
function getLastPartOfPath(path) {
|
|
37
|
+
return path.replace(/\\/g, '/').split('/').pop() || '';
|
|
38
|
+
}
|
|
39
|
+
exports.getLastPartOfPath = getLastPartOfPath;
|
|
24
40
|
/**
|
|
25
41
|
*
|
|
26
42
|
* The language service is case insensitive, and would provide
|
|
@@ -63,14 +79,13 @@ function isNotNullOrUndefined(val) {
|
|
|
63
79
|
return val !== undefined && val !== null;
|
|
64
80
|
}
|
|
65
81
|
exports.isNotNullOrUndefined = isNotNullOrUndefined;
|
|
66
|
-
|
|
67
|
-
function isInRange(positionToTest, range) {
|
|
82
|
+
function isInRange(range, positionToTest) {
|
|
68
83
|
return isBeforeOrEqualToPosition(range.end, positionToTest) && isBeforeOrEqualToPosition(positionToTest, range.start);
|
|
69
84
|
}
|
|
70
85
|
exports.isInRange = isInRange;
|
|
71
|
-
/** */
|
|
72
86
|
function isBeforeOrEqualToPosition(position, positionToTest) {
|
|
73
|
-
return positionToTest.line < position.line ||
|
|
87
|
+
return (positionToTest.line < position.line ||
|
|
88
|
+
(positionToTest.line === position.line && positionToTest.character <= position.character));
|
|
74
89
|
}
|
|
75
90
|
exports.isBeforeOrEqualToPosition = isBeforeOrEqualToPosition;
|
|
76
91
|
/**
|
|
@@ -79,9 +94,9 @@ exports.isBeforeOrEqualToPosition = isBeforeOrEqualToPosition;
|
|
|
79
94
|
*
|
|
80
95
|
* @param fn The function with it's argument
|
|
81
96
|
* @param determineIfSame The function which determines if the previous invocation should be canceld or not
|
|
82
|
-
* @param
|
|
97
|
+
* @param milliseconds Number of miliseconds to debounce
|
|
83
98
|
*/
|
|
84
|
-
function debounceSameArg(fn, shouldCancelPrevious,
|
|
99
|
+
function debounceSameArg(fn, shouldCancelPrevious, milliseconds) {
|
|
85
100
|
let timeout;
|
|
86
101
|
let prevArg;
|
|
87
102
|
return (arg) => {
|
|
@@ -92,31 +107,31 @@ function debounceSameArg(fn, shouldCancelPrevious, miliseconds) {
|
|
|
92
107
|
timeout = setTimeout(() => {
|
|
93
108
|
fn(arg);
|
|
94
109
|
prevArg = undefined;
|
|
95
|
-
},
|
|
110
|
+
}, milliseconds);
|
|
96
111
|
};
|
|
97
112
|
}
|
|
98
113
|
exports.debounceSameArg = debounceSameArg;
|
|
99
114
|
/**
|
|
100
|
-
* Debounces a function but also waits at minimum the specified number of
|
|
115
|
+
* Debounces a function but also waits at minimum the specified number of milliseconds until
|
|
101
116
|
* the next invocation. This avoids needless calls when a synchronous call (like diagnostics)
|
|
102
117
|
* took too long and the whole timeout of the next call was eaten up already.
|
|
103
118
|
*
|
|
104
119
|
* @param fn The function with it's argument
|
|
105
|
-
* @param
|
|
120
|
+
* @param milliseconds Number of milliseconds to debounce/throttle
|
|
106
121
|
*/
|
|
107
|
-
function debounceThrottle(fn,
|
|
122
|
+
function debounceThrottle(fn, milliseconds) {
|
|
108
123
|
let timeout;
|
|
109
|
-
let lastInvocation = Date.now() -
|
|
124
|
+
let lastInvocation = Date.now() - milliseconds;
|
|
110
125
|
function maybeCall(...args) {
|
|
111
126
|
clearTimeout(timeout);
|
|
112
127
|
timeout = setTimeout(() => {
|
|
113
|
-
if (Date.now() - lastInvocation <
|
|
128
|
+
if (Date.now() - lastInvocation < milliseconds) {
|
|
114
129
|
maybeCall(...args);
|
|
115
130
|
return;
|
|
116
131
|
}
|
|
117
132
|
fn(...args);
|
|
118
133
|
lastInvocation = Date.now();
|
|
119
|
-
},
|
|
134
|
+
}, milliseconds);
|
|
120
135
|
}
|
|
121
136
|
return maybeCall;
|
|
122
137
|
}
|
package/package.json
CHANGED
|
@@ -1,42 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"bin": {
|
|
9
|
-
"astro-ls": "./bin/
|
|
9
|
+
"astro-ls": "./bin/nodeServer.js"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
13
|
-
"astro.d.ts",
|
|
14
13
|
"bin",
|
|
15
14
|
"types"
|
|
16
15
|
],
|
|
17
16
|
"scripts": {
|
|
18
17
|
"build": "tsc",
|
|
19
18
|
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
|
20
|
-
"test": "
|
|
19
|
+
"test": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --require ts-node/register \"test/**/*.ts\" --exclude \"test/**/*.d.ts\""
|
|
21
20
|
},
|
|
22
21
|
"dependencies": {
|
|
22
|
+
"@astrojs/svelte-language-integration": "^0.1.0",
|
|
23
|
+
"@vscode/emmet-helper": "^2.8.4",
|
|
23
24
|
"lodash": "^4.17.21",
|
|
24
25
|
"source-map": "^0.7.3",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"vscode-
|
|
28
|
-
"
|
|
29
|
-
"vscode-html-languageservice": "^3.0.3",
|
|
30
|
-
"vscode-languageserver": "6.1.1",
|
|
26
|
+
"typescript": "~4.6.2",
|
|
27
|
+
"vscode-css-languageservice": "^5.1.13",
|
|
28
|
+
"vscode-html-languageservice": "^4.2.2",
|
|
29
|
+
"vscode-languageserver": "7.0.0",
|
|
31
30
|
"vscode-languageserver-protocol": "^3.16.0",
|
|
32
31
|
"vscode-languageserver-textdocument": "^1.0.1",
|
|
33
32
|
"vscode-languageserver-types": "^3.16.0",
|
|
34
33
|
"vscode-uri": "^3.0.2"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
|
-
"@types/
|
|
38
|
-
"
|
|
36
|
+
"@types/chai": "^4.3.0",
|
|
37
|
+
"@types/lodash": "^4.14.179",
|
|
38
|
+
"@types/mocha": "^9.1.0",
|
|
39
|
+
"@types/sinon": "^10.0.11",
|
|
40
|
+
"astro": "^0.23.7",
|
|
39
41
|
"astro-scripts": "0.0.1",
|
|
40
|
-
"
|
|
42
|
+
"chai": "^4.3.6",
|
|
43
|
+
"cross-env": "^7.0.3",
|
|
44
|
+
"mocha": "^9.2.2",
|
|
45
|
+
"sinon": "^13.0.1",
|
|
46
|
+
"ts-node": "^10.7.0"
|
|
41
47
|
}
|
|
42
48
|
}
|
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,202 +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
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.TypeScriptDocumentSnapshot = exports.DocumentFragmentSnapshot = exports.createDocumentSnapshot = void 0;
|
|
26
|
-
const ts = __importStar(require("typescript"));
|
|
27
|
-
const documents_1 = require("../../core/documents");
|
|
28
|
-
const utils_1 = require("../../core/documents/utils");
|
|
29
|
-
const utils_2 = require("../../utils");
|
|
30
|
-
const utils_3 = require("./utils");
|
|
31
|
-
const os_1 = require("os");
|
|
32
|
-
const astro2tsx_1 = __importDefault(require("./astro2tsx"));
|
|
33
|
-
const createDocumentSnapshot = (filePath, currentText, createDocument) => {
|
|
34
|
-
var _a;
|
|
35
|
-
const text = currentText || ((_a = ts.sys.readFile(filePath)) !== null && _a !== void 0 ? _a : '');
|
|
36
|
-
if ((0, utils_3.isAstroFilePath)(filePath)) {
|
|
37
|
-
if (!createDocument)
|
|
38
|
-
throw new Error('Astro documents require the "createDocument" utility to be provided');
|
|
39
|
-
const snapshot = new AstroDocumentSnapshot(createDocument(filePath, text, currentText !== null));
|
|
40
|
-
return snapshot;
|
|
41
|
-
}
|
|
42
|
-
return new TypeScriptDocumentSnapshot(0, filePath, text);
|
|
43
|
-
};
|
|
44
|
-
exports.createDocumentSnapshot = createDocumentSnapshot;
|
|
45
|
-
class AstroDocumentSnapshot {
|
|
46
|
-
constructor(doc) {
|
|
47
|
-
this.doc = doc;
|
|
48
|
-
this.version = this.doc.version;
|
|
49
|
-
this.scriptKind = ts.ScriptKind.Unknown;
|
|
50
|
-
this.parserError = null;
|
|
51
|
-
}
|
|
52
|
-
async getFragment() {
|
|
53
|
-
const uri = (0, utils_2.pathToUrl)(this.filePath);
|
|
54
|
-
const mapper = await this.getMapper(uri);
|
|
55
|
-
return new DocumentFragmentSnapshot(mapper, this.doc);
|
|
56
|
-
}
|
|
57
|
-
async destroyFragment() {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
get text() {
|
|
61
|
-
let raw = this.doc.getText();
|
|
62
|
-
return (0, astro2tsx_1.default)(raw).code;
|
|
63
|
-
}
|
|
64
|
-
get filePath() {
|
|
65
|
-
return this.doc.getFilePath() || '';
|
|
66
|
-
}
|
|
67
|
-
getText(start, end) {
|
|
68
|
-
return this.text.substring(start, end);
|
|
69
|
-
}
|
|
70
|
-
getLength() {
|
|
71
|
-
return this.text.length;
|
|
72
|
-
}
|
|
73
|
-
getFullText() {
|
|
74
|
-
return this.text;
|
|
75
|
-
}
|
|
76
|
-
getChangeRange() {
|
|
77
|
-
return undefined;
|
|
78
|
-
}
|
|
79
|
-
positionAt(offset) {
|
|
80
|
-
return (0, utils_1.positionAt)(offset, this.text);
|
|
81
|
-
}
|
|
82
|
-
getLineContainingOffset(offset) {
|
|
83
|
-
const chunks = this.getText(0, offset).split(os_1.EOL);
|
|
84
|
-
return chunks[chunks.length - 1];
|
|
85
|
-
}
|
|
86
|
-
offsetAt(position) {
|
|
87
|
-
return (0, utils_1.offsetAt)(position, this.text);
|
|
88
|
-
}
|
|
89
|
-
getMapper(uri) {
|
|
90
|
-
return new documents_1.IdentityMapper(uri);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
class DocumentFragmentSnapshot {
|
|
94
|
-
constructor(mapper, parent) {
|
|
95
|
-
this.mapper = mapper;
|
|
96
|
-
this.parent = parent;
|
|
97
|
-
this.parserError = null;
|
|
98
|
-
this.scriptKind = ts.ScriptKind.TSX;
|
|
99
|
-
this.scriptInfo = null;
|
|
100
|
-
const filePath = parent.getFilePath();
|
|
101
|
-
if (!filePath)
|
|
102
|
-
throw new Error('Cannot create a document fragment from a non-local document');
|
|
103
|
-
const text = parent.getText();
|
|
104
|
-
this.version = parent.version;
|
|
105
|
-
this.filePath = (0, utils_3.toVirtualAstroFilePath)(filePath);
|
|
106
|
-
this.url = (0, utils_3.toVirtualAstroFilePath)(filePath);
|
|
107
|
-
this.text = (0, astro2tsx_1.default)(text).code;
|
|
108
|
-
}
|
|
109
|
-
getText(start, end) {
|
|
110
|
-
return this.text.substring(start, end);
|
|
111
|
-
}
|
|
112
|
-
getLength() {
|
|
113
|
-
return this.text.length;
|
|
114
|
-
}
|
|
115
|
-
getFullText() {
|
|
116
|
-
return this.text;
|
|
117
|
-
}
|
|
118
|
-
getChangeRange() {
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
positionAt(offset) {
|
|
122
|
-
return (0, utils_1.positionAt)(offset, this.text);
|
|
123
|
-
}
|
|
124
|
-
getLineContainingOffset(offset) {
|
|
125
|
-
const chunks = this.getText(0, offset).split(os_1.EOL);
|
|
126
|
-
return chunks[chunks.length - 1];
|
|
127
|
-
}
|
|
128
|
-
offsetAt(position) {
|
|
129
|
-
return (0, utils_1.offsetAt)(position, this.text);
|
|
130
|
-
}
|
|
131
|
-
getOriginalPosition(pos) {
|
|
132
|
-
return this.mapper.getOriginalPosition(pos);
|
|
133
|
-
}
|
|
134
|
-
getGeneratedPosition(pos) {
|
|
135
|
-
return this.mapper.getGeneratedPosition(pos);
|
|
136
|
-
}
|
|
137
|
-
isInGenerated(pos) {
|
|
138
|
-
return !(0, utils_1.isInTag)(pos, this.parent.styleInfo);
|
|
139
|
-
}
|
|
140
|
-
getURL() {
|
|
141
|
-
return this.url;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
exports.DocumentFragmentSnapshot = DocumentFragmentSnapshot;
|
|
145
|
-
class TypeScriptDocumentSnapshot {
|
|
146
|
-
constructor(version, filePath, text) {
|
|
147
|
-
this.version = version;
|
|
148
|
-
this.filePath = filePath;
|
|
149
|
-
this.text = text;
|
|
150
|
-
this.scriptKind = (0, utils_3.getScriptKindFromFileName)(this.filePath);
|
|
151
|
-
this.scriptInfo = null;
|
|
152
|
-
this.parserError = null;
|
|
153
|
-
this.url = (0, utils_2.pathToUrl)(filePath);
|
|
154
|
-
}
|
|
155
|
-
getText(start, end) {
|
|
156
|
-
return this.text.substring(start, end);
|
|
157
|
-
}
|
|
158
|
-
getLength() {
|
|
159
|
-
return this.text.length;
|
|
160
|
-
}
|
|
161
|
-
getFullText() {
|
|
162
|
-
return this.text;
|
|
163
|
-
}
|
|
164
|
-
getChangeRange() {
|
|
165
|
-
return undefined;
|
|
166
|
-
}
|
|
167
|
-
positionAt(offset) {
|
|
168
|
-
return (0, utils_1.positionAt)(offset, this.text);
|
|
169
|
-
}
|
|
170
|
-
offsetAt(position) {
|
|
171
|
-
return (0, utils_1.offsetAt)(position, this.text);
|
|
172
|
-
}
|
|
173
|
-
async getFragment() {
|
|
174
|
-
return this;
|
|
175
|
-
}
|
|
176
|
-
getOriginalPosition(pos) {
|
|
177
|
-
return pos;
|
|
178
|
-
}
|
|
179
|
-
destroyFragment() {
|
|
180
|
-
// nothing to clean up
|
|
181
|
-
}
|
|
182
|
-
getLineContainingOffset(offset) {
|
|
183
|
-
const chunks = this.getText(0, offset).split('\n');
|
|
184
|
-
return chunks[chunks.length - 1];
|
|
185
|
-
}
|
|
186
|
-
update(changes) {
|
|
187
|
-
for (const change of changes) {
|
|
188
|
-
let start = 0;
|
|
189
|
-
let end = 0;
|
|
190
|
-
if ('range' in change) {
|
|
191
|
-
start = this.offsetAt(change.range.start);
|
|
192
|
-
end = this.offsetAt(change.range.end);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
end = this.getLength();
|
|
196
|
-
}
|
|
197
|
-
this.text = this.text.slice(0, start) + change.text + this.text.slice(end);
|
|
198
|
-
}
|
|
199
|
-
this.version++;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
exports.TypeScriptDocumentSnapshot = TypeScriptDocumentSnapshot;
|
|
@@ -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,97 +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
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.SnapshotManager = void 0;
|
|
23
|
-
const ts = __importStar(require("typescript"));
|
|
24
|
-
const utils_1 = require("./utils");
|
|
25
|
-
const DocumentSnapshot_1 = require("./DocumentSnapshot");
|
|
26
|
-
class SnapshotManager {
|
|
27
|
-
constructor(projectFiles, fileSpec, workspaceRoot) {
|
|
28
|
-
this.projectFiles = projectFiles;
|
|
29
|
-
this.fileSpec = fileSpec;
|
|
30
|
-
this.workspaceRoot = workspaceRoot;
|
|
31
|
-
this.documents = new Map();
|
|
32
|
-
this.lastLogged = new Date(new Date().getTime() - 60001);
|
|
33
|
-
this.watchExtensions = [ts.Extension.Dts, ts.Extension.Js, ts.Extension.Jsx, ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Json];
|
|
34
|
-
}
|
|
35
|
-
updateProjectFiles() {
|
|
36
|
-
const { include, exclude } = this.fileSpec;
|
|
37
|
-
if ((include === null || include === void 0 ? void 0 : include.length) === 0)
|
|
38
|
-
return;
|
|
39
|
-
const projectFiles = ts.sys.readDirectory(this.workspaceRoot, this.watchExtensions, exclude, include);
|
|
40
|
-
this.projectFiles = Array.from(new Set([...this.projectFiles, ...projectFiles]));
|
|
41
|
-
}
|
|
42
|
-
updateProjectFile(fileName, changes) {
|
|
43
|
-
const previousSnapshot = this.get(fileName);
|
|
44
|
-
if (changes) {
|
|
45
|
-
if (!(previousSnapshot instanceof DocumentSnapshot_1.TypeScriptDocumentSnapshot)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
previousSnapshot.update(changes);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
const newSnapshot = (0, DocumentSnapshot_1.createDocumentSnapshot)(fileName, null);
|
|
52
|
-
if (previousSnapshot) {
|
|
53
|
-
newSnapshot.version = previousSnapshot.version + 1;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
// ensure it's greater than initial version
|
|
57
|
-
// so that ts server picks up the change
|
|
58
|
-
newSnapshot.version += 1;
|
|
59
|
-
}
|
|
60
|
-
this.set(fileName, newSnapshot);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
has(fileName) {
|
|
64
|
-
return this.projectFiles.includes(fileName) || this.getFileNames().includes(fileName);
|
|
65
|
-
}
|
|
66
|
-
get(fileName) {
|
|
67
|
-
return this.documents.get(fileName);
|
|
68
|
-
}
|
|
69
|
-
set(fileName, snapshot) {
|
|
70
|
-
return this.documents.set(fileName, snapshot);
|
|
71
|
-
}
|
|
72
|
-
delete(fileName) {
|
|
73
|
-
this.projectFiles = this.projectFiles.filter((s) => s !== fileName);
|
|
74
|
-
return this.documents.delete(fileName);
|
|
75
|
-
}
|
|
76
|
-
getFileNames() {
|
|
77
|
-
return Array.from(this.documents.keys()).map((fileName) => (0, utils_1.toVirtualAstroFilePath)(fileName));
|
|
78
|
-
}
|
|
79
|
-
getProjectFileNames() {
|
|
80
|
-
return [...this.projectFiles];
|
|
81
|
-
}
|
|
82
|
-
logStatistics() {
|
|
83
|
-
const date = new Date();
|
|
84
|
-
// Don't use setInterval because that will keep tests running forever
|
|
85
|
-
if (date.getTime() - this.lastLogged.getTime() > 60000) {
|
|
86
|
-
this.lastLogged = date;
|
|
87
|
-
const projectFiles = this.getProjectFileNames();
|
|
88
|
-
const allFiles = Array.from(new Set([...projectFiles, ...this.getFileNames()]));
|
|
89
|
-
console.log('SnapshotManager File Statistics:\n' +
|
|
90
|
-
`Project files: ${projectFiles.length}\n` +
|
|
91
|
-
`Astro files: ${allFiles.filter((name) => name.endsWith('.astro')).length}\n` +
|
|
92
|
-
`From node_modules: ${allFiles.filter((name) => name.includes('node_modules')).length}\n` +
|
|
93
|
-
`Total: ${allFiles.length}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
exports.SnapshotManager = SnapshotManager;
|