@astrojs/language-server 0.9.3 → 0.12.1
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 +10 -9
- package/dist/plugins/PluginHost.js +30 -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 +22 -12
- package/dist/plugins/css/CSSPlugin.js +112 -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 +222 -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 +91 -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/server.js
CHANGED
|
@@ -1,42 +1,67 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const plugins_1 = require("./plugins");
|
|
26
|
+
exports.startLanguageServer = void 0;
|
|
27
|
+
const vscode = __importStar(require("vscode-languageserver"));
|
|
28
|
+
const ConfigManager_1 = require("./core/config/ConfigManager");
|
|
29
|
+
const DocumentManager_1 = require("./core/documents/DocumentManager");
|
|
8
30
|
const DiagnosticsManager_1 = require("./core/DiagnosticsManager");
|
|
31
|
+
const AstroPlugin_1 = require("./plugins/astro/AstroPlugin");
|
|
32
|
+
const CSSPlugin_1 = require("./plugins/css/CSSPlugin");
|
|
33
|
+
const HTMLPlugin_1 = require("./plugins/html/HTMLPlugin");
|
|
34
|
+
const PluginHost_1 = require("./plugins/PluginHost");
|
|
35
|
+
const TypeScriptPlugin_1 = require("./plugins/typescript/TypeScriptPlugin");
|
|
9
36
|
const utils_1 = require("./utils");
|
|
10
|
-
const TagCloseRequest = new
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
21
|
-
const workspaceUris = (_b = (_a = evt.workspaceFolders) === null || _a === void 0 ? void 0 : _a.map((folder) => folder.uri.toString())) !== null && _b !== void 0 ? _b : [(_c = evt.rootUri) !== null && _c !== void 0 ? _c : ''];
|
|
37
|
+
const TagCloseRequest = new vscode.RequestType('html/tag');
|
|
38
|
+
// Start the language server
|
|
39
|
+
function startLanguageServer(connection) {
|
|
40
|
+
// Create our managers
|
|
41
|
+
const configManager = new ConfigManager_1.ConfigManager();
|
|
42
|
+
const documentManager = new DocumentManager_1.DocumentManager();
|
|
43
|
+
const pluginHost = new PluginHost_1.PluginHost(documentManager);
|
|
44
|
+
connection.onInitialize((params) => {
|
|
45
|
+
var _a, _b, _c, _d, _e, _f;
|
|
46
|
+
const workspaceUris = (_b = (_a = params.workspaceFolders) === null || _a === void 0 ? void 0 : _a.map((folder) => folder.uri.toString())) !== null && _b !== void 0 ? _b : [(_c = params.rootUri) !== null && _c !== void 0 ? _c : ''];
|
|
22
47
|
pluginHost.initialize({
|
|
23
|
-
filterIncompleteCompletions: !((_d =
|
|
24
|
-
definitionLinkSupport: !!((_f = (_e =
|
|
48
|
+
filterIncompleteCompletions: !((_d = params.initializationOptions) === null || _d === void 0 ? void 0 : _d.dontFilterIncompleteCompletions),
|
|
49
|
+
definitionLinkSupport: !!((_f = (_e = params.capabilities.textDocument) === null || _e === void 0 ? void 0 : _e.definition) === null || _f === void 0 ? void 0 : _f.linkSupport),
|
|
25
50
|
});
|
|
26
|
-
|
|
27
|
-
pluginHost.
|
|
28
|
-
pluginHost.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
configManager.updateEmmetConfig(
|
|
51
|
+
// Register plugins
|
|
52
|
+
pluginHost.registerPlugin(new HTMLPlugin_1.HTMLPlugin(configManager));
|
|
53
|
+
pluginHost.registerPlugin(new CSSPlugin_1.CSSPlugin(configManager));
|
|
54
|
+
// We don't currently support running the TypeScript and Astro plugin in the browser
|
|
55
|
+
if (params.initializationOptions.environment !== 'browser') {
|
|
56
|
+
pluginHost.registerPlugin(new AstroPlugin_1.AstroPlugin(documentManager, configManager, workspaceUris));
|
|
57
|
+
pluginHost.registerPlugin(new TypeScriptPlugin_1.TypeScriptPlugin(documentManager, configManager, workspaceUris));
|
|
58
|
+
}
|
|
59
|
+
// Update language-server config with what the user supplied to us at launch
|
|
60
|
+
configManager.updateConfig(params.initializationOptions.configuration.astro);
|
|
61
|
+
configManager.updateEmmetConfig(params.initializationOptions.configuration.emmet);
|
|
37
62
|
return {
|
|
38
63
|
capabilities: {
|
|
39
|
-
textDocumentSync:
|
|
64
|
+
textDocumentSync: vscode.TextDocumentSyncKind.Incremental,
|
|
40
65
|
foldingRangeProvider: true,
|
|
41
66
|
definitionProvider: true,
|
|
42
67
|
renameProvider: true,
|
|
@@ -69,6 +94,7 @@ function startServer() {
|
|
|
69
94
|
':',
|
|
70
95
|
],
|
|
71
96
|
},
|
|
97
|
+
colorProvider: true,
|
|
72
98
|
hoverProvider: true,
|
|
73
99
|
signatureHelpProvider: {
|
|
74
100
|
triggerCharacters: ['(', ',', '<'],
|
|
@@ -77,17 +103,22 @@ function startServer() {
|
|
|
77
103
|
},
|
|
78
104
|
};
|
|
79
105
|
});
|
|
106
|
+
// On update of the user configuration of the language-server
|
|
107
|
+
connection.onDidChangeConfiguration(({ settings }) => {
|
|
108
|
+
configManager.updateConfig(settings.astro);
|
|
109
|
+
configManager.updateEmmetConfig(settings.emmet);
|
|
110
|
+
});
|
|
80
111
|
// Documents
|
|
81
|
-
connection.onDidOpenTextDocument((
|
|
82
|
-
|
|
83
|
-
|
|
112
|
+
connection.onDidOpenTextDocument((params) => {
|
|
113
|
+
documentManager.openDocument(params.textDocument);
|
|
114
|
+
documentManager.markAsOpenedInClient(params.textDocument.uri);
|
|
84
115
|
});
|
|
85
|
-
connection.onDidCloseTextDocument((
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
connection.onDidChangeTextDocument((evt) => {
|
|
89
|
-
docManager.updateDocument(evt.textDocument.uri, evt.contentChanges);
|
|
116
|
+
connection.onDidCloseTextDocument((params) => documentManager.closeDocument(params.textDocument.uri));
|
|
117
|
+
connection.onDidChangeTextDocument((params) => {
|
|
118
|
+
documentManager.updateDocument(params.textDocument, params.contentChanges);
|
|
90
119
|
});
|
|
120
|
+
const diagnosticsManager = new DiagnosticsManager_1.DiagnosticsManager(connection.sendDiagnostics, documentManager, pluginHost.getDiagnostics.bind(pluginHost));
|
|
121
|
+
const updateAllDiagnostics = (0, utils_1.debounceThrottle)(() => diagnosticsManager.updateAll(), 1000);
|
|
91
122
|
connection.onDidChangeWatchedFiles((evt) => {
|
|
92
123
|
const params = evt.changes
|
|
93
124
|
.map((change) => ({
|
|
@@ -98,15 +129,10 @@ function startServer() {
|
|
|
98
129
|
pluginHost.onWatchFileChanges(params);
|
|
99
130
|
updateAllDiagnostics();
|
|
100
131
|
});
|
|
101
|
-
//connection.onDidChangeTextDocument(updateAllDiagnostics);
|
|
102
|
-
// Config
|
|
103
|
-
connection.onDidChangeConfiguration(({ settings }) => {
|
|
104
|
-
var _a;
|
|
105
|
-
configManager.update((_a = settings.astro) === null || _a === void 0 ? void 0 : _a.plugin);
|
|
106
|
-
configManager.updateEmmetConfig(settings.emmet);
|
|
107
|
-
configManager.updateTsJsUserPreferences(settings);
|
|
108
|
-
});
|
|
109
132
|
// Features
|
|
133
|
+
connection.onHover((params) => pluginHost.doHover(params.textDocument, params.position));
|
|
134
|
+
connection.onDefinition((evt) => pluginHost.getDefinitions(evt.textDocument, evt.position));
|
|
135
|
+
connection.onFoldingRanges((evt) => pluginHost.getFoldingRanges(evt.textDocument));
|
|
110
136
|
connection.onCompletion(async (evt) => {
|
|
111
137
|
const promise = pluginHost.getCompletions(evt.textDocument, evt.position, evt.context);
|
|
112
138
|
return promise;
|
|
@@ -118,14 +144,25 @@ function startServer() {
|
|
|
118
144
|
}
|
|
119
145
|
return pluginHost.resolveCompletion(data, completionItem);
|
|
120
146
|
});
|
|
121
|
-
connection.
|
|
122
|
-
connection.
|
|
123
|
-
connection.onFoldingRanges((evt) => pluginHost.getFoldingRanges(evt.textDocument));
|
|
147
|
+
connection.onDocumentColor((params) => pluginHost.getDocumentColors(params.textDocument));
|
|
148
|
+
connection.onColorPresentation((params) => pluginHost.getColorPresentations(params.textDocument, params.range, params.color));
|
|
124
149
|
connection.onRequest(TagCloseRequest, (evt) => pluginHost.doTagComplete(evt.textDocument, evt.position));
|
|
125
150
|
connection.onSignatureHelp((evt, cancellationToken) => pluginHost.getSignatureHelp(evt.textDocument, evt.position, evt.context, cancellationToken));
|
|
126
|
-
connection.onRenameRequest(evt => pluginHost.rename(evt.textDocument, evt.position, evt.newName));
|
|
127
|
-
|
|
128
|
-
|
|
151
|
+
connection.onRenameRequest((evt) => pluginHost.rename(evt.textDocument, evt.position, evt.newName));
|
|
152
|
+
connection.onDidSaveTextDocument(updateAllDiagnostics);
|
|
153
|
+
connection.onNotification('$/onDidChangeNonAstroFile', async (e) => {
|
|
154
|
+
const path = (0, utils_1.urlToPath)(e.uri);
|
|
155
|
+
if (path) {
|
|
156
|
+
pluginHost.updateNonAstroFile(path, e.changes);
|
|
157
|
+
}
|
|
158
|
+
updateAllDiagnostics();
|
|
159
|
+
});
|
|
160
|
+
documentManager.on('documentChange', (0, utils_1.debounceThrottle)(async (document) => diagnosticsManager.update(document), 1000));
|
|
161
|
+
documentManager.on('documentClose', (document) => diagnosticsManager.removeDiagnostics(document));
|
|
162
|
+
// Taking off 🚀
|
|
163
|
+
connection.onInitialized(() => {
|
|
164
|
+
connection.console.log('Successfully initialized! 🚀');
|
|
165
|
+
});
|
|
129
166
|
connection.listen();
|
|
130
167
|
}
|
|
131
|
-
exports.
|
|
168
|
+
exports.startLanguageServer = startLanguageServer;
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,10 +2,20 @@ import { Position, Range } from 'vscode-languageserver';
|
|
|
2
2
|
import { Node } from 'vscode-html-languageservice';
|
|
3
3
|
/** Normalizes a document URI */
|
|
4
4
|
export declare function normalizeUri(uri: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Some paths (on windows) start with a upper case driver letter, some don't.
|
|
7
|
+
* This is normalized here.
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizePath(path: string): string;
|
|
5
10
|
/** Turns a URL into a normalized FS Path */
|
|
6
11
|
export declare function urlToPath(stringUrl: string): string | null;
|
|
7
12
|
/** Converts a path to a URL */
|
|
8
13
|
export declare function pathToUrl(path: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Given a path like foo/bar or foo/bar.astro , returns its last path
|
|
16
|
+
* (bar or bar.astro in this example).
|
|
17
|
+
*/
|
|
18
|
+
export declare function getLastPartOfPath(path: string): string;
|
|
9
19
|
/**
|
|
10
20
|
*
|
|
11
21
|
* The language service is case insensitive, and would provide
|
|
@@ -25,9 +35,7 @@ export declare function flatten<T>(arr: T[][]): T[];
|
|
|
25
35
|
/** Clamps a number between min and max */
|
|
26
36
|
export declare function clamp(num: number, min: number, max: number): number;
|
|
27
37
|
export declare function isNotNullOrUndefined<T>(val: T | undefined | null): val is T;
|
|
28
|
-
|
|
29
|
-
export declare function isInRange(positionToTest: Position, range: Range): boolean;
|
|
30
|
-
/** */
|
|
38
|
+
export declare function isInRange(range: Range, positionToTest: Position): boolean;
|
|
31
39
|
export declare function isBeforeOrEqualToPosition(position: Position, positionToTest: Position): boolean;
|
|
32
40
|
/**
|
|
33
41
|
* Debounces a function but cancels previous invocation only if
|
|
@@ -35,15 +43,15 @@ export declare function isBeforeOrEqualToPosition(position: Position, positionTo
|
|
|
35
43
|
*
|
|
36
44
|
* @param fn The function with it's argument
|
|
37
45
|
* @param determineIfSame The function which determines if the previous invocation should be canceld or not
|
|
38
|
-
* @param
|
|
46
|
+
* @param milliseconds Number of miliseconds to debounce
|
|
39
47
|
*/
|
|
40
|
-
export declare function debounceSameArg<T>(fn: (arg: T) => void, shouldCancelPrevious: (newArg: T, prevArg?: T) => boolean,
|
|
48
|
+
export declare function debounceSameArg<T>(fn: (arg: T) => void, shouldCancelPrevious: (newArg: T, prevArg?: T) => boolean, milliseconds: number): (arg: T) => void;
|
|
41
49
|
/**
|
|
42
|
-
* Debounces a function but also waits at minimum the specified number of
|
|
50
|
+
* Debounces a function but also waits at minimum the specified number of milliseconds until
|
|
43
51
|
* the next invocation. This avoids needless calls when a synchronous call (like diagnostics)
|
|
44
52
|
* took too long and the whole timeout of the next call was eaten up already.
|
|
45
53
|
*
|
|
46
54
|
* @param fn The function with it's argument
|
|
47
|
-
* @param
|
|
55
|
+
* @param milliseconds Number of milliseconds to debounce/throttle
|
|
48
56
|
*/
|
|
49
|
-
export declare function debounceThrottle<T extends (...args: any) => void>(fn: T,
|
|
57
|
+
export declare function debounceThrottle<T extends (...args: any) => void>(fn: T, milliseconds: number): T;
|
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.1",
|
|
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;
|