@astrojs/language-server 0.7.19 → 0.8.4
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 +24 -0
- package/dist/check.js +2 -1
- package/dist/core/config/ConfigManager.js +8 -6
- package/dist/core/documents/Document.js +6 -6
- package/dist/core/documents/DocumentBase.js +2 -2
- package/dist/core/documents/DocumentManager.js +6 -6
- package/dist/core/documents/DocumentMapper.js +9 -7
- package/dist/core/documents/parseAstro.js +3 -3
- package/dist/core/documents/parseHtml.js +2 -2
- package/dist/core/documents/utils.js +7 -6
- package/dist/plugins/PluginHost.js +7 -6
- package/dist/plugins/astro/AstroPlugin.js +6 -6
- package/dist/plugins/astro/features/CompletionProvider.js +15 -14
- package/dist/plugins/css/CSSDocument.js +1 -1
- package/dist/plugins/css/CSSPlugin.js +9 -9
- package/dist/plugins/css/StyleAttributeDocument.js +1 -1
- package/dist/plugins/html/HTMLPlugin.js +4 -4
- package/dist/plugins/typescript/DocumentSnapshot.js +17 -16
- package/dist/plugins/typescript/LanguageServiceManager.js +7 -7
- package/dist/plugins/typescript/SnapshotManager.js +3 -3
- package/dist/plugins/typescript/TypeScriptPlugin.js +11 -11
- package/dist/plugins/typescript/astro-sys.js +5 -5
- package/dist/plugins/typescript/astro2tsx.js +1 -1
- package/dist/plugins/typescript/features/CompletionsProvider.js +6 -5
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +12 -11
- package/dist/plugins/typescript/features/HoverProvider.js +4 -4
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +4 -4
- package/dist/plugins/typescript/features/utils.js +2 -1
- package/dist/plugins/typescript/languageService.js +8 -8
- package/dist/plugins/typescript/module-loader.js +6 -6
- package/dist/plugins/typescript/previewer.js +1 -1
- package/dist/plugins/typescript/utils.js +3 -3
- package/dist/server.js +15 -13
- package/dist/utils.js +2 -1
- package/package.json +5 -3
|
@@ -31,8 +31,9 @@ const utils_3 = require("./utils");
|
|
|
31
31
|
const os_1 = require("os");
|
|
32
32
|
const astro2tsx_1 = __importDefault(require("./astro2tsx"));
|
|
33
33
|
const createDocumentSnapshot = (filePath, currentText, createDocument) => {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
var _a;
|
|
35
|
+
const text = currentText || ((_a = ts.sys.readFile(filePath)) !== null && _a !== void 0 ? _a : '');
|
|
36
|
+
if ((0, utils_3.isAstroFilePath)(filePath)) {
|
|
36
37
|
if (!createDocument)
|
|
37
38
|
throw new Error('Astro documents require the "createDocument" utility to be provided');
|
|
38
39
|
const snapshot = new AstroDocumentSnapshot(createDocument(filePath, text, currentText !== null));
|
|
@@ -49,7 +50,7 @@ class AstroDocumentSnapshot {
|
|
|
49
50
|
this.parserError = null;
|
|
50
51
|
}
|
|
51
52
|
async getFragment() {
|
|
52
|
-
const uri = utils_2.pathToUrl(this.filePath);
|
|
53
|
+
const uri = (0, utils_2.pathToUrl)(this.filePath);
|
|
53
54
|
const mapper = await this.getMapper(uri);
|
|
54
55
|
return new DocumentFragmentSnapshot(mapper, this.doc);
|
|
55
56
|
}
|
|
@@ -58,7 +59,7 @@ class AstroDocumentSnapshot {
|
|
|
58
59
|
}
|
|
59
60
|
get text() {
|
|
60
61
|
let raw = this.doc.getText();
|
|
61
|
-
return astro2tsx_1.default(raw).code;
|
|
62
|
+
return (0, astro2tsx_1.default)(raw).code;
|
|
62
63
|
}
|
|
63
64
|
get filePath() {
|
|
64
65
|
return this.doc.getFilePath() || '';
|
|
@@ -76,14 +77,14 @@ class AstroDocumentSnapshot {
|
|
|
76
77
|
return undefined;
|
|
77
78
|
}
|
|
78
79
|
positionAt(offset) {
|
|
79
|
-
return utils_1.positionAt(offset, this.text);
|
|
80
|
+
return (0, utils_1.positionAt)(offset, this.text);
|
|
80
81
|
}
|
|
81
82
|
getLineContainingOffset(offset) {
|
|
82
83
|
const chunks = this.getText(0, offset).split(os_1.EOL);
|
|
83
84
|
return chunks[chunks.length - 1];
|
|
84
85
|
}
|
|
85
86
|
offsetAt(position) {
|
|
86
|
-
return utils_1.offsetAt(position, this.text);
|
|
87
|
+
return (0, utils_1.offsetAt)(position, this.text);
|
|
87
88
|
}
|
|
88
89
|
getMapper(uri) {
|
|
89
90
|
return new documents_1.IdentityMapper(uri);
|
|
@@ -101,9 +102,9 @@ class DocumentFragmentSnapshot {
|
|
|
101
102
|
throw new Error('Cannot create a document fragment from a non-local document');
|
|
102
103
|
const text = parent.getText();
|
|
103
104
|
this.version = parent.version;
|
|
104
|
-
this.filePath = utils_3.toVirtualAstroFilePath(filePath);
|
|
105
|
-
this.url = utils_3.toVirtualAstroFilePath(filePath);
|
|
106
|
-
this.text = astro2tsx_1.default(text).code;
|
|
105
|
+
this.filePath = (0, utils_3.toVirtualAstroFilePath)(filePath);
|
|
106
|
+
this.url = (0, utils_3.toVirtualAstroFilePath)(filePath);
|
|
107
|
+
this.text = (0, astro2tsx_1.default)(text).code;
|
|
107
108
|
}
|
|
108
109
|
getText(start, end) {
|
|
109
110
|
return this.text.substring(start, end);
|
|
@@ -118,14 +119,14 @@ class DocumentFragmentSnapshot {
|
|
|
118
119
|
return undefined;
|
|
119
120
|
}
|
|
120
121
|
positionAt(offset) {
|
|
121
|
-
return utils_1.positionAt(offset, this.text);
|
|
122
|
+
return (0, utils_1.positionAt)(offset, this.text);
|
|
122
123
|
}
|
|
123
124
|
getLineContainingOffset(offset) {
|
|
124
125
|
const chunks = this.getText(0, offset).split(os_1.EOL);
|
|
125
126
|
return chunks[chunks.length - 1];
|
|
126
127
|
}
|
|
127
128
|
offsetAt(position) {
|
|
128
|
-
return utils_1.offsetAt(position, this.text);
|
|
129
|
+
return (0, utils_1.offsetAt)(position, this.text);
|
|
129
130
|
}
|
|
130
131
|
getOriginalPosition(pos) {
|
|
131
132
|
return this.mapper.getOriginalPosition(pos);
|
|
@@ -134,7 +135,7 @@ class DocumentFragmentSnapshot {
|
|
|
134
135
|
return this.mapper.getGeneratedPosition(pos);
|
|
135
136
|
}
|
|
136
137
|
isInGenerated(pos) {
|
|
137
|
-
return !utils_1.isInTag(pos, this.parent.styleInfo);
|
|
138
|
+
return !(0, utils_1.isInTag)(pos, this.parent.styleInfo);
|
|
138
139
|
}
|
|
139
140
|
getURL() {
|
|
140
141
|
return this.url;
|
|
@@ -146,10 +147,10 @@ class TypeScriptDocumentSnapshot {
|
|
|
146
147
|
this.version = version;
|
|
147
148
|
this.filePath = filePath;
|
|
148
149
|
this.text = text;
|
|
149
|
-
this.scriptKind = utils_3.getScriptKindFromFileName(this.filePath);
|
|
150
|
+
this.scriptKind = (0, utils_3.getScriptKindFromFileName)(this.filePath);
|
|
150
151
|
this.scriptInfo = null;
|
|
151
152
|
this.parserError = null;
|
|
152
|
-
this.url = utils_2.pathToUrl(filePath);
|
|
153
|
+
this.url = (0, utils_2.pathToUrl)(filePath);
|
|
153
154
|
}
|
|
154
155
|
getText(start, end) {
|
|
155
156
|
return this.text.substring(start, end);
|
|
@@ -164,10 +165,10 @@ class TypeScriptDocumentSnapshot {
|
|
|
164
165
|
return undefined;
|
|
165
166
|
}
|
|
166
167
|
positionAt(offset) {
|
|
167
|
-
return utils_1.positionAt(offset, this.text);
|
|
168
|
+
return (0, utils_1.positionAt)(offset, this.text);
|
|
168
169
|
}
|
|
169
170
|
offsetAt(position) {
|
|
170
|
-
return utils_1.offsetAt(position, this.text);
|
|
171
|
+
return (0, utils_1.offsetAt)(position, this.text);
|
|
171
172
|
}
|
|
172
173
|
async getFragment() {
|
|
173
174
|
return this;
|
|
@@ -6,7 +6,7 @@ const languageService_1 = require("./languageService");
|
|
|
6
6
|
class LanguageServiceManager {
|
|
7
7
|
constructor(docManager, configManager, workspaceUris) {
|
|
8
8
|
this.createDocument = (fileName, content, overrideText) => {
|
|
9
|
-
const uri = utils_1.pathToUrl(fileName);
|
|
9
|
+
const uri = (0, utils_1.pathToUrl)(fileName);
|
|
10
10
|
const document = this.docManager.openDocument({
|
|
11
11
|
languageId: 'astro',
|
|
12
12
|
version: 0,
|
|
@@ -27,14 +27,14 @@ class LanguageServiceManager {
|
|
|
27
27
|
// This refreshes the document in the ts language service
|
|
28
28
|
this.getTypeScriptDoc(document);
|
|
29
29
|
};
|
|
30
|
-
docManager.on('documentChange', utils_1.debounceSameArg(handleDocumentChange, (newDoc, prevDoc) => newDoc.uri === prevDoc
|
|
30
|
+
docManager.on('documentChange', (0, utils_1.debounceSameArg)(handleDocumentChange, (newDoc, prevDoc) => newDoc.uri === (prevDoc === null || prevDoc === void 0 ? void 0 : prevDoc.uri), 1000));
|
|
31
31
|
docManager.on('documentOpen', handleDocumentChange);
|
|
32
32
|
}
|
|
33
33
|
getWorkspaceRoot(fileName) {
|
|
34
34
|
if (this.workspaceUris.length === 1)
|
|
35
|
-
return utils_1.urlToPath(this.workspaceUris[0]);
|
|
35
|
+
return (0, utils_1.urlToPath)(this.workspaceUris[0]);
|
|
36
36
|
return this.workspaceUris.reduce((found, curr) => {
|
|
37
|
-
const url = utils_1.urlToPath(curr);
|
|
37
|
+
const url = (0, utils_1.urlToPath)(curr);
|
|
38
38
|
if (fileName.startsWith(url) && curr.length < url.length)
|
|
39
39
|
return url;
|
|
40
40
|
return found;
|
|
@@ -46,18 +46,18 @@ class LanguageServiceManager {
|
|
|
46
46
|
return tsService.updateDocument(pathOrDoc);
|
|
47
47
|
}
|
|
48
48
|
async getTypeScriptDoc(document) {
|
|
49
|
-
const lang = await languageService_1.getLanguageServiceForDocument(document, this.workspaceUris, this.docContext);
|
|
49
|
+
const lang = await (0, languageService_1.getLanguageServiceForDocument)(document, this.workspaceUris, this.docContext);
|
|
50
50
|
const tsDoc = await this.getSnapshot(document);
|
|
51
51
|
return { tsDoc, lang };
|
|
52
52
|
}
|
|
53
53
|
async getTypeScriptLangForPath(filePath) {
|
|
54
|
-
return languageService_1.getLanguageServiceForPath(filePath, this.workspaceUris, this.docContext);
|
|
54
|
+
return (0, languageService_1.getLanguageServiceForPath)(filePath, this.workspaceUris, this.docContext);
|
|
55
55
|
}
|
|
56
56
|
async getSnapshotManager(filePath) {
|
|
57
57
|
return (await this.getTypeScriptLanguageService(filePath)).snapshotManager;
|
|
58
58
|
}
|
|
59
59
|
getTypeScriptLanguageService(filePath) {
|
|
60
|
-
return languageService_1.getLanguageService(filePath, this.workspaceUris, this.docContext);
|
|
60
|
+
return (0, languageService_1.getLanguageService)(filePath, this.workspaceUris, this.docContext);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
exports.LanguageServiceManager = LanguageServiceManager;
|
|
@@ -34,7 +34,7 @@ class SnapshotManager {
|
|
|
34
34
|
}
|
|
35
35
|
updateProjectFiles() {
|
|
36
36
|
const { include, exclude } = this.fileSpec;
|
|
37
|
-
if (include
|
|
37
|
+
if ((include === null || include === void 0 ? void 0 : include.length) === 0)
|
|
38
38
|
return;
|
|
39
39
|
const projectFiles = ts.sys.readDirectory(this.workspaceRoot, this.watchExtensions, exclude, include);
|
|
40
40
|
this.projectFiles = Array.from(new Set([...this.projectFiles, ...projectFiles]));
|
|
@@ -48,7 +48,7 @@ class SnapshotManager {
|
|
|
48
48
|
previousSnapshot.update(changes);
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
const newSnapshot = DocumentSnapshot_1.createDocumentSnapshot(fileName, null);
|
|
51
|
+
const newSnapshot = (0, DocumentSnapshot_1.createDocumentSnapshot)(fileName, null);
|
|
52
52
|
if (previousSnapshot) {
|
|
53
53
|
newSnapshot.version = previousSnapshot.version + 1;
|
|
54
54
|
}
|
|
@@ -74,7 +74,7 @@ class SnapshotManager {
|
|
|
74
74
|
return this.documents.delete(fileName);
|
|
75
75
|
}
|
|
76
76
|
getFileNames() {
|
|
77
|
-
return Array.from(this.documents.keys()).map((fileName) => utils_1.toVirtualAstroFilePath(fileName));
|
|
77
|
+
return Array.from(this.documents.keys()).map((fileName) => (0, utils_1.toVirtualAstroFilePath)(fileName));
|
|
78
78
|
}
|
|
79
79
|
getProjectFileNames() {
|
|
80
80
|
return [...this.projectFiles];
|
|
@@ -50,7 +50,7 @@ class TypeScriptPlugin {
|
|
|
50
50
|
const { lang, tsDoc } = await this.languageServiceManager.getTypeScriptDoc(document);
|
|
51
51
|
const fragment = await tsDoc.getFragment();
|
|
52
52
|
const offset = fragment.offsetAt(fragment.getGeneratedPosition(position));
|
|
53
|
-
let renames = lang.findRenameLocations(utils_1.toVirtualAstroFilePath(tsDoc.filePath), offset, false, false, true);
|
|
53
|
+
let renames = lang.findRenameLocations((0, utils_1.toVirtualAstroFilePath)(tsDoc.filePath), offset, false, false, true);
|
|
54
54
|
if (!renames) {
|
|
55
55
|
return null;
|
|
56
56
|
}
|
|
@@ -58,13 +58,13 @@ class TypeScriptPlugin {
|
|
|
58
58
|
changes: {}
|
|
59
59
|
};
|
|
60
60
|
renames.forEach(rename => {
|
|
61
|
-
const filePath = utils_1.ensureRealAstroFilePath(rename.fileName);
|
|
61
|
+
const filePath = (0, utils_1.ensureRealAstroFilePath)(rename.fileName);
|
|
62
62
|
if (!(filePath in edit.changes)) {
|
|
63
63
|
edit.changes[filePath] = [];
|
|
64
64
|
}
|
|
65
65
|
edit.changes[filePath].push({
|
|
66
66
|
newText: newName,
|
|
67
|
-
range: utils_1.convertToLocationRange(fragment, rename.textSpan)
|
|
67
|
+
range: (0, utils_1.convertToLocationRange)(fragment, rename.textSpan)
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
return edit;
|
|
@@ -80,7 +80,7 @@ class TypeScriptPlugin {
|
|
|
80
80
|
const { lang, tsDoc } = await this.languageServiceManager.getTypeScriptDoc(document);
|
|
81
81
|
const mainFragment = await tsDoc.getFragment();
|
|
82
82
|
const filePath = tsDoc.filePath;
|
|
83
|
-
const tsFilePath = utils_1.toVirtualAstroFilePath(filePath);
|
|
83
|
+
const tsFilePath = (0, utils_1.toVirtualAstroFilePath)(filePath);
|
|
84
84
|
const fragmentPosition = mainFragment.getGeneratedPosition(position);
|
|
85
85
|
const fragmentOffset = mainFragment.offsetAt(fragmentPosition);
|
|
86
86
|
let defs = lang.getDefinitionAndBoundSpan(tsFilePath, fragmentOffset);
|
|
@@ -98,10 +98,10 @@ class TypeScriptPlugin {
|
|
|
98
98
|
docs.set(tsDoc.filePath, { fragment: mainFragment, snapshot: tsDoc });
|
|
99
99
|
const result = await Promise.all(defs.definitions.map(async (def) => {
|
|
100
100
|
const { fragment, snapshot } = await docs.retrieve(def.fileName);
|
|
101
|
-
if (utils_3.isNoTextSpanInGeneratedCode(snapshot.getFullText(), def.textSpan)) {
|
|
102
|
-
const fileName = utils_1.ensureRealAstroFilePath(def.fileName);
|
|
103
|
-
const textSpan = utils_1.isVirtualAstroFilePath(tsFilePath) ? { start: 0, length: 0 } : def.textSpan;
|
|
104
|
-
return vscode_languageserver_1.LocationLink.create(utils_2.pathToUrl(fileName), utils_1.convertToLocationRange(fragment, textSpan), utils_1.convertToLocationRange(fragment, textSpan), utils_1.convertToLocationRange(mainFragment, defs.textSpan));
|
|
101
|
+
if ((0, utils_3.isNoTextSpanInGeneratedCode)(snapshot.getFullText(), def.textSpan)) {
|
|
102
|
+
const fileName = (0, utils_1.ensureRealAstroFilePath)(def.fileName);
|
|
103
|
+
const textSpan = (0, utils_1.isVirtualAstroFilePath)(tsFilePath) ? { start: 0, length: 0 } : def.textSpan;
|
|
104
|
+
return vscode_languageserver_1.LocationLink.create((0, utils_2.pathToUrl)(fileName), (0, utils_1.convertToLocationRange)(fragment, textSpan), (0, utils_1.convertToLocationRange)(fragment, textSpan), (0, utils_1.convertToLocationRange)(mainFragment, defs.textSpan));
|
|
105
105
|
}
|
|
106
106
|
}));
|
|
107
107
|
return result.filter(utils_2.isNotNullOrUndefined);
|
|
@@ -115,7 +115,7 @@ class TypeScriptPlugin {
|
|
|
115
115
|
async onWatchFileChanges(onWatchFileChangesParams) {
|
|
116
116
|
const doneUpdateProjectFiles = new Set();
|
|
117
117
|
for (const { fileName, changeType } of onWatchFileChangesParams) {
|
|
118
|
-
const scriptKind = utils_1.getScriptKindFromFileName(fileName);
|
|
118
|
+
const scriptKind = (0, utils_1.getScriptKindFromFileName)(fileName);
|
|
119
119
|
if (scriptKind === ts.ScriptKind.Unknown) {
|
|
120
120
|
// We don't deal with svelte files here
|
|
121
121
|
continue;
|
|
@@ -149,7 +149,7 @@ class TypeScriptPlugin {
|
|
|
149
149
|
}
|
|
150
150
|
getGoToDefinitionRefsForImportSpecifier(tsFilePath, offset, lang) {
|
|
151
151
|
const program = lang.getProgram();
|
|
152
|
-
const sourceFile = program
|
|
152
|
+
const sourceFile = program === null || program === void 0 ? void 0 : program.getSourceFile(tsFilePath);
|
|
153
153
|
if (sourceFile) {
|
|
154
154
|
let node = ts.getTouchingPropertyName(sourceFile, offset);
|
|
155
155
|
if (node && node.kind === typescript_1.SyntaxKind.Identifier) {
|
|
@@ -157,7 +157,7 @@ class TypeScriptPlugin {
|
|
|
157
157
|
let decl = node.parent.parent;
|
|
158
158
|
let spec = ts.isStringLiteral(decl.moduleSpecifier) && decl.moduleSpecifier.text;
|
|
159
159
|
if (spec) {
|
|
160
|
-
let fileName = path_1.join(path_1.dirname(tsFilePath), spec);
|
|
160
|
+
let fileName = (0, path_1.join)((0, path_1.dirname)(tsFilePath), spec);
|
|
161
161
|
let start = node.pos + 1;
|
|
162
162
|
let def = {
|
|
163
163
|
definitions: [
|
|
@@ -33,7 +33,7 @@ function createAstroSys(getSnapshot) {
|
|
|
33
33
|
const AstroSys = {
|
|
34
34
|
...ts.sys,
|
|
35
35
|
fileExists(path) {
|
|
36
|
-
let doesExist = ts.sys.fileExists(utils_1.ensureRealAstroFilePath(path));
|
|
36
|
+
let doesExist = ts.sys.fileExists((0, utils_1.ensureRealAstroFilePath)(path));
|
|
37
37
|
return doesExist;
|
|
38
38
|
},
|
|
39
39
|
directoryExists(path) {
|
|
@@ -43,14 +43,14 @@ function createAstroSys(getSnapshot) {
|
|
|
43
43
|
return ts.sys.directoryExists(path);
|
|
44
44
|
},
|
|
45
45
|
readFile(path) {
|
|
46
|
-
if (utils_1.isAstroFilePath(path) || utils_1.isVirtualAstroFilePath(path)) {
|
|
46
|
+
if ((0, utils_1.isAstroFilePath)(path) || (0, utils_1.isVirtualAstroFilePath)(path)) {
|
|
47
47
|
console.log('readFile', path);
|
|
48
48
|
}
|
|
49
49
|
const snapshot = getSnapshot(path);
|
|
50
50
|
return snapshot.getFullText();
|
|
51
51
|
},
|
|
52
52
|
readDirectory(path, extensions, exclude, include, depth) {
|
|
53
|
-
const extensionsWithAstro = (extensions
|
|
53
|
+
const extensionsWithAstro = (extensions !== null && extensions !== void 0 ? extensions : []).concat(...['.astro', '.svelte', '.vue']);
|
|
54
54
|
const result = ts.sys.readDirectory(path, extensionsWithAstro, exclude, include, depth);
|
|
55
55
|
return result;
|
|
56
56
|
},
|
|
@@ -58,8 +58,8 @@ function createAstroSys(getSnapshot) {
|
|
|
58
58
|
if (ts.sys.realpath) {
|
|
59
59
|
const realpath = ts.sys.realpath;
|
|
60
60
|
AstroSys.realpath = function (path) {
|
|
61
|
-
if (utils_1.isVirtualAstroFilePath(path)) {
|
|
62
|
-
return realpath(utils_1.toRealAstroFilePath(path)) + '.ts';
|
|
61
|
+
if ((0, utils_1.isVirtualAstroFilePath)(path)) {
|
|
62
|
+
return realpath((0, utils_1.toRealAstroFilePath)(path)) + '.ts';
|
|
63
63
|
}
|
|
64
64
|
return realpath(path);
|
|
65
65
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const fs_1 = require("fs");
|
|
4
4
|
const os_1 = require("os");
|
|
5
|
-
const ASTRO_DEFINITION_BYTES = fs_1.readFileSync(require.resolve('../../../astro.d.ts'));
|
|
5
|
+
const ASTRO_DEFINITION_BYTES = (0, fs_1.readFileSync)(require.resolve('../../../astro.d.ts'));
|
|
6
6
|
const ASTRO_DEFINITION_STR = ASTRO_DEFINITION_BYTES.toString('utf-8');
|
|
7
7
|
function addProps(content, dtsContent) {
|
|
8
8
|
let defaultExportType = 'AstroBuiltinProps & Record<string, any>';
|
|
@@ -34,8 +34,9 @@ class CompletionsProviderImpl {
|
|
|
34
34
|
this.lang = lang;
|
|
35
35
|
}
|
|
36
36
|
async getCompletions(document, position, _completionContext) {
|
|
37
|
+
var _a;
|
|
37
38
|
// TODO: handle inside expression
|
|
38
|
-
if (!utils_1.isInsideFrontmatter(document.getText(), document.offsetAt(position))) {
|
|
39
|
+
if (!(0, utils_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position))) {
|
|
39
40
|
return null;
|
|
40
41
|
}
|
|
41
42
|
const filePath = document.getFilePath();
|
|
@@ -44,7 +45,7 @@ class CompletionsProviderImpl {
|
|
|
44
45
|
const { tsDoc, lang } = await this.lang.getTypeScriptDoc(document);
|
|
45
46
|
const fragment = await tsDoc.getFragment();
|
|
46
47
|
const offset = document.offsetAt(position);
|
|
47
|
-
const entries = lang.getCompletionsAtPosition(fragment.filePath, offset, completionOptions)
|
|
48
|
+
const entries = ((_a = lang.getCompletionsAtPosition(fragment.filePath, offset, completionOptions)) === null || _a === void 0 ? void 0 : _a.entries) || [];
|
|
48
49
|
const completionItems = entries
|
|
49
50
|
.map((entry) => this.toCompletionItem(fragment, entry, document.uri, position, new Set()))
|
|
50
51
|
.filter((i) => i);
|
|
@@ -53,7 +54,7 @@ class CompletionsProviderImpl {
|
|
|
53
54
|
async resolveCompletion(document, completionItem) {
|
|
54
55
|
const { data: comp } = completionItem;
|
|
55
56
|
const { tsDoc, lang } = await this.lang.getTypeScriptDoc(document);
|
|
56
|
-
let filePath = utils_2.toVirtualAstroFilePath(tsDoc.filePath);
|
|
57
|
+
let filePath = (0, utils_2.toVirtualAstroFilePath)(tsDoc.filePath);
|
|
57
58
|
if (!comp || !filePath) {
|
|
58
59
|
return completionItem;
|
|
59
60
|
}
|
|
@@ -77,8 +78,8 @@ class CompletionsProviderImpl {
|
|
|
77
78
|
return {
|
|
78
79
|
label: comp.name,
|
|
79
80
|
insertText: comp.insertText,
|
|
80
|
-
kind: utils_2.scriptElementKindToCompletionItemKind(comp.kind),
|
|
81
|
-
commitCharacters: utils_2.getCommitCharactersForScriptElement(comp.kind),
|
|
81
|
+
kind: (0, utils_2.scriptElementKindToCompletionItemKind)(comp.kind),
|
|
82
|
+
commitCharacters: (0, utils_2.getCommitCharactersForScriptElement)(comp.kind),
|
|
82
83
|
// Make sure svelte component takes precedence
|
|
83
84
|
sortText: comp.sortText,
|
|
84
85
|
preselect: comp.isRecommended,
|
|
@@ -14,11 +14,12 @@ class DiagnosticsProviderImpl {
|
|
|
14
14
|
this.languageServiceManager = languageServiceManager;
|
|
15
15
|
}
|
|
16
16
|
async getDiagnostics(document, _cancellationToken) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
var _a, _b, _c, _d, _e;
|
|
18
|
+
if ((((_a = document.getFilePath()) === null || _a === void 0 ? void 0 : _a.includes('/node_modules/')) ||
|
|
19
|
+
((_b = document.getFilePath()) === null || _b === void 0 ? void 0 : _b.includes('\\node_modules\\'))) &&
|
|
19
20
|
// Sapper convention: Put stuff inside node_modules below src
|
|
20
|
-
!(document.getFilePath()
|
|
21
|
-
document.getFilePath()
|
|
21
|
+
!(((_c = document.getFilePath()) === null || _c === void 0 ? void 0 : _c.includes('/src/node_modules/')) ||
|
|
22
|
+
((_d = document.getFilePath()) === null || _d === void 0 ? void 0 : _d.includes('\\src\\node_modules\\')))) {
|
|
22
23
|
// Don't return diagnostics for files inside node_modules. These are considered read-only (cannot be changed)
|
|
23
24
|
// and in case of svelte-check they would pollute/skew the output
|
|
24
25
|
return [];
|
|
@@ -37,7 +38,7 @@ class DiagnosticsProviderImpl {
|
|
|
37
38
|
}
|
|
38
39
|
];
|
|
39
40
|
}
|
|
40
|
-
const filePath = utils_1.toVirtualAstroFilePath(tsDoc.filePath);
|
|
41
|
+
const filePath = (0, utils_1.toVirtualAstroFilePath)(tsDoc.filePath);
|
|
41
42
|
const { script: scriptBoundaries, markdown: markdownBoundaries } = this.getTagBoundaries(lang, filePath);
|
|
42
43
|
const syntaxDiagnostics = lang.getSyntacticDiagnostics(filePath);
|
|
43
44
|
const suggestionDiagnostics = lang.getSuggestionDiagnostics(filePath);
|
|
@@ -50,13 +51,13 @@ class DiagnosticsProviderImpl {
|
|
|
50
51
|
...semanticDiagnostics
|
|
51
52
|
];
|
|
52
53
|
const fragment = await tsDoc.getFragment();
|
|
53
|
-
const sourceFile = lang.getProgram()
|
|
54
|
+
const sourceFile = (_e = lang.getProgram()) === null || _e === void 0 ? void 0 : _e.getSourceFile(filePath);
|
|
54
55
|
const isNoFalsePositiveInst = isNoFalsePositive();
|
|
55
56
|
return diagnostics
|
|
56
57
|
.filter(isNotGenerated(tsDoc.getText(0, tsDoc.getLength())))
|
|
57
58
|
.map((diagnostic) => ({
|
|
58
|
-
range: utils_1.convertRange(tsDoc, diagnostic),
|
|
59
|
-
severity: utils_1.mapSeverity(diagnostic.category),
|
|
59
|
+
range: (0, utils_1.convertRange)(tsDoc, diagnostic),
|
|
60
|
+
severity: (0, utils_1.mapSeverity)(diagnostic.category),
|
|
60
61
|
source: isTypescript ? 'ts' : 'js',
|
|
61
62
|
message: typescript_1.default.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
|
|
62
63
|
code: diagnostic.code,
|
|
@@ -81,7 +82,7 @@ class DiagnosticsProviderImpl {
|
|
|
81
82
|
}
|
|
82
83
|
getTagBoundaries(lang, tsFilePath) {
|
|
83
84
|
const program = lang.getProgram();
|
|
84
|
-
const sourceFile = program
|
|
85
|
+
const sourceFile = program === null || program === void 0 ? void 0 : program.getSourceFile(tsFilePath);
|
|
85
86
|
const boundaries = {
|
|
86
87
|
script: [],
|
|
87
88
|
markdown: []
|
|
@@ -125,7 +126,7 @@ function getDiagnosticTag(diagnostic) {
|
|
|
125
126
|
}
|
|
126
127
|
function mapRange(fragment, _document) {
|
|
127
128
|
return (diagnostic) => {
|
|
128
|
-
let range = documents_1.mapRangeToOriginal(fragment, diagnostic.range);
|
|
129
|
+
let range = (0, documents_1.mapRangeToOriginal)(fragment, diagnostic.range);
|
|
129
130
|
if (range.start.line < 0) {
|
|
130
131
|
// Could be a props error?
|
|
131
132
|
// From svelte
|
|
@@ -255,6 +256,6 @@ function isNotGenerated(text) {
|
|
|
255
256
|
if (diagnostic.start === undefined || diagnostic.length === undefined) {
|
|
256
257
|
return true;
|
|
257
258
|
}
|
|
258
|
-
return !utils_2.isInGeneratedCode(text, diagnostic.start, diagnostic.start + diagnostic.length);
|
|
259
|
+
return !(0, utils_2.isInGeneratedCode)(text, diagnostic.start, diagnostic.start + diagnostic.length);
|
|
259
260
|
};
|
|
260
261
|
}
|
|
@@ -17,7 +17,7 @@ class HoverProviderImpl {
|
|
|
17
17
|
const { lang, tsDoc } = await this.getLSAndTSDoc(document);
|
|
18
18
|
const fragment = await tsDoc.getFragment();
|
|
19
19
|
const offset = fragment.offsetAt(fragment.getGeneratedPosition(position));
|
|
20
|
-
const filePath = utils_1.toVirtualAstroFilePath(tsDoc.filePath);
|
|
20
|
+
const filePath = (0, utils_1.toVirtualAstroFilePath)(tsDoc.filePath);
|
|
21
21
|
let info = lang.getQuickInfoAtPosition(filePath, offset);
|
|
22
22
|
if (!info) {
|
|
23
23
|
return null;
|
|
@@ -28,11 +28,11 @@ class HoverProviderImpl {
|
|
|
28
28
|
kind: value.kind
|
|
29
29
|
}));
|
|
30
30
|
const declaration = typescript_1.default.displayPartsToString(displayParts);
|
|
31
|
-
const documentation = previewer_1.getMarkdownDocumentation(info.documentation, info.tags);
|
|
31
|
+
const documentation = (0, previewer_1.getMarkdownDocumentation)(info.documentation, info.tags);
|
|
32
32
|
// https://microsoft.github.io/language-server-protocol/specification#textDocument_hover
|
|
33
33
|
const contents = ['```typescript', declaration, '```'].concat(documentation ? ['---', documentation] : []).join('\n');
|
|
34
|
-
return documents_1.mapObjWithRangeToOriginal(fragment, {
|
|
35
|
-
range: utils_1.convertRange(fragment, textSpan),
|
|
34
|
+
return (0, documents_1.mapObjWithRangeToOriginal)(fragment, {
|
|
35
|
+
range: (0, utils_1.convertRange)(fragment, textSpan),
|
|
36
36
|
contents,
|
|
37
37
|
});
|
|
38
38
|
}
|
|
@@ -15,12 +15,12 @@ class SignatureHelpProviderImpl {
|
|
|
15
15
|
async getSignatureHelp(document, position, context, cancellationToken) {
|
|
16
16
|
const { lang, tsDoc } = await this.lang.getTypeScriptDoc(document);
|
|
17
17
|
const fragment = await tsDoc.getFragment();
|
|
18
|
-
if (cancellationToken
|
|
18
|
+
if (cancellationToken === null || cancellationToken === void 0 ? void 0 : cancellationToken.isCancellationRequested) {
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
21
21
|
const offset = fragment.offsetAt(fragment.getGeneratedPosition(position));
|
|
22
22
|
const triggerReason = this.toTsTriggerReason(context);
|
|
23
|
-
const info = lang.getSignatureHelpItems(utils_1.toVirtualAstroFilePath(tsDoc.filePath), offset, triggerReason ? { triggerReason } : undefined);
|
|
23
|
+
const info = lang.getSignatureHelpItems((0, utils_1.toVirtualAstroFilePath)(tsDoc.filePath), offset, triggerReason ? { triggerReason } : undefined);
|
|
24
24
|
if (!info || info.items.some((signature) => this.isInSvelte2tsxGeneratedFunction(signature))) {
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
@@ -41,7 +41,7 @@ class SignatureHelpProviderImpl {
|
|
|
41
41
|
* adopted from https://github.com/microsoft/vscode/blob/265a2f6424dfbd3a9788652c7d376a7991d049a3/extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts#L103
|
|
42
42
|
*/
|
|
43
43
|
toTsTriggerReason(context) {
|
|
44
|
-
switch (context
|
|
44
|
+
switch (context === null || context === void 0 ? void 0 : context.triggerKind) {
|
|
45
45
|
case vscode_languageserver_1.SignatureHelpTriggerKind.TriggerCharacter:
|
|
46
46
|
if (context.triggerCharacter) {
|
|
47
47
|
if (this.isReTrigger(context.isRetrigger, context.triggerCharacter)) {
|
|
@@ -83,7 +83,7 @@ class SignatureHelpProviderImpl {
|
|
|
83
83
|
signatureLabel += separatorLabel;
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
|
-
const signatureDocumentation = previewer_1.getMarkdownDocumentation(item.documentation, item.tags.filter((tag) => tag.name !== 'param'));
|
|
86
|
+
const signatureDocumentation = (0, previewer_1.getMarkdownDocumentation)(item.documentation, item.tags.filter((tag) => tag.name !== 'param'));
|
|
87
87
|
return {
|
|
88
88
|
label: prefixLabel + signatureLabel + suffixLabel,
|
|
89
89
|
documentation: signatureDocumentation
|
|
@@ -33,7 +33,8 @@ class SnapshotFragmentMap {
|
|
|
33
33
|
return this.map.get(fileName);
|
|
34
34
|
}
|
|
35
35
|
getFragment(fileName) {
|
|
36
|
-
|
|
36
|
+
var _a;
|
|
37
|
+
return (_a = this.map.get(fileName)) === null || _a === void 0 ? void 0 : _a.fragment;
|
|
37
38
|
}
|
|
38
39
|
async retrieve(fileName) {
|
|
39
40
|
let snapshotFragment = this.get(fileName);
|
|
@@ -29,7 +29,7 @@ const DocumentSnapshot_1 = require("./DocumentSnapshot");
|
|
|
29
29
|
const module_loader_1 = require("./module-loader");
|
|
30
30
|
const services = new Map();
|
|
31
31
|
async function getLanguageService(path, workspaceUris, docContext) {
|
|
32
|
-
const tsconfigPath = utils_1.findTsConfigPath(path, workspaceUris);
|
|
32
|
+
const tsconfigPath = (0, utils_1.findTsConfigPath)(path, workspaceUris);
|
|
33
33
|
const workspaceRoot = docContext.getWorkspaceRoot(path);
|
|
34
34
|
let service;
|
|
35
35
|
if (services.has(tsconfigPath)) {
|
|
@@ -71,7 +71,7 @@ async function createLanguageService(tsconfigPath, workspaceRoot, docContext) {
|
|
|
71
71
|
module: ts.ModuleKind.ESNext,
|
|
72
72
|
target: ts.ScriptTarget.ESNext
|
|
73
73
|
};
|
|
74
|
-
const project = ts.parseJsonConfigFileContent(configJson, parseConfigHost, workspaceRoot, existingCompilerOptions, path_1.basename(tsconfigPath), undefined, [
|
|
74
|
+
const project = ts.parseJsonConfigFileContent(configJson, parseConfigHost, workspaceRoot, existingCompilerOptions, (0, path_1.basename)(tsconfigPath), undefined, [
|
|
75
75
|
{ extension: '.vue', isMixedContent: true, scriptKind: ts.ScriptKind.Deferred },
|
|
76
76
|
{ extension: '.svelte', isMixedContent: true, scriptKind: ts.ScriptKind.Deferred },
|
|
77
77
|
{ extension: '.astro', isMixedContent: true, scriptKind: ts.ScriptKind.Deferred },
|
|
@@ -81,7 +81,7 @@ async function createLanguageService(tsconfigPath, workspaceRoot, docContext) {
|
|
|
81
81
|
exclude: ['node_modules', 'dist'],
|
|
82
82
|
include: ['src'],
|
|
83
83
|
}, workspaceRoot || process.cwd());
|
|
84
|
-
const astroModuleLoader = module_loader_1.createAstroModuleLoader(getScriptSnapshot, {});
|
|
84
|
+
const astroModuleLoader = (0, module_loader_1.createAstroModuleLoader)(getScriptSnapshot, {});
|
|
85
85
|
const host = {
|
|
86
86
|
getNewLine: () => ts.sys.newLine,
|
|
87
87
|
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
|
|
@@ -123,28 +123,28 @@ async function createLanguageService(tsconfigPath, workspaceRoot, docContext) {
|
|
|
123
123
|
snapshotManager.delete(filePath);
|
|
124
124
|
}
|
|
125
125
|
function updateDocument(documentOrFilePath) {
|
|
126
|
-
const filePath = utils_1.ensureRealAstroFilePath(typeof documentOrFilePath === 'string' ? documentOrFilePath : documentOrFilePath.getFilePath() || '');
|
|
126
|
+
const filePath = (0, utils_1.ensureRealAstroFilePath)(typeof documentOrFilePath === 'string' ? documentOrFilePath : documentOrFilePath.getFilePath() || '');
|
|
127
127
|
const document = typeof documentOrFilePath === 'string' ? undefined : documentOrFilePath;
|
|
128
128
|
if (!filePath) {
|
|
129
129
|
throw new Error(`Unable to find document`);
|
|
130
130
|
}
|
|
131
131
|
const previousSnapshot = snapshotManager.get(filePath);
|
|
132
|
-
if (document && previousSnapshot
|
|
132
|
+
if (document && (previousSnapshot === null || previousSnapshot === void 0 ? void 0 : previousSnapshot.version.toString()) === `${document.version}`) {
|
|
133
133
|
return previousSnapshot;
|
|
134
134
|
}
|
|
135
135
|
const currentText = document ? document.getText() : null;
|
|
136
|
-
const snapshot = DocumentSnapshot_1.createDocumentSnapshot(filePath, currentText, docContext.createDocument);
|
|
136
|
+
const snapshot = (0, DocumentSnapshot_1.createDocumentSnapshot)(filePath, currentText, docContext.createDocument);
|
|
137
137
|
snapshotManager.set(filePath, snapshot);
|
|
138
138
|
onProjectUpdated();
|
|
139
139
|
return snapshot;
|
|
140
140
|
}
|
|
141
141
|
function getScriptSnapshot(fileName) {
|
|
142
|
-
fileName = utils_1.ensureRealAstroFilePath(fileName);
|
|
142
|
+
fileName = (0, utils_1.ensureRealAstroFilePath)(fileName);
|
|
143
143
|
let doc = snapshotManager.get(fileName);
|
|
144
144
|
if (doc) {
|
|
145
145
|
return doc;
|
|
146
146
|
}
|
|
147
|
-
doc = DocumentSnapshot_1.createDocumentSnapshot(fileName, null, docContext.createDocument);
|
|
147
|
+
doc = (0, DocumentSnapshot_1.createDocumentSnapshot)(fileName, null, docContext.createDocument);
|
|
148
148
|
snapshotManager.set(fileName, doc);
|
|
149
149
|
return doc;
|
|
150
150
|
}
|
|
@@ -41,7 +41,7 @@ class ModuleResolutionCache {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
getKey(moduleName, containingFile) {
|
|
44
|
-
return containingFile + ':::' + utils_1.ensureRealAstroFilePath(moduleName);
|
|
44
|
+
return containingFile + ':::' + (0, utils_1.ensureRealAstroFilePath)(moduleName);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
@@ -57,7 +57,7 @@ class ModuleResolutionCache {
|
|
|
57
57
|
* @param compilerOptions The typescript compiler options
|
|
58
58
|
*/
|
|
59
59
|
function createAstroModuleLoader(getSnapshot, compilerOptions) {
|
|
60
|
-
const astroSys = astro_sys_1.createAstroSys(getSnapshot);
|
|
60
|
+
const astroSys = (0, astro_sys_1.createAstroSys)(getSnapshot);
|
|
61
61
|
const moduleCache = new ModuleResolutionCache();
|
|
62
62
|
return {
|
|
63
63
|
fileExists: astroSys.fileExists,
|
|
@@ -86,17 +86,17 @@ function createAstroModuleLoader(getSnapshot, compilerOptions) {
|
|
|
86
86
|
// If that does not bring up anything, try the Astro Module loader
|
|
87
87
|
// which is able to deal with .astro files.
|
|
88
88
|
const tsResolvedModule = typescript_1.default.resolveModuleName(name, containingFile, compilerOptions, typescript_1.default.sys).resolvedModule;
|
|
89
|
-
if (tsResolvedModule && !utils_1.isVirtualAstroFilePath(tsResolvedModule.resolvedFileName)) {
|
|
89
|
+
if (tsResolvedModule && !(0, utils_1.isVirtualAstroFilePath)(tsResolvedModule.resolvedFileName)) {
|
|
90
90
|
return tsResolvedModule;
|
|
91
91
|
}
|
|
92
92
|
const astroResolvedModule = typescript_1.default.resolveModuleName(name, containingFile, compilerOptions, astroSys).resolvedModule;
|
|
93
|
-
if (!astroResolvedModule || !utils_1.isVirtualAstroFilePath(astroResolvedModule.resolvedFileName)) {
|
|
93
|
+
if (!astroResolvedModule || !(0, utils_1.isVirtualAstroFilePath)(astroResolvedModule.resolvedFileName)) {
|
|
94
94
|
return astroResolvedModule;
|
|
95
95
|
}
|
|
96
|
-
const resolvedFileName = utils_1.ensureRealAstroFilePath(astroResolvedModule.resolvedFileName);
|
|
96
|
+
const resolvedFileName = (0, utils_1.ensureRealAstroFilePath)(astroResolvedModule.resolvedFileName);
|
|
97
97
|
const snapshot = getSnapshot(resolvedFileName);
|
|
98
98
|
const resolvedastroModule = {
|
|
99
|
-
extension: utils_1.getExtensionFromScriptKind(snapshot && snapshot.scriptKind),
|
|
99
|
+
extension: (0, utils_1.getExtensionFromScriptKind)(snapshot && snapshot.scriptKind),
|
|
100
100
|
resolvedFileName,
|
|
101
101
|
};
|
|
102
102
|
return resolvedastroModule;
|
|
@@ -72,7 +72,7 @@ function getTagBodyText(tag) {
|
|
|
72
72
|
function getTagDocumentation(tag) {
|
|
73
73
|
function getWithType() {
|
|
74
74
|
const body = (typescript_1.default.displayPartsToString(tag.text) || '').split(/^(\S+)\s*-?\s*/);
|
|
75
|
-
if (body
|
|
75
|
+
if ((body === null || body === void 0 ? void 0 : body.length) === 3) {
|
|
76
76
|
const param = body[1];
|
|
77
77
|
const doc = body[2];
|
|
78
78
|
const label = `*@${tag.name}* \`${param}\``;
|
|
@@ -151,7 +151,7 @@ function convertRange(document, range) {
|
|
|
151
151
|
}
|
|
152
152
|
exports.convertRange = convertRange;
|
|
153
153
|
function convertToLocationRange(defDoc, textSpan) {
|
|
154
|
-
const range = documents_1.mapRangeToOriginal(defDoc, convertRange(defDoc, textSpan));
|
|
154
|
+
const range = (0, documents_1.mapRangeToOriginal)(defDoc, convertRange(defDoc, textSpan));
|
|
155
155
|
// Some definition like the svelte component class definition don't exist in the original, so we map to 0,1
|
|
156
156
|
if (range.start.line < 0) {
|
|
157
157
|
range.start.line = 0;
|
|
@@ -226,7 +226,7 @@ function ensureRealFilePath(filePath) {
|
|
|
226
226
|
}
|
|
227
227
|
exports.ensureRealFilePath = ensureRealFilePath;
|
|
228
228
|
function findTsConfigPath(fileName, rootUris) {
|
|
229
|
-
const searchDir = path_1.dirname(fileName);
|
|
229
|
+
const searchDir = (0, path_1.dirname)(fileName);
|
|
230
230
|
const path = ts.findConfigFile(searchDir, ts.sys.fileExists, 'tsconfig.json') || ts.findConfigFile(searchDir, ts.sys.fileExists, 'jsconfig.json') || '';
|
|
231
231
|
// Don't return config files that exceed the current workspace context.
|
|
232
232
|
return !!path && rootUris.some((rootUri) => isSubPath(rootUri, path)) ? path : '';
|
|
@@ -234,7 +234,7 @@ function findTsConfigPath(fileName, rootUris) {
|
|
|
234
234
|
exports.findTsConfigPath = findTsConfigPath;
|
|
235
235
|
/** */
|
|
236
236
|
function isSubPath(uri, possibleSubPath) {
|
|
237
|
-
return utils_1.pathToUrl(possibleSubPath).startsWith(uri);
|
|
237
|
+
return (0, utils_1.pathToUrl)(possibleSubPath).startsWith(uri);
|
|
238
238
|
}
|
|
239
239
|
exports.isSubPath = isSubPath;
|
|
240
240
|
/** Substitutes */
|