@astrojs/language-server 0.11.0 → 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 +6 -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 +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 +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 +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 -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 +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 +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 +16 -23
- package/dist/plugins/typescript/TypeScriptPlugin.js +43 -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 +17 -37
- 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/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 +8 -12
- package/dist/plugins/typescript/utils.js +105 -158
- 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 +18 -12
- 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
|
@@ -1,73 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
const
|
|
28
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
6
|
+
exports.ensureRealFilePath = exports.ensureRealAstroFilePath = exports.toRealAstroFilePath = exports.toVirtualFilePath = exports.toVirtualAstroFilePath = exports.isVirtualFilePath = exports.isVirtualSvelteFilePath = exports.isVirtualVueFilePath = exports.isVirtualAstroFilePath = exports.isFrameworkFilePath = exports.isAstroFilePath = exports.isVirtualFrameworkFilePath = exports.getFrameworkFromFilePath = exports.convertToLocationRange = exports.convertRange = exports.mapSeverity = exports.getScriptKindFromFileName = exports.isSubPath = exports.findTsConfigPath = exports.getExtensionFromScriptKind = exports.getCommitCharactersForScriptElement = exports.scriptElementKindToCompletionItemKind = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
29
8
|
const path_1 = require("path");
|
|
30
9
|
const utils_1 = require("../../utils");
|
|
10
|
+
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
31
11
|
const documents_1 = require("../../core/documents");
|
|
32
12
|
function scriptElementKindToCompletionItemKind(kind) {
|
|
33
13
|
switch (kind) {
|
|
34
|
-
case
|
|
35
|
-
case
|
|
14
|
+
case typescript_1.default.ScriptElementKind.primitiveType:
|
|
15
|
+
case typescript_1.default.ScriptElementKind.keyword:
|
|
36
16
|
return vscode_languageserver_1.CompletionItemKind.Keyword;
|
|
37
|
-
case
|
|
17
|
+
case typescript_1.default.ScriptElementKind.constElement:
|
|
38
18
|
return vscode_languageserver_1.CompletionItemKind.Constant;
|
|
39
|
-
case
|
|
40
|
-
case
|
|
41
|
-
case
|
|
42
|
-
case
|
|
19
|
+
case typescript_1.default.ScriptElementKind.letElement:
|
|
20
|
+
case typescript_1.default.ScriptElementKind.variableElement:
|
|
21
|
+
case typescript_1.default.ScriptElementKind.localVariableElement:
|
|
22
|
+
case typescript_1.default.ScriptElementKind.alias:
|
|
43
23
|
return vscode_languageserver_1.CompletionItemKind.Variable;
|
|
44
|
-
case
|
|
45
|
-
case
|
|
46
|
-
case
|
|
24
|
+
case typescript_1.default.ScriptElementKind.memberVariableElement:
|
|
25
|
+
case typescript_1.default.ScriptElementKind.memberGetAccessorElement:
|
|
26
|
+
case typescript_1.default.ScriptElementKind.memberSetAccessorElement:
|
|
47
27
|
return vscode_languageserver_1.CompletionItemKind.Field;
|
|
48
|
-
case
|
|
28
|
+
case typescript_1.default.ScriptElementKind.functionElement:
|
|
49
29
|
return vscode_languageserver_1.CompletionItemKind.Function;
|
|
50
|
-
case
|
|
51
|
-
case
|
|
52
|
-
case
|
|
53
|
-
case
|
|
30
|
+
case typescript_1.default.ScriptElementKind.memberFunctionElement:
|
|
31
|
+
case typescript_1.default.ScriptElementKind.constructSignatureElement:
|
|
32
|
+
case typescript_1.default.ScriptElementKind.callSignatureElement:
|
|
33
|
+
case typescript_1.default.ScriptElementKind.indexSignatureElement:
|
|
54
34
|
return vscode_languageserver_1.CompletionItemKind.Method;
|
|
55
|
-
case
|
|
35
|
+
case typescript_1.default.ScriptElementKind.enumElement:
|
|
56
36
|
return vscode_languageserver_1.CompletionItemKind.Enum;
|
|
57
|
-
case
|
|
58
|
-
case
|
|
37
|
+
case typescript_1.default.ScriptElementKind.moduleElement:
|
|
38
|
+
case typescript_1.default.ScriptElementKind.externalModuleName:
|
|
59
39
|
return vscode_languageserver_1.CompletionItemKind.Module;
|
|
60
|
-
case
|
|
61
|
-
case
|
|
40
|
+
case typescript_1.default.ScriptElementKind.classElement:
|
|
41
|
+
case typescript_1.default.ScriptElementKind.typeElement:
|
|
62
42
|
return vscode_languageserver_1.CompletionItemKind.Class;
|
|
63
|
-
case
|
|
43
|
+
case typescript_1.default.ScriptElementKind.interfaceElement:
|
|
64
44
|
return vscode_languageserver_1.CompletionItemKind.Interface;
|
|
65
|
-
case
|
|
66
|
-
case
|
|
45
|
+
case typescript_1.default.ScriptElementKind.warning:
|
|
46
|
+
case typescript_1.default.ScriptElementKind.scriptElement:
|
|
67
47
|
return vscode_languageserver_1.CompletionItemKind.File;
|
|
68
|
-
case
|
|
48
|
+
case typescript_1.default.ScriptElementKind.directory:
|
|
69
49
|
return vscode_languageserver_1.CompletionItemKind.Folder;
|
|
70
|
-
case
|
|
50
|
+
case typescript_1.default.ScriptElementKind.string:
|
|
71
51
|
return vscode_languageserver_1.CompletionItemKind.Constant;
|
|
72
52
|
}
|
|
73
53
|
return vscode_languageserver_1.CompletionItemKind.Property;
|
|
@@ -76,25 +56,25 @@ exports.scriptElementKindToCompletionItemKind = scriptElementKindToCompletionIte
|
|
|
76
56
|
function getCommitCharactersForScriptElement(kind) {
|
|
77
57
|
const commitCharacters = [];
|
|
78
58
|
switch (kind) {
|
|
79
|
-
case
|
|
80
|
-
case
|
|
81
|
-
case
|
|
82
|
-
case
|
|
83
|
-
case
|
|
84
|
-
case
|
|
85
|
-
case
|
|
59
|
+
case typescript_1.default.ScriptElementKind.memberGetAccessorElement:
|
|
60
|
+
case typescript_1.default.ScriptElementKind.memberSetAccessorElement:
|
|
61
|
+
case typescript_1.default.ScriptElementKind.constructSignatureElement:
|
|
62
|
+
case typescript_1.default.ScriptElementKind.callSignatureElement:
|
|
63
|
+
case typescript_1.default.ScriptElementKind.indexSignatureElement:
|
|
64
|
+
case typescript_1.default.ScriptElementKind.enumElement:
|
|
65
|
+
case typescript_1.default.ScriptElementKind.interfaceElement:
|
|
86
66
|
commitCharacters.push('.');
|
|
87
67
|
break;
|
|
88
|
-
case
|
|
89
|
-
case
|
|
90
|
-
case
|
|
91
|
-
case
|
|
92
|
-
case
|
|
93
|
-
case
|
|
94
|
-
case
|
|
95
|
-
case
|
|
96
|
-
case
|
|
97
|
-
case
|
|
68
|
+
case typescript_1.default.ScriptElementKind.moduleElement:
|
|
69
|
+
case typescript_1.default.ScriptElementKind.alias:
|
|
70
|
+
case typescript_1.default.ScriptElementKind.constElement:
|
|
71
|
+
case typescript_1.default.ScriptElementKind.letElement:
|
|
72
|
+
case typescript_1.default.ScriptElementKind.variableElement:
|
|
73
|
+
case typescript_1.default.ScriptElementKind.localVariableElement:
|
|
74
|
+
case typescript_1.default.ScriptElementKind.memberVariableElement:
|
|
75
|
+
case typescript_1.default.ScriptElementKind.classElement:
|
|
76
|
+
case typescript_1.default.ScriptElementKind.functionElement:
|
|
77
|
+
case typescript_1.default.ScriptElementKind.memberFunctionElement:
|
|
98
78
|
commitCharacters.push('.', ',');
|
|
99
79
|
commitCharacters.push('(');
|
|
100
80
|
break;
|
|
@@ -102,54 +82,66 @@ function getCommitCharactersForScriptElement(kind) {
|
|
|
102
82
|
return commitCharacters.length === 0 ? undefined : commitCharacters;
|
|
103
83
|
}
|
|
104
84
|
exports.getCommitCharactersForScriptElement = getCommitCharactersForScriptElement;
|
|
105
|
-
function
|
|
106
|
-
switch (
|
|
107
|
-
case
|
|
108
|
-
return
|
|
109
|
-
case
|
|
110
|
-
return
|
|
111
|
-
case
|
|
112
|
-
return
|
|
113
|
-
case
|
|
114
|
-
return
|
|
85
|
+
function getExtensionFromScriptKind(kind) {
|
|
86
|
+
switch (kind) {
|
|
87
|
+
case typescript_1.default.ScriptKind.JSX:
|
|
88
|
+
return typescript_1.default.Extension.Jsx;
|
|
89
|
+
case typescript_1.default.ScriptKind.TS:
|
|
90
|
+
return typescript_1.default.Extension.Ts;
|
|
91
|
+
case typescript_1.default.ScriptKind.TSX:
|
|
92
|
+
return typescript_1.default.Extension.Tsx;
|
|
93
|
+
case typescript_1.default.ScriptKind.JSON:
|
|
94
|
+
return typescript_1.default.Extension.Json;
|
|
95
|
+
case typescript_1.default.ScriptKind.JS:
|
|
96
|
+
default:
|
|
97
|
+
return typescript_1.default.Extension.Js;
|
|
115
98
|
}
|
|
116
|
-
return vscode_languageserver_1.DiagnosticSeverity.Error;
|
|
117
99
|
}
|
|
118
|
-
exports.
|
|
100
|
+
exports.getExtensionFromScriptKind = getExtensionFromScriptKind;
|
|
101
|
+
function findTsConfigPath(fileName, rootUris) {
|
|
102
|
+
const searchDir = (0, path_1.dirname)(fileName);
|
|
103
|
+
const path = typescript_1.default.findConfigFile(searchDir, typescript_1.default.sys.fileExists, 'tsconfig.json') ||
|
|
104
|
+
typescript_1.default.findConfigFile(searchDir, typescript_1.default.sys.fileExists, 'jsconfig.json') ||
|
|
105
|
+
'';
|
|
106
|
+
// Don't return config files that exceed the current workspace context.
|
|
107
|
+
return !!path && rootUris.some((rootUri) => isSubPath(rootUri, path)) ? path : '';
|
|
108
|
+
}
|
|
109
|
+
exports.findTsConfigPath = findTsConfigPath;
|
|
110
|
+
function isSubPath(uri, possibleSubPath) {
|
|
111
|
+
return (0, utils_1.pathToUrl)(possibleSubPath).startsWith(uri);
|
|
112
|
+
}
|
|
113
|
+
exports.isSubPath = isSubPath;
|
|
119
114
|
function getScriptKindFromFileName(fileName) {
|
|
120
|
-
const ext = fileName.
|
|
115
|
+
const ext = fileName.substring(fileName.lastIndexOf('.'));
|
|
121
116
|
switch (ext.toLowerCase()) {
|
|
122
|
-
case
|
|
123
|
-
return
|
|
124
|
-
case
|
|
125
|
-
return
|
|
126
|
-
case
|
|
127
|
-
return
|
|
128
|
-
case
|
|
129
|
-
return
|
|
130
|
-
case
|
|
131
|
-
return
|
|
117
|
+
case typescript_1.default.Extension.Js:
|
|
118
|
+
return typescript_1.default.ScriptKind.JS;
|
|
119
|
+
case typescript_1.default.Extension.Jsx:
|
|
120
|
+
return typescript_1.default.ScriptKind.JSX;
|
|
121
|
+
case typescript_1.default.Extension.Ts:
|
|
122
|
+
return typescript_1.default.ScriptKind.TS;
|
|
123
|
+
case typescript_1.default.Extension.Tsx:
|
|
124
|
+
return typescript_1.default.ScriptKind.TSX;
|
|
125
|
+
case typescript_1.default.Extension.Json:
|
|
126
|
+
return typescript_1.default.ScriptKind.JSON;
|
|
132
127
|
default:
|
|
133
|
-
return
|
|
128
|
+
return typescript_1.default.ScriptKind.Unknown;
|
|
134
129
|
}
|
|
135
130
|
}
|
|
136
131
|
exports.getScriptKindFromFileName = getScriptKindFromFileName;
|
|
137
|
-
function
|
|
138
|
-
switch (
|
|
139
|
-
case
|
|
140
|
-
return
|
|
141
|
-
case
|
|
142
|
-
return
|
|
143
|
-
case
|
|
144
|
-
return
|
|
145
|
-
case
|
|
146
|
-
return
|
|
147
|
-
case ts.ScriptKind.JS:
|
|
148
|
-
default:
|
|
149
|
-
return ts.Extension.Js;
|
|
132
|
+
function mapSeverity(category) {
|
|
133
|
+
switch (category) {
|
|
134
|
+
case typescript_1.default.DiagnosticCategory.Error:
|
|
135
|
+
return vscode_languageserver_1.DiagnosticSeverity.Error;
|
|
136
|
+
case typescript_1.default.DiagnosticCategory.Warning:
|
|
137
|
+
return vscode_languageserver_1.DiagnosticSeverity.Warning;
|
|
138
|
+
case typescript_1.default.DiagnosticCategory.Suggestion:
|
|
139
|
+
return vscode_languageserver_1.DiagnosticSeverity.Hint;
|
|
140
|
+
case typescript_1.default.DiagnosticCategory.Message:
|
|
141
|
+
return vscode_languageserver_1.DiagnosticSeverity.Information;
|
|
150
142
|
}
|
|
151
143
|
}
|
|
152
|
-
exports.
|
|
144
|
+
exports.mapSeverity = mapSeverity;
|
|
153
145
|
function convertRange(document, range) {
|
|
154
146
|
return vscode_languageserver_1.Range.create(document.positionAt(range.start || 0), document.positionAt((range.start || 0) + (range.length || 0)));
|
|
155
147
|
}
|
|
@@ -169,8 +161,13 @@ function convertToLocationRange(defDoc, textSpan) {
|
|
|
169
161
|
exports.convertToLocationRange = convertToLocationRange;
|
|
170
162
|
const VirtualExtension = {
|
|
171
163
|
ts: 'ts',
|
|
172
|
-
tsx: 'tsx'
|
|
164
|
+
tsx: 'tsx',
|
|
173
165
|
};
|
|
166
|
+
function getFrameworkFromFilePath(filePath) {
|
|
167
|
+
filePath = ensureRealFilePath(filePath);
|
|
168
|
+
return (0, path_1.extname)(filePath).substring(1);
|
|
169
|
+
}
|
|
170
|
+
exports.getFrameworkFromFilePath = getFrameworkFromFilePath;
|
|
174
171
|
function isVirtualFrameworkFilePath(ext, virtualExt, filePath) {
|
|
175
172
|
return filePath.endsWith('.' + ext + '.' + virtualExt);
|
|
176
173
|
}
|
|
@@ -191,20 +188,12 @@ function isVirtualVueFilePath(filePath) {
|
|
|
191
188
|
return isVirtualFrameworkFilePath('vue', VirtualExtension.tsx, filePath);
|
|
192
189
|
}
|
|
193
190
|
exports.isVirtualVueFilePath = isVirtualVueFilePath;
|
|
194
|
-
function isVirtualJsxFilePath(filePath) {
|
|
195
|
-
return isVirtualFrameworkFilePath('jsx', VirtualExtension.ts, filePath) || isVirtualFrameworkFilePath('tsx', VirtualExtension.ts, filePath);
|
|
196
|
-
}
|
|
197
|
-
exports.isVirtualJsxFilePath = isVirtualJsxFilePath;
|
|
198
191
|
function isVirtualSvelteFilePath(filePath) {
|
|
199
192
|
return isVirtualFrameworkFilePath('svelte', VirtualExtension.tsx, filePath);
|
|
200
193
|
}
|
|
201
194
|
exports.isVirtualSvelteFilePath = isVirtualSvelteFilePath;
|
|
202
|
-
function isVirtualTsFilePath(filePath) {
|
|
203
|
-
return isVirtualFrameworkFilePath('ts', VirtualExtension.tsx, filePath);
|
|
204
|
-
}
|
|
205
|
-
exports.isVirtualTsFilePath = isVirtualTsFilePath;
|
|
206
195
|
function isVirtualFilePath(filePath) {
|
|
207
|
-
return isVirtualAstroFilePath(filePath) || isVirtualVueFilePath(filePath) || isVirtualSvelteFilePath(filePath)
|
|
196
|
+
return isVirtualAstroFilePath(filePath) || isVirtualVueFilePath(filePath) || isVirtualSvelteFilePath(filePath);
|
|
208
197
|
}
|
|
209
198
|
exports.isVirtualFilePath = isVirtualFilePath;
|
|
210
199
|
function toVirtualAstroFilePath(filePath) {
|
|
@@ -223,7 +212,7 @@ function toVirtualFilePath(filePath) {
|
|
|
223
212
|
if (isVirtualFilePath(filePath)) {
|
|
224
213
|
return filePath;
|
|
225
214
|
}
|
|
226
|
-
else if (isFrameworkFilePath(filePath) || isAstroFilePath(filePath)
|
|
215
|
+
else if (isFrameworkFilePath(filePath) || isAstroFilePath(filePath)) {
|
|
227
216
|
return `${filePath}.tsx`;
|
|
228
217
|
}
|
|
229
218
|
else {
|
|
@@ -249,45 +238,3 @@ function ensureRealFilePath(filePath) {
|
|
|
249
238
|
}
|
|
250
239
|
}
|
|
251
240
|
exports.ensureRealFilePath = ensureRealFilePath;
|
|
252
|
-
function findTsConfigPath(fileName, rootUris) {
|
|
253
|
-
const searchDir = (0, path_1.dirname)(fileName);
|
|
254
|
-
const path = ts.findConfigFile(searchDir, ts.sys.fileExists, 'tsconfig.json') || ts.findConfigFile(searchDir, ts.sys.fileExists, 'jsconfig.json') || '';
|
|
255
|
-
// Don't return config files that exceed the current workspace context.
|
|
256
|
-
return !!path && rootUris.some((rootUri) => isSubPath(rootUri, path)) ? path : '';
|
|
257
|
-
}
|
|
258
|
-
exports.findTsConfigPath = findTsConfigPath;
|
|
259
|
-
/** */
|
|
260
|
-
function isSubPath(uri, possibleSubPath) {
|
|
261
|
-
return (0, utils_1.pathToUrl)(possibleSubPath).startsWith(uri);
|
|
262
|
-
}
|
|
263
|
-
exports.isSubPath = isSubPath;
|
|
264
|
-
/** Substitutes */
|
|
265
|
-
function substituteWithWhitespace(result, start, end, oldContent, before, after) {
|
|
266
|
-
let accumulatedWS = 0;
|
|
267
|
-
result += before;
|
|
268
|
-
for (let i = start + before.length; i < end; i++) {
|
|
269
|
-
let ch = oldContent[i];
|
|
270
|
-
if (ch === '\n' || ch === '\r') {
|
|
271
|
-
// only write new lines, skip the whitespace
|
|
272
|
-
accumulatedWS = 0;
|
|
273
|
-
result += ch;
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
accumulatedWS++;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
result = append(result, ' ', accumulatedWS - after.length);
|
|
280
|
-
result += after;
|
|
281
|
-
return result;
|
|
282
|
-
}
|
|
283
|
-
exports.substituteWithWhitespace = substituteWithWhitespace;
|
|
284
|
-
function append(result, str, n) {
|
|
285
|
-
while (n > 0) {
|
|
286
|
-
if (n & 1) {
|
|
287
|
-
result += str;
|
|
288
|
-
}
|
|
289
|
-
n >>= 1;
|
|
290
|
-
str += str;
|
|
291
|
-
}
|
|
292
|
-
return result;
|
|
293
|
-
}
|
package/dist/server.d.ts
CHANGED
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,
|
|
@@ -77,17 +102,22 @@ function startServer() {
|
|
|
77
102
|
},
|
|
78
103
|
};
|
|
79
104
|
});
|
|
105
|
+
// On update of the user configuration of the language-server
|
|
106
|
+
connection.onDidChangeConfiguration(({ settings }) => {
|
|
107
|
+
configManager.updateConfig(settings.astro);
|
|
108
|
+
configManager.updateEmmetConfig(settings.emmet);
|
|
109
|
+
});
|
|
80
110
|
// Documents
|
|
81
|
-
connection.onDidOpenTextDocument((
|
|
82
|
-
|
|
83
|
-
|
|
111
|
+
connection.onDidOpenTextDocument((params) => {
|
|
112
|
+
documentManager.openDocument(params.textDocument);
|
|
113
|
+
documentManager.markAsOpenedInClient(params.textDocument.uri);
|
|
84
114
|
});
|
|
85
|
-
connection.onDidCloseTextDocument((
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
connection.onDidChangeTextDocument((evt) => {
|
|
89
|
-
docManager.updateDocument(evt.textDocument.uri, evt.contentChanges);
|
|
115
|
+
connection.onDidCloseTextDocument((params) => documentManager.closeDocument(params.textDocument.uri));
|
|
116
|
+
connection.onDidChangeTextDocument((params) => {
|
|
117
|
+
documentManager.updateDocument(params.textDocument, params.contentChanges);
|
|
90
118
|
});
|
|
119
|
+
const diagnosticsManager = new DiagnosticsManager_1.DiagnosticsManager(connection.sendDiagnostics, documentManager, pluginHost.getDiagnostics.bind(pluginHost));
|
|
120
|
+
const updateAllDiagnostics = (0, utils_1.debounceThrottle)(() => diagnosticsManager.updateAll(), 1000);
|
|
91
121
|
connection.onDidChangeWatchedFiles((evt) => {
|
|
92
122
|
const params = evt.changes
|
|
93
123
|
.map((change) => ({
|
|
@@ -98,15 +128,10 @@ function startServer() {
|
|
|
98
128
|
pluginHost.onWatchFileChanges(params);
|
|
99
129
|
updateAllDiagnostics();
|
|
100
130
|
});
|
|
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
131
|
// Features
|
|
132
|
+
connection.onHover((params) => pluginHost.doHover(params.textDocument, params.position));
|
|
133
|
+
connection.onDefinition((evt) => pluginHost.getDefinitions(evt.textDocument, evt.position));
|
|
134
|
+
connection.onFoldingRanges((evt) => pluginHost.getFoldingRanges(evt.textDocument));
|
|
110
135
|
connection.onCompletion(async (evt) => {
|
|
111
136
|
const promise = pluginHost.getCompletions(evt.textDocument, evt.position, evt.context);
|
|
112
137
|
return promise;
|
|
@@ -118,14 +143,23 @@ function startServer() {
|
|
|
118
143
|
}
|
|
119
144
|
return pluginHost.resolveCompletion(data, completionItem);
|
|
120
145
|
});
|
|
121
|
-
connection.onHover((evt) => pluginHost.doHover(evt.textDocument, evt.position));
|
|
122
|
-
connection.onDefinition((evt) => pluginHost.getDefinitions(evt.textDocument, evt.position));
|
|
123
|
-
connection.onFoldingRanges((evt) => pluginHost.getFoldingRanges(evt.textDocument));
|
|
124
146
|
connection.onRequest(TagCloseRequest, (evt) => pluginHost.doTagComplete(evt.textDocument, evt.position));
|
|
125
147
|
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
|
-
|
|
148
|
+
connection.onRenameRequest((evt) => pluginHost.rename(evt.textDocument, evt.position, evt.newName));
|
|
149
|
+
connection.onDidSaveTextDocument(updateAllDiagnostics);
|
|
150
|
+
connection.onNotification('$/onDidChangeNonAstroFile', async (e) => {
|
|
151
|
+
const path = (0, utils_1.urlToPath)(e.uri);
|
|
152
|
+
if (path) {
|
|
153
|
+
pluginHost.updateNonAstroFile(path, e.changes);
|
|
154
|
+
}
|
|
155
|
+
updateAllDiagnostics();
|
|
156
|
+
});
|
|
157
|
+
documentManager.on('documentChange', (0, utils_1.debounceThrottle)(async (document) => diagnosticsManager.update(document), 1000));
|
|
158
|
+
documentManager.on('documentClose', (document) => diagnosticsManager.removeDiagnostics(document));
|
|
159
|
+
// Taking off 🚀
|
|
160
|
+
connection.onInitialized(() => {
|
|
161
|
+
connection.console.log('Successfully initialized! 🚀');
|
|
162
|
+
});
|
|
129
163
|
connection.listen();
|
|
130
164
|
}
|
|
131
|
-
exports.
|
|
165
|
+
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;
|