@astrojs/language-server 0.9.3 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/bin/browserServer.js +3 -0
- package/bin/nodeServer.js +3 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +8 -0
- package/dist/check.js +2 -5
- package/dist/core/DiagnosticsManager.d.ts +3 -3
- package/dist/core/DiagnosticsManager.js +2 -2
- package/dist/core/config/ConfigManager.d.ts +19 -164
- package/dist/core/config/ConfigManager.js +62 -101
- package/dist/core/config/index.d.ts +1 -0
- package/dist/core/config/index.js +6 -1
- package/dist/core/config/interfaces.d.ts +123 -0
- package/dist/core/config/interfaces.js +2 -0
- package/dist/core/documents/AstroDocument.d.ts +18 -0
- package/dist/core/documents/AstroDocument.js +37 -0
- package/dist/core/documents/DocumentBase.d.ts +10 -2
- package/dist/core/documents/DocumentBase.js +15 -50
- package/dist/core/documents/DocumentManager.d.ts +12 -16
- package/dist/core/documents/DocumentManager.js +32 -26
- package/dist/core/documents/DocumentMapper.js +3 -1
- package/dist/core/documents/index.d.ts +1 -1
- package/dist/core/documents/index.js +6 -2
- package/dist/core/documents/parseAstro.d.ts +2 -2
- package/dist/core/documents/parseHtml.d.ts +2 -2
- package/dist/core/documents/parseHtml.js +4 -1
- package/dist/core/documents/utils.d.ts +22 -26
- package/dist/core/documents/utils.js +96 -134
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -3
- package/dist/node.d.ts +1 -0
- package/dist/node.js +29 -0
- package/dist/plugins/PluginHost.d.ts +10 -9
- package/dist/plugins/PluginHost.js +30 -36
- package/dist/plugins/astro/AstroPlugin.d.ts +11 -12
- package/dist/plugins/astro/AstroPlugin.js +17 -38
- package/dist/plugins/astro/features/{CompletionProvider.d.ts → CompletionsProvider.d.ts} +5 -5
- package/dist/plugins/astro/features/{CompletionProvider.js → CompletionsProvider.js} +33 -54
- package/dist/plugins/css/CSSDocument.d.ts +3 -3
- package/dist/plugins/css/CSSDocument.js +7 -16
- package/dist/plugins/css/CSSPlugin.d.ts +22 -12
- package/dist/plugins/css/CSSPlugin.js +112 -41
- package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
- package/dist/plugins/css/StyleAttributeDocument.js +2 -2
- package/dist/plugins/css/features/astro-selectors.d.ts +2 -0
- package/dist/plugins/css/features/astro-selectors.js +16 -0
- package/dist/plugins/css/features/{getIdClassCompletion.d.ts → getIdClassCompletions.d.ts} +3 -3
- package/dist/plugins/css/features/{getIdClassCompletion.js → getIdClassCompletions.js} +10 -9
- package/dist/plugins/css/{service.d.ts → language-service.d.ts} +0 -0
- package/dist/plugins/css/{service.js → language-service.js} +2 -1
- package/dist/plugins/html/HTMLPlugin.d.ts +15 -17
- package/dist/plugins/html/HTMLPlugin.js +33 -41
- package/dist/plugins/index.d.ts +2 -2
- package/dist/plugins/index.js +7 -3
- package/dist/plugins/interfaces.d.ts +35 -48
- package/dist/plugins/typescript/LanguageServiceManager.d.ts +33 -14
- package/dist/plugins/typescript/LanguageServiceManager.js +57 -32
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +16 -23
- package/dist/plugins/typescript/TypeScriptPlugin.js +48 -56
- package/dist/plugins/typescript/astro-sys.d.ts +5 -3
- package/dist/plugins/typescript/astro-sys.js +24 -41
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +6 -6
- package/dist/plugins/typescript/features/CompletionsProvider.js +17 -33
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +4 -4
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +22 -61
- package/dist/plugins/typescript/features/HoverProvider.d.ts +4 -5
- package/dist/plugins/typescript/features/HoverProvider.js +9 -10
- package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +4 -5
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +15 -11
- package/dist/plugins/typescript/features/utils.d.ts +1 -12
- package/dist/plugins/typescript/features/utils.js +2 -22
- package/dist/plugins/typescript/language-service.d.ts +38 -0
- package/dist/plugins/typescript/language-service.js +222 -0
- package/dist/plugins/typescript/module-loader.d.ts +5 -8
- package/dist/plugins/typescript/module-loader.js +43 -23
- package/dist/plugins/typescript/{DocumentSnapshot.d.ts → snapshots/DocumentSnapshot.d.ts} +45 -42
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +135 -0
- package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +42 -0
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +197 -0
- package/dist/plugins/typescript/snapshots/utils.d.ts +28 -0
- package/dist/plugins/typescript/snapshots/utils.js +84 -0
- package/dist/plugins/typescript/utils.d.ts +10 -11
- package/dist/plugins/typescript/utils.js +122 -151
- package/dist/server.d.ts +2 -4
- package/dist/server.js +91 -54
- package/dist/utils.d.ts +16 -8
- package/dist/utils.js +29 -14
- package/package.json +19 -13
- package/bin/server.js +0 -7
- package/dist/core/documents/Document.d.ts +0 -51
- package/dist/core/documents/Document.js +0 -135
- package/dist/plugins/typescript/DocumentSnapshot.js +0 -202
- package/dist/plugins/typescript/SnapshotManager.d.ts +0 -24
- package/dist/plugins/typescript/SnapshotManager.js +0 -97
- package/dist/plugins/typescript/languageService.d.ts +0 -17
- package/dist/plugins/typescript/languageService.js +0 -169
- package/types/index.d.ts +0 -4
|
@@ -1,33 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { CompletionContext, DefinitionLink, Position } from 'vscode-languageserver';
|
|
6
|
-
import { SnapshotManager } from './SnapshotManager';
|
|
1
|
+
import { CancellationToken, CompletionContext, DefinitionLink, Diagnostic, Hover, Position, SignatureHelp, SignatureHelpContext, TextDocumentContentChangeEvent, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
|
+
import { ConfigManager } from '../../core/config';
|
|
3
|
+
import { AstroDocument, DocumentManager } from '../../core/documents';
|
|
4
|
+
import { AppCompletionItem, AppCompletionList, OnWatchFileChangesParam, Plugin } from '../interfaces';
|
|
7
5
|
import { CompletionEntryWithIdentifer } from './features/CompletionsProvider';
|
|
8
|
-
export declare class TypeScriptPlugin implements
|
|
9
|
-
|
|
10
|
-
private
|
|
6
|
+
export declare class TypeScriptPlugin implements Plugin {
|
|
7
|
+
__name: string;
|
|
8
|
+
private configManager;
|
|
11
9
|
private readonly languageServiceManager;
|
|
12
|
-
pluginName: string;
|
|
13
10
|
private readonly completionProvider;
|
|
14
11
|
private readonly hoverProvider;
|
|
15
12
|
private readonly signatureHelpProvider;
|
|
16
13
|
private readonly diagnosticsProvider;
|
|
17
14
|
constructor(docManager: DocumentManager, configManager: ConfigManager, workspaceUris: string[]);
|
|
18
|
-
doHover(document:
|
|
19
|
-
rename(document:
|
|
20
|
-
getCompletions(document:
|
|
21
|
-
resolveCompletion(document:
|
|
22
|
-
getDefinitions(document:
|
|
23
|
-
getDiagnostics(document:
|
|
24
|
-
onWatchFileChanges(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
getSnapshotManager(fileName: string): Promise<SnapshotManager>;
|
|
15
|
+
doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
|
|
16
|
+
rename(document: AstroDocument, position: Position, newName: string): Promise<WorkspaceEdit | null>;
|
|
17
|
+
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList<CompletionEntryWithIdentifer> | null>;
|
|
18
|
+
resolveCompletion(document: AstroDocument, completionItem: AppCompletionItem<CompletionEntryWithIdentifer>): Promise<AppCompletionItem<CompletionEntryWithIdentifer>>;
|
|
19
|
+
getDefinitions(document: AstroDocument, position: Position): Promise<DefinitionLink[]>;
|
|
20
|
+
getDiagnostics(document: AstroDocument, cancellationToken?: CancellationToken): Promise<Diagnostic[]>;
|
|
21
|
+
onWatchFileChanges(onWatchFileChangesParas: OnWatchFileChangesParam[]): Promise<void>;
|
|
22
|
+
updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): Promise<void>;
|
|
23
|
+
getSignatureHelp(document: AstroDocument, position: Position, context: SignatureHelpContext | undefined, cancellationToken?: CancellationToken): Promise<SignatureHelp | null>;
|
|
31
24
|
private goToDefinitionFoundOnlyAlias;
|
|
32
25
|
private getGoToDefinitionRefsForImportSpecifier;
|
|
33
26
|
private featureEnabled;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -20,24 +24,22 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
24
|
};
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
26
|
exports.TypeScriptPlugin = void 0;
|
|
23
|
-
const
|
|
24
|
-
const typescript_1 = require("typescript");
|
|
27
|
+
const typescript_1 = __importStar(require("typescript"));
|
|
25
28
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const utils_1 = require("./utils");
|
|
29
|
-
const utils_2 = require("../../utils");
|
|
29
|
+
const path_1 = require("path");
|
|
30
|
+
const utils_1 = require("../../utils");
|
|
30
31
|
const CompletionsProvider_1 = require("./features/CompletionsProvider");
|
|
31
|
-
const HoverProvider_1 = require("./features/HoverProvider");
|
|
32
32
|
const DiagnosticsProvider_1 = require("./features/DiagnosticsProvider");
|
|
33
|
-
const
|
|
33
|
+
const HoverProvider_1 = require("./features/HoverProvider");
|
|
34
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");
|
|
35
38
|
class TypeScriptPlugin {
|
|
36
39
|
constructor(docManager, configManager, workspaceUris) {
|
|
37
|
-
this.
|
|
38
|
-
this.docManager = docManager;
|
|
40
|
+
this.__name = 'typescript';
|
|
39
41
|
this.configManager = configManager;
|
|
40
|
-
this.languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(docManager,
|
|
42
|
+
this.languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(docManager, workspaceUris, configManager);
|
|
41
43
|
this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(this.languageServiceManager);
|
|
42
44
|
this.hoverProvider = new HoverProvider_1.HoverProviderImpl(this.languageServiceManager);
|
|
43
45
|
this.signatureHelpProvider = new SignatureHelpProvider_1.SignatureHelpProviderImpl(this.languageServiceManager);
|
|
@@ -47,24 +49,24 @@ class TypeScriptPlugin {
|
|
|
47
49
|
return this.hoverProvider.doHover(document, position);
|
|
48
50
|
}
|
|
49
51
|
async rename(document, position, newName) {
|
|
50
|
-
const { lang, tsDoc } = await this.languageServiceManager.
|
|
51
|
-
const fragment = await tsDoc.
|
|
52
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
53
|
+
const fragment = await tsDoc.createFragment();
|
|
52
54
|
const offset = fragment.offsetAt(fragment.getGeneratedPosition(position));
|
|
53
|
-
let renames = lang.findRenameLocations((0,
|
|
55
|
+
let renames = lang.findRenameLocations((0, utils_3.toVirtualAstroFilePath)(tsDoc.filePath), offset, false, false, true);
|
|
54
56
|
if (!renames) {
|
|
55
57
|
return null;
|
|
56
58
|
}
|
|
57
59
|
let edit = {
|
|
58
|
-
changes: {}
|
|
60
|
+
changes: {},
|
|
59
61
|
};
|
|
60
|
-
renames.forEach(rename => {
|
|
61
|
-
const filePath = (0,
|
|
62
|
+
renames.forEach((rename) => {
|
|
63
|
+
const filePath = (0, utils_3.ensureRealFilePath)(rename.fileName);
|
|
62
64
|
if (!(filePath in edit.changes)) {
|
|
63
65
|
edit.changes[filePath] = [];
|
|
64
66
|
}
|
|
65
67
|
edit.changes[filePath].push({
|
|
66
68
|
newText: newName,
|
|
67
|
-
range: (0,
|
|
69
|
+
range: (0, utils_3.convertToLocationRange)(fragment, rename.textSpan),
|
|
68
70
|
});
|
|
69
71
|
});
|
|
70
72
|
return edit;
|
|
@@ -77,10 +79,10 @@ class TypeScriptPlugin {
|
|
|
77
79
|
return this.completionProvider.resolveCompletion(document, completionItem);
|
|
78
80
|
}
|
|
79
81
|
async getDefinitions(document, position) {
|
|
80
|
-
const { lang, tsDoc } = await this.languageServiceManager.
|
|
81
|
-
const mainFragment = await tsDoc.
|
|
82
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
83
|
+
const mainFragment = await tsDoc.createFragment();
|
|
82
84
|
const filePath = tsDoc.filePath;
|
|
83
|
-
const tsFilePath = (0,
|
|
85
|
+
const tsFilePath = (0, utils_3.toVirtualAstroFilePath)(filePath);
|
|
84
86
|
const fragmentPosition = mainFragment.getGeneratedPosition(position);
|
|
85
87
|
const fragmentOffset = mainFragment.offsetAt(fragmentPosition);
|
|
86
88
|
let defs = lang.getDefinitionAndBoundSpan(tsFilePath, fragmentOffset);
|
|
@@ -94,17 +96,16 @@ class TypeScriptPlugin {
|
|
|
94
96
|
defs = importDef;
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
|
-
const docs = new
|
|
99
|
+
const docs = new utils_2.SnapshotFragmentMap(this.languageServiceManager);
|
|
98
100
|
docs.set(tsDoc.filePath, { fragment: mainFragment, snapshot: tsDoc });
|
|
99
101
|
const result = await Promise.all(defs.definitions.map(async (def) => {
|
|
100
102
|
const { fragment, snapshot } = await docs.retrieve(def.fileName);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
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));
|
|
106
107
|
}));
|
|
107
|
-
return result.filter(
|
|
108
|
+
return result.filter(utils_1.isNotNullOrUndefined);
|
|
108
109
|
}
|
|
109
110
|
async getDiagnostics(document, cancellationToken) {
|
|
110
111
|
if (!this.featureEnabled('diagnostics')) {
|
|
@@ -112,38 +113,31 @@ class TypeScriptPlugin {
|
|
|
112
113
|
}
|
|
113
114
|
return this.diagnosticsProvider.getDiagnostics(document, cancellationToken);
|
|
114
115
|
}
|
|
115
|
-
async onWatchFileChanges(
|
|
116
|
-
|
|
117
|
-
for (const { fileName, changeType } of
|
|
118
|
-
const scriptKind = (0,
|
|
119
|
-
if (scriptKind ===
|
|
120
|
-
// 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) {
|
|
121
121
|
continue;
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
snapshotManager.updateProjectFiles();
|
|
127
|
-
doneUpdateProjectFiles.add(snapshotManager);
|
|
128
|
-
}
|
|
123
|
+
if (changeType === vscode_languageserver_1.FileChangeType.Created && !doneUpdateProjectFiles) {
|
|
124
|
+
doneUpdateProjectFiles = true;
|
|
125
|
+
await this.languageServiceManager.updateProjectFiles();
|
|
129
126
|
}
|
|
130
127
|
else if (changeType === vscode_languageserver_1.FileChangeType.Deleted) {
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
await this.languageServiceManager.deleteSnapshot(fileName);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
await this.languageServiceManager.updateExistingNonAstroFile(fileName);
|
|
133
132
|
}
|
|
134
|
-
snapshotManager.updateProjectFile(fileName);
|
|
135
133
|
}
|
|
136
134
|
}
|
|
135
|
+
async updateNonAstroFile(fileName, changes) {
|
|
136
|
+
await this.languageServiceManager.updateExistingNonAstroFile(fileName, changes);
|
|
137
|
+
}
|
|
137
138
|
async getSignatureHelp(document, position, context, cancellationToken) {
|
|
138
139
|
return this.signatureHelpProvider.getSignatureHelp(document, position, context, cancellationToken);
|
|
139
140
|
}
|
|
140
|
-
/**
|
|
141
|
-
*
|
|
142
|
-
* @internal
|
|
143
|
-
*/
|
|
144
|
-
async getSnapshotManager(fileName) {
|
|
145
|
-
return this.languageServiceManager.getSnapshotManager(fileName);
|
|
146
|
-
}
|
|
147
141
|
goToDefinitionFoundOnlyAlias(tsFileName, defs) {
|
|
148
142
|
return !!(defs.length === 1 && defs[0].kind === 'alias' && defs[0].fileName === tsFileName);
|
|
149
143
|
}
|
|
@@ -151,11 +145,11 @@ class TypeScriptPlugin {
|
|
|
151
145
|
const program = lang.getProgram();
|
|
152
146
|
const sourceFile = program === null || program === void 0 ? void 0 : program.getSourceFile(tsFilePath);
|
|
153
147
|
if (sourceFile) {
|
|
154
|
-
let node =
|
|
148
|
+
let node = typescript_1.default.getTouchingPropertyName(sourceFile, offset);
|
|
155
149
|
if (node && node.kind === typescript_1.SyntaxKind.Identifier) {
|
|
156
150
|
if (node.parent.kind === typescript_1.SyntaxKind.ImportClause) {
|
|
157
151
|
let decl = node.parent.parent;
|
|
158
|
-
let spec =
|
|
152
|
+
let spec = typescript_1.default.isStringLiteral(decl.moduleSpecifier) && decl.moduleSpecifier.text;
|
|
159
153
|
if (spec) {
|
|
160
154
|
let fileName = (0, path_1.join)((0, path_1.dirname)(tsFilePath), spec);
|
|
161
155
|
let start = node.pos + 1;
|
|
@@ -184,10 +178,8 @@ class TypeScriptPlugin {
|
|
|
184
178
|
}
|
|
185
179
|
}
|
|
186
180
|
}
|
|
187
|
-
// This exists so we can make features toggleable in the future.
|
|
188
181
|
featureEnabled(feature) {
|
|
189
|
-
return (this.configManager.enabled('typescript.
|
|
190
|
-
this.configManager.enabled(`typescript.${feature}.enable`));
|
|
182
|
+
return (this.configManager.enabled('typescript.enabled') && this.configManager.enabled(`typescript.${feature}.enabled`));
|
|
191
183
|
}
|
|
192
184
|
}
|
|
193
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,65 +1,48 @@
|
|
|
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
6
|
exports.createAstroSys = void 0;
|
|
23
|
-
const
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
24
8
|
const utils_1 = require("./utils");
|
|
25
|
-
const ignoredDirectories = [
|
|
26
|
-
"node_modules/@types/react"
|
|
27
|
-
];
|
|
28
|
-
const ignoredDirectoriesExp = new RegExp("(" + ignoredDirectories.map(n => n + "$").join("|") + ")");
|
|
29
9
|
/**
|
|
30
10
|
* This should only be accessed by TS Astro module resolution.
|
|
31
11
|
*/
|
|
32
12
|
function createAstroSys(getSnapshot) {
|
|
13
|
+
const fileExistsCache = new Map();
|
|
33
14
|
const AstroSys = {
|
|
34
|
-
...
|
|
15
|
+
...typescript_1.default.sys,
|
|
35
16
|
fileExists(path) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
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;
|
|
44
22
|
},
|
|
45
23
|
readFile(path) {
|
|
46
|
-
if ((0, utils_1.isAstroFilePath)(path) || (0, utils_1.isVirtualAstroFilePath)(path)) {
|
|
47
|
-
console.log('readFile', path);
|
|
48
|
-
}
|
|
49
24
|
const snapshot = getSnapshot(path);
|
|
50
|
-
return snapshot.
|
|
25
|
+
return snapshot.getText(0, snapshot.getLength());
|
|
51
26
|
},
|
|
52
27
|
readDirectory(path, extensions, exclude, include, depth) {
|
|
53
28
|
const extensionsWithAstro = (extensions !== null && extensions !== void 0 ? extensions : []).concat(...['.astro', '.svelte', '.vue']);
|
|
54
|
-
const result =
|
|
29
|
+
const result = typescript_1.default.sys.readDirectory(path, extensionsWithAstro, exclude, include, depth);
|
|
55
30
|
return result;
|
|
56
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
|
+
},
|
|
57
40
|
};
|
|
58
|
-
if (
|
|
59
|
-
const realpath =
|
|
41
|
+
if (typescript_1.default.sys.realpath) {
|
|
42
|
+
const realpath = typescript_1.default.sys.realpath;
|
|
60
43
|
AstroSys.realpath = function (path) {
|
|
61
|
-
if ((0, utils_1.
|
|
62
|
-
return realpath((0, utils_1.
|
|
44
|
+
if ((0, utils_1.isVirtualFilePath)(path)) {
|
|
45
|
+
return realpath((0, utils_1.ensureRealFilePath)(path)) + '.tsx';
|
|
63
46
|
}
|
|
64
47
|
return realpath(path);
|
|
65
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,37 +1,21 @@
|
|
|
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
6
|
exports.CompletionsProviderImpl = void 0;
|
|
23
7
|
const utils_1 = require("../../../core/documents/utils");
|
|
24
|
-
const
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
25
9
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
26
10
|
const utils_2 = require("../utils");
|
|
27
11
|
const completionOptions = Object.freeze({
|
|
28
12
|
importModuleSpecifierPreference: 'relative',
|
|
29
|
-
importModuleSpecifierEnding: '
|
|
13
|
+
importModuleSpecifierEnding: 'auto',
|
|
30
14
|
quotePreference: 'single',
|
|
31
15
|
});
|
|
32
16
|
class CompletionsProviderImpl {
|
|
33
|
-
constructor(
|
|
34
|
-
this.
|
|
17
|
+
constructor(languageServiceManager) {
|
|
18
|
+
this.languageServiceManager = languageServiceManager;
|
|
35
19
|
}
|
|
36
20
|
async getCompletions(document, position, _completionContext) {
|
|
37
21
|
var _a;
|
|
@@ -39,13 +23,11 @@ class CompletionsProviderImpl {
|
|
|
39
23
|
if (!(0, utils_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position))) {
|
|
40
24
|
return null;
|
|
41
25
|
}
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const { tsDoc, lang } = await this.lang.getTypeScriptDoc(document);
|
|
46
|
-
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();
|
|
47
29
|
const offset = document.offsetAt(position);
|
|
48
|
-
const entries = ((_a = lang.getCompletionsAtPosition(
|
|
30
|
+
const entries = ((_a = lang.getCompletionsAtPosition(filePath, offset, completionOptions)) === null || _a === void 0 ? void 0 : _a.entries) || [];
|
|
49
31
|
const completionItems = entries
|
|
50
32
|
.map((entry) => this.toCompletionItem(fragment, entry, document.uri, position, new Set()))
|
|
51
33
|
.filter((i) => i);
|
|
@@ -53,12 +35,12 @@ class CompletionsProviderImpl {
|
|
|
53
35
|
}
|
|
54
36
|
async resolveCompletion(document, completionItem) {
|
|
55
37
|
const { data: comp } = completionItem;
|
|
56
|
-
const {
|
|
38
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
57
39
|
let filePath = (0, utils_2.toVirtualAstroFilePath)(tsDoc.filePath);
|
|
58
40
|
if (!comp || !filePath) {
|
|
59
41
|
return completionItem;
|
|
60
42
|
}
|
|
61
|
-
const fragment = await tsDoc.
|
|
43
|
+
const fragment = await tsDoc.createFragment();
|
|
62
44
|
const detail = lang.getCompletionEntryDetails(filePath, // fileName
|
|
63
45
|
fragment.offsetAt(comp.position), // position
|
|
64
46
|
comp.name, // entryName
|
|
@@ -93,12 +75,14 @@ class CompletionsProviderImpl {
|
|
|
93
75
|
}
|
|
94
76
|
getCompletionDocument(compDetail) {
|
|
95
77
|
const { source, documentation: tsDocumentation, displayParts, tags } = compDetail;
|
|
96
|
-
let detail =
|
|
78
|
+
let detail = typescript_1.default.displayPartsToString(displayParts);
|
|
97
79
|
if (source) {
|
|
98
|
-
const importPath =
|
|
80
|
+
const importPath = typescript_1.default.displayPartsToString(source);
|
|
99
81
|
detail = `Auto import from ${importPath}\n${detail}`;
|
|
100
82
|
}
|
|
101
|
-
const documentation = tsDocumentation
|
|
83
|
+
const documentation = tsDocumentation
|
|
84
|
+
? { value: tsDocumentation.join('\n'), kind: vscode_languageserver_1.MarkupKind.Markdown }
|
|
85
|
+
: undefined;
|
|
102
86
|
return {
|
|
103
87
|
documentation,
|
|
104
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
|
}
|