@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
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { offsetAt } from './core/documents';
|
|
1
|
+
export * as protocol from '@volar/language-server/protocol';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return check_1.DiagnosticSeverity; } });
|
|
7
|
-
var documents_1 = require("./core/documents");
|
|
8
|
-
Object.defineProperty(exports, "offsetAt", { enumerable: true, get: function () { return documents_1.offsetAt; } });
|
|
26
|
+
exports.protocol = void 0;
|
|
27
|
+
exports.protocol = __importStar(require("@volar/language-server/protocol"));
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.plugin = void 0;
|
|
7
|
+
const volar_service_css_1 = __importDefault(require("volar-service-css"));
|
|
8
|
+
const volar_service_emmet_1 = __importDefault(require("volar-service-emmet"));
|
|
9
|
+
const volar_service_prettier_1 = __importDefault(require("volar-service-prettier"));
|
|
10
|
+
const volar_service_typescript_twoslash_queries_1 = __importDefault(require("volar-service-typescript-twoslash-queries"));
|
|
11
|
+
const core_1 = require("./core");
|
|
12
|
+
const svelte_js_1 = require("./core/svelte.js");
|
|
13
|
+
const utils_1 = require("./core/utils");
|
|
14
|
+
const vue_js_1 = require("./core/vue.js");
|
|
15
|
+
const importPackage_js_1 = require("./importPackage.js");
|
|
16
|
+
const astro_js_1 = __importDefault(require("./plugins/astro.js"));
|
|
17
|
+
const html_js_1 = __importDefault(require("./plugins/html.js"));
|
|
18
|
+
const index_js_1 = __importDefault(require("./plugins/typescript/index.js"));
|
|
19
|
+
const plugin = (initOptions, modules) => ({
|
|
20
|
+
extraFileExtensions: [
|
|
21
|
+
{ extension: 'astro', isMixedContent: true, scriptKind: 7 },
|
|
22
|
+
{ extension: 'vue', isMixedContent: true, scriptKind: 7 },
|
|
23
|
+
{ extension: 'svelte', isMixedContent: true, scriptKind: 7 },
|
|
24
|
+
],
|
|
25
|
+
watchFileExtensions: [
|
|
26
|
+
'js',
|
|
27
|
+
'cjs',
|
|
28
|
+
'mjs',
|
|
29
|
+
'ts',
|
|
30
|
+
'cts',
|
|
31
|
+
'mts',
|
|
32
|
+
'jsx',
|
|
33
|
+
'tsx',
|
|
34
|
+
'json',
|
|
35
|
+
'astro',
|
|
36
|
+
'vue',
|
|
37
|
+
'svelte',
|
|
38
|
+
],
|
|
39
|
+
resolveConfig(config, ctx) {
|
|
40
|
+
config.languages ??= {};
|
|
41
|
+
if (ctx) {
|
|
42
|
+
config.languages.astro = (0, core_1.getLanguageModule)((0, utils_1.getAstroInstall)([ctx.project.rootUri.fsPath]), modules.typescript);
|
|
43
|
+
config.languages.vue = (0, vue_js_1.getVueLanguageModule)();
|
|
44
|
+
config.languages.svelte = (0, svelte_js_1.getSvelteLanguageModule)();
|
|
45
|
+
}
|
|
46
|
+
config.services ??= {};
|
|
47
|
+
config.services.html ??= (0, html_js_1.default)();
|
|
48
|
+
config.services.css ??= (0, volar_service_css_1.default)();
|
|
49
|
+
config.services.emmet ??= (0, volar_service_emmet_1.default)();
|
|
50
|
+
config.services.typescript ??= (0, index_js_1.default)();
|
|
51
|
+
config.services.typescripttwoslash ??= (0, volar_service_typescript_twoslash_queries_1.default)();
|
|
52
|
+
config.services.astro ??= (0, astro_js_1.default)();
|
|
53
|
+
config.services.prettier ??= (0, volar_service_prettier_1.default)({
|
|
54
|
+
languages: ['astro'],
|
|
55
|
+
additionalOptions: (resolvedConfig) => {
|
|
56
|
+
function getAstroPrettierPlugin() {
|
|
57
|
+
if (!ctx?.project.rootUri)
|
|
58
|
+
return [];
|
|
59
|
+
const rootDir = ctx.env.uriToFileName(ctx?.project.rootUri.toString());
|
|
60
|
+
const prettier = (0, importPackage_js_1.importPrettier)(rootDir);
|
|
61
|
+
const hasPluginLoadedAlready = prettier
|
|
62
|
+
.getSupportInfo()
|
|
63
|
+
.languages.some((l) => l.name === 'astro');
|
|
64
|
+
return hasPluginLoadedAlready ? [] : [(0, importPackage_js_1.getPrettierPluginPath)(rootDir)];
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
plugins: [...getAstroPrettierPlugin(), ...(resolvedConfig.plugins ?? [])],
|
|
68
|
+
parser: 'astro',
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
return config;
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
exports.plugin = plugin;
|
|
76
|
+
//# sourceMappingURL=languageServerPlugin.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_1 = require("@volar/language-server/node");
|
|
4
|
+
const languageServerPlugin_js_1 = require("./languageServerPlugin.js");
|
|
5
|
+
(0, node_1.startLanguageServer)((0, node_1.createConnection)(), languageServerPlugin_js_1.plugin);
|
|
6
|
+
//# sourceMappingURL=nodeServer.js.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const language_server_1 = require("@volar/language-server");
|
|
7
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const index_js_1 = require("../core/index.js");
|
|
10
|
+
const utils_js_1 = require("../utils.js");
|
|
11
|
+
exports.default = () => (context, modules) => {
|
|
12
|
+
return {
|
|
13
|
+
triggerCharacters: ['-'],
|
|
14
|
+
provideCompletionItems(document, position, completionContext, token) {
|
|
15
|
+
if (token.isCancellationRequested)
|
|
16
|
+
return null;
|
|
17
|
+
let items = [];
|
|
18
|
+
const [file] = context.documents.getVirtualFileByUri(document.uri);
|
|
19
|
+
if (!(file instanceof index_js_1.AstroFile))
|
|
20
|
+
return;
|
|
21
|
+
if (completionContext.triggerCharacter === '-') {
|
|
22
|
+
const frontmatterCompletion = getFrontmatterCompletion(file, document, position);
|
|
23
|
+
if (frontmatterCompletion)
|
|
24
|
+
items.push(frontmatterCompletion);
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
isIncomplete: false,
|
|
28
|
+
items: items,
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
provideSemanticDiagnostics(document, token) {
|
|
32
|
+
if (token.isCancellationRequested)
|
|
33
|
+
return [];
|
|
34
|
+
const [file] = context.documents.getVirtualFileByUri(document.uri);
|
|
35
|
+
if (!(file instanceof index_js_1.AstroFile))
|
|
36
|
+
return;
|
|
37
|
+
return file.compilerDiagnostics.map(compilerMessageToDiagnostic);
|
|
38
|
+
function compilerMessageToDiagnostic(message) {
|
|
39
|
+
return {
|
|
40
|
+
message: message.text + '\n\n' + message.hint,
|
|
41
|
+
range: language_server_1.Range.create(message.location.line - 1, message.location.column - 1, message.location.line, message.location.length),
|
|
42
|
+
code: message.code,
|
|
43
|
+
severity: message.severity,
|
|
44
|
+
source: 'astro',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
provideCodeLenses(document, token) {
|
|
49
|
+
if (token.isCancellationRequested)
|
|
50
|
+
return;
|
|
51
|
+
if (!modules?.typescript || !context?.typescript || !(0, utils_js_1.isTsDocument)(document.languageId))
|
|
52
|
+
return;
|
|
53
|
+
const ts = modules?.typescript;
|
|
54
|
+
const tsProgram = context.typescript.languageService.getProgram();
|
|
55
|
+
if (!tsProgram)
|
|
56
|
+
return;
|
|
57
|
+
const globcodeLens = [];
|
|
58
|
+
const sourceFile = tsProgram.getSourceFile(context.env.uriToFileName(document.uri));
|
|
59
|
+
function walk() {
|
|
60
|
+
return ts.forEachChild(sourceFile, function cb(node) {
|
|
61
|
+
if (ts.isCallExpression(node) && node.expression.getText() === 'Astro.glob') {
|
|
62
|
+
const globText = node.arguments.at(0).getText().slice(1, -1);
|
|
63
|
+
globcodeLens.push(getGlobResultAsCodeLens(globText, (0, node_path_1.dirname)(context.env.uriToFileName(document.uri)), document.positionAt(node.arguments.pos)));
|
|
64
|
+
}
|
|
65
|
+
return ts.forEachChild(node, cb);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
walk();
|
|
69
|
+
return globcodeLens;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
function getGlobResultAsCodeLens(globText, dir, position) {
|
|
74
|
+
const globResult = fast_glob_1.default.sync(globText, {
|
|
75
|
+
cwd: dir,
|
|
76
|
+
onlyFiles: true,
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
range: language_server_1.Range.create(position, position),
|
|
80
|
+
command: { title: `Matches ${globResult.length} files`, command: '' },
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function getFrontmatterCompletion(file, document, position) {
|
|
84
|
+
const base = {
|
|
85
|
+
kind: language_server_1.CompletionItemKind.Snippet,
|
|
86
|
+
label: '---',
|
|
87
|
+
sortText: '\0',
|
|
88
|
+
preselect: true,
|
|
89
|
+
detail: 'Create component script block',
|
|
90
|
+
insertTextFormat: language_server_1.InsertTextFormat.Snippet,
|
|
91
|
+
commitCharacters: [],
|
|
92
|
+
};
|
|
93
|
+
const documentLines = document.getText().split(/\r?\n/);
|
|
94
|
+
const { line, character } = document.positionAt(document.offsetAt(position));
|
|
95
|
+
const prefix = documentLines[line].slice(0, character);
|
|
96
|
+
if (file.astroMeta.frontmatter.status === 'doesnt-exist') {
|
|
97
|
+
return {
|
|
98
|
+
...base,
|
|
99
|
+
insertText: '---\n$0\n---',
|
|
100
|
+
textEdit: prefix.match(/^\s*\-+/)
|
|
101
|
+
? language_server_1.TextEdit.replace({ start: { ...position, character: 0 }, end: position }, '---\n$0\n---')
|
|
102
|
+
: undefined,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (file.astroMeta.frontmatter.status === 'open') {
|
|
106
|
+
let insertText = '---';
|
|
107
|
+
// If the current line is a full component script starter/ender, the user expects a full frontmatter
|
|
108
|
+
// completion and not just a completion for "---" on the same line (which result in, well, nothing)
|
|
109
|
+
if (prefix === '---') {
|
|
110
|
+
insertText = '---\n$0\n---';
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
...base,
|
|
114
|
+
insertText,
|
|
115
|
+
detail: insertText === '---' ? 'Close component script block' : 'Create component script block',
|
|
116
|
+
textEdit: prefix.match(/^\s*\-+/)
|
|
117
|
+
? language_server_1.TextEdit.replace({ start: { ...position, character: 0 }, end: position }, insertText)
|
|
118
|
+
: undefined,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=astro.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const volar_service_html_1 = __importDefault(require("volar-service-html"));
|
|
7
|
+
const index_js_1 = require("../core/index.js");
|
|
8
|
+
const utils_js_1 = require("../utils.js");
|
|
9
|
+
const html_data_js_1 = require("./html-data.js");
|
|
10
|
+
exports.default = () => (context) => {
|
|
11
|
+
const htmlPlugin = (0, volar_service_html_1.default)()(context);
|
|
12
|
+
if (!context) {
|
|
13
|
+
return { triggerCharacters: htmlPlugin.triggerCharacters };
|
|
14
|
+
}
|
|
15
|
+
htmlPlugin.updateCustomData([html_data_js_1.astroAttributes, html_data_js_1.astroElements, html_data_js_1.classListAttribute]);
|
|
16
|
+
return {
|
|
17
|
+
...htmlPlugin,
|
|
18
|
+
provideCompletionItems(document, position, completionContext, token) {
|
|
19
|
+
if (document.languageId !== 'html')
|
|
20
|
+
return;
|
|
21
|
+
const [_, source] = context.documents.getVirtualFileByUri(document.uri);
|
|
22
|
+
const rootVirtualFile = source?.root;
|
|
23
|
+
if (!(rootVirtualFile instanceof index_js_1.AstroFile))
|
|
24
|
+
return;
|
|
25
|
+
// Don't return completions if the current node is a component
|
|
26
|
+
if ((0, utils_js_1.isInComponentStartTag)(rootVirtualFile.htmlDocument, document.offsetAt(position))) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return htmlPlugin.provideCompletionItems(document, position, completionContext, token);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=html.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CodeAction } from '@volar/language-service';
|
|
2
|
+
import type { TextDocument } from 'vscode-html-languageservice';
|
|
3
|
+
import type { AstroFile } from '../../core/index.js';
|
|
4
|
+
export declare function enhancedProvideCodeActions(codeActions: CodeAction[], file: AstroFile, document: TextDocument, newLine: string): CodeAction[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enhancedProvideCodeActions = void 0;
|
|
4
|
+
const language_service_1 = require("@volar/language-service");
|
|
5
|
+
const utils_js_1 = require("../../utils.js");
|
|
6
|
+
function enhancedProvideCodeActions(codeActions, file, document, newLine) {
|
|
7
|
+
codeActions = codeActions.map((codeAction) => {
|
|
8
|
+
if (!codeAction.edit)
|
|
9
|
+
return codeAction;
|
|
10
|
+
codeAction.edit.documentChanges = codeAction.edit.documentChanges?.map((change) => {
|
|
11
|
+
if (language_service_1.TextDocumentEdit.is(change)) {
|
|
12
|
+
change.edits = change.edits.map((edit) => {
|
|
13
|
+
// Move code actions adding new imports to the frontmatter, as by default they'll be outside of it
|
|
14
|
+
// TODO: This is a bit brittle, but we're unfortunately too late into the process to be able to tell the `fixName`
|
|
15
|
+
// Maybe contribute upstream to pass the `fixName` through `data`?
|
|
16
|
+
if (edit.newText.trim().startsWith('import ')) {
|
|
17
|
+
if (file.astroMeta.frontmatter.status === 'doesnt-exist') {
|
|
18
|
+
return (0, utils_js_1.getNewFrontmatterEdit)(edit, newLine);
|
|
19
|
+
}
|
|
20
|
+
if (file.astroMeta.frontmatter.status === 'open') {
|
|
21
|
+
return (0, utils_js_1.getOpenFrontmatterEdit)(edit, newLine);
|
|
22
|
+
}
|
|
23
|
+
edit.range = (0, utils_js_1.ensureRangeIsInFrontmatter)(edit.range, file.astroMeta.frontmatter);
|
|
24
|
+
}
|
|
25
|
+
// Some code actions will insert code at the end of the generated TSX file, so we'll manually
|
|
26
|
+
// redirect it to the end of the frontmatter instead, or create a frontmatter if one doesn't exist
|
|
27
|
+
if (edit.range.start.line > document.lineCount) {
|
|
28
|
+
switch (file.astroMeta.frontmatter.status) {
|
|
29
|
+
case 'open':
|
|
30
|
+
return (0, utils_js_1.getOpenFrontmatterEdit)(edit, newLine);
|
|
31
|
+
case 'closed':
|
|
32
|
+
const position = (0, utils_js_1.PointToPosition)(file.astroMeta.frontmatter.position.end);
|
|
33
|
+
edit.range = language_service_1.Range.create(position, position);
|
|
34
|
+
return edit;
|
|
35
|
+
case 'doesnt-exist':
|
|
36
|
+
return (0, utils_js_1.getNewFrontmatterEdit)(edit, newLine);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return edit;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return change;
|
|
43
|
+
});
|
|
44
|
+
return codeAction;
|
|
45
|
+
});
|
|
46
|
+
return codeActions;
|
|
47
|
+
}
|
|
48
|
+
exports.enhancedProvideCodeActions = enhancedProvideCodeActions;
|
|
49
|
+
//# sourceMappingURL=codeActions.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CompletionItem, CompletionList, ServiceContext } from '@volar/language-service';
|
|
2
|
+
export declare function enhancedProvideCompletionItems(completions: CompletionList): CompletionList;
|
|
3
|
+
export declare function enhancedResolveCompletionItem(resolvedCompletion: CompletionItem, originalItem: CompletionItem, context: ServiceContext): CompletionItem;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enhancedResolveCompletionItem = exports.enhancedProvideCompletionItems = void 0;
|
|
4
|
+
const language_service_1 = require("@volar/language-service");
|
|
5
|
+
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
6
|
+
const index_js_1 = require("../../core/index.js");
|
|
7
|
+
const utils_js_1 = require("../../utils.js");
|
|
8
|
+
const defaultHTMLProvider = (0, vscode_html_languageservice_1.getDefaultHTMLDataProvider)();
|
|
9
|
+
const defaultTags = new Set(defaultHTMLProvider.provideTags().map((tag) => tag.name));
|
|
10
|
+
const defaultAttributes = new Set(defaultHTMLProvider.provideTags().flatMap((tag) => tag.attributes.map((attr) => attr.name)));
|
|
11
|
+
function enhancedProvideCompletionItems(completions) {
|
|
12
|
+
completions.items = completions.items.filter(isValidCompletion).map((completion) => {
|
|
13
|
+
const source = completion?.data?.originalItem?.source;
|
|
14
|
+
if (source) {
|
|
15
|
+
// For components import, use the file kind and sort them higher, as they're often what the user want over something else
|
|
16
|
+
if (['.astro', '.svelte', '.vue'].some((ext) => source.endsWith(ext))) {
|
|
17
|
+
completion.kind = language_service_1.CompletionItemKind.File;
|
|
18
|
+
completion.detail = completion.detail + '\n\n' + source;
|
|
19
|
+
completion.sortText = '\0';
|
|
20
|
+
completion.data.isComponent = true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return completion;
|
|
24
|
+
});
|
|
25
|
+
return completions;
|
|
26
|
+
}
|
|
27
|
+
exports.enhancedProvideCompletionItems = enhancedProvideCompletionItems;
|
|
28
|
+
function enhancedResolveCompletionItem(resolvedCompletion, originalItem, context) {
|
|
29
|
+
// Make sure we keep our icons even when the completion is resolved
|
|
30
|
+
if (resolvedCompletion.data.isComponent) {
|
|
31
|
+
resolvedCompletion.detail = getDetailForFileCompletion(resolvedCompletion.detail ?? '', resolvedCompletion.data.originalItem.source);
|
|
32
|
+
}
|
|
33
|
+
// Properly handle completions with actions to make sure their edits end up in the frontmatter when needed
|
|
34
|
+
const [_, source] = context.documents.getVirtualFileByUri(originalItem.data.uri);
|
|
35
|
+
const file = source?.root;
|
|
36
|
+
if (!(file instanceof index_js_1.AstroFile) || !context.host)
|
|
37
|
+
return resolvedCompletion;
|
|
38
|
+
const newLine = context.host.getNewLine ? context.host.getNewLine() : '\n';
|
|
39
|
+
resolvedCompletion.additionalTextEdits = resolvedCompletion.additionalTextEdits?.map((edit) => {
|
|
40
|
+
if (file.astroMeta.frontmatter.status === 'doesnt-exist') {
|
|
41
|
+
return (0, utils_js_1.getNewFrontmatterEdit)(edit, newLine);
|
|
42
|
+
}
|
|
43
|
+
if (file.astroMeta.frontmatter.status === 'open') {
|
|
44
|
+
return (0, utils_js_1.getOpenFrontmatterEdit)(edit, newLine);
|
|
45
|
+
}
|
|
46
|
+
edit.range = (0, utils_js_1.ensureRangeIsInFrontmatter)(edit.range, file.astroMeta.frontmatter);
|
|
47
|
+
return edit;
|
|
48
|
+
});
|
|
49
|
+
return resolvedCompletion;
|
|
50
|
+
}
|
|
51
|
+
exports.enhancedResolveCompletionItem = enhancedResolveCompletionItem;
|
|
52
|
+
function getDetailForFileCompletion(detail, source) {
|
|
53
|
+
return `${detail}\n\n${source}`;
|
|
54
|
+
}
|
|
55
|
+
// When Svelte components are imported, we have to reference the svelte2tsx's types to properly type the component
|
|
56
|
+
// An unfortunate downside of this is that it pollutes completions, so let's filter those internal types manually
|
|
57
|
+
const svelte2tsxTypes = new Set([
|
|
58
|
+
'Svelte2TsxComponent',
|
|
59
|
+
'Svelte2TsxComponentConstructorParameters',
|
|
60
|
+
'SvelteComponentConstructor',
|
|
61
|
+
'SvelteActionReturnType',
|
|
62
|
+
'SvelteTransitionConfig',
|
|
63
|
+
'SvelteTransitionReturnType',
|
|
64
|
+
'SvelteAnimationReturnType',
|
|
65
|
+
'SvelteWithOptionalProps',
|
|
66
|
+
'SvelteAllProps',
|
|
67
|
+
'SveltePropsAnyFallback',
|
|
68
|
+
'SvelteSlotsAnyFallback',
|
|
69
|
+
'SvelteRestProps',
|
|
70
|
+
'SvelteSlots',
|
|
71
|
+
'SvelteStore',
|
|
72
|
+
]);
|
|
73
|
+
function isValidCompletion(completion) {
|
|
74
|
+
const isSvelte2tsxCompletion = completion.label.startsWith('__sveltets_') || svelte2tsxTypes.has(completion.label);
|
|
75
|
+
if (defaultTags.has(completion.label) || defaultAttributes.has(completion.label))
|
|
76
|
+
return false;
|
|
77
|
+
if (isSvelte2tsxCompletion)
|
|
78
|
+
return false;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=completions.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Diagnostic } from '@volar/language-service';
|
|
2
|
+
export declare enum DiagnosticCodes {
|
|
3
|
+
IS_NOT_A_MODULE = 2306,
|
|
4
|
+
CANNOT_FIND_MODULE = 2307,
|
|
5
|
+
DUPLICATED_JSX_ATTRIBUTES = 17001,
|
|
6
|
+
CANT_RETURN_OUTSIDE_FUNC = 1108,
|
|
7
|
+
ISOLATED_MODULE_COMPILE_ERR = 1208,
|
|
8
|
+
TYPE_NOT_ASSIGNABLE = 2322,
|
|
9
|
+
JSX_NO_CLOSING_TAG = 17008,
|
|
10
|
+
JSX_ELEMENT_NO_CALL = 2604
|
|
11
|
+
}
|
|
12
|
+
export declare function enhancedProvideSemanticDiagnostics(originalDiagnostics: Diagnostic[], documentLineCount: number): Diagnostic[];
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enhancedProvideSemanticDiagnostics = exports.DiagnosticCodes = void 0;
|
|
4
|
+
// List of codes:
|
|
5
|
+
// https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
|
|
6
|
+
var DiagnosticCodes;
|
|
7
|
+
(function (DiagnosticCodes) {
|
|
8
|
+
DiagnosticCodes[DiagnosticCodes["IS_NOT_A_MODULE"] = 2306] = "IS_NOT_A_MODULE";
|
|
9
|
+
DiagnosticCodes[DiagnosticCodes["CANNOT_FIND_MODULE"] = 2307] = "CANNOT_FIND_MODULE";
|
|
10
|
+
DiagnosticCodes[DiagnosticCodes["DUPLICATED_JSX_ATTRIBUTES"] = 17001] = "DUPLICATED_JSX_ATTRIBUTES";
|
|
11
|
+
DiagnosticCodes[DiagnosticCodes["CANT_RETURN_OUTSIDE_FUNC"] = 1108] = "CANT_RETURN_OUTSIDE_FUNC";
|
|
12
|
+
DiagnosticCodes[DiagnosticCodes["ISOLATED_MODULE_COMPILE_ERR"] = 1208] = "ISOLATED_MODULE_COMPILE_ERR";
|
|
13
|
+
DiagnosticCodes[DiagnosticCodes["TYPE_NOT_ASSIGNABLE"] = 2322] = "TYPE_NOT_ASSIGNABLE";
|
|
14
|
+
DiagnosticCodes[DiagnosticCodes["JSX_NO_CLOSING_TAG"] = 17008] = "JSX_NO_CLOSING_TAG";
|
|
15
|
+
DiagnosticCodes[DiagnosticCodes["JSX_ELEMENT_NO_CALL"] = 2604] = "JSX_ELEMENT_NO_CALL";
|
|
16
|
+
})(DiagnosticCodes = exports.DiagnosticCodes || (exports.DiagnosticCodes = {}));
|
|
17
|
+
function enhancedProvideSemanticDiagnostics(originalDiagnostics, documentLineCount) {
|
|
18
|
+
const diagnostics = originalDiagnostics
|
|
19
|
+
.filter((diagnostic) => diagnostic.range.start.line <= documentLineCount &&
|
|
20
|
+
isNoCantReturnOutsideFunction(diagnostic) &&
|
|
21
|
+
isNoIsolatedModuleError(diagnostic) &&
|
|
22
|
+
isNoJsxCannotHaveMultipleAttrsError(diagnostic))
|
|
23
|
+
.map(enhanceIfNecessary);
|
|
24
|
+
return diagnostics;
|
|
25
|
+
}
|
|
26
|
+
exports.enhancedProvideSemanticDiagnostics = enhancedProvideSemanticDiagnostics;
|
|
27
|
+
/**
|
|
28
|
+
* Some diagnostics have JSX-specific nomenclature or unclear description. Enhance them for more clarity.
|
|
29
|
+
*/
|
|
30
|
+
function enhanceIfNecessary(diagnostic) {
|
|
31
|
+
// When the language integrations are not installed, the content of the imported snapshot is empty
|
|
32
|
+
// As such, it triggers the "is not a module error", which we can enhance with a more helpful message for the related framework
|
|
33
|
+
if (diagnostic.code === DiagnosticCodes.IS_NOT_A_MODULE) {
|
|
34
|
+
if (diagnostic.message.includes('.svelte')) {
|
|
35
|
+
diagnostic.message +=
|
|
36
|
+
'\n\nIs the `@astrojs/svelte` package installed? You can add it to your project by running the following command: `astro add svelte`. If already installed, restarting the language server might be necessary in order for the change to take effect.';
|
|
37
|
+
}
|
|
38
|
+
if (diagnostic.message.includes('.vue')) {
|
|
39
|
+
diagnostic.message +=
|
|
40
|
+
'\n\nIs the `@astrojs/vue` package installed? You can add it to your project by running the following command: `astro add vue`. If already installed, restarting the language server might be necessary in order for the change to take effect.';
|
|
41
|
+
}
|
|
42
|
+
return diagnostic;
|
|
43
|
+
}
|
|
44
|
+
if (diagnostic.code === DiagnosticCodes.CANNOT_FIND_MODULE &&
|
|
45
|
+
diagnostic.message.includes('astro:content')) {
|
|
46
|
+
diagnostic.message +=
|
|
47
|
+
"\n\nIf you're using content collections, make sure to run `astro dev`, `astro build` or `astro sync` to first generate the types so you can import from them. If you already ran one of those commands, restarting the language server might be necessary in order for the change to take effect.";
|
|
48
|
+
return diagnostic;
|
|
49
|
+
}
|
|
50
|
+
// JSX element has no closing tag. JSX -> HTML
|
|
51
|
+
if (diagnostic.code === DiagnosticCodes.JSX_NO_CLOSING_TAG) {
|
|
52
|
+
return {
|
|
53
|
+
...diagnostic,
|
|
54
|
+
message: diagnostic.message.replace('JSX', 'HTML'),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// JSX Element can't be constructed or called. This happens on syntax errors / invalid components
|
|
58
|
+
if (diagnostic.code === DiagnosticCodes.JSX_ELEMENT_NO_CALL) {
|
|
59
|
+
return {
|
|
60
|
+
...diagnostic,
|
|
61
|
+
message: diagnostic.message
|
|
62
|
+
.replace('JSX element type', 'Component')
|
|
63
|
+
.replace('does not have any construct or call signatures.', 'is not a valid component.\n\nIf this is a Svelte or Vue component, it might have a syntax error that makes it impossible to parse.'),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// For the rare case where an user might try to put a client directive on something that is not a component
|
|
67
|
+
if (diagnostic.code === DiagnosticCodes.TYPE_NOT_ASSIGNABLE) {
|
|
68
|
+
if (diagnostic.message.includes("Property 'client:") &&
|
|
69
|
+
diagnostic.message.includes("to type 'HTMLAttributes")) {
|
|
70
|
+
return {
|
|
71
|
+
...diagnostic,
|
|
72
|
+
message: diagnostic.message + '\n\nClient directives are only available on framework components.',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return diagnostic;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Astro allows multiple attributes to have the same name
|
|
80
|
+
*/
|
|
81
|
+
function isNoJsxCannotHaveMultipleAttrsError(diagnostic) {
|
|
82
|
+
return diagnostic.code !== DiagnosticCodes.DUPLICATED_JSX_ATTRIBUTES;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Ignore "Can't return outside of function body"
|
|
86
|
+
* Since the frontmatter is at the top level, users trying to return a Response for SSR mode run into this
|
|
87
|
+
* TODO: Update the TSX shape so this is not an issue anymore
|
|
88
|
+
*/
|
|
89
|
+
function isNoCantReturnOutsideFunction(diagnostic) {
|
|
90
|
+
return diagnostic.code !== DiagnosticCodes.CANT_RETURN_OUTSIDE_FUNC;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* When the content of the file is invalid and can't be parsed properly for TSX generation, TS will show an error about
|
|
94
|
+
* how the current module can't be compiled under --isolatedModule, this is confusing to users so let's ignore this
|
|
95
|
+
*/
|
|
96
|
+
function isNoIsolatedModuleError(diagnostic) {
|
|
97
|
+
return diagnostic.code !== DiagnosticCodes.ISOLATED_MODULE_COMPILE_ERR;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const volar_service_typescript_1 = __importDefault(require("volar-service-typescript"));
|
|
7
|
+
const index_js_1 = require("../../core/index.js");
|
|
8
|
+
const codeActions_js_1 = require("./codeActions.js");
|
|
9
|
+
const completions_js_1 = require("./completions.js");
|
|
10
|
+
const diagnostics_js_1 = require("./diagnostics.js");
|
|
11
|
+
exports.default = () => (context, modules) => {
|
|
12
|
+
const typeScriptPlugin = (0, volar_service_typescript_1.default)()(context, modules);
|
|
13
|
+
if (!context) {
|
|
14
|
+
return { triggerCharacters: typeScriptPlugin.triggerCharacters };
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
...typeScriptPlugin,
|
|
18
|
+
async provideCompletionItems(document, position, completionContext, token) {
|
|
19
|
+
const originalCompletions = await typeScriptPlugin.provideCompletionItems(document, position, completionContext, token);
|
|
20
|
+
if (!originalCompletions)
|
|
21
|
+
return null;
|
|
22
|
+
return (0, completions_js_1.enhancedProvideCompletionItems)(originalCompletions);
|
|
23
|
+
},
|
|
24
|
+
async resolveCompletionItem(item, token) {
|
|
25
|
+
const resolvedCompletionItem = await typeScriptPlugin.resolveCompletionItem(item, token);
|
|
26
|
+
if (!resolvedCompletionItem)
|
|
27
|
+
return item;
|
|
28
|
+
return (0, completions_js_1.enhancedResolveCompletionItem)(resolvedCompletionItem, item, context);
|
|
29
|
+
},
|
|
30
|
+
async provideCodeActions(document, range, codeActionContext, token) {
|
|
31
|
+
const codeActions = await typeScriptPlugin.provideCodeActions(document, range, codeActionContext, token);
|
|
32
|
+
if (!codeActions)
|
|
33
|
+
return null;
|
|
34
|
+
const [_, source] = context.documents.getVirtualFileByUri(document.uri);
|
|
35
|
+
const file = source?.root;
|
|
36
|
+
if (!(file instanceof index_js_1.AstroFile) || !context.host)
|
|
37
|
+
return codeActions;
|
|
38
|
+
const newLine = context.host.getNewLine ? context.host.getNewLine() : '\n';
|
|
39
|
+
return (0, codeActions_js_1.enhancedProvideCodeActions)(codeActions, file, context.documents.getDocumentByFileName(file.snapshot, file.sourceFileName), newLine);
|
|
40
|
+
},
|
|
41
|
+
async provideSemanticDiagnostics(document, token) {
|
|
42
|
+
const [_, source] = context.documents.getVirtualFileByUri(document.uri);
|
|
43
|
+
const file = source?.root;
|
|
44
|
+
if (!(file instanceof index_js_1.AstroFile))
|
|
45
|
+
return null;
|
|
46
|
+
// If we have compiler errors, our TSX isn't valid so don't bother showing TS errors
|
|
47
|
+
if (file.hasCompilationErrors)
|
|
48
|
+
return null;
|
|
49
|
+
const diagnostics = await typeScriptPlugin.provideSemanticDiagnostics(document, token);
|
|
50
|
+
if (!diagnostics)
|
|
51
|
+
return null;
|
|
52
|
+
const astroDocument = context.documents.getDocumentByFileName(file.snapshot, file.sourceFileName);
|
|
53
|
+
return (0, diagnostics_js_1.enhancedProvideSemanticDiagnostics)(diagnostics, astroDocument.lineCount);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=index.js.map
|