@astrojs/language-server 1.0.4 → 2.0.0-next.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/LICENSE +3 -5
- package/bin/nodeServer.js +7 -3
- package/dist/core/astro2tsx.d.ts +6 -0
- package/dist/core/astro2tsx.js +119 -0
- package/dist/core/compilerUtils.d.ts +27 -0
- package/dist/core/compilerUtils.js +52 -0
- package/dist/core/index.d.ts +27 -0
- package/dist/core/index.js +119 -0
- package/dist/core/parseAstro.d.ts +27 -0
- package/dist/core/parseAstro.js +47 -0
- package/dist/core/parseCSS.d.ts +7 -0
- package/dist/core/parseCSS.js +116 -0
- package/dist/core/parseHTML.d.ts +7 -0
- package/dist/core/parseHTML.js +113 -0
- package/dist/core/parseJS.d.ts +7 -0
- package/dist/core/parseJS.js +236 -0
- package/dist/core/svelte.d.ts +18 -0
- package/dist/core/svelte.js +45 -0
- package/dist/core/utils.d.ts +14 -0
- package/dist/core/utils.js +138 -0
- package/dist/core/vue.d.ts +18 -0
- package/dist/core/vue.js +45 -0
- package/dist/importPackage.d.ts +1 -1
- package/dist/importPackage.js +4 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +26 -6
- package/dist/languageServerPlugin.d.ts +2 -0
- package/dist/languageServerPlugin.js +76 -0
- package/dist/nodeServer.js +6 -0
- package/dist/plugins/astro.d.ts +3 -0
- package/dist/plugins/astro.js +123 -0
- package/dist/plugins/{html/features/astro-attributes.js → html-data.js} +1 -0
- package/dist/plugins/html.d.ts +3 -0
- package/dist/plugins/html.js +33 -0
- package/dist/plugins/typescript/codeActions.d.ts +4 -0
- package/dist/plugins/typescript/codeActions.js +49 -0
- package/dist/plugins/typescript/completions.d.ts +3 -0
- package/dist/plugins/typescript/completions.js +81 -0
- package/dist/plugins/typescript/diagnostics.d.ts +12 -0
- package/dist/plugins/typescript/diagnostics.js +99 -0
- package/dist/plugins/typescript/index.d.ts +3 -0
- package/dist/plugins/typescript/index.js +57 -0
- package/dist/utils.d.ts +19 -69
- package/dist/utils.js +66 -239
- package/package.json +37 -38
- package/types/astro-jsx.d.ts +49 -5
- package/bin/browserServer.js +0 -3
- package/dist/browser.js +0 -15
- package/dist/check.d.ts +0 -23
- package/dist/check.js +0 -60
- package/dist/core/DiagnosticsManager.d.ts +0 -13
- package/dist/core/DiagnosticsManager.js +0 -29
- package/dist/core/config/ConfigManager.d.ts +0 -43
- package/dist/core/config/ConfigManager.js +0 -226
- package/dist/core/config/index.d.ts +0 -2
- package/dist/core/config/index.js +0 -18
- package/dist/core/config/interfaces.d.ts +0 -77
- package/dist/core/config/interfaces.js +0 -2
- package/dist/core/documents/AstroDocument.d.ts +0 -19
- package/dist/core/documents/AstroDocument.js +0 -43
- package/dist/core/documents/DocumentBase.d.ts +0 -68
- package/dist/core/documents/DocumentBase.js +0 -75
- package/dist/core/documents/DocumentManager.d.ts +0 -23
- package/dist/core/documents/DocumentManager.js +0 -100
- package/dist/core/documents/DocumentMapper.d.ts +0 -94
- package/dist/core/documents/DocumentMapper.js +0 -264
- package/dist/core/documents/index.d.ts +0 -5
- package/dist/core/documents/index.js +0 -21
- package/dist/core/documents/parseAstro.d.ts +0 -15
- package/dist/core/documents/parseAstro.js +0 -63
- package/dist/core/documents/parseHtml.d.ts +0 -13
- package/dist/core/documents/parseHtml.js +0 -126
- package/dist/core/documents/utils.d.ts +0 -63
- package/dist/core/documents/utils.js +0 -223
- package/dist/node.d.ts +0 -1
- package/dist/node.js +0 -43
- package/dist/plugins/PluginHost.d.ts +0 -42
- package/dist/plugins/PluginHost.js +0 -206
- package/dist/plugins/astro/AstroPlugin.d.ts +0 -17
- package/dist/plugins/astro/AstroPlugin.js +0 -90
- package/dist/plugins/astro/features/CompletionsProvider.d.ts +0 -17
- package/dist/plugins/astro/features/CompletionsProvider.js +0 -242
- package/dist/plugins/astro/features/DiagnosticsProvider.d.ts +0 -10
- package/dist/plugins/astro/features/DiagnosticsProvider.js +0 -23
- package/dist/plugins/css/CSSDocument.d.ts +0 -45
- package/dist/plugins/css/CSSDocument.js +0 -68
- package/dist/plugins/css/CSSPlugin.d.ts +0 -39
- package/dist/plugins/css/CSSPlugin.js +0 -274
- package/dist/plugins/css/StyleAttributeDocument.d.ts +0 -40
- package/dist/plugins/css/StyleAttributeDocument.js +0 -64
- package/dist/plugins/css/features/astro-selectors.d.ts +0 -2
- package/dist/plugins/css/features/astro-selectors.js +0 -15
- package/dist/plugins/css/features/getIdClassCompletions.d.ts +0 -19
- package/dist/plugins/css/features/getIdClassCompletions.js +0 -57
- package/dist/plugins/css/language-service.d.ts +0 -3
- package/dist/plugins/css/language-service.js +0 -47
- package/dist/plugins/html/HTMLPlugin.d.ts +0 -33
- package/dist/plugins/html/HTMLPlugin.js +0 -198
- package/dist/plugins/html/utils.d.ts +0 -6
- package/dist/plugins/html/utils.js +0 -11
- package/dist/plugins/index.d.ts +0 -6
- package/dist/plugins/index.js +0 -22
- package/dist/plugins/interfaces.d.ts +0 -101
- package/dist/plugins/interfaces.js +0 -2
- package/dist/plugins/typescript/LanguageServiceManager.d.ts +0 -47
- package/dist/plugins/typescript/LanguageServiceManager.js +0 -97
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +0 -54
- package/dist/plugins/typescript/TypeScriptPlugin.js +0 -152
- package/dist/plugins/typescript/astro-sys.d.ts +0 -8
- package/dist/plugins/typescript/astro-sys.js +0 -46
- package/dist/plugins/typescript/astro2tsx.d.ts +0 -2
- package/dist/plugins/typescript/astro2tsx.js +0 -26
- package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +0 -17
- package/dist/plugins/typescript/features/CodeActionsProvider.js +0 -212
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +0 -31
- package/dist/plugins/typescript/features/CompletionsProvider.js +0 -294
- package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/DefinitionsProvider.js +0 -58
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +0 -25
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +0 -249
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +0 -11
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +0 -67
- package/dist/plugins/typescript/features/FileReferencesProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/FileReferencesProvider.js +0 -27
- package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +0 -12
- package/dist/plugins/typescript/features/FoldingRangesProvider.js +0 -71
- package/dist/plugins/typescript/features/HoverProvider.d.ts +0 -10
- package/dist/plugins/typescript/features/HoverProvider.js +0 -50
- package/dist/plugins/typescript/features/ImplementationsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/ImplementationsProvider.js +0 -53
- package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +0 -13
- package/dist/plugins/typescript/features/InlayHintsProvider.js +0 -30
- package/dist/plugins/typescript/features/ReferencesProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/ReferencesProvider.js +0 -55
- package/dist/plugins/typescript/features/RenameProvider.d.ts +0 -13
- package/dist/plugins/typescript/features/RenameProvider.js +0 -60
- package/dist/plugins/typescript/features/SemanticTokenProvider.d.ts +0 -16
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +0 -75
- package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +0 -22
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +0 -111
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.js +0 -54
- package/dist/plugins/typescript/features/utils.d.ts +0 -14
- package/dist/plugins/typescript/features/utils.js +0 -48
- package/dist/plugins/typescript/language-service.d.ts +0 -42
- package/dist/plugins/typescript/language-service.js +0 -277
- package/dist/plugins/typescript/module-loader.d.ts +0 -23
- package/dist/plugins/typescript/module-loader.js +0 -155
- package/dist/plugins/typescript/previewer.d.ts +0 -7
- package/dist/plugins/typescript/previewer.js +0 -108
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +0 -95
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +0 -187
- package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +0 -44
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +0 -179
- package/dist/plugins/typescript/snapshots/utils.d.ts +0 -29
- package/dist/plugins/typescript/snapshots/utils.js +0 -106
- package/dist/plugins/typescript/utils.d.ts +0 -75
- package/dist/plugins/typescript/utils.js +0 -366
- package/dist/server.d.ts +0 -6
- package/dist/server.js +0 -275
- package/types/README.md +0 -5
- /package/dist/{browser.d.ts → nodeServer.d.ts} +0 -0
- /package/dist/plugins/{html/features/astro-attributes.d.ts → html-data.d.ts} +0 -0
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.SnapshotManager = exports.GlobalSnapshotManager = void 0;
|
|
27
|
-
const events_1 = require("events");
|
|
28
|
-
const utils_1 = require("../../../utils");
|
|
29
|
-
const DocumentSnapshot_1 = require("./DocumentSnapshot");
|
|
30
|
-
const DocumentSnapshotUtils = __importStar(require("./utils"));
|
|
31
|
-
/**
|
|
32
|
-
* Every snapshot corresponds to a unique file on disk.
|
|
33
|
-
* A snapshot can be part of multiple projects, but for a given file path
|
|
34
|
-
* there can be only one snapshot.
|
|
35
|
-
*/
|
|
36
|
-
class GlobalSnapshotManager {
|
|
37
|
-
constructor(ts) {
|
|
38
|
-
this.ts = ts;
|
|
39
|
-
this.emitter = new events_1.EventEmitter();
|
|
40
|
-
this.documents = new Map();
|
|
41
|
-
}
|
|
42
|
-
get(fileName) {
|
|
43
|
-
fileName = (0, utils_1.normalizePath)(fileName);
|
|
44
|
-
return this.documents.get(fileName);
|
|
45
|
-
}
|
|
46
|
-
set(fileName, document) {
|
|
47
|
-
fileName = (0, utils_1.normalizePath)(fileName);
|
|
48
|
-
this.documents.set(fileName, document);
|
|
49
|
-
this.emitter.emit('change', fileName, document);
|
|
50
|
-
}
|
|
51
|
-
delete(fileName) {
|
|
52
|
-
fileName = (0, utils_1.normalizePath)(fileName);
|
|
53
|
-
this.documents.delete(fileName);
|
|
54
|
-
this.emitter.emit('change', fileName, undefined);
|
|
55
|
-
}
|
|
56
|
-
updateNonAstroFile(fileName, changes, newText) {
|
|
57
|
-
fileName = (0, utils_1.normalizePath)(fileName);
|
|
58
|
-
const previousSnapshot = this.get(fileName);
|
|
59
|
-
const canBePartiallyUpdated = changes && previousSnapshot instanceof DocumentSnapshot_1.TypeScriptDocumentSnapshot && previousSnapshot.supportPartialUpdate;
|
|
60
|
-
if (canBePartiallyUpdated) {
|
|
61
|
-
previousSnapshot.update(changes);
|
|
62
|
-
this.emitter.emit('change', fileName, previousSnapshot);
|
|
63
|
-
return previousSnapshot;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
const newSnapshot = DocumentSnapshotUtils.createFromNonAstroFilePath(fileName, this.ts, newText);
|
|
67
|
-
if (previousSnapshot) {
|
|
68
|
-
newSnapshot.version = previousSnapshot.version + 1;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
// ensure it's greater than initial version
|
|
72
|
-
// so that ts server picks up the change
|
|
73
|
-
newSnapshot.version += 1;
|
|
74
|
-
}
|
|
75
|
-
this.set(fileName, newSnapshot);
|
|
76
|
-
this.emitter.emit('change', fileName, newSnapshot);
|
|
77
|
-
return newSnapshot;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
onChange(listener) {
|
|
81
|
-
this.emitter.on('change', listener);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.GlobalSnapshotManager = GlobalSnapshotManager;
|
|
85
|
-
/**
|
|
86
|
-
* Should only be used by `language-service.ts`
|
|
87
|
-
*/
|
|
88
|
-
class SnapshotManager {
|
|
89
|
-
constructor(globalSnapshotsManager, projectFiles, fileSpec, workspaceRoot, ts) {
|
|
90
|
-
this.globalSnapshotsManager = globalSnapshotsManager;
|
|
91
|
-
this.projectFiles = projectFiles;
|
|
92
|
-
this.fileSpec = fileSpec;
|
|
93
|
-
this.workspaceRoot = workspaceRoot;
|
|
94
|
-
this.ts = ts;
|
|
95
|
-
this.documents = new Map();
|
|
96
|
-
this.lastLogged = new Date(new Date().getTime() - 60001);
|
|
97
|
-
this.globalSnapshotsManager.onChange((fileName, document) => {
|
|
98
|
-
// Only delete/update snapshots, don't add new ones,
|
|
99
|
-
// as they could be from another TS service and this
|
|
100
|
-
// snapshot manager can't reach this file.
|
|
101
|
-
// For these, instead wait on a `get` method invocation
|
|
102
|
-
// and set them "manually" in the set/update methods.
|
|
103
|
-
if (!document) {
|
|
104
|
-
this.documents.delete(fileName);
|
|
105
|
-
}
|
|
106
|
-
else if (this.documents.has(fileName)) {
|
|
107
|
-
this.documents.set(fileName, document);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
updateProjectFiles() {
|
|
112
|
-
const { include, exclude } = this.fileSpec;
|
|
113
|
-
// Since we default to not include anything,
|
|
114
|
-
// just don't waste time on this
|
|
115
|
-
if (include?.length === 0) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const projectFiles = this.ts.sys
|
|
119
|
-
.readDirectory(this.workspaceRoot, [...Object.values(this.ts.Extension), '.astro', '.svelte', '.vue'], exclude, include)
|
|
120
|
-
.map(utils_1.normalizePath);
|
|
121
|
-
this.projectFiles = Array.from(new Set([...this.projectFiles, ...projectFiles]));
|
|
122
|
-
}
|
|
123
|
-
updateNonAstroFile(fileName, changes, text) {
|
|
124
|
-
const snapshot = this.globalSnapshotsManager.updateNonAstroFile(fileName, changes, text);
|
|
125
|
-
// This isn't duplicated logic to the listener, because this could
|
|
126
|
-
// be a new snapshot which the listener wouldn't add.
|
|
127
|
-
if (snapshot) {
|
|
128
|
-
this.documents.set((0, utils_1.normalizePath)(fileName), snapshot);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
has(fileName) {
|
|
132
|
-
fileName = (0, utils_1.normalizePath)(fileName);
|
|
133
|
-
return this.projectFiles.includes(fileName) || this.getFileNames().includes(fileName);
|
|
134
|
-
}
|
|
135
|
-
set(fileName, snapshot) {
|
|
136
|
-
this.globalSnapshotsManager.set(fileName, snapshot);
|
|
137
|
-
// This isn't duplicated logic to the listener, because this could
|
|
138
|
-
// be a new snapshot which the listener wouldn't add.
|
|
139
|
-
this.documents.set((0, utils_1.normalizePath)(fileName), snapshot);
|
|
140
|
-
}
|
|
141
|
-
get(fileName) {
|
|
142
|
-
fileName = (0, utils_1.normalizePath)(fileName);
|
|
143
|
-
let snapshot = this.documents.get(fileName);
|
|
144
|
-
if (!snapshot) {
|
|
145
|
-
snapshot = this.globalSnapshotsManager.get(fileName);
|
|
146
|
-
if (snapshot) {
|
|
147
|
-
this.documents.set(fileName, snapshot);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return snapshot;
|
|
151
|
-
}
|
|
152
|
-
delete(fileName) {
|
|
153
|
-
fileName = (0, utils_1.normalizePath)(fileName);
|
|
154
|
-
this.projectFiles = this.projectFiles.filter((s) => s !== fileName);
|
|
155
|
-
this.globalSnapshotsManager.delete(fileName);
|
|
156
|
-
}
|
|
157
|
-
getFileNames() {
|
|
158
|
-
return Array.from(this.documents.keys());
|
|
159
|
-
}
|
|
160
|
-
getProjectFileNames() {
|
|
161
|
-
return [...this.projectFiles];
|
|
162
|
-
}
|
|
163
|
-
logStatistics() {
|
|
164
|
-
const date = new Date();
|
|
165
|
-
// Don't use setInterval because that will keep tests running forever
|
|
166
|
-
if (date.getTime() - this.lastLogged.getTime() > 60000) {
|
|
167
|
-
this.lastLogged = date;
|
|
168
|
-
const projectFiles = this.getProjectFileNames();
|
|
169
|
-
const allFiles = Array.from(new Set([...projectFiles, ...this.getFileNames()]));
|
|
170
|
-
// eslint-disable-next-line no-console
|
|
171
|
-
console.log('SnapshotManager File Statistics:\n' +
|
|
172
|
-
`Project files: ${projectFiles.length}\n` +
|
|
173
|
-
`Astro files: ${allFiles.filter((name) => name.endsWith('.astro')).length}\n` +
|
|
174
|
-
`From node_modules: ${allFiles.filter((name) => name.includes('node_modules')).length}\n` +
|
|
175
|
-
`Total: ${allFiles.length}`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
exports.SnapshotManager = SnapshotManager;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { AstroDocument } from '../../../core/documents';
|
|
2
|
-
import { FrameworkExt } from '../utils';
|
|
3
|
-
import { AstroSnapshot, TypeScriptDocumentSnapshot } from './DocumentSnapshot';
|
|
4
|
-
export declare function createFromDocument(document: AstroDocument, ts: typeof import('typescript/lib/tsserverlibrary')): AstroSnapshot;
|
|
5
|
-
/**
|
|
6
|
-
* Returns an Astro or Framework or a ts/js snapshot from a file path, depending on the file contents.
|
|
7
|
-
* @param filePath path to the file
|
|
8
|
-
* @param createDocument function that is used to create a document in case it's an Astro file
|
|
9
|
-
*/
|
|
10
|
-
export declare function createFromFilePath(filePath: string, createDocument: (filePath: string, text: string) => AstroDocument, ts: typeof import('typescript/lib/tsserverlibrary')): AstroSnapshot | TypeScriptDocumentSnapshot;
|
|
11
|
-
/**
|
|
12
|
-
* Return a Framework or a TS snapshot from a file path, depending on the file contents
|
|
13
|
-
* Unlike createFromFilePath, this does not support creating an Astro snapshot
|
|
14
|
-
*/
|
|
15
|
-
export declare function createFromNonAstroFilePath(filePath: string, ts: typeof import('typescript/lib/tsserverlibrary'), forceText?: string): TypeScriptDocumentSnapshot;
|
|
16
|
-
/**
|
|
17
|
-
* Returns a ts/js snapshot from a file path.
|
|
18
|
-
* @param filePath path to the js/ts file
|
|
19
|
-
* @param options options that apply in case it's a svelte file
|
|
20
|
-
*/
|
|
21
|
-
export declare function createFromTSFilePath(filePath: string, ts: typeof import('typescript/lib/tsserverlibrary'), forceText?: string): TypeScriptDocumentSnapshot;
|
|
22
|
-
/**
|
|
23
|
-
* Returns an Astro snapshot from a file path.
|
|
24
|
-
* @param filePath path to the Astro file
|
|
25
|
-
* @param createDocument function that is used to create a document
|
|
26
|
-
*/
|
|
27
|
-
export declare function createFromAstroFilePath(filePath: string, createDocument: (filePath: string, text: string) => AstroDocument, ts: typeof import('typescript/lib/tsserverlibrary')): AstroSnapshot;
|
|
28
|
-
export declare function createFromFrameworkFilePath(filePath: string, framework: FrameworkExt, ts: typeof import('typescript/lib/tsserverlibrary'), forceText?: string): TypeScriptDocumentSnapshot;
|
|
29
|
-
export declare function classNameFromFilename(filename: string): string;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.classNameFromFilename = exports.createFromFrameworkFilePath = exports.createFromAstroFilePath = exports.createFromTSFilePath = exports.createFromNonAstroFilePath = exports.createFromFilePath = exports.createFromDocument = void 0;
|
|
4
|
-
const vscode_uri_1 = require("vscode-uri");
|
|
5
|
-
const importPackage_1 = require("../../../importPackage");
|
|
6
|
-
const utils_1 = require("../../../utils");
|
|
7
|
-
const astro2tsx_1 = require("../astro2tsx");
|
|
8
|
-
const utils_2 = require("../utils");
|
|
9
|
-
const DocumentSnapshot_1 = require("./DocumentSnapshot");
|
|
10
|
-
// Utilities to create Snapshots from different contexts
|
|
11
|
-
function createFromDocument(document, ts) {
|
|
12
|
-
const { code, map, diagnostics } = (0, astro2tsx_1.astro2tsx)(document.getText(), document.getURL());
|
|
13
|
-
const sourceMap = map;
|
|
14
|
-
return new DocumentSnapshot_1.AstroSnapshot(document, code, sourceMap, ts.ScriptKind.TSX, diagnostics);
|
|
15
|
-
}
|
|
16
|
-
exports.createFromDocument = createFromDocument;
|
|
17
|
-
/**
|
|
18
|
-
* Returns an Astro or Framework or a ts/js snapshot from a file path, depending on the file contents.
|
|
19
|
-
* @param filePath path to the file
|
|
20
|
-
* @param createDocument function that is used to create a document in case it's an Astro file
|
|
21
|
-
*/
|
|
22
|
-
function createFromFilePath(filePath, createDocument, ts) {
|
|
23
|
-
if ((0, utils_2.isAstroFilePath)(filePath)) {
|
|
24
|
-
return createFromAstroFilePath(filePath, createDocument, ts);
|
|
25
|
-
}
|
|
26
|
-
else if ((0, utils_2.isFrameworkFilePath)(filePath)) {
|
|
27
|
-
const framework = (0, utils_2.getFrameworkFromFilePath)(filePath);
|
|
28
|
-
return createFromFrameworkFilePath(filePath, framework, ts);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
return createFromTSFilePath(filePath, ts);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.createFromFilePath = createFromFilePath;
|
|
35
|
-
/**
|
|
36
|
-
* Return a Framework or a TS snapshot from a file path, depending on the file contents
|
|
37
|
-
* Unlike createFromFilePath, this does not support creating an Astro snapshot
|
|
38
|
-
*/
|
|
39
|
-
function createFromNonAstroFilePath(filePath, ts, forceText) {
|
|
40
|
-
if ((0, utils_2.isFrameworkFilePath)(filePath)) {
|
|
41
|
-
const framework = (0, utils_2.getFrameworkFromFilePath)(filePath);
|
|
42
|
-
return createFromFrameworkFilePath(filePath, framework, ts, forceText);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
return createFromTSFilePath(filePath, ts, forceText);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.createFromNonAstroFilePath = createFromNonAstroFilePath;
|
|
49
|
-
/**
|
|
50
|
-
* Returns a ts/js snapshot from a file path.
|
|
51
|
-
* @param filePath path to the js/ts file
|
|
52
|
-
* @param options options that apply in case it's a svelte file
|
|
53
|
-
*/
|
|
54
|
-
function createFromTSFilePath(filePath, ts, forceText) {
|
|
55
|
-
const originalText = forceText ?? ts.sys.readFile(filePath) ?? '';
|
|
56
|
-
return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, originalText, (0, utils_2.getScriptKindFromFileName)(filePath, ts), true);
|
|
57
|
-
}
|
|
58
|
-
exports.createFromTSFilePath = createFromTSFilePath;
|
|
59
|
-
/**
|
|
60
|
-
* Returns an Astro snapshot from a file path.
|
|
61
|
-
* @param filePath path to the Astro file
|
|
62
|
-
* @param createDocument function that is used to create a document
|
|
63
|
-
*/
|
|
64
|
-
function createFromAstroFilePath(filePath, createDocument, ts) {
|
|
65
|
-
const originalText = ts.sys.readFile(filePath) ?? '';
|
|
66
|
-
return createFromDocument(createDocument(filePath, originalText), ts);
|
|
67
|
-
}
|
|
68
|
-
exports.createFromAstroFilePath = createFromAstroFilePath;
|
|
69
|
-
function createFromFrameworkFilePath(filePath, framework, ts, forceText) {
|
|
70
|
-
const className = classNameFromFilename(filePath);
|
|
71
|
-
const originalText = forceText ?? ts.sys.readFile(filePath) ?? '';
|
|
72
|
-
let code = '';
|
|
73
|
-
if (framework === 'svelte') {
|
|
74
|
-
const svelteIntegration = (0, importPackage_1.importSvelteIntegration)(filePath);
|
|
75
|
-
if (svelteIntegration) {
|
|
76
|
-
code = svelteIntegration.toTSX(originalText, className);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else if (framework === 'vue') {
|
|
80
|
-
const vueIntegration = (0, importPackage_1.importVueIntegration)(filePath);
|
|
81
|
-
if (vueIntegration) {
|
|
82
|
-
code = vueIntegration.toTSX(originalText, className);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, code, ts.ScriptKind.TSX, false);
|
|
86
|
-
}
|
|
87
|
-
exports.createFromFrameworkFilePath = createFromFrameworkFilePath;
|
|
88
|
-
function classNameFromFilename(filename) {
|
|
89
|
-
const url = vscode_uri_1.URI.parse(filename);
|
|
90
|
-
const withoutExtensions = vscode_uri_1.Utils.basename(url).slice(0, -vscode_uri_1.Utils.extname(url).length);
|
|
91
|
-
const withoutInvalidCharacters = withoutExtensions
|
|
92
|
-
.split('')
|
|
93
|
-
// Although "-" is invalid, we leave it in, pascal-case-handling will throw it out later
|
|
94
|
-
.filter((char) => /[A-Za-z$_\d-]/.test(char))
|
|
95
|
-
.join('');
|
|
96
|
-
const firstValidCharIdx = withoutInvalidCharacters
|
|
97
|
-
.split('')
|
|
98
|
-
// Although _ and $ are valid first characters for classes, they are invalid first characters
|
|
99
|
-
// for tag names. For a better import autocompletion experience, we therefore throw them out.
|
|
100
|
-
.findIndex((char) => /[A-Za-z]/.test(char));
|
|
101
|
-
const withoutLeadingInvalidCharacters = withoutInvalidCharacters.substr(firstValidCharIdx);
|
|
102
|
-
const inPascalCase = (0, utils_1.toPascalCase)(withoutLeadingInvalidCharacters);
|
|
103
|
-
const finalName = firstValidCharIdx === -1 ? `A${inPascalCase}` : inPascalCase;
|
|
104
|
-
return finalName;
|
|
105
|
-
}
|
|
106
|
-
exports.classNameFromFilename = classNameFromFilename;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type ts from 'typescript';
|
|
2
|
-
import type { Node } from 'vscode-html-languageservice';
|
|
3
|
-
import { CompletionItemKind, Position, Range, SemanticTokensLegend, SymbolKind } from 'vscode-languageserver';
|
|
4
|
-
import { AstroDocument, TagInformation } from '../../core/documents';
|
|
5
|
-
import type { AstroSnapshot, DocumentSnapshot, ScriptTagDocumentSnapshot } from './snapshots/DocumentSnapshot';
|
|
6
|
-
export declare const enum TokenType {
|
|
7
|
-
class = 0,
|
|
8
|
-
enum = 1,
|
|
9
|
-
interface = 2,
|
|
10
|
-
namespace = 3,
|
|
11
|
-
typeParameter = 4,
|
|
12
|
-
type = 5,
|
|
13
|
-
parameter = 6,
|
|
14
|
-
variable = 7,
|
|
15
|
-
enumMember = 8,
|
|
16
|
-
property = 9,
|
|
17
|
-
function = 10,
|
|
18
|
-
method = 11
|
|
19
|
-
}
|
|
20
|
-
export declare const enum TokenModifier {
|
|
21
|
-
declaration = 0,
|
|
22
|
-
static = 1,
|
|
23
|
-
async = 2,
|
|
24
|
-
readonly = 3,
|
|
25
|
-
defaultLibrary = 4,
|
|
26
|
-
local = 5
|
|
27
|
-
}
|
|
28
|
-
export declare function getSemanticTokenLegend(): SemanticTokensLegend;
|
|
29
|
-
export declare function symbolKindFromString(kind: string): SymbolKind;
|
|
30
|
-
export declare function scriptElementKindToCompletionItemKind(kind: ts.ScriptElementKind, ts: typeof import('typescript/lib/tsserverlibrary')): CompletionItemKind;
|
|
31
|
-
export declare function getCommitCharactersForScriptElement(kind: ts.ScriptElementKind, ts: typeof import('typescript/lib/tsserverlibrary')): string[] | undefined;
|
|
32
|
-
export declare function getExtensionFromScriptKind(kind: ts.ScriptKind | undefined, ts: typeof import('typescript/lib/tsserverlibrary')): ts.Extension;
|
|
33
|
-
export declare function findTsConfigPath(fileName: string, rootUris: string[], ts: typeof import('typescript/lib/tsserverlibrary')): string;
|
|
34
|
-
export declare function isSubPath(uri: string, possibleSubPath: string): boolean;
|
|
35
|
-
export declare function getScriptKindFromFileName(fileName: string, ts: typeof import('typescript/lib/tsserverlibrary')): ts.ScriptKind;
|
|
36
|
-
export declare function convertRange(document: {
|
|
37
|
-
positionAt: (offset: number) => Position;
|
|
38
|
-
}, range: {
|
|
39
|
-
start?: number;
|
|
40
|
-
length?: number;
|
|
41
|
-
}): Range;
|
|
42
|
-
export declare function convertToLocationRange(defDoc: DocumentSnapshot, textSpan: ts.TextSpan): Range;
|
|
43
|
-
export declare function ensureFrontmatterInsert(resultRange: Range, document: AstroDocument): Range;
|
|
44
|
-
export declare function checkEndOfFileCodeInsert(resultRange: Range, document: AstroDocument): Range;
|
|
45
|
-
export declare function removeAstroComponentSuffix(name: string): string;
|
|
46
|
-
export type FrameworkExt = 'astro' | 'vue' | 'jsx' | 'tsx' | 'svelte';
|
|
47
|
-
type FrameworkVirtualExt = 'ts' | 'tsx';
|
|
48
|
-
export declare function getFrameworkFromFilePath(filePath: string): FrameworkExt;
|
|
49
|
-
export declare function isVirtualFrameworkFilePath(ext: FrameworkExt, virtualExt: FrameworkVirtualExt, filePath: string): boolean;
|
|
50
|
-
export declare function isAstroFilePath(filePath: string): boolean;
|
|
51
|
-
export declare function isFrameworkFilePath(filePath: string): boolean;
|
|
52
|
-
export declare function isVirtualAstroFilePath(filePath: string): boolean;
|
|
53
|
-
export declare function isVirtualVueFilePath(filePath: string): boolean;
|
|
54
|
-
export declare function isVirtualSvelteFilePath(filePath: string): boolean;
|
|
55
|
-
export declare function isVirtualFilePath(filePath: string): boolean;
|
|
56
|
-
export declare function toVirtualAstroFilePath(filePath: string): string;
|
|
57
|
-
export declare function toVirtualFilePath(filePath: string): string;
|
|
58
|
-
export declare function toRealAstroFilePath(filePath: string): string;
|
|
59
|
-
export declare function ensureRealAstroFilePath(filePath: string): string;
|
|
60
|
-
export declare function ensureRealFilePath(filePath: string): string;
|
|
61
|
-
export declare function isDocumentSymbolsPath(filePath: string): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Return if a script tag is TypeScript or JavaScript
|
|
64
|
-
*/
|
|
65
|
-
export declare function getScriptTagLanguage(scriptTag: TagInformation): 'js' | 'ts';
|
|
66
|
-
export declare function getScriptTagSnapshot(snapshot: AstroSnapshot, document: AstroDocument, tagInfo: Node | {
|
|
67
|
-
start: number;
|
|
68
|
-
end: number;
|
|
69
|
-
}, position?: Position): {
|
|
70
|
-
snapshot: ScriptTagDocumentSnapshot;
|
|
71
|
-
filePath: string;
|
|
72
|
-
index: number;
|
|
73
|
-
offset: number;
|
|
74
|
-
};
|
|
75
|
-
export {};
|