@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
|
@@ -24,24 +24,22 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.TypeScriptPlugin = void 0;
|
|
27
|
-
const
|
|
28
|
-
const typescript_1 = require("typescript");
|
|
27
|
+
const typescript_1 = __importStar(require("typescript"));
|
|
29
28
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const utils_1 = require("./utils");
|
|
33
|
-
const utils_2 = require("../../utils");
|
|
29
|
+
const path_1 = require("path");
|
|
30
|
+
const utils_1 = require("../../utils");
|
|
34
31
|
const CompletionsProvider_1 = require("./features/CompletionsProvider");
|
|
35
|
-
const HoverProvider_1 = require("./features/HoverProvider");
|
|
36
32
|
const DiagnosticsProvider_1 = require("./features/DiagnosticsProvider");
|
|
37
|
-
const
|
|
33
|
+
const HoverProvider_1 = require("./features/HoverProvider");
|
|
38
34
|
const SignatureHelpProvider_1 = require("./features/SignatureHelpProvider");
|
|
35
|
+
const utils_2 = require("./features/utils");
|
|
36
|
+
const LanguageServiceManager_1 = require("./LanguageServiceManager");
|
|
37
|
+
const utils_3 = require("./utils");
|
|
39
38
|
class TypeScriptPlugin {
|
|
40
39
|
constructor(docManager, configManager, workspaceUris) {
|
|
41
|
-
this.
|
|
42
|
-
this.docManager = docManager;
|
|
40
|
+
this.__name = 'typescript';
|
|
43
41
|
this.configManager = configManager;
|
|
44
|
-
this.languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(docManager,
|
|
42
|
+
this.languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(docManager, workspaceUris, configManager);
|
|
45
43
|
this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(this.languageServiceManager);
|
|
46
44
|
this.hoverProvider = new HoverProvider_1.HoverProviderImpl(this.languageServiceManager);
|
|
47
45
|
this.signatureHelpProvider = new SignatureHelpProvider_1.SignatureHelpProviderImpl(this.languageServiceManager);
|
|
@@ -51,24 +49,24 @@ class TypeScriptPlugin {
|
|
|
51
49
|
return this.hoverProvider.doHover(document, position);
|
|
52
50
|
}
|
|
53
51
|
async rename(document, position, newName) {
|
|
54
|
-
const { lang, tsDoc } = await this.languageServiceManager.
|
|
55
|
-
const fragment = await tsDoc.
|
|
52
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
53
|
+
const fragment = await tsDoc.createFragment();
|
|
56
54
|
const offset = fragment.offsetAt(fragment.getGeneratedPosition(position));
|
|
57
|
-
let renames = lang.findRenameLocations((0,
|
|
55
|
+
let renames = lang.findRenameLocations((0, utils_3.toVirtualAstroFilePath)(tsDoc.filePath), offset, false, false, true);
|
|
58
56
|
if (!renames) {
|
|
59
57
|
return null;
|
|
60
58
|
}
|
|
61
59
|
let edit = {
|
|
62
|
-
changes: {}
|
|
60
|
+
changes: {},
|
|
63
61
|
};
|
|
64
|
-
renames.forEach(rename => {
|
|
65
|
-
const filePath = (0,
|
|
62
|
+
renames.forEach((rename) => {
|
|
63
|
+
const filePath = (0, utils_3.ensureRealFilePath)(rename.fileName);
|
|
66
64
|
if (!(filePath in edit.changes)) {
|
|
67
65
|
edit.changes[filePath] = [];
|
|
68
66
|
}
|
|
69
67
|
edit.changes[filePath].push({
|
|
70
68
|
newText: newName,
|
|
71
|
-
range: (0,
|
|
69
|
+
range: (0, utils_3.convertToLocationRange)(fragment, rename.textSpan),
|
|
72
70
|
});
|
|
73
71
|
});
|
|
74
72
|
return edit;
|
|
@@ -81,10 +79,10 @@ class TypeScriptPlugin {
|
|
|
81
79
|
return this.completionProvider.resolveCompletion(document, completionItem);
|
|
82
80
|
}
|
|
83
81
|
async getDefinitions(document, position) {
|
|
84
|
-
const { lang, tsDoc } = await this.languageServiceManager.
|
|
85
|
-
const mainFragment = await tsDoc.
|
|
82
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
83
|
+
const mainFragment = await tsDoc.createFragment();
|
|
86
84
|
const filePath = tsDoc.filePath;
|
|
87
|
-
const tsFilePath = (0,
|
|
85
|
+
const tsFilePath = (0, utils_3.toVirtualAstroFilePath)(filePath);
|
|
88
86
|
const fragmentPosition = mainFragment.getGeneratedPosition(position);
|
|
89
87
|
const fragmentOffset = mainFragment.offsetAt(fragmentPosition);
|
|
90
88
|
let defs = lang.getDefinitionAndBoundSpan(tsFilePath, fragmentOffset);
|
|
@@ -98,17 +96,16 @@ class TypeScriptPlugin {
|
|
|
98
96
|
defs = importDef;
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
|
-
const docs = new
|
|
99
|
+
const docs = new utils_2.SnapshotFragmentMap(this.languageServiceManager);
|
|
102
100
|
docs.set(tsDoc.filePath, { fragment: mainFragment, snapshot: tsDoc });
|
|
103
101
|
const result = await Promise.all(defs.definitions.map(async (def) => {
|
|
104
102
|
const { fragment, snapshot } = await docs.retrieve(def.fileName);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
103
|
+
const fileName = (0, utils_3.ensureRealFilePath)(def.fileName);
|
|
104
|
+
// Since we converted our files to TSX and we don't have sourcemaps, we don't know where the function is, unfortunate
|
|
105
|
+
const textSpan = (0, utils_3.isVirtualFilePath)(tsFilePath) ? { start: 0, length: 0 } : def.textSpan;
|
|
106
|
+
return vscode_languageserver_1.LocationLink.create((0, utils_1.pathToUrl)(fileName), (0, utils_3.convertToLocationRange)(fragment, textSpan), (0, utils_3.convertToLocationRange)(fragment, textSpan), (0, utils_3.convertToLocationRange)(mainFragment, defs.textSpan));
|
|
110
107
|
}));
|
|
111
|
-
return result.filter(
|
|
108
|
+
return result.filter(utils_1.isNotNullOrUndefined);
|
|
112
109
|
}
|
|
113
110
|
async getDiagnostics(document, cancellationToken) {
|
|
114
111
|
if (!this.featureEnabled('diagnostics')) {
|
|
@@ -116,38 +113,31 @@ class TypeScriptPlugin {
|
|
|
116
113
|
}
|
|
117
114
|
return this.diagnosticsProvider.getDiagnostics(document, cancellationToken);
|
|
118
115
|
}
|
|
119
|
-
async onWatchFileChanges(
|
|
120
|
-
|
|
121
|
-
for (const { fileName, changeType } of
|
|
122
|
-
const scriptKind = (0,
|
|
123
|
-
if (scriptKind ===
|
|
124
|
-
// We don't deal with svelte files here
|
|
116
|
+
async onWatchFileChanges(onWatchFileChangesParas) {
|
|
117
|
+
let doneUpdateProjectFiles = false;
|
|
118
|
+
for (const { fileName, changeType } of onWatchFileChangesParas) {
|
|
119
|
+
const scriptKind = (0, utils_3.getScriptKindFromFileName)(fileName);
|
|
120
|
+
if (scriptKind === typescript_1.default.ScriptKind.Unknown) {
|
|
125
121
|
continue;
|
|
126
122
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
snapshotManager.updateProjectFiles();
|
|
131
|
-
doneUpdateProjectFiles.add(snapshotManager);
|
|
132
|
-
}
|
|
123
|
+
if (changeType === vscode_languageserver_1.FileChangeType.Created && !doneUpdateProjectFiles) {
|
|
124
|
+
doneUpdateProjectFiles = true;
|
|
125
|
+
await this.languageServiceManager.updateProjectFiles();
|
|
133
126
|
}
|
|
134
127
|
else if (changeType === vscode_languageserver_1.FileChangeType.Deleted) {
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
await this.languageServiceManager.deleteSnapshot(fileName);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
await this.languageServiceManager.updateExistingNonAstroFile(fileName);
|
|
137
132
|
}
|
|
138
|
-
snapshotManager.updateProjectFile(fileName);
|
|
139
133
|
}
|
|
140
134
|
}
|
|
135
|
+
async updateNonAstroFile(fileName, changes) {
|
|
136
|
+
await this.languageServiceManager.updateExistingNonAstroFile(fileName, changes);
|
|
137
|
+
}
|
|
141
138
|
async getSignatureHelp(document, position, context, cancellationToken) {
|
|
142
139
|
return this.signatureHelpProvider.getSignatureHelp(document, position, context, cancellationToken);
|
|
143
140
|
}
|
|
144
|
-
/**
|
|
145
|
-
*
|
|
146
|
-
* @internal
|
|
147
|
-
*/
|
|
148
|
-
async getSnapshotManager(fileName) {
|
|
149
|
-
return this.languageServiceManager.getSnapshotManager(fileName);
|
|
150
|
-
}
|
|
151
141
|
goToDefinitionFoundOnlyAlias(tsFileName, defs) {
|
|
152
142
|
return !!(defs.length === 1 && defs[0].kind === 'alias' && defs[0].fileName === tsFileName);
|
|
153
143
|
}
|
|
@@ -155,11 +145,11 @@ class TypeScriptPlugin {
|
|
|
155
145
|
const program = lang.getProgram();
|
|
156
146
|
const sourceFile = program === null || program === void 0 ? void 0 : program.getSourceFile(tsFilePath);
|
|
157
147
|
if (sourceFile) {
|
|
158
|
-
let node =
|
|
148
|
+
let node = typescript_1.default.getTouchingPropertyName(sourceFile, offset);
|
|
159
149
|
if (node && node.kind === typescript_1.SyntaxKind.Identifier) {
|
|
160
150
|
if (node.parent.kind === typescript_1.SyntaxKind.ImportClause) {
|
|
161
151
|
let decl = node.parent.parent;
|
|
162
|
-
let spec =
|
|
152
|
+
let spec = typescript_1.default.isStringLiteral(decl.moduleSpecifier) && decl.moduleSpecifier.text;
|
|
163
153
|
if (spec) {
|
|
164
154
|
let fileName = (0, path_1.join)((0, path_1.dirname)(tsFilePath), spec);
|
|
165
155
|
let start = node.pos + 1;
|
|
@@ -188,10 +178,8 @@ class TypeScriptPlugin {
|
|
|
188
178
|
}
|
|
189
179
|
}
|
|
190
180
|
}
|
|
191
|
-
// This exists so we can make features toggleable in the future.
|
|
192
181
|
featureEnabled(feature) {
|
|
193
|
-
return (this.configManager.enabled('typescript.
|
|
194
|
-
this.configManager.enabled(`typescript.${feature}.enable`));
|
|
182
|
+
return (this.configManager.enabled('typescript.enabled') && this.configManager.enabled(`typescript.${feature}.enabled`));
|
|
195
183
|
}
|
|
196
184
|
}
|
|
197
185
|
exports.TypeScriptPlugin = TypeScriptPlugin;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DocumentSnapshot } from './DocumentSnapshot';
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { DocumentSnapshot } from './snapshots/DocumentSnapshot';
|
|
3
3
|
/**
|
|
4
4
|
* This should only be accessed by TS Astro module resolution.
|
|
5
5
|
*/
|
|
6
|
-
export declare function createAstroSys(getSnapshot: (fileName: string) => DocumentSnapshot): ts.System
|
|
6
|
+
export declare function createAstroSys(getSnapshot: (fileName: string) => DocumentSnapshot): ts.System & {
|
|
7
|
+
deleteFromCache: (path: string) => void;
|
|
8
|
+
};
|
|
@@ -1,69 +1,48 @@
|
|
|
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
6
|
exports.createAstroSys = void 0;
|
|
27
|
-
const
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
28
8
|
const utils_1 = require("./utils");
|
|
29
|
-
const ignoredDirectories = [
|
|
30
|
-
"node_modules/@types/react"
|
|
31
|
-
];
|
|
32
|
-
const ignoredDirectoriesExp = new RegExp("(" + ignoredDirectories.map(n => n + "$").join("|") + ")");
|
|
33
9
|
/**
|
|
34
10
|
* This should only be accessed by TS Astro module resolution.
|
|
35
11
|
*/
|
|
36
12
|
function createAstroSys(getSnapshot) {
|
|
13
|
+
const fileExistsCache = new Map();
|
|
37
14
|
const AstroSys = {
|
|
38
|
-
...
|
|
15
|
+
...typescript_1.default.sys,
|
|
39
16
|
fileExists(path) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
return ts.sys.directoryExists(path);
|
|
17
|
+
var _a;
|
|
18
|
+
path = (0, utils_1.ensureRealFilePath)(path);
|
|
19
|
+
const exists = (_a = fileExistsCache.get(path)) !== null && _a !== void 0 ? _a : typescript_1.default.sys.fileExists(path);
|
|
20
|
+
fileExistsCache.set(path, exists);
|
|
21
|
+
return exists;
|
|
48
22
|
},
|
|
49
23
|
readFile(path) {
|
|
50
|
-
if ((0, utils_1.isAstroFilePath)(path) || (0, utils_1.isVirtualAstroFilePath)(path)) {
|
|
51
|
-
console.log('readFile', path);
|
|
52
|
-
}
|
|
53
24
|
const snapshot = getSnapshot(path);
|
|
54
|
-
return snapshot.
|
|
25
|
+
return snapshot.getText(0, snapshot.getLength());
|
|
55
26
|
},
|
|
56
27
|
readDirectory(path, extensions, exclude, include, depth) {
|
|
57
28
|
const extensionsWithAstro = (extensions !== null && extensions !== void 0 ? extensions : []).concat(...['.astro', '.svelte', '.vue']);
|
|
58
|
-
const result =
|
|
29
|
+
const result = typescript_1.default.sys.readDirectory(path, extensionsWithAstro, exclude, include, depth);
|
|
59
30
|
return result;
|
|
60
31
|
},
|
|
32
|
+
deleteFile(path) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
fileExistsCache.delete((0, utils_1.ensureRealFilePath)(path));
|
|
35
|
+
return (_b = (_a = typescript_1.default.sys).deleteFile) === null || _b === void 0 ? void 0 : _b.call(_a, path);
|
|
36
|
+
},
|
|
37
|
+
deleteFromCache(path) {
|
|
38
|
+
fileExistsCache.delete((0, utils_1.ensureRealFilePath)(path));
|
|
39
|
+
},
|
|
61
40
|
};
|
|
62
|
-
if (
|
|
63
|
-
const realpath =
|
|
41
|
+
if (typescript_1.default.sys.realpath) {
|
|
42
|
+
const realpath = typescript_1.default.sys.realpath;
|
|
64
43
|
AstroSys.realpath = function (path) {
|
|
65
|
-
if ((0, utils_1.
|
|
66
|
-
return realpath((0, utils_1.
|
|
44
|
+
if ((0, utils_1.isVirtualFilePath)(path)) {
|
|
45
|
+
return realpath((0, utils_1.ensureRealFilePath)(path)) + '.tsx';
|
|
67
46
|
}
|
|
68
47
|
return realpath(path);
|
|
69
48
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { CompletionContext, Position, TextDocumentIdentifier } from 'vscode-languageserver';
|
|
2
2
|
import type { LanguageServiceManager } from '../LanguageServiceManager';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { AstroDocument } from '../../../core/documents';
|
|
4
|
+
import ts from 'typescript';
|
|
5
5
|
import { AppCompletionItem, AppCompletionList, CompletionsProvider } from '../../interfaces';
|
|
6
6
|
export interface CompletionEntryWithIdentifer extends ts.CompletionEntry, TextDocumentIdentifier {
|
|
7
7
|
position: Position;
|
|
8
8
|
}
|
|
9
9
|
export declare class CompletionsProviderImpl implements CompletionsProvider<CompletionEntryWithIdentifer> {
|
|
10
|
-
private
|
|
11
|
-
constructor(
|
|
12
|
-
getCompletions(document:
|
|
13
|
-
resolveCompletion(document:
|
|
10
|
+
private languageServiceManager;
|
|
11
|
+
constructor(languageServiceManager: LanguageServiceManager);
|
|
12
|
+
getCompletions(document: AstroDocument, position: Position, _completionContext?: CompletionContext): Promise<AppCompletionList<CompletionEntryWithIdentifer> | null>;
|
|
13
|
+
resolveCompletion(document: AstroDocument, completionItem: AppCompletionItem<CompletionEntryWithIdentifer>): Promise<AppCompletionItem<CompletionEntryWithIdentifer>>;
|
|
14
14
|
private toCompletionItem;
|
|
15
15
|
private getCompletionDocument;
|
|
16
16
|
}
|
|
@@ -1,41 +1,21 @@
|
|
|
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
6
|
exports.CompletionsProviderImpl = void 0;
|
|
27
7
|
const utils_1 = require("../../../core/documents/utils");
|
|
28
|
-
const
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
29
9
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
30
10
|
const utils_2 = require("../utils");
|
|
31
11
|
const completionOptions = Object.freeze({
|
|
32
12
|
importModuleSpecifierPreference: 'relative',
|
|
33
|
-
importModuleSpecifierEnding: '
|
|
13
|
+
importModuleSpecifierEnding: 'auto',
|
|
34
14
|
quotePreference: 'single',
|
|
35
15
|
});
|
|
36
16
|
class CompletionsProviderImpl {
|
|
37
|
-
constructor(
|
|
38
|
-
this.
|
|
17
|
+
constructor(languageServiceManager) {
|
|
18
|
+
this.languageServiceManager = languageServiceManager;
|
|
39
19
|
}
|
|
40
20
|
async getCompletions(document, position, _completionContext) {
|
|
41
21
|
var _a;
|
|
@@ -43,13 +23,11 @@ class CompletionsProviderImpl {
|
|
|
43
23
|
if (!(0, utils_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position))) {
|
|
44
24
|
return null;
|
|
45
25
|
}
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const { tsDoc, lang } = await this.lang.getTypeScriptDoc(document);
|
|
50
|
-
const fragment = await tsDoc.getFragment();
|
|
26
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
27
|
+
const filePath = (0, utils_2.toVirtualAstroFilePath)(tsDoc.filePath);
|
|
28
|
+
const fragment = await tsDoc.createFragment();
|
|
51
29
|
const offset = document.offsetAt(position);
|
|
52
|
-
const entries = ((_a = lang.getCompletionsAtPosition(
|
|
30
|
+
const entries = ((_a = lang.getCompletionsAtPosition(filePath, offset, completionOptions)) === null || _a === void 0 ? void 0 : _a.entries) || [];
|
|
53
31
|
const completionItems = entries
|
|
54
32
|
.map((entry) => this.toCompletionItem(fragment, entry, document.uri, position, new Set()))
|
|
55
33
|
.filter((i) => i);
|
|
@@ -57,12 +35,12 @@ class CompletionsProviderImpl {
|
|
|
57
35
|
}
|
|
58
36
|
async resolveCompletion(document, completionItem) {
|
|
59
37
|
const { data: comp } = completionItem;
|
|
60
|
-
const {
|
|
38
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
61
39
|
let filePath = (0, utils_2.toVirtualAstroFilePath)(tsDoc.filePath);
|
|
62
40
|
if (!comp || !filePath) {
|
|
63
41
|
return completionItem;
|
|
64
42
|
}
|
|
65
|
-
const fragment = await tsDoc.
|
|
43
|
+
const fragment = await tsDoc.createFragment();
|
|
66
44
|
const detail = lang.getCompletionEntryDetails(filePath, // fileName
|
|
67
45
|
fragment.offsetAt(comp.position), // position
|
|
68
46
|
comp.name, // entryName
|
|
@@ -97,12 +75,14 @@ class CompletionsProviderImpl {
|
|
|
97
75
|
}
|
|
98
76
|
getCompletionDocument(compDetail) {
|
|
99
77
|
const { source, documentation: tsDocumentation, displayParts, tags } = compDetail;
|
|
100
|
-
let detail =
|
|
78
|
+
let detail = typescript_1.default.displayPartsToString(displayParts);
|
|
101
79
|
if (source) {
|
|
102
|
-
const importPath =
|
|
80
|
+
const importPath = typescript_1.default.displayPartsToString(source);
|
|
103
81
|
detail = `Auto import from ${importPath}\n${detail}`;
|
|
104
82
|
}
|
|
105
|
-
const documentation = tsDocumentation
|
|
83
|
+
const documentation = tsDocumentation
|
|
84
|
+
? { value: tsDocumentation.join('\n'), kind: vscode_languageserver_1.MarkupKind.Markdown }
|
|
85
|
+
: undefined;
|
|
106
86
|
return {
|
|
107
87
|
documentation,
|
|
108
88
|
detail,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { CancellationToken
|
|
2
|
-
import {
|
|
1
|
+
import { CancellationToken } from 'vscode-languageserver';
|
|
2
|
+
import { Diagnostic } from 'vscode-languageserver-types';
|
|
3
|
+
import { AstroDocument } from '../../../core/documents';
|
|
3
4
|
import { DiagnosticsProvider } from '../../interfaces';
|
|
4
5
|
import { LanguageServiceManager } from '../LanguageServiceManager';
|
|
5
6
|
export declare class DiagnosticsProviderImpl implements DiagnosticsProvider {
|
|
6
7
|
private readonly languageServiceManager;
|
|
7
8
|
constructor(languageServiceManager: LanguageServiceManager);
|
|
8
|
-
getDiagnostics(document:
|
|
9
|
-
private getLSAndTSDoc;
|
|
9
|
+
getDiagnostics(document: AstroDocument, _cancellationToken?: CancellationToken): Promise<Diagnostic[]>;
|
|
10
10
|
private getTagBoundaries;
|
|
11
11
|
}
|
|
@@ -5,66 +5,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DiagnosticsProviderImpl = void 0;
|
|
7
7
|
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
-
const
|
|
8
|
+
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
9
9
|
const documents_1 = require("../../../core/documents");
|
|
10
10
|
const utils_1 = require("../utils");
|
|
11
|
-
const utils_2 = require("./utils");
|
|
12
11
|
class DiagnosticsProviderImpl {
|
|
13
12
|
constructor(languageServiceManager) {
|
|
14
13
|
this.languageServiceManager = languageServiceManager;
|
|
15
14
|
}
|
|
16
15
|
async getDiagnostics(document, _cancellationToken) {
|
|
17
|
-
var _a, _b, _c
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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\\')))) {
|
|
23
|
-
// Don't return diagnostics for files inside node_modules. These are considered read-only (cannot be changed)
|
|
24
|
-
// and in case of svelte-check they would pollute/skew the output
|
|
16
|
+
var _a, _b, _c;
|
|
17
|
+
// Don't return diagnostics for files inside node_modules. These are considered read-only
|
|
18
|
+
// and they would pollute the output for astro check
|
|
19
|
+
if (((_a = document.getFilePath()) === null || _a === void 0 ? void 0 : _a.includes('/node_modules/')) || ((_b = document.getFilePath()) === null || _b === void 0 ? void 0 : _b.includes('\\node_modules\\'))) {
|
|
25
20
|
return [];
|
|
26
21
|
}
|
|
27
|
-
const { lang, tsDoc } = await this.getLSAndTSDoc(document);
|
|
28
|
-
const isTypescript = tsDoc.scriptKind === typescript_1.default.ScriptKind.TSX;
|
|
29
|
-
// Document preprocessing failed, show parser error instead
|
|
30
|
-
if (tsDoc.parserError) {
|
|
31
|
-
return [
|
|
32
|
-
{
|
|
33
|
-
range: tsDoc.parserError.range,
|
|
34
|
-
severity: vscode_languageserver_1.DiagnosticSeverity.Error,
|
|
35
|
-
source: isTypescript ? 'ts' : 'js',
|
|
36
|
-
message: tsDoc.parserError.message,
|
|
37
|
-
code: tsDoc.parserError.code
|
|
38
|
-
}
|
|
39
|
-
];
|
|
40
|
-
}
|
|
22
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
41
23
|
const filePath = (0, utils_1.toVirtualAstroFilePath)(tsDoc.filePath);
|
|
42
24
|
const { script: scriptBoundaries, markdown: markdownBoundaries } = this.getTagBoundaries(lang, filePath);
|
|
43
25
|
const syntaxDiagnostics = lang.getSyntacticDiagnostics(filePath);
|
|
44
26
|
const suggestionDiagnostics = lang.getSuggestionDiagnostics(filePath);
|
|
45
|
-
const semanticDiagnostics = lang.getSemanticDiagnostics(filePath).filter(d => {
|
|
46
|
-
return
|
|
27
|
+
const semanticDiagnostics = lang.getSemanticDiagnostics(filePath).filter((d) => {
|
|
28
|
+
return isNoWithinScript(scriptBoundaries, d);
|
|
47
29
|
});
|
|
48
|
-
const diagnostics = [
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
...semanticDiagnostics
|
|
52
|
-
];
|
|
53
|
-
const fragment = await tsDoc.getFragment();
|
|
54
|
-
const sourceFile = (_e = lang.getProgram()) === null || _e === void 0 ? void 0 : _e.getSourceFile(filePath);
|
|
30
|
+
const diagnostics = [...syntaxDiagnostics, ...suggestionDiagnostics, ...semanticDiagnostics];
|
|
31
|
+
const fragment = await tsDoc.createFragment();
|
|
32
|
+
const sourceFile = (_c = lang.getProgram()) === null || _c === void 0 ? void 0 : _c.getSourceFile(filePath);
|
|
55
33
|
const isNoFalsePositiveInst = isNoFalsePositive();
|
|
56
34
|
return diagnostics
|
|
57
|
-
.filter(isNotGenerated(tsDoc.getText(0, tsDoc.getLength())))
|
|
58
35
|
.map((diagnostic) => ({
|
|
59
36
|
range: (0, utils_1.convertRange)(tsDoc, diagnostic),
|
|
60
37
|
severity: (0, utils_1.mapSeverity)(diagnostic.category),
|
|
61
|
-
source:
|
|
38
|
+
source: 'ts',
|
|
62
39
|
message: typescript_1.default.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
|
|
63
40
|
code: diagnostic.code,
|
|
64
|
-
tags: getDiagnosticTag(diagnostic)
|
|
41
|
+
tags: getDiagnosticTag(diagnostic),
|
|
65
42
|
}))
|
|
66
43
|
.map(mapRange(fragment, document))
|
|
67
|
-
.filter(diag => {
|
|
44
|
+
.filter((diag) => {
|
|
68
45
|
return (hasNoNegativeLines(diag) &&
|
|
69
46
|
isNoFalsePositiveInst(diag) &&
|
|
70
47
|
isNoJSXImplicitRuntimeWarning(diag) &&
|
|
@@ -77,21 +54,18 @@ class DiagnosticsProviderImpl {
|
|
|
77
54
|
})
|
|
78
55
|
.map(enhanceIfNecessary);
|
|
79
56
|
}
|
|
80
|
-
async getLSAndTSDoc(document) {
|
|
81
|
-
return this.languageServiceManager.getTypeScriptDoc(document);
|
|
82
|
-
}
|
|
83
57
|
getTagBoundaries(lang, tsFilePath) {
|
|
84
58
|
const program = lang.getProgram();
|
|
85
59
|
const sourceFile = program === null || program === void 0 ? void 0 : program.getSourceFile(tsFilePath);
|
|
86
60
|
const boundaries = {
|
|
87
61
|
script: [],
|
|
88
|
-
markdown: []
|
|
62
|
+
markdown: [],
|
|
89
63
|
};
|
|
90
64
|
if (!sourceFile) {
|
|
91
65
|
return boundaries;
|
|
92
66
|
}
|
|
93
67
|
function findScript(parent) {
|
|
94
|
-
typescript_1.default.forEachChild(parent, node => {
|
|
68
|
+
typescript_1.default.forEachChild(parent, (node) => {
|
|
95
69
|
if (typescript_1.default.isJsxElement(node)) {
|
|
96
70
|
let tagName = node.openingElement.tagName.getText();
|
|
97
71
|
switch (tagName) {
|
|
@@ -117,10 +91,10 @@ exports.DiagnosticsProviderImpl = DiagnosticsProviderImpl;
|
|
|
117
91
|
function getDiagnosticTag(diagnostic) {
|
|
118
92
|
const tags = [];
|
|
119
93
|
if (diagnostic.reportsUnnecessary) {
|
|
120
|
-
tags.push(
|
|
94
|
+
tags.push(vscode_languageserver_types_1.DiagnosticTag.Unnecessary);
|
|
121
95
|
}
|
|
122
96
|
if (diagnostic.reportsDeprecated) {
|
|
123
|
-
tags.push(
|
|
97
|
+
tags.push(vscode_languageserver_types_1.DiagnosticTag.Deprecated);
|
|
124
98
|
}
|
|
125
99
|
return tags;
|
|
126
100
|
}
|
|
@@ -144,7 +118,7 @@ function hasNoNegativeLines(diagnostic) {
|
|
|
144
118
|
}
|
|
145
119
|
function isNoFalsePositive() {
|
|
146
120
|
return (diagnostic) => {
|
|
147
|
-
return
|
|
121
|
+
return isNoJsxCannotHaveMultipleAttrsError(diagnostic);
|
|
148
122
|
};
|
|
149
123
|
}
|
|
150
124
|
/**
|
|
@@ -226,7 +200,7 @@ function enhanceIfNecessary(diagnostic) {
|
|
|
226
200
|
' import type { SvelteComponentTyped } from "svelte";\n' +
|
|
227
201
|
' class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}\n\n' +
|
|
228
202
|
'Underlying error:\n' +
|
|
229
|
-
diagnostic.message
|
|
203
|
+
diagnostic.message,
|
|
230
204
|
};
|
|
231
205
|
}
|
|
232
206
|
if (diagnostic.code === 2607) {
|
|
@@ -235,27 +209,14 @@ function enhanceIfNecessary(diagnostic) {
|
|
|
235
209
|
message: 'Element does not support attributes because ' +
|
|
236
210
|
'type definitions are missing for this Svelte Component or element cannot be used as such.\n\n' +
|
|
237
211
|
'Underlying error:\n' +
|
|
238
|
-
diagnostic.message
|
|
212
|
+
diagnostic.message,
|
|
239
213
|
};
|
|
240
214
|
}
|
|
241
215
|
if (diagnostic.code === 1184) {
|
|
242
216
|
return {
|
|
243
217
|
...diagnostic,
|
|
244
|
-
message: diagnostic.message +
|
|
245
|
-
'\nIf this is a declare statement, move it into <script context="module">..</script>'
|
|
218
|
+
message: diagnostic.message + '\nIf this is a declare statement, move it into <script context="module">..</script>',
|
|
246
219
|
};
|
|
247
220
|
}
|
|
248
221
|
return diagnostic;
|
|
249
222
|
}
|
|
250
|
-
/**
|
|
251
|
-
* Checks if diagnostic is not within a section that should be completely ignored
|
|
252
|
-
* because it's purely generated.
|
|
253
|
-
*/
|
|
254
|
-
function isNotGenerated(text) {
|
|
255
|
-
return (diagnostic) => {
|
|
256
|
-
if (diagnostic.start === undefined || diagnostic.length === undefined) {
|
|
257
|
-
return true;
|
|
258
|
-
}
|
|
259
|
-
return !(0, utils_2.isInGeneratedCode)(text, diagnostic.start, diagnostic.start + diagnostic.length);
|
|
260
|
-
};
|
|
261
|
-
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { LanguageServiceManager } from '../LanguageServiceManager';
|
|
2
2
|
import { Hover, Position } from 'vscode-languageserver';
|
|
3
|
-
import {
|
|
3
|
+
import { AstroDocument } from '../../../core/documents';
|
|
4
4
|
import { HoverProvider } from '../../interfaces';
|
|
5
5
|
export declare class HoverProviderImpl implements HoverProvider {
|
|
6
|
-
private readonly
|
|
7
|
-
constructor(
|
|
8
|
-
doHover(document:
|
|
9
|
-
private getLSAndTSDoc;
|
|
6
|
+
private readonly languageServiceManager;
|
|
7
|
+
constructor(languageServiceManager: LanguageServiceManager);
|
|
8
|
+
doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
|
|
10
9
|
}
|