@astrojs/language-server 0.9.2 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/bin/browserServer.js +3 -0
- package/bin/nodeServer.js +3 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +8 -0
- package/dist/check.js +2 -5
- package/dist/core/DiagnosticsManager.d.ts +3 -3
- package/dist/core/DiagnosticsManager.js +2 -2
- package/dist/core/config/ConfigManager.d.ts +19 -164
- package/dist/core/config/ConfigManager.js +62 -101
- package/dist/core/config/index.d.ts +1 -0
- package/dist/core/config/index.js +6 -1
- package/dist/core/config/interfaces.d.ts +123 -0
- package/dist/core/config/interfaces.js +2 -0
- package/dist/core/documents/AstroDocument.d.ts +18 -0
- package/dist/core/documents/AstroDocument.js +37 -0
- package/dist/core/documents/DocumentBase.d.ts +10 -2
- package/dist/core/documents/DocumentBase.js +15 -50
- package/dist/core/documents/DocumentManager.d.ts +12 -16
- package/dist/core/documents/DocumentManager.js +32 -26
- package/dist/core/documents/DocumentMapper.js +3 -1
- package/dist/core/documents/index.d.ts +1 -1
- package/dist/core/documents/index.js +6 -2
- package/dist/core/documents/parseAstro.d.ts +2 -2
- package/dist/core/documents/parseHtml.d.ts +2 -2
- package/dist/core/documents/parseHtml.js +4 -1
- package/dist/core/documents/utils.d.ts +22 -26
- package/dist/core/documents/utils.js +96 -134
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -3
- package/dist/node.d.ts +1 -0
- package/dist/node.js +29 -0
- package/dist/plugins/PluginHost.d.ts +8 -9
- package/dist/plugins/PluginHost.js +22 -36
- package/dist/plugins/astro/AstroPlugin.d.ts +11 -12
- package/dist/plugins/astro/AstroPlugin.js +17 -38
- package/dist/plugins/astro/features/{CompletionProvider.d.ts → CompletionsProvider.d.ts} +5 -5
- package/dist/plugins/astro/features/{CompletionProvider.js → CompletionsProvider.js} +33 -54
- package/dist/plugins/css/CSSDocument.d.ts +3 -3
- package/dist/plugins/css/CSSDocument.js +7 -16
- package/dist/plugins/css/CSSPlugin.d.ts +19 -11
- package/dist/plugins/css/CSSPlugin.js +63 -41
- package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
- package/dist/plugins/css/StyleAttributeDocument.js +2 -2
- package/dist/plugins/css/features/astro-selectors.d.ts +2 -0
- package/dist/plugins/css/features/astro-selectors.js +16 -0
- package/dist/plugins/css/features/{getIdClassCompletion.d.ts → getIdClassCompletions.d.ts} +3 -3
- package/dist/plugins/css/features/{getIdClassCompletion.js → getIdClassCompletions.js} +10 -9
- package/dist/plugins/css/{service.d.ts → language-service.d.ts} +0 -0
- package/dist/plugins/css/{service.js → language-service.js} +2 -1
- package/dist/plugins/html/HTMLPlugin.d.ts +15 -17
- package/dist/plugins/html/HTMLPlugin.js +33 -41
- package/dist/plugins/index.d.ts +2 -2
- package/dist/plugins/index.js +7 -3
- package/dist/plugins/interfaces.d.ts +35 -48
- package/dist/plugins/typescript/LanguageServiceManager.d.ts +33 -14
- package/dist/plugins/typescript/LanguageServiceManager.js +57 -32
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +16 -23
- package/dist/plugins/typescript/TypeScriptPlugin.js +48 -56
- package/dist/plugins/typescript/astro-sys.d.ts +5 -3
- package/dist/plugins/typescript/astro-sys.js +24 -41
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +6 -6
- package/dist/plugins/typescript/features/CompletionsProvider.js +17 -33
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +4 -4
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +22 -61
- package/dist/plugins/typescript/features/HoverProvider.d.ts +4 -5
- package/dist/plugins/typescript/features/HoverProvider.js +9 -10
- package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +4 -5
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +15 -11
- package/dist/plugins/typescript/features/utils.d.ts +1 -12
- package/dist/plugins/typescript/features/utils.js +2 -22
- package/dist/plugins/typescript/language-service.d.ts +38 -0
- package/dist/plugins/typescript/language-service.js +227 -0
- package/dist/plugins/typescript/module-loader.d.ts +5 -8
- package/dist/plugins/typescript/module-loader.js +43 -23
- package/dist/plugins/typescript/{DocumentSnapshot.d.ts → snapshots/DocumentSnapshot.d.ts} +45 -42
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +135 -0
- package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +42 -0
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +197 -0
- package/dist/plugins/typescript/snapshots/utils.d.ts +28 -0
- package/dist/plugins/typescript/snapshots/utils.js +84 -0
- package/dist/plugins/typescript/utils.d.ts +10 -11
- package/dist/plugins/typescript/utils.js +122 -151
- package/dist/server.d.ts +2 -4
- package/dist/server.js +88 -54
- package/dist/utils.d.ts +16 -8
- package/dist/utils.js +29 -14
- package/package.json +19 -13
- package/bin/server.js +0 -7
- package/dist/core/documents/Document.d.ts +0 -51
- package/dist/core/documents/Document.js +0 -135
- package/dist/plugins/typescript/DocumentSnapshot.js +0 -202
- package/dist/plugins/typescript/SnapshotManager.d.ts +0 -24
- package/dist/plugins/typescript/SnapshotManager.js +0 -97
- package/dist/plugins/typescript/languageService.d.ts +0 -17
- package/dist/plugins/typescript/languageService.js +0 -169
- package/types/index.d.ts +0 -4
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
import { Document } from '../../core/documents';
|
|
3
|
-
import { SnapshotManager } from './SnapshotManager';
|
|
4
|
-
export interface LanguageServiceContainer {
|
|
5
|
-
readonly tsconfigPath: string;
|
|
6
|
-
readonly snapshotManager: SnapshotManager;
|
|
7
|
-
getService(): ts.LanguageService;
|
|
8
|
-
updateDocument(documentOrFilePath: Document | string): ts.IScriptSnapshot;
|
|
9
|
-
deleteDocument(filePath: string): void;
|
|
10
|
-
}
|
|
11
|
-
export interface LanguageServiceDocumentContext {
|
|
12
|
-
getWorkspaceRoot(fileName: string): string;
|
|
13
|
-
createDocument: (fileName: string, content: string, overrideText: boolean) => Document;
|
|
14
|
-
}
|
|
15
|
-
export declare function getLanguageService(path: string, workspaceUris: string[], docContext: LanguageServiceDocumentContext): Promise<LanguageServiceContainer>;
|
|
16
|
-
export declare function getLanguageServiceForDocument(document: Document, workspaceUris: string[], docContext: LanguageServiceDocumentContext): Promise<ts.LanguageService>;
|
|
17
|
-
export declare function getLanguageServiceForPath(path: string, workspaceUris: string[], docContext: LanguageServiceDocumentContext): Promise<ts.LanguageService>;
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable require-jsdoc */
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
6
|
-
}) : (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
o[k2] = m[k];
|
|
9
|
-
}));
|
|
10
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
11
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12
|
-
}) : function(o, v) {
|
|
13
|
-
o["default"] = v;
|
|
14
|
-
});
|
|
15
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
16
|
-
if (mod && mod.__esModule) return mod;
|
|
17
|
-
var result = {};
|
|
18
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
19
|
-
__setModuleDefault(result, mod);
|
|
20
|
-
return result;
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.getLanguageServiceForPath = exports.getLanguageServiceForDocument = exports.getLanguageService = void 0;
|
|
24
|
-
const ts = __importStar(require("typescript"));
|
|
25
|
-
const path_1 = require("path");
|
|
26
|
-
const utils_1 = require("./utils");
|
|
27
|
-
const SnapshotManager_1 = require("./SnapshotManager");
|
|
28
|
-
const DocumentSnapshot_1 = require("./DocumentSnapshot");
|
|
29
|
-
const module_loader_1 = require("./module-loader");
|
|
30
|
-
const services = new Map();
|
|
31
|
-
async function getLanguageService(path, workspaceUris, docContext) {
|
|
32
|
-
const tsconfigPath = (0, utils_1.findTsConfigPath)(path, workspaceUris);
|
|
33
|
-
const workspaceRoot = docContext.getWorkspaceRoot(path);
|
|
34
|
-
let service;
|
|
35
|
-
if (services.has(tsconfigPath)) {
|
|
36
|
-
service = (await services.get(tsconfigPath));
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
const newServicePromise = createLanguageService(tsconfigPath, workspaceRoot, docContext);
|
|
40
|
-
services.set(tsconfigPath, newServicePromise);
|
|
41
|
-
service = await newServicePromise;
|
|
42
|
-
}
|
|
43
|
-
return service;
|
|
44
|
-
}
|
|
45
|
-
exports.getLanguageService = getLanguageService;
|
|
46
|
-
async function getLanguageServiceForDocument(document, workspaceUris, docContext) {
|
|
47
|
-
return getLanguageServiceForPath(document.getFilePath() || '', workspaceUris, docContext);
|
|
48
|
-
}
|
|
49
|
-
exports.getLanguageServiceForDocument = getLanguageServiceForDocument;
|
|
50
|
-
async function getLanguageServiceForPath(path, workspaceUris, docContext) {
|
|
51
|
-
return (await getLanguageService(path, workspaceUris, docContext)).getService();
|
|
52
|
-
}
|
|
53
|
-
exports.getLanguageServiceForPath = getLanguageServiceForPath;
|
|
54
|
-
async function createLanguageService(tsconfigPath, workspaceRoot, docContext) {
|
|
55
|
-
var _a, _b, _c;
|
|
56
|
-
const parseConfigHost = {
|
|
57
|
-
...ts.sys,
|
|
58
|
-
readDirectory: (path, extensions, exclude, include, depth) => {
|
|
59
|
-
return ts.sys.readDirectory(path, [...extensions, '.vue', '.svelte', '.astro', '.js', '.jsx'], exclude, include, depth);
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
let configJson = (tsconfigPath && ts.readConfigFile(tsconfigPath, ts.sys.readFile).config) || {};
|
|
63
|
-
// If our user has types in their config but it doesn't include the types needed for Astro, add them to the config
|
|
64
|
-
if (((_a = configJson.compilerOptions) === null || _a === void 0 ? void 0 : _a.types) &&
|
|
65
|
-
!((_b = configJson.compilerOptions) === null || _b === void 0 ? void 0 : _b.types.includes("astro/env"))) {
|
|
66
|
-
configJson.compilerOptions.types.push("astro/env");
|
|
67
|
-
}
|
|
68
|
-
configJson.compilerOptions = Object.assign(getDefaultCompilerOptions(), configJson.compilerOptions);
|
|
69
|
-
// If the user supplied exclude, let's use theirs
|
|
70
|
-
(_c = configJson.exclude) !== null && _c !== void 0 ? _c : (configJson.exclude = getDefaultExclude());
|
|
71
|
-
// Delete include so that .astro files don't get mistakenly excluded by the user
|
|
72
|
-
delete configJson.include;
|
|
73
|
-
// Everything here will always, unconditionally, be in the resulting config, not the opposite, tricky
|
|
74
|
-
const existingCompilerOptions = {
|
|
75
|
-
// Setting strict to true for .astro files leads to a lot of unrelated errors (see language-tools#91) so we force it off for .astro files
|
|
76
|
-
strict: false,
|
|
77
|
-
jsx: ts.JsxEmit.Preserve,
|
|
78
|
-
module: ts.ModuleKind.ESNext,
|
|
79
|
-
target: ts.ScriptTarget.ESNext,
|
|
80
|
-
};
|
|
81
|
-
const project = ts.parseJsonConfigFileContent(configJson, parseConfigHost, workspaceRoot, existingCompilerOptions, (0, path_1.basename)(tsconfigPath), undefined, [
|
|
82
|
-
{ extension: '.vue', isMixedContent: true, scriptKind: ts.ScriptKind.Deferred },
|
|
83
|
-
{ extension: '.svelte', isMixedContent: true, scriptKind: ts.ScriptKind.Deferred },
|
|
84
|
-
{ extension: '.astro', isMixedContent: true, scriptKind: ts.ScriptKind.Deferred },
|
|
85
|
-
]);
|
|
86
|
-
let projectVersion = 0;
|
|
87
|
-
const snapshotManager = new SnapshotManager_1.SnapshotManager(project.fileNames, {
|
|
88
|
-
exclude: ['node_modules', 'dist'],
|
|
89
|
-
include: ['src'],
|
|
90
|
-
}, workspaceRoot || process.cwd());
|
|
91
|
-
const astroModuleLoader = (0, module_loader_1.createAstroModuleLoader)(getScriptSnapshot, {});
|
|
92
|
-
const host = {
|
|
93
|
-
getNewLine: () => ts.sys.newLine,
|
|
94
|
-
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
|
|
95
|
-
readFile: astroModuleLoader.readFile,
|
|
96
|
-
writeFile: astroModuleLoader.writeFile,
|
|
97
|
-
fileExists: astroModuleLoader.fileExists,
|
|
98
|
-
directoryExists: astroModuleLoader.directoryExists,
|
|
99
|
-
getDirectories: astroModuleLoader.getDirectories,
|
|
100
|
-
readDirectory: astroModuleLoader.readDirectory,
|
|
101
|
-
realpath: astroModuleLoader.realpath,
|
|
102
|
-
getCompilationSettings: () => project.options,
|
|
103
|
-
getCurrentDirectory: () => workspaceRoot,
|
|
104
|
-
getDefaultLibFileName: () => ts.getDefaultLibFilePath(project.options),
|
|
105
|
-
getProjectVersion: () => projectVersion.toString(),
|
|
106
|
-
getScriptFileNames: () => Array.from(new Set([...snapshotManager.getFileNames(), ...snapshotManager.getProjectFileNames()])),
|
|
107
|
-
getScriptSnapshot,
|
|
108
|
-
getScriptVersion: (fileName) => {
|
|
109
|
-
let snapshotVersion = getScriptSnapshot(fileName).version.toString();
|
|
110
|
-
return snapshotVersion;
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
const languageService = ts.createLanguageService(host);
|
|
114
|
-
const languageServiceProxy = new Proxy(languageService, {
|
|
115
|
-
get(target, prop) {
|
|
116
|
-
return Reflect.get(target, prop);
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
return {
|
|
120
|
-
tsconfigPath,
|
|
121
|
-
snapshotManager,
|
|
122
|
-
getService: () => languageServiceProxy,
|
|
123
|
-
updateDocument,
|
|
124
|
-
deleteDocument,
|
|
125
|
-
};
|
|
126
|
-
function onProjectUpdated() {
|
|
127
|
-
projectVersion++;
|
|
128
|
-
}
|
|
129
|
-
function deleteDocument(filePath) {
|
|
130
|
-
snapshotManager.delete(filePath);
|
|
131
|
-
}
|
|
132
|
-
function updateDocument(documentOrFilePath) {
|
|
133
|
-
const filePath = (0, utils_1.ensureRealAstroFilePath)(typeof documentOrFilePath === 'string' ? documentOrFilePath : documentOrFilePath.getFilePath() || '');
|
|
134
|
-
const document = typeof documentOrFilePath === 'string' ? undefined : documentOrFilePath;
|
|
135
|
-
if (!filePath) {
|
|
136
|
-
throw new Error(`Unable to find document`);
|
|
137
|
-
}
|
|
138
|
-
const previousSnapshot = snapshotManager.get(filePath);
|
|
139
|
-
if (document && (previousSnapshot === null || previousSnapshot === void 0 ? void 0 : previousSnapshot.version.toString()) === `${document.version}`) {
|
|
140
|
-
return previousSnapshot;
|
|
141
|
-
}
|
|
142
|
-
const currentText = document ? document.getText() : null;
|
|
143
|
-
const snapshot = (0, DocumentSnapshot_1.createDocumentSnapshot)(filePath, currentText, docContext.createDocument);
|
|
144
|
-
snapshotManager.set(filePath, snapshot);
|
|
145
|
-
onProjectUpdated();
|
|
146
|
-
return snapshot;
|
|
147
|
-
}
|
|
148
|
-
function getScriptSnapshot(fileName) {
|
|
149
|
-
fileName = (0, utils_1.ensureRealAstroFilePath)(fileName);
|
|
150
|
-
let doc = snapshotManager.get(fileName);
|
|
151
|
-
if (doc) {
|
|
152
|
-
return doc;
|
|
153
|
-
}
|
|
154
|
-
doc = (0, DocumentSnapshot_1.createDocumentSnapshot)(fileName, null, docContext.createDocument);
|
|
155
|
-
snapshotManager.set(fileName, doc);
|
|
156
|
-
return doc;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function getDefaultCompilerOptions() {
|
|
160
|
-
return {
|
|
161
|
-
maxNodeModuleJsDepth: 2,
|
|
162
|
-
allowSyntheticDefaultImports: true,
|
|
163
|
-
allowJs: true,
|
|
164
|
-
types: ["astro/env"]
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
function getDefaultExclude() {
|
|
168
|
-
return ['dist', 'node_modules'];
|
|
169
|
-
}
|
package/types/index.d.ts
DELETED