@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
|
@@ -1,69 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
4
|
};
|
|
21
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.
|
|
23
|
-
const
|
|
24
|
-
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"));
|
|
25
8
|
const path_1 = require("path");
|
|
26
9
|
const utils_1 = require("../../utils");
|
|
10
|
+
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
27
11
|
const documents_1 = require("../../core/documents");
|
|
28
12
|
function scriptElementKindToCompletionItemKind(kind) {
|
|
29
13
|
switch (kind) {
|
|
30
|
-
case
|
|
31
|
-
case
|
|
14
|
+
case typescript_1.default.ScriptElementKind.primitiveType:
|
|
15
|
+
case typescript_1.default.ScriptElementKind.keyword:
|
|
32
16
|
return vscode_languageserver_1.CompletionItemKind.Keyword;
|
|
33
|
-
case
|
|
17
|
+
case typescript_1.default.ScriptElementKind.constElement:
|
|
34
18
|
return vscode_languageserver_1.CompletionItemKind.Constant;
|
|
35
|
-
case
|
|
36
|
-
case
|
|
37
|
-
case
|
|
38
|
-
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:
|
|
39
23
|
return vscode_languageserver_1.CompletionItemKind.Variable;
|
|
40
|
-
case
|
|
41
|
-
case
|
|
42
|
-
case
|
|
24
|
+
case typescript_1.default.ScriptElementKind.memberVariableElement:
|
|
25
|
+
case typescript_1.default.ScriptElementKind.memberGetAccessorElement:
|
|
26
|
+
case typescript_1.default.ScriptElementKind.memberSetAccessorElement:
|
|
43
27
|
return vscode_languageserver_1.CompletionItemKind.Field;
|
|
44
|
-
case
|
|
28
|
+
case typescript_1.default.ScriptElementKind.functionElement:
|
|
45
29
|
return vscode_languageserver_1.CompletionItemKind.Function;
|
|
46
|
-
case
|
|
47
|
-
case
|
|
48
|
-
case
|
|
49
|
-
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:
|
|
50
34
|
return vscode_languageserver_1.CompletionItemKind.Method;
|
|
51
|
-
case
|
|
35
|
+
case typescript_1.default.ScriptElementKind.enumElement:
|
|
52
36
|
return vscode_languageserver_1.CompletionItemKind.Enum;
|
|
53
|
-
case
|
|
54
|
-
case
|
|
37
|
+
case typescript_1.default.ScriptElementKind.moduleElement:
|
|
38
|
+
case typescript_1.default.ScriptElementKind.externalModuleName:
|
|
55
39
|
return vscode_languageserver_1.CompletionItemKind.Module;
|
|
56
|
-
case
|
|
57
|
-
case
|
|
40
|
+
case typescript_1.default.ScriptElementKind.classElement:
|
|
41
|
+
case typescript_1.default.ScriptElementKind.typeElement:
|
|
58
42
|
return vscode_languageserver_1.CompletionItemKind.Class;
|
|
59
|
-
case
|
|
43
|
+
case typescript_1.default.ScriptElementKind.interfaceElement:
|
|
60
44
|
return vscode_languageserver_1.CompletionItemKind.Interface;
|
|
61
|
-
case
|
|
62
|
-
case
|
|
45
|
+
case typescript_1.default.ScriptElementKind.warning:
|
|
46
|
+
case typescript_1.default.ScriptElementKind.scriptElement:
|
|
63
47
|
return vscode_languageserver_1.CompletionItemKind.File;
|
|
64
|
-
case
|
|
48
|
+
case typescript_1.default.ScriptElementKind.directory:
|
|
65
49
|
return vscode_languageserver_1.CompletionItemKind.Folder;
|
|
66
|
-
case
|
|
50
|
+
case typescript_1.default.ScriptElementKind.string:
|
|
67
51
|
return vscode_languageserver_1.CompletionItemKind.Constant;
|
|
68
52
|
}
|
|
69
53
|
return vscode_languageserver_1.CompletionItemKind.Property;
|
|
@@ -72,25 +56,25 @@ exports.scriptElementKindToCompletionItemKind = scriptElementKindToCompletionIte
|
|
|
72
56
|
function getCommitCharactersForScriptElement(kind) {
|
|
73
57
|
const commitCharacters = [];
|
|
74
58
|
switch (kind) {
|
|
75
|
-
case
|
|
76
|
-
case
|
|
77
|
-
case
|
|
78
|
-
case
|
|
79
|
-
case
|
|
80
|
-
case
|
|
81
|
-
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:
|
|
82
66
|
commitCharacters.push('.');
|
|
83
67
|
break;
|
|
84
|
-
case
|
|
85
|
-
case
|
|
86
|
-
case
|
|
87
|
-
case
|
|
88
|
-
case
|
|
89
|
-
case
|
|
90
|
-
case
|
|
91
|
-
case
|
|
92
|
-
case
|
|
93
|
-
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:
|
|
94
78
|
commitCharacters.push('.', ',');
|
|
95
79
|
commitCharacters.push('(');
|
|
96
80
|
break;
|
|
@@ -98,54 +82,66 @@ function getCommitCharactersForScriptElement(kind) {
|
|
|
98
82
|
return commitCharacters.length === 0 ? undefined : commitCharacters;
|
|
99
83
|
}
|
|
100
84
|
exports.getCommitCharactersForScriptElement = getCommitCharactersForScriptElement;
|
|
101
|
-
function
|
|
102
|
-
switch (
|
|
103
|
-
case
|
|
104
|
-
return
|
|
105
|
-
case
|
|
106
|
-
return
|
|
107
|
-
case
|
|
108
|
-
return
|
|
109
|
-
case
|
|
110
|
-
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;
|
|
111
98
|
}
|
|
112
|
-
return vscode_languageserver_1.DiagnosticSeverity.Error;
|
|
113
99
|
}
|
|
114
|
-
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;
|
|
115
114
|
function getScriptKindFromFileName(fileName) {
|
|
116
|
-
const ext = fileName.
|
|
115
|
+
const ext = fileName.substring(fileName.lastIndexOf('.'));
|
|
117
116
|
switch (ext.toLowerCase()) {
|
|
118
|
-
case
|
|
119
|
-
return
|
|
120
|
-
case
|
|
121
|
-
return
|
|
122
|
-
case
|
|
123
|
-
return
|
|
124
|
-
case
|
|
125
|
-
return
|
|
126
|
-
case
|
|
127
|
-
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;
|
|
128
127
|
default:
|
|
129
|
-
return
|
|
128
|
+
return typescript_1.default.ScriptKind.Unknown;
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
131
|
exports.getScriptKindFromFileName = getScriptKindFromFileName;
|
|
133
|
-
function
|
|
134
|
-
switch (
|
|
135
|
-
case
|
|
136
|
-
return
|
|
137
|
-
case
|
|
138
|
-
return
|
|
139
|
-
case
|
|
140
|
-
return
|
|
141
|
-
case
|
|
142
|
-
return
|
|
143
|
-
case ts.ScriptKind.JS:
|
|
144
|
-
default:
|
|
145
|
-
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;
|
|
146
142
|
}
|
|
147
143
|
}
|
|
148
|
-
exports.
|
|
144
|
+
exports.mapSeverity = mapSeverity;
|
|
149
145
|
function convertRange(document, range) {
|
|
150
146
|
return vscode_languageserver_1.Range.create(document.positionAt(range.start || 0), document.positionAt((range.start || 0) + (range.length || 0)));
|
|
151
147
|
}
|
|
@@ -165,8 +161,13 @@ function convertToLocationRange(defDoc, textSpan) {
|
|
|
165
161
|
exports.convertToLocationRange = convertToLocationRange;
|
|
166
162
|
const VirtualExtension = {
|
|
167
163
|
ts: 'ts',
|
|
168
|
-
tsx: 'tsx'
|
|
164
|
+
tsx: 'tsx',
|
|
169
165
|
};
|
|
166
|
+
function getFrameworkFromFilePath(filePath) {
|
|
167
|
+
filePath = ensureRealFilePath(filePath);
|
|
168
|
+
return (0, path_1.extname)(filePath).substring(1);
|
|
169
|
+
}
|
|
170
|
+
exports.getFrameworkFromFilePath = getFrameworkFromFilePath;
|
|
170
171
|
function isVirtualFrameworkFilePath(ext, virtualExt, filePath) {
|
|
171
172
|
return filePath.endsWith('.' + ext + '.' + virtualExt);
|
|
172
173
|
}
|
|
@@ -175,24 +176,24 @@ function isAstroFilePath(filePath) {
|
|
|
175
176
|
return filePath.endsWith('.astro');
|
|
176
177
|
}
|
|
177
178
|
exports.isAstroFilePath = isAstroFilePath;
|
|
179
|
+
function isFrameworkFilePath(filePath) {
|
|
180
|
+
return filePath.endsWith('.svelte') || filePath.endsWith('.vue');
|
|
181
|
+
}
|
|
182
|
+
exports.isFrameworkFilePath = isFrameworkFilePath;
|
|
178
183
|
function isVirtualAstroFilePath(filePath) {
|
|
179
184
|
return isVirtualFrameworkFilePath('astro', VirtualExtension.tsx, filePath);
|
|
180
185
|
}
|
|
181
186
|
exports.isVirtualAstroFilePath = isVirtualAstroFilePath;
|
|
182
187
|
function isVirtualVueFilePath(filePath) {
|
|
183
|
-
return isVirtualFrameworkFilePath('vue', VirtualExtension.
|
|
188
|
+
return isVirtualFrameworkFilePath('vue', VirtualExtension.tsx, filePath);
|
|
184
189
|
}
|
|
185
190
|
exports.isVirtualVueFilePath = isVirtualVueFilePath;
|
|
186
|
-
function isVirtualJsxFilePath(filePath) {
|
|
187
|
-
return isVirtualFrameworkFilePath('jsx', VirtualExtension.ts, filePath) || isVirtualFrameworkFilePath('tsx', VirtualExtension.ts, filePath);
|
|
188
|
-
}
|
|
189
|
-
exports.isVirtualJsxFilePath = isVirtualJsxFilePath;
|
|
190
191
|
function isVirtualSvelteFilePath(filePath) {
|
|
191
|
-
return isVirtualFrameworkFilePath('svelte', VirtualExtension.
|
|
192
|
+
return isVirtualFrameworkFilePath('svelte', VirtualExtension.tsx, filePath);
|
|
192
193
|
}
|
|
193
194
|
exports.isVirtualSvelteFilePath = isVirtualSvelteFilePath;
|
|
194
195
|
function isVirtualFilePath(filePath) {
|
|
195
|
-
return isVirtualAstroFilePath(filePath) || isVirtualVueFilePath(filePath) || isVirtualSvelteFilePath(filePath)
|
|
196
|
+
return isVirtualAstroFilePath(filePath) || isVirtualVueFilePath(filePath) || isVirtualSvelteFilePath(filePath);
|
|
196
197
|
}
|
|
197
198
|
exports.isVirtualFilePath = isVirtualFilePath;
|
|
198
199
|
function toVirtualAstroFilePath(filePath) {
|
|
@@ -207,6 +208,18 @@ function toVirtualAstroFilePath(filePath) {
|
|
|
207
208
|
}
|
|
208
209
|
}
|
|
209
210
|
exports.toVirtualAstroFilePath = toVirtualAstroFilePath;
|
|
211
|
+
function toVirtualFilePath(filePath) {
|
|
212
|
+
if (isVirtualFilePath(filePath)) {
|
|
213
|
+
return filePath;
|
|
214
|
+
}
|
|
215
|
+
else if (isFrameworkFilePath(filePath) || isAstroFilePath(filePath)) {
|
|
216
|
+
return `${filePath}.tsx`;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
return filePath;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
exports.toVirtualFilePath = toVirtualFilePath;
|
|
210
223
|
function toRealAstroFilePath(filePath) {
|
|
211
224
|
return filePath.slice(0, -'.tsx'.length);
|
|
212
225
|
}
|
|
@@ -225,45 +238,3 @@ function ensureRealFilePath(filePath) {
|
|
|
225
238
|
}
|
|
226
239
|
}
|
|
227
240
|
exports.ensureRealFilePath = ensureRealFilePath;
|
|
228
|
-
function findTsConfigPath(fileName, rootUris) {
|
|
229
|
-
const searchDir = (0, path_1.dirname)(fileName);
|
|
230
|
-
const path = ts.findConfigFile(searchDir, ts.sys.fileExists, 'tsconfig.json') || ts.findConfigFile(searchDir, ts.sys.fileExists, 'jsconfig.json') || '';
|
|
231
|
-
// Don't return config files that exceed the current workspace context.
|
|
232
|
-
return !!path && rootUris.some((rootUri) => isSubPath(rootUri, path)) ? path : '';
|
|
233
|
-
}
|
|
234
|
-
exports.findTsConfigPath = findTsConfigPath;
|
|
235
|
-
/** */
|
|
236
|
-
function isSubPath(uri, possibleSubPath) {
|
|
237
|
-
return (0, utils_1.pathToUrl)(possibleSubPath).startsWith(uri);
|
|
238
|
-
}
|
|
239
|
-
exports.isSubPath = isSubPath;
|
|
240
|
-
/** Substitutes */
|
|
241
|
-
function substituteWithWhitespace(result, start, end, oldContent, before, after) {
|
|
242
|
-
let accumulatedWS = 0;
|
|
243
|
-
result += before;
|
|
244
|
-
for (let i = start + before.length; i < end; i++) {
|
|
245
|
-
let ch = oldContent[i];
|
|
246
|
-
if (ch === '\n' || ch === '\r') {
|
|
247
|
-
// only write new lines, skip the whitespace
|
|
248
|
-
accumulatedWS = 0;
|
|
249
|
-
result += ch;
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
accumulatedWS++;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
result = append(result, ' ', accumulatedWS - after.length);
|
|
256
|
-
result += after;
|
|
257
|
-
return result;
|
|
258
|
-
}
|
|
259
|
-
exports.substituteWithWhitespace = substituteWithWhitespace;
|
|
260
|
-
function append(result, str, n) {
|
|
261
|
-
while (n > 0) {
|
|
262
|
-
if (n & 1) {
|
|
263
|
-
result += str;
|
|
264
|
-
}
|
|
265
|
-
n >>= 1;
|
|
266
|
-
str += str;
|
|
267
|
-
}
|
|
268
|
-
return result;
|
|
269
|
-
}
|
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;
|