@astrojs/language-server 2.8.3 → 2.8.4
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/dist/languageServerPlugin.js +4 -2
- package/dist/plugins/html.js +45 -6
- package/dist/plugins/typescript/codeActions.js +2 -8
- package/dist/plugins/typescript/completions.js +2 -7
- package/dist/plugins/typescript/utils.d.ts +3 -0
- package/dist/plugins/typescript/utils.js +21 -0
- package/package.json +7 -7
|
@@ -73,16 +73,18 @@ function createServerOptions(connection, ts) {
|
|
|
73
73
|
function getPrettierService() {
|
|
74
74
|
let prettier;
|
|
75
75
|
let prettierPluginPath;
|
|
76
|
+
let hasShownNotification = false;
|
|
76
77
|
return (0, volar_service_prettier_1.create)((context) => {
|
|
77
78
|
const workspaceUri = vscode_uri_1.URI.parse(context.env.workspaceFolder);
|
|
78
79
|
if (workspaceUri.scheme === 'file') {
|
|
79
80
|
prettier = (0, importPackage_js_1.importPrettier)(workspaceUri.fsPath);
|
|
80
81
|
prettierPluginPath = (0, importPackage_js_1.getPrettierPluginPath)(workspaceUri.fsPath);
|
|
81
|
-
if (!prettier || !prettierPluginPath) {
|
|
82
|
+
if ((!prettier || !prettierPluginPath) && !hasShownNotification) {
|
|
82
83
|
connection.sendNotification(node_1.ShowMessageNotification.type, {
|
|
83
|
-
message: "Couldn't load `prettier` or `prettier-plugin-astro`. Formatting will not work. Please make sure those two packages are installed into your project.",
|
|
84
|
+
message: "Couldn't load `prettier` or `prettier-plugin-astro`. Formatting will not work. Please make sure those two packages are installed into your project and restart the language server.",
|
|
84
85
|
type: node_1.MessageType.Warning,
|
|
85
86
|
});
|
|
87
|
+
hasShownNotification = true;
|
|
86
88
|
}
|
|
87
89
|
return prettier;
|
|
88
90
|
}
|
package/dist/plugins/html.js
CHANGED
|
@@ -1,22 +1,61 @@
|
|
|
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
26
|
exports.create = void 0;
|
|
4
27
|
const language_server_1 = require("@volar/language-server");
|
|
5
28
|
const volar_service_html_1 = require("volar-service-html");
|
|
29
|
+
const html = __importStar(require("vscode-html-languageservice"));
|
|
30
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
6
31
|
const index_js_1 = require("../core/index.js");
|
|
7
32
|
const html_data_js_1 = require("./html-data.js");
|
|
8
33
|
const utils_js_1 = require("./utils.js");
|
|
9
34
|
const create = () => {
|
|
10
|
-
const htmlServicePlugin = (0, volar_service_html_1.create)(
|
|
35
|
+
const htmlServicePlugin = (0, volar_service_html_1.create)({
|
|
36
|
+
getCustomData: async (context) => {
|
|
37
|
+
const customData = (await context.env.getConfiguration?.('html.customData')) ?? [];
|
|
38
|
+
const newData = [];
|
|
39
|
+
for (const customDataPath of customData) {
|
|
40
|
+
const uri = vscode_uri_1.Utils.resolvePath(vscode_uri_1.URI.parse(context.env.workspaceFolder), customDataPath);
|
|
41
|
+
const json = await context.env.fs?.readFile?.(uri.toString());
|
|
42
|
+
if (json) {
|
|
43
|
+
try {
|
|
44
|
+
const data = JSON.parse(json);
|
|
45
|
+
newData.push(html.newHTMLDataProvider(customDataPath, data));
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error(error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return [...newData, html_data_js_1.astroAttributes, html_data_js_1.astroElements, html_data_js_1.classListAttribute];
|
|
53
|
+
},
|
|
54
|
+
});
|
|
11
55
|
return {
|
|
12
56
|
...htmlServicePlugin,
|
|
13
57
|
create(context) {
|
|
14
58
|
const htmlPlugin = htmlServicePlugin.create(context);
|
|
15
|
-
htmlPlugin.provide['html/updateCustomData']?.([
|
|
16
|
-
html_data_js_1.astroAttributes,
|
|
17
|
-
html_data_js_1.astroElements,
|
|
18
|
-
html_data_js_1.classListAttribute,
|
|
19
|
-
]);
|
|
20
59
|
return {
|
|
21
60
|
...htmlPlugin,
|
|
22
61
|
async provideCompletionItems(document, position, completionContext, token) {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.enhancedResolveCodeAction = exports.enhancedProvideCodeActions = void 0;
|
|
4
4
|
const language_server_1 = require("@volar/language-server");
|
|
5
5
|
const index_js_1 = require("../../core/index.js");
|
|
6
|
-
const utils_js_1 = require("
|
|
6
|
+
const utils_js_1 = require("./utils.js");
|
|
7
7
|
function enhancedProvideCodeActions(codeActions, context) {
|
|
8
8
|
return codeActions.map((codeAction) => mapCodeAction(codeAction, context));
|
|
9
9
|
}
|
|
@@ -26,13 +26,7 @@ function mapCodeAction(codeAction, context) {
|
|
|
26
26
|
const code = source?.generated?.code;
|
|
27
27
|
if (!virtualFile || !(code instanceof index_js_1.AstroVirtualCode))
|
|
28
28
|
return change;
|
|
29
|
-
change.edits = change.edits.map((edit) =>
|
|
30
|
-
const shouldModifyEdit = (0, utils_js_1.editShouldBeInFrontmatter)(edit.range, code.astroMeta);
|
|
31
|
-
if (shouldModifyEdit.itShould) {
|
|
32
|
-
edit = (0, utils_js_1.ensureProperEditForFrontmatter)(edit, code.astroMeta, '\n');
|
|
33
|
-
}
|
|
34
|
-
return edit;
|
|
35
|
-
});
|
|
29
|
+
change.edits = change.edits.map((edit) => (0, utils_js_1.mapEdit)(edit, code, virtualFile.languageId));
|
|
36
30
|
}
|
|
37
31
|
return change;
|
|
38
32
|
});
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.enhancedResolveCompletionItem = exports.enhancedProvideCompletionItems = void 0;
|
|
4
4
|
const language_server_1 = require("@volar/language-server");
|
|
5
5
|
const index_js_1 = require("../../core/index.js");
|
|
6
|
-
const utils_js_1 = require("
|
|
6
|
+
const utils_js_1 = require("./utils.js");
|
|
7
7
|
function enhancedProvideCompletionItems(completions) {
|
|
8
8
|
completions.items = completions.items.filter(isValidCompletion).map((completion) => {
|
|
9
9
|
const source = completion?.data?.originalItem?.source;
|
|
@@ -35,12 +35,7 @@ function enhancedResolveCompletionItem(resolvedCompletion, context) {
|
|
|
35
35
|
const code = source?.generated?.code;
|
|
36
36
|
if (!virtualFile || !(code instanceof index_js_1.AstroVirtualCode))
|
|
37
37
|
return resolvedCompletion;
|
|
38
|
-
resolvedCompletion.additionalTextEdits = resolvedCompletion.additionalTextEdits.map((edit) =>
|
|
39
|
-
if ((0, utils_js_1.editShouldBeInFrontmatter)(edit.range, code.astroMeta).itShould) {
|
|
40
|
-
edit = (0, utils_js_1.ensureProperEditForFrontmatter)(edit, code.astroMeta, '\n');
|
|
41
|
-
}
|
|
42
|
-
return edit;
|
|
43
|
-
});
|
|
38
|
+
resolvedCompletion.additionalTextEdits = resolvedCompletion.additionalTextEdits.map((edit) => (0, utils_js_1.mapEdit)(edit, code, virtualFile.languageId));
|
|
44
39
|
}
|
|
45
40
|
return resolvedCompletion;
|
|
46
41
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapEdit = void 0;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
function mapEdit(edit, code, languageId) {
|
|
6
|
+
// Don't attempt to move the edit to the frontmatter if the file isn't the root TSX file, it means it's a script tag
|
|
7
|
+
if (languageId === 'typescriptreact') {
|
|
8
|
+
if ((0, utils_js_1.editShouldBeInFrontmatter)(edit.range, code.astroMeta).itShould) {
|
|
9
|
+
edit = (0, utils_js_1.ensureProperEditForFrontmatter)(edit, code.astroMeta, '\n');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
// If the edit is at the start of the file, add a newline before it, otherwise we'll get `<script>text`
|
|
14
|
+
if (edit.range.start.line === 0 && edit.range.start.character === 0) {
|
|
15
|
+
edit.newText = '\n' + edit.newText;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return edit;
|
|
19
|
+
}
|
|
20
|
+
exports.mapEdit = mapEdit;
|
|
21
|
+
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.4",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@astrojs/compiler": "^2.7.0",
|
|
24
24
|
"@jridgewell/sourcemap-codec": "^1.4.15",
|
|
25
|
-
"@volar/kit": "~2.1.
|
|
26
|
-
"@volar/language-core": "~2.1.
|
|
27
|
-
"@volar/language-server": "~2.1.
|
|
28
|
-
"@volar/language-service": "~2.1.
|
|
29
|
-
"@volar/typescript": "~2.1.
|
|
25
|
+
"@volar/kit": "~2.1.5",
|
|
26
|
+
"@volar/language-core": "~2.1.5",
|
|
27
|
+
"@volar/language-server": "~2.1.5",
|
|
28
|
+
"@volar/language-service": "~2.1.5",
|
|
29
|
+
"@volar/typescript": "~2.1.5",
|
|
30
30
|
"fast-glob": "^3.2.12",
|
|
31
31
|
"volar-service-css": "0.0.34",
|
|
32
32
|
"volar-service-emmet": "0.0.34",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@types/chai": "^4.3.5",
|
|
45
45
|
"@types/mocha": "^10.0.1",
|
|
46
46
|
"@types/node": "^18.17.8",
|
|
47
|
-
"@volar/test-utils": "~2.1.
|
|
47
|
+
"@volar/test-utils": "~2.1.5",
|
|
48
48
|
"astro": "^4.3.5",
|
|
49
49
|
"chai": "^4.3.7",
|
|
50
50
|
"mocha": "^10.2.0",
|