@astrojs/language-server 0.20.3 → 0.21.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 +11 -0
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +2 -0
- package/dist/plugins/typescript/TypeScriptPlugin.js +5 -0
- package/dist/plugins/typescript/astro2tsx.d.ts +1 -2
- package/dist/plugins/typescript/astro2tsx.js +0 -4
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +0 -5
- package/dist/plugins/typescript/features/FoldingRangesProvider.js +1 -1
- package/dist/plugins/typescript/language-service.js +6 -30
- package/dist/plugins/typescript/snapshots/utils.d.ts +1 -0
- package/dist/plugins/typescript/snapshots/utils.js +2 -1
- package/dist/server.js +13 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @astrojs/language-server
|
|
2
2
|
|
|
3
|
+
## 0.21.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 574b75d: Remove support for the Markdown component
|
|
8
|
+
- d23ba22: Changed how Astro's types are consumed to avoid making type acquisition explicit inside Astro files
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 81f3aa5: Added a debug command to show the currently opened document's TSX output
|
|
13
|
+
|
|
3
14
|
## 0.20.3
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -3,6 +3,7 @@ import { ConfigManager } from '../../core/config';
|
|
|
3
3
|
import { AstroDocument, DocumentManager } from '../../core/documents';
|
|
4
4
|
import { AppCompletionItem, AppCompletionList, OnWatchFileChangesParam, Plugin } from '../interfaces';
|
|
5
5
|
import { CompletionItemData } from './features/CompletionsProvider';
|
|
6
|
+
import { Astro2TSXResult } from './astro2tsx';
|
|
6
7
|
export declare class TypeScriptPlugin implements Plugin {
|
|
7
8
|
__name: string;
|
|
8
9
|
private configManager;
|
|
@@ -34,5 +35,6 @@ export declare class TypeScriptPlugin implements Plugin {
|
|
|
34
35
|
onWatchFileChanges(onWatchFileChangesParas: OnWatchFileChangesParam[]): Promise<void>;
|
|
35
36
|
updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): Promise<void>;
|
|
36
37
|
getSignatureHelp(document: AstroDocument, position: Position, context: SignatureHelpContext | undefined, cancellationToken?: CancellationToken): Promise<SignatureHelp | null>;
|
|
38
|
+
getTSXForDocument(document: AstroDocument): Astro2TSXResult;
|
|
37
39
|
private featureEnabled;
|
|
38
40
|
}
|
|
@@ -19,6 +19,8 @@ const CodeActionsProvider_1 = require("./features/CodeActionsProvider");
|
|
|
19
19
|
const DefinitionsProvider_1 = require("./features/DefinitionsProvider");
|
|
20
20
|
const InlayHintsProvider_1 = require("./features/InlayHintsProvider");
|
|
21
21
|
const FormattingProvider_1 = require("./features/FormattingProvider");
|
|
22
|
+
const astro2tsx_1 = __importDefault(require("./astro2tsx"));
|
|
23
|
+
const utils_2 = require("./snapshots/utils");
|
|
22
24
|
class TypeScriptPlugin {
|
|
23
25
|
constructor(docManager, configManager, workspaceUris) {
|
|
24
26
|
this.__name = 'typescript';
|
|
@@ -137,6 +139,9 @@ class TypeScriptPlugin {
|
|
|
137
139
|
async getSignatureHelp(document, position, context, cancellationToken) {
|
|
138
140
|
return this.signatureHelpProvider.getSignatureHelp(document, position, context, cancellationToken);
|
|
139
141
|
}
|
|
142
|
+
getTSXForDocument(document) {
|
|
143
|
+
return (0, astro2tsx_1.default)(document.getText(), (0, utils_2.classNameFromFilename)(document.getURL()));
|
|
144
|
+
}
|
|
140
145
|
async featureEnabled(document, feature) {
|
|
141
146
|
return ((await this.configManager.isEnabled(document, 'typescript')) &&
|
|
142
147
|
(await this.configManager.isEnabled(document, 'typescript', feature)));
|
|
@@ -41,10 +41,6 @@ function default_1(content, className) {
|
|
|
41
41
|
// Turn styles tags into internal strings
|
|
42
42
|
.replace(/<\s*style([^>]*)>(.*?)<\s*\/\s*style>/gs, (_whole, attrs, children) => {
|
|
43
43
|
return `<style${attrs}>{\`${escapeTemplateLiteralContent(children)}\`}</style>`;
|
|
44
|
-
})
|
|
45
|
-
// Turn Markdown tags into internal strings
|
|
46
|
-
.replace(/<\s*Markdown([^>]*)>(.*?)<\s*\/\s*Markdown>/gs, (_whole, attrs, children) => {
|
|
47
|
-
return `<Markdown${attrs}>{\`${escapeTemplateLiteralContent(children)}\`}</Markdown>`;
|
|
48
44
|
})
|
|
49
45
|
// Turn scripts into function calls
|
|
50
46
|
.replace(/<\s*script([^\/>]*)>(.*?)<\s*\/\s*script>/gs, (_whole, attrs, children, offset) => {
|
|
@@ -95,7 +95,6 @@ class DiagnosticsProviderImpl {
|
|
|
95
95
|
const sourceFile = program?.getSourceFile(tsFilePath);
|
|
96
96
|
const boundaries = {
|
|
97
97
|
script: [],
|
|
98
|
-
markdown: [],
|
|
99
98
|
};
|
|
100
99
|
if (!sourceFile) {
|
|
101
100
|
return boundaries;
|
|
@@ -110,10 +109,6 @@ class DiagnosticsProviderImpl {
|
|
|
110
109
|
boundaries.script.push([node.getStart(), node.getEnd()]);
|
|
111
110
|
break;
|
|
112
111
|
}
|
|
113
|
-
case 'Markdown': {
|
|
114
|
-
boundaries.markdown.push([node.getStart(), node.getEnd()]);
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
112
|
}
|
|
118
113
|
}
|
|
119
114
|
findTags(node);
|
|
@@ -19,7 +19,7 @@ class FoldingRangesProviderImpl {
|
|
|
19
19
|
const node = html.findNodeAt(span.textSpan.start);
|
|
20
20
|
// Due to how our TSX output transform those tags into function calls or template literals
|
|
21
21
|
// TypeScript thinks of those as outlining spans, which is fine but we don't want folding ranges for those
|
|
22
|
-
return node.tag !== 'script' && node.tag !== 'style'
|
|
22
|
+
return node.tag !== 'script' && node.tag !== 'style';
|
|
23
23
|
});
|
|
24
24
|
const scriptOutliningSpans = [];
|
|
25
25
|
document.scriptTags.forEach((scriptTag) => {
|
|
@@ -80,6 +80,11 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
|
|
|
80
80
|
let projectVersion = 0;
|
|
81
81
|
const snapshotManager = new SnapshotManager_1.SnapshotManager(docContext.globalSnapshotManager, files, fullConfig, tsconfigRoot || process.cwd());
|
|
82
82
|
const astroModuleLoader = (0, module_loader_1.createAstroModuleLoader)(getScriptSnapshot, compilerOptions);
|
|
83
|
+
const scriptFileNames = [];
|
|
84
|
+
if (astroVersion.exist) {
|
|
85
|
+
const astroDir = (0, path_1.dirname)(require.resolve('astro', { paths: [workspacePath] }));
|
|
86
|
+
scriptFileNames.push(...['./env.d.ts', './astro-jsx.d.ts'].map((f) => typescript_1.default.sys.resolvePath((0, path_1.resolve)(astroDir, f))));
|
|
87
|
+
}
|
|
83
88
|
let languageServerDirectory;
|
|
84
89
|
try {
|
|
85
90
|
languageServerDirectory = (0, path_1.dirname)(require.resolve('@astrojs/language-server'));
|
|
@@ -87,7 +92,6 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
|
|
|
87
92
|
catch (e) {
|
|
88
93
|
languageServerDirectory = __dirname;
|
|
89
94
|
}
|
|
90
|
-
const scriptFileNames = [];
|
|
91
95
|
// Before Astro 1.0, JSX definitions were inside of the language-server instead of inside Astro
|
|
92
96
|
// TODO: Remove this and astro-jsx.d.ts in types when we consider having support for Astro < 1.0 unnecessary
|
|
93
97
|
if ((astroVersion.major === 0 || astroVersion.full === '1.0.0-beta.0') &&
|
|
@@ -221,23 +225,7 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
|
|
|
221
225
|
});
|
|
222
226
|
}
|
|
223
227
|
function getParsedTSConfig() {
|
|
224
|
-
let configJson = (tsconfigPath && typescript_1.default.readConfigFile(tsconfigPath, typescript_1.default.sys.readFile).config) || {
|
|
225
|
-
compilerOptions: getDefaultCompilerOptions(astroVersion),
|
|
226
|
-
};
|
|
227
|
-
// If our user has types in their config but it doesn't include the types needed for Astro, add them to the config
|
|
228
|
-
if (configJson.compilerOptions?.types) {
|
|
229
|
-
if (!configJson.compilerOptions?.types.includes('astro/env')) {
|
|
230
|
-
configJson.compilerOptions.types.push('astro/env');
|
|
231
|
-
}
|
|
232
|
-
if ((astroVersion.major >= 1 || astroVersion.full.startsWith('0.0.0-rc-')) &&
|
|
233
|
-
astroVersion.full !== '1.0.0-beta.0' &&
|
|
234
|
-
!configJson.compilerOptions?.types.includes('astro/astro-jsx')) {
|
|
235
|
-
configJson.compilerOptions.types.push('astro/astro-jsx');
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
configJson.compilerOptions = Object.assign(getDefaultCompilerOptions(astroVersion), configJson.compilerOptions);
|
|
240
|
-
}
|
|
228
|
+
let configJson = (tsconfigPath && typescript_1.default.readConfigFile(tsconfigPath, typescript_1.default.sys.readFile).config) || {};
|
|
241
229
|
// Delete include so that .astro files don't get mistakenly excluded by the user
|
|
242
230
|
delete configJson.include;
|
|
243
231
|
// If the user supplied exclude, let's use theirs otherwise, use ours
|
|
@@ -273,18 +261,6 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
|
|
|
273
261
|
};
|
|
274
262
|
}
|
|
275
263
|
}
|
|
276
|
-
/**
|
|
277
|
-
* Default compiler configuration used when the user doesn't have any
|
|
278
|
-
*/
|
|
279
|
-
function getDefaultCompilerOptions(astroVersion) {
|
|
280
|
-
const types = ['astro/env'];
|
|
281
|
-
if ((astroVersion.major >= 1 && astroVersion.full !== '1.0.0-beta.0') || astroVersion.full.startsWith('0.0.0-rc-')) {
|
|
282
|
-
types.push('astro/astro-jsx');
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
types: types,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
264
|
function getDefaultExclude() {
|
|
289
265
|
return ['dist', 'node_modules'];
|
|
290
266
|
}
|
|
@@ -26,3 +26,4 @@ export declare function createFromTSFilePath(filePath: string): TypeScriptDocume
|
|
|
26
26
|
*/
|
|
27
27
|
export declare function createFromAstroFilePath(filePath: string, createDocument: (filePath: string, text: string) => AstroDocument): AstroSnapshot;
|
|
28
28
|
export declare function createFromFrameworkFilePath(filePath: string, framework: FrameworkExt): TypeScriptDocumentSnapshot;
|
|
29
|
+
export declare function classNameFromFilename(filename: string): string;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createFromFrameworkFilePath = exports.createFromAstroFilePath = exports.createFromTSFilePath = exports.createFromNonAstroFilePath = exports.createFromFilePath = exports.createFromDocument = void 0;
|
|
6
|
+
exports.classNameFromFilename = exports.createFromFrameworkFilePath = exports.createFromAstroFilePath = exports.createFromTSFilePath = exports.createFromNonAstroFilePath = exports.createFromFilePath = exports.createFromDocument = void 0;
|
|
7
7
|
const typescript_1 = __importDefault(require("typescript"));
|
|
8
8
|
const astro2tsx_1 = __importDefault(require("../astro2tsx"));
|
|
9
9
|
const vscode_uri_1 = require("vscode-uri");
|
|
@@ -106,3 +106,4 @@ function classNameFromFilename(filename) {
|
|
|
106
106
|
const finalName = firstValidCharIdx === -1 ? `A${inPascalCase}` : inPascalCase;
|
|
107
107
|
return finalName;
|
|
108
108
|
}
|
|
109
|
+
exports.classNameFromFilename = classNameFromFilename;
|
package/dist/server.js
CHANGED
|
@@ -44,6 +44,7 @@ function startLanguageServer(connection) {
|
|
|
44
44
|
const documentManager = new DocumentManager_1.DocumentManager();
|
|
45
45
|
const pluginHost = new PluginHost_1.PluginHost(documentManager);
|
|
46
46
|
const configManager = new ConfigManager_1.ConfigManager(connection);
|
|
47
|
+
let typescriptPlugin = undefined;
|
|
47
48
|
let hasConfigurationCapability = false;
|
|
48
49
|
connection.onInitialize((params) => {
|
|
49
50
|
const workspaceUris = params.workspaceFolders?.map((folder) => folder.uri.toString()) ?? [params.rootUri ?? ''];
|
|
@@ -72,8 +73,9 @@ function startLanguageServer(connection) {
|
|
|
72
73
|
pluginHost.registerPlugin(new CSSPlugin_1.CSSPlugin(configManager));
|
|
73
74
|
// We don't currently support running the TypeScript and Astro plugin in the browser
|
|
74
75
|
if (params.initializationOptions.environment !== 'browser') {
|
|
76
|
+
typescriptPlugin = new plugins_1.TypeScriptPlugin(documentManager, configManager, workspaceUris);
|
|
75
77
|
pluginHost.registerPlugin(new AstroPlugin_1.AstroPlugin(documentManager, configManager, workspaceUris));
|
|
76
|
-
pluginHost.registerPlugin(
|
|
78
|
+
pluginHost.registerPlugin(typescriptPlugin);
|
|
77
79
|
}
|
|
78
80
|
return {
|
|
79
81
|
capabilities: {
|
|
@@ -212,6 +214,16 @@ function startLanguageServer(connection) {
|
|
|
212
214
|
}
|
|
213
215
|
updateAllDiagnostics();
|
|
214
216
|
});
|
|
217
|
+
connection.onRequest('$/getTSXOutput', async (uri) => {
|
|
218
|
+
const doc = documentManager.get(uri);
|
|
219
|
+
if (!doc) {
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
if (doc) {
|
|
223
|
+
const tsxOutput = typescriptPlugin.getTSXForDocument(doc);
|
|
224
|
+
return tsxOutput.code;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
215
227
|
documentManager.on('documentChange', (0, utils_1.debounceThrottle)(async (document) => diagnosticsManager.update(document), 1000));
|
|
216
228
|
documentManager.on('documentClose', (document) => {
|
|
217
229
|
diagnosticsManager.removeDiagnostics(document);
|