@astrojs/language-server 0.20.3 → 0.22.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +1 -2
  3. package/dist/check.js +4 -1
  4. package/dist/core/config/ConfigManager.d.ts +1 -2
  5. package/dist/core/config/ConfigManager.js +0 -7
  6. package/dist/importPackage.d.ts +4 -1
  7. package/dist/importPackage.js +22 -9
  8. package/dist/plugins/PluginHost.d.ts +1 -0
  9. package/dist/plugins/PluginHost.js +4 -0
  10. package/dist/plugins/astro/AstroPlugin.d.ts +5 -3
  11. package/dist/plugins/astro/AstroPlugin.js +35 -3
  12. package/dist/plugins/css/language-service.d.ts +1 -1
  13. package/dist/plugins/html/HTMLPlugin.d.ts +1 -2
  14. package/dist/plugins/html/HTMLPlugin.js +0 -18
  15. package/dist/plugins/interfaces.d.ts +5 -2
  16. package/dist/plugins/typescript/TypeScriptPlugin.d.ts +8 -5
  17. package/dist/plugins/typescript/TypeScriptPlugin.js +12 -8
  18. package/dist/plugins/typescript/astro2tsx.d.ts +1 -2
  19. package/dist/plugins/typescript/astro2tsx.js +0 -4
  20. package/dist/plugins/typescript/features/DiagnosticsProvider.js +0 -5
  21. package/dist/plugins/typescript/features/FoldingRangesProvider.js +1 -1
  22. package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +9 -0
  23. package/dist/plugins/typescript/features/TypeDefinitionsProvider.js +55 -0
  24. package/dist/plugins/typescript/language-service.js +12 -38
  25. package/dist/plugins/typescript/snapshots/utils.d.ts +1 -0
  26. package/dist/plugins/typescript/snapshots/utils.js +2 -1
  27. package/dist/server.js +22 -5
  28. package/dist/utils.d.ts +9 -7
  29. package/dist/utils.js +25 -16
  30. package/package.json +4 -1
  31. package/types/README.md +5 -0
  32. package/types/astro-jsx.d.ts +854 -477
  33. package/types/env.d.ts +22 -0
  34. package/dist/plugins/typescript/features/FormattingProvider.d.ts +0 -11
  35. package/dist/plugins/typescript/features/FormattingProvider.js +0 -132
package/types/env.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Astro global available in all contexts in .astro files
3
+ *
4
+ * [Astro documentation](https://docs.astro.build/reference/api-reference/#astro-global)
5
+ */
6
+ declare const Astro: any;
7
+ declare const Fragment: any;
8
+
9
+ declare module '*.md' {
10
+ const md: any;
11
+ export default md;
12
+ }
13
+
14
+ declare module '*.mdx' {
15
+ const mdx: any;
16
+ export default mdx;
17
+ }
18
+
19
+ declare module '*.html' {
20
+ const html: any;
21
+ export default html;
22
+ }
@@ -1,11 +0,0 @@
1
- import { FormattingOptions, TextEdit } from 'vscode-languageserver-types';
2
- import { ConfigManager } from '../../../core/config';
3
- import { AstroDocument } from '../../../core/documents';
4
- import { FormattingProvider } from '../../interfaces';
5
- import { LanguageServiceManager } from '../LanguageServiceManager';
6
- export declare class FormattingProviderImpl implements FormattingProvider {
7
- private languageServiceManager;
8
- private configManager;
9
- constructor(languageServiceManager: LanguageServiceManager, configManager: ConfigManager);
10
- formatDocument(document: AstroDocument, options: FormattingOptions): Promise<TextEdit[]>;
11
- }
@@ -1,132 +0,0 @@
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.FormattingProviderImpl = void 0;
7
- const typescript_1 = __importDefault(require("typescript"));
8
- const vscode_languageserver_types_1 = require("vscode-languageserver-types");
9
- const utils_1 = require("../utils");
10
- class FormattingProviderImpl {
11
- constructor(languageServiceManager, configManager) {
12
- this.languageServiceManager = languageServiceManager;
13
- this.configManager = configManager;
14
- }
15
- async formatDocument(document, options) {
16
- const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
17
- const filePath = (0, utils_1.toVirtualAstroFilePath)(tsDoc.filePath);
18
- const formatConfig = await this.configManager.getTSFormatConfig(document, options);
19
- let frontmatterEdits = [];
20
- let scriptTagsEdits = [];
21
- if (document.astroMeta.frontmatter.state === 'closed') {
22
- const start = document.positionAt(document.astroMeta.frontmatter.startOffset + 3);
23
- start.line += 1;
24
- start.character = 0;
25
- const startOffset = document.offsetAt(start);
26
- const endOffset = document.astroMeta.frontmatter.endOffset;
27
- const astroFormatConfig = await this.configManager.getAstroFormatConfig(document);
28
- const settings = {
29
- ...formatConfig,
30
- baseIndentSize: astroFormatConfig.indentFrontmatter ? formatConfig.tabSize ?? 0 : undefined,
31
- };
32
- frontmatterEdits = lang.getFormattingEditsForRange(filePath, startOffset, endOffset, settings);
33
- if (astroFormatConfig.newLineAfterFrontmatter) {
34
- const templateStart = document.positionAt(endOffset + 3);
35
- templateStart.line += 1;
36
- templateStart.character = 0;
37
- frontmatterEdits.push({
38
- span: { start: document.offsetAt(templateStart), length: 0 },
39
- newText: '\n',
40
- });
41
- }
42
- }
43
- document.scriptTags.forEach((scriptTag) => {
44
- const { filePath: scriptFilePath, snapshot: scriptTagSnapshot } = (0, utils_1.getScriptTagSnapshot)(tsDoc, document, scriptTag.container);
45
- const startLine = document.offsetAt(vscode_languageserver_types_1.Position.create(scriptTag.startPos.line, 0));
46
- const initialIndentLevel = computeInitialIndent(document, startLine, options);
47
- const baseIndent = (formatConfig.tabSize ?? 0) * (initialIndentLevel + 1);
48
- const formatSettings = {
49
- baseIndentSize: baseIndent,
50
- indentStyle: typescript_1.default.IndentStyle.Smart,
51
- ...formatConfig,
52
- };
53
- let edits = lang.getFormattingEditsForDocument(scriptFilePath, formatSettings);
54
- if (edits) {
55
- edits = edits
56
- .map((edit) => {
57
- edit.span.start = document.offsetAt(scriptTagSnapshot.getOriginalPosition(scriptTagSnapshot.positionAt(edit.span.start)));
58
- return edit;
59
- })
60
- .filter((edit) => {
61
- return (scriptTagSnapshot.isInGenerated(document.positionAt(edit.span.start)) &&
62
- scriptTag.end !== edit.span.start &&
63
- // Don't format the last line of the file as it's in most case the indentation
64
- scriptTag.endPos.line !== document.positionAt(edit.span.start).line);
65
- });
66
- const endLine = document.getLineUntilOffset(document.offsetAt(scriptTag.endPos));
67
- if (isWhitespaceOnly(endLine)) {
68
- const endLineStartOffset = document.offsetAt(vscode_languageserver_types_1.Position.create(scriptTag.endPos.line, 0));
69
- const lastLineIndentRange = vscode_languageserver_types_1.Range.create(vscode_languageserver_types_1.Position.create(scriptTag.endPos.line, 0), scriptTag.endPos);
70
- const newText = generateIndent(initialIndentLevel, options);
71
- if (endLine !== newText) {
72
- edits.push({
73
- span: {
74
- start: endLineStartOffset,
75
- length: lastLineIndentRange.end.character,
76
- },
77
- newText,
78
- });
79
- }
80
- }
81
- }
82
- scriptTagsEdits.push(...edits);
83
- });
84
- return [...frontmatterEdits, ...scriptTagsEdits].map((edit) => ({
85
- range: (0, utils_1.convertRange)(document, edit.span),
86
- newText: edit.newText,
87
- }));
88
- }
89
- }
90
- exports.FormattingProviderImpl = FormattingProviderImpl;
91
- function computeInitialIndent(document, lineStart, options) {
92
- let content = document.getText();
93
- let i = lineStart;
94
- let nChars = 0;
95
- let tabSize = options.tabSize || 4;
96
- while (i < content.length) {
97
- let ch = content.charAt(i);
98
- if (ch === ' ') {
99
- nChars++;
100
- }
101
- else if (ch === '\t') {
102
- nChars += tabSize;
103
- }
104
- else {
105
- break;
106
- }
107
- i++;
108
- }
109
- return Math.floor(nChars / tabSize);
110
- }
111
- function generateIndent(level, options) {
112
- if (options.insertSpaces) {
113
- return repeat(' ', level * options.tabSize);
114
- }
115
- else {
116
- return repeat('\t', level);
117
- }
118
- }
119
- function repeat(value, count) {
120
- let s = '';
121
- while (count > 0) {
122
- if ((count & 1) === 1) {
123
- s += value;
124
- }
125
- value += value;
126
- count = count >>> 1;
127
- }
128
- return s;
129
- }
130
- function isWhitespaceOnly(str) {
131
- return /^\s*$/.test(str);
132
- }