@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.
Files changed (163) hide show
  1. package/LICENSE +3 -5
  2. package/bin/nodeServer.js +7 -3
  3. package/dist/core/astro2tsx.d.ts +6 -0
  4. package/dist/core/astro2tsx.js +119 -0
  5. package/dist/core/compilerUtils.d.ts +27 -0
  6. package/dist/core/compilerUtils.js +52 -0
  7. package/dist/core/index.d.ts +27 -0
  8. package/dist/core/index.js +119 -0
  9. package/dist/core/parseAstro.d.ts +27 -0
  10. package/dist/core/parseAstro.js +47 -0
  11. package/dist/core/parseCSS.d.ts +7 -0
  12. package/dist/core/parseCSS.js +116 -0
  13. package/dist/core/parseHTML.d.ts +7 -0
  14. package/dist/core/parseHTML.js +113 -0
  15. package/dist/core/parseJS.d.ts +7 -0
  16. package/dist/core/parseJS.js +236 -0
  17. package/dist/core/svelte.d.ts +18 -0
  18. package/dist/core/svelte.js +45 -0
  19. package/dist/core/utils.d.ts +14 -0
  20. package/dist/core/utils.js +138 -0
  21. package/dist/core/vue.d.ts +18 -0
  22. package/dist/core/vue.js +45 -0
  23. package/dist/importPackage.d.ts +1 -1
  24. package/dist/importPackage.js +4 -3
  25. package/dist/index.d.ts +1 -2
  26. package/dist/index.js +26 -6
  27. package/dist/languageServerPlugin.d.ts +2 -0
  28. package/dist/languageServerPlugin.js +76 -0
  29. package/dist/nodeServer.js +6 -0
  30. package/dist/plugins/astro.d.ts +3 -0
  31. package/dist/plugins/astro.js +123 -0
  32. package/dist/plugins/{html/features/astro-attributes.js → html-data.js} +1 -0
  33. package/dist/plugins/html.d.ts +3 -0
  34. package/dist/plugins/html.js +33 -0
  35. package/dist/plugins/typescript/codeActions.d.ts +4 -0
  36. package/dist/plugins/typescript/codeActions.js +49 -0
  37. package/dist/plugins/typescript/completions.d.ts +3 -0
  38. package/dist/plugins/typescript/completions.js +81 -0
  39. package/dist/plugins/typescript/diagnostics.d.ts +12 -0
  40. package/dist/plugins/typescript/diagnostics.js +99 -0
  41. package/dist/plugins/typescript/index.d.ts +3 -0
  42. package/dist/plugins/typescript/index.js +57 -0
  43. package/dist/utils.d.ts +19 -69
  44. package/dist/utils.js +66 -239
  45. package/package.json +37 -38
  46. package/types/astro-jsx.d.ts +49 -5
  47. package/bin/browserServer.js +0 -3
  48. package/dist/browser.js +0 -15
  49. package/dist/check.d.ts +0 -23
  50. package/dist/check.js +0 -60
  51. package/dist/core/DiagnosticsManager.d.ts +0 -13
  52. package/dist/core/DiagnosticsManager.js +0 -29
  53. package/dist/core/config/ConfigManager.d.ts +0 -43
  54. package/dist/core/config/ConfigManager.js +0 -226
  55. package/dist/core/config/index.d.ts +0 -2
  56. package/dist/core/config/index.js +0 -18
  57. package/dist/core/config/interfaces.d.ts +0 -77
  58. package/dist/core/config/interfaces.js +0 -2
  59. package/dist/core/documents/AstroDocument.d.ts +0 -19
  60. package/dist/core/documents/AstroDocument.js +0 -43
  61. package/dist/core/documents/DocumentBase.d.ts +0 -68
  62. package/dist/core/documents/DocumentBase.js +0 -75
  63. package/dist/core/documents/DocumentManager.d.ts +0 -23
  64. package/dist/core/documents/DocumentManager.js +0 -100
  65. package/dist/core/documents/DocumentMapper.d.ts +0 -94
  66. package/dist/core/documents/DocumentMapper.js +0 -264
  67. package/dist/core/documents/index.d.ts +0 -5
  68. package/dist/core/documents/index.js +0 -21
  69. package/dist/core/documents/parseAstro.d.ts +0 -15
  70. package/dist/core/documents/parseAstro.js +0 -63
  71. package/dist/core/documents/parseHtml.d.ts +0 -13
  72. package/dist/core/documents/parseHtml.js +0 -126
  73. package/dist/core/documents/utils.d.ts +0 -63
  74. package/dist/core/documents/utils.js +0 -223
  75. package/dist/node.d.ts +0 -1
  76. package/dist/node.js +0 -43
  77. package/dist/plugins/PluginHost.d.ts +0 -42
  78. package/dist/plugins/PluginHost.js +0 -206
  79. package/dist/plugins/astro/AstroPlugin.d.ts +0 -17
  80. package/dist/plugins/astro/AstroPlugin.js +0 -90
  81. package/dist/plugins/astro/features/CompletionsProvider.d.ts +0 -17
  82. package/dist/plugins/astro/features/CompletionsProvider.js +0 -242
  83. package/dist/plugins/astro/features/DiagnosticsProvider.d.ts +0 -10
  84. package/dist/plugins/astro/features/DiagnosticsProvider.js +0 -23
  85. package/dist/plugins/css/CSSDocument.d.ts +0 -45
  86. package/dist/plugins/css/CSSDocument.js +0 -68
  87. package/dist/plugins/css/CSSPlugin.d.ts +0 -39
  88. package/dist/plugins/css/CSSPlugin.js +0 -274
  89. package/dist/plugins/css/StyleAttributeDocument.d.ts +0 -40
  90. package/dist/plugins/css/StyleAttributeDocument.js +0 -64
  91. package/dist/plugins/css/features/astro-selectors.d.ts +0 -2
  92. package/dist/plugins/css/features/astro-selectors.js +0 -15
  93. package/dist/plugins/css/features/getIdClassCompletions.d.ts +0 -19
  94. package/dist/plugins/css/features/getIdClassCompletions.js +0 -57
  95. package/dist/plugins/css/language-service.d.ts +0 -3
  96. package/dist/plugins/css/language-service.js +0 -47
  97. package/dist/plugins/html/HTMLPlugin.d.ts +0 -33
  98. package/dist/plugins/html/HTMLPlugin.js +0 -198
  99. package/dist/plugins/html/utils.d.ts +0 -6
  100. package/dist/plugins/html/utils.js +0 -11
  101. package/dist/plugins/index.d.ts +0 -6
  102. package/dist/plugins/index.js +0 -22
  103. package/dist/plugins/interfaces.d.ts +0 -101
  104. package/dist/plugins/interfaces.js +0 -2
  105. package/dist/plugins/typescript/LanguageServiceManager.d.ts +0 -47
  106. package/dist/plugins/typescript/LanguageServiceManager.js +0 -97
  107. package/dist/plugins/typescript/TypeScriptPlugin.d.ts +0 -54
  108. package/dist/plugins/typescript/TypeScriptPlugin.js +0 -152
  109. package/dist/plugins/typescript/astro-sys.d.ts +0 -8
  110. package/dist/plugins/typescript/astro-sys.js +0 -46
  111. package/dist/plugins/typescript/astro2tsx.d.ts +0 -2
  112. package/dist/plugins/typescript/astro2tsx.js +0 -26
  113. package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +0 -17
  114. package/dist/plugins/typescript/features/CodeActionsProvider.js +0 -212
  115. package/dist/plugins/typescript/features/CompletionsProvider.d.ts +0 -31
  116. package/dist/plugins/typescript/features/CompletionsProvider.js +0 -294
  117. package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +0 -9
  118. package/dist/plugins/typescript/features/DefinitionsProvider.js +0 -58
  119. package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +0 -25
  120. package/dist/plugins/typescript/features/DiagnosticsProvider.js +0 -249
  121. package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +0 -11
  122. package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +0 -67
  123. package/dist/plugins/typescript/features/FileReferencesProvider.d.ts +0 -9
  124. package/dist/plugins/typescript/features/FileReferencesProvider.js +0 -27
  125. package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +0 -12
  126. package/dist/plugins/typescript/features/FoldingRangesProvider.js +0 -71
  127. package/dist/plugins/typescript/features/HoverProvider.d.ts +0 -10
  128. package/dist/plugins/typescript/features/HoverProvider.js +0 -50
  129. package/dist/plugins/typescript/features/ImplementationsProvider.d.ts +0 -9
  130. package/dist/plugins/typescript/features/ImplementationsProvider.js +0 -53
  131. package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +0 -13
  132. package/dist/plugins/typescript/features/InlayHintsProvider.js +0 -30
  133. package/dist/plugins/typescript/features/ReferencesProvider.d.ts +0 -9
  134. package/dist/plugins/typescript/features/ReferencesProvider.js +0 -55
  135. package/dist/plugins/typescript/features/RenameProvider.d.ts +0 -13
  136. package/dist/plugins/typescript/features/RenameProvider.js +0 -60
  137. package/dist/plugins/typescript/features/SemanticTokenProvider.d.ts +0 -16
  138. package/dist/plugins/typescript/features/SemanticTokenProvider.js +0 -75
  139. package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +0 -22
  140. package/dist/plugins/typescript/features/SignatureHelpProvider.js +0 -111
  141. package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +0 -9
  142. package/dist/plugins/typescript/features/TypeDefinitionsProvider.js +0 -54
  143. package/dist/plugins/typescript/features/utils.d.ts +0 -14
  144. package/dist/plugins/typescript/features/utils.js +0 -48
  145. package/dist/plugins/typescript/language-service.d.ts +0 -42
  146. package/dist/plugins/typescript/language-service.js +0 -277
  147. package/dist/plugins/typescript/module-loader.d.ts +0 -23
  148. package/dist/plugins/typescript/module-loader.js +0 -155
  149. package/dist/plugins/typescript/previewer.d.ts +0 -7
  150. package/dist/plugins/typescript/previewer.js +0 -108
  151. package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +0 -95
  152. package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +0 -187
  153. package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +0 -44
  154. package/dist/plugins/typescript/snapshots/SnapshotManager.js +0 -179
  155. package/dist/plugins/typescript/snapshots/utils.d.ts +0 -29
  156. package/dist/plugins/typescript/snapshots/utils.js +0 -106
  157. package/dist/plugins/typescript/utils.d.ts +0 -75
  158. package/dist/plugins/typescript/utils.js +0 -366
  159. package/dist/server.d.ts +0 -6
  160. package/dist/server.js +0 -275
  161. package/types/README.md +0 -5
  162. /package/dist/{browser.d.ts → nodeServer.d.ts} +0 -0
  163. /package/dist/plugins/{html/features/astro-attributes.d.ts → html-data.d.ts} +0 -0
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CSSDocument = void 0;
4
- const documents_1 = require("../../core/documents");
5
- const language_service_1 = require("./language-service");
6
- class CSSDocument extends documents_1.ReadableDocument {
7
- constructor(parent, styleInfo) {
8
- super();
9
- this.parent = parent;
10
- this.styleInfo = styleInfo;
11
- this.version = this.parent.version;
12
- this.languageId = this.language;
13
- this.stylesheet = (0, language_service_1.getLanguageService)(this.language).parseStylesheet(this);
14
- }
15
- /**
16
- * Get the fragment position relative to the parent
17
- * @param pos Position in fragment
18
- */
19
- getOriginalPosition(pos) {
20
- const parentOffset = this.styleInfo.start + this.offsetAt(pos);
21
- return this.parent.positionAt(parentOffset);
22
- }
23
- /**
24
- * Get the position relative to the start of the fragment
25
- * @param pos Position in parent
26
- */
27
- getGeneratedPosition(pos) {
28
- const fragmentOffset = this.parent.offsetAt(pos) - this.styleInfo.start;
29
- return this.positionAt(fragmentOffset);
30
- }
31
- /**
32
- * Returns true if the given parent position is inside of this fragment
33
- * @param pos Position in parent
34
- */
35
- isInGenerated(pos) {
36
- const offset = this.parent.offsetAt(pos);
37
- return offset >= this.styleInfo.start && offset <= this.styleInfo.end;
38
- }
39
- /**
40
- * Get the fragment text from the parent
41
- */
42
- getText() {
43
- return this.parent.getText().slice(this.styleInfo.start, this.styleInfo.end);
44
- }
45
- /**
46
- * Returns the length of the fragment as calculated from the start and end position
47
- */
48
- getTextLength() {
49
- return this.styleInfo.end - this.styleInfo.start;
50
- }
51
- /**
52
- * Return the parent file path
53
- */
54
- getFilePath() {
55
- return this.parent.getFilePath();
56
- }
57
- getURL() {
58
- return this.parent.getURL();
59
- }
60
- getAttributes() {
61
- return this.styleInfo.attributes;
62
- }
63
- get language() {
64
- const attrs = this.getAttributes();
65
- return attrs.lang || attrs.type || 'css';
66
- }
67
- }
68
- exports.CSSDocument = CSSDocument;
@@ -1,39 +0,0 @@
1
- import { Color, ColorInformation, ColorPresentation, CompletionContext, CompletionList, FoldingRange, Hover, Position, Range, SymbolInformation, WorkspaceEdit } from 'vscode-languageserver';
2
- import type { ConfigManager } from '../../core/config/ConfigManager';
3
- import { AstroDocument } from '../../core/documents';
4
- import type { Plugin } from '../interfaces';
5
- export declare class CSSPlugin implements Plugin {
6
- __name: string;
7
- private configManager;
8
- private cssDocuments;
9
- private triggerCharacters;
10
- constructor(configManager: ConfigManager);
11
- doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
12
- private doHoverInternal;
13
- getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<CompletionList | null>;
14
- private getCompletionsInternal;
15
- getDocumentColors(document: AstroDocument): Promise<ColorInformation[]>;
16
- getColorPresentations(document: AstroDocument, range: Range, color: Color): Promise<ColorPresentation[]>;
17
- prepareRename(document: AstroDocument, position: Position): Range | null;
18
- rename(document: AstroDocument, position: Position, newName: string): WorkspaceEdit | null;
19
- getFoldingRanges(document: AstroDocument): FoldingRange[] | null;
20
- getDocumentSymbols(document: AstroDocument): Promise<SymbolInformation[]>;
21
- private inStyleAttributeWithoutInterpolation;
22
- /**
23
- * Get the associated CSS Document for a style tag
24
- */
25
- private getCSSDocumentForStyleTag;
26
- /**
27
- * Get all the CSSDocuments in a document
28
- */
29
- private getCSSDocumentsForDocument;
30
- /**
31
- * Get all the stylesheets (Stylesheet type) in a document
32
- */
33
- private getStylesheetsForDocument;
34
- /**
35
- * Get style tag at position for a document
36
- */
37
- private getStyleTagForPosition;
38
- private featureEnabled;
39
- }
@@ -1,274 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CSSPlugin = void 0;
4
- const emmet_helper_1 = require("@vscode/emmet-helper");
5
- const vscode_languageserver_1 = require("vscode-languageserver");
6
- const documents_1 = require("../../core/documents");
7
- const parseHtml_1 = require("../../core/documents/parseHtml");
8
- const CSSDocument_1 = require("./CSSDocument");
9
- const getIdClassCompletions_1 = require("./features/getIdClassCompletions");
10
- const language_service_1 = require("./language-service");
11
- const StyleAttributeDocument_1 = require("./StyleAttributeDocument");
12
- class CSSPlugin {
13
- constructor(configManager) {
14
- this.__name = 'css';
15
- this.cssDocuments = new WeakMap();
16
- this.triggerCharacters = new Set(['.', ':', '-', '/']);
17
- this.configManager = configManager;
18
- }
19
- async doHover(document, position) {
20
- if (!(await this.featureEnabled(document, 'hover'))) {
21
- return null;
22
- }
23
- if ((0, documents_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position))) {
24
- return null;
25
- }
26
- const styleTag = this.getStyleTagForPosition(document, position);
27
- // We technically can return results even for open tags, however, a lot of the info returned is not valid
28
- // Since most editors will automatically close the tag before the user start working in them, this shouldn't be a problem
29
- if (styleTag && !styleTag.closed) {
30
- return null;
31
- }
32
- // If we don't have a style tag at this position, we might be in a style property instead, let's check
33
- if (!styleTag) {
34
- const attributeContext = (0, parseHtml_1.getAttributeContextAtPosition)(document, position);
35
- if (!attributeContext) {
36
- return null;
37
- }
38
- if (this.inStyleAttributeWithoutInterpolation(attributeContext, document.getText())) {
39
- const [start, end] = attributeContext.valueRange;
40
- return this.doHoverInternal(new StyleAttributeDocument_1.StyleAttributeDocument(document, start, end), position);
41
- }
42
- return null;
43
- }
44
- const cssDocument = this.getCSSDocumentForStyleTag(styleTag, document);
45
- const cssLang = extractLanguage(cssDocument);
46
- if (!isSupportedByLangService(cssLang)) {
47
- return null;
48
- }
49
- return this.doHoverInternal(cssDocument, position);
50
- }
51
- doHoverInternal(cssDocument, position) {
52
- const hoverInfo = (0, language_service_1.getLanguageService)(extractLanguage(cssDocument)).doHover(cssDocument, cssDocument.getGeneratedPosition(position), cssDocument.stylesheet);
53
- return hoverInfo ? (0, documents_1.mapHoverToParent)(cssDocument, hoverInfo) : hoverInfo;
54
- }
55
- async getCompletions(document, position, completionContext) {
56
- if (!(await this.featureEnabled(document, 'completions'))) {
57
- return null;
58
- }
59
- if ((0, documents_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position))) {
60
- return null;
61
- }
62
- const triggerCharacter = completionContext?.triggerCharacter;
63
- const triggerKind = completionContext?.triggerKind;
64
- const isCustomTriggerCharacter = triggerKind === vscode_languageserver_1.CompletionTriggerKind.TriggerCharacter;
65
- if (isCustomTriggerCharacter && triggerCharacter && !this.triggerCharacters.has(triggerCharacter)) {
66
- return null;
67
- }
68
- const styleTag = this.getStyleTagForPosition(document, position);
69
- if (styleTag && !styleTag.closed) {
70
- return null;
71
- }
72
- if (!styleTag) {
73
- const attributeContext = (0, parseHtml_1.getAttributeContextAtPosition)(document, position);
74
- if (!attributeContext) {
75
- return null;
76
- }
77
- if (this.inStyleAttributeWithoutInterpolation(attributeContext, document.getText())) {
78
- const [start, end] = attributeContext.valueRange;
79
- return await this.getCompletionsInternal(document, position, new StyleAttributeDocument_1.StyleAttributeDocument(document, start, end));
80
- }
81
- // If we're not in a style attribute, instead give completions for ids and classes used in the current document
82
- else if ((attributeContext.name == 'id' || attributeContext.name == 'class') && attributeContext.inValue) {
83
- const stylesheets = this.getStylesheetsForDocument(document);
84
- return (0, getIdClassCompletions_1.getIdClassCompletion)(stylesheets, attributeContext);
85
- }
86
- return null;
87
- }
88
- const cssDocument = this.getCSSDocumentForStyleTag(styleTag, document);
89
- return await this.getCompletionsInternal(document, position, cssDocument);
90
- }
91
- async getCompletionsInternal(document, position, cssDocument) {
92
- const emmetConfig = await this.configManager.getEmmetConfig(document);
93
- if (isSASS(cssDocument)) {
94
- // The CSS language service does not support SASS (not to be confused with SCSS)
95
- // however we can at least still at least provide Emmet completions in SASS blocks
96
- return (0, emmet_helper_1.doComplete)(document, position, 'sass', emmetConfig) || null;
97
- }
98
- const cssLang = extractLanguage(cssDocument);
99
- const langService = (0, language_service_1.getLanguageService)(cssLang);
100
- let emmetResults = {
101
- isIncomplete: false,
102
- items: [],
103
- };
104
- const extensionConfig = await this.configManager.getConfig('astro', document.uri);
105
- if (extensionConfig?.css?.completions?.emmet ?? true) {
106
- langService.setCompletionParticipants([
107
- {
108
- onCssProperty: (context) => {
109
- if (context?.propertyName) {
110
- emmetResults =
111
- (0, emmet_helper_1.doComplete)(cssDocument, cssDocument.getGeneratedPosition(position), (0, language_service_1.getLanguage)(cssLang), emmetConfig) || emmetResults;
112
- }
113
- },
114
- onCssPropertyValue: (context) => {
115
- if (context?.propertyValue) {
116
- emmetResults =
117
- (0, emmet_helper_1.doComplete)(cssDocument, cssDocument.getGeneratedPosition(position), (0, language_service_1.getLanguage)(cssLang), emmetConfig) || emmetResults;
118
- }
119
- },
120
- },
121
- ]);
122
- }
123
- const results = langService.doComplete(cssDocument, cssDocument.getGeneratedPosition(position), cssDocument.stylesheet);
124
- return vscode_languageserver_1.CompletionList.create([...(results ? results.items : []), ...emmetResults.items].map((completionItem) => (0, documents_1.mapCompletionItemToOriginal)(cssDocument, completionItem)),
125
- // Emmet completions change on every keystroke, so they are never complete
126
- emmetResults.items.length > 0);
127
- }
128
- async getDocumentColors(document) {
129
- if (!(await this.featureEnabled(document, 'documentColors'))) {
130
- return [];
131
- }
132
- const allColorInfo = this.getCSSDocumentsForDocument(document).flatMap((cssDoc) => {
133
- const cssLang = extractLanguage(cssDoc);
134
- const langService = (0, language_service_1.getLanguageService)(cssLang);
135
- if (!isSupportedByLangService(cssLang)) {
136
- return [];
137
- }
138
- return langService
139
- .findDocumentColors(cssDoc, cssDoc.stylesheet)
140
- .map((colorInfo) => (0, documents_1.mapObjWithRangeToOriginal)(cssDoc, colorInfo));
141
- });
142
- return allColorInfo;
143
- }
144
- async getColorPresentations(document, range, color) {
145
- if (!(await this.featureEnabled(document, 'documentColors'))) {
146
- return [];
147
- }
148
- const allColorPres = this.getCSSDocumentsForDocument(document).flatMap((cssDoc) => {
149
- const cssLang = extractLanguage(cssDoc);
150
- const langService = (0, language_service_1.getLanguageService)(cssLang);
151
- if ((!cssDoc.isInGenerated(range.start) && !cssDoc.isInGenerated(range.end)) ||
152
- !isSupportedByLangService(cssLang)) {
153
- return [];
154
- }
155
- return langService
156
- .getColorPresentations(cssDoc, cssDoc.stylesheet, color, (0, documents_1.mapRangeToGenerated)(cssDoc, range))
157
- .map((colorPres) => (0, documents_1.mapColorPresentationToOriginal)(cssDoc, colorPres));
158
- });
159
- return allColorPres;
160
- }
161
- prepareRename(document, position) {
162
- const styleTag = this.getStyleTagForPosition(document, position);
163
- if (!styleTag) {
164
- return null;
165
- }
166
- const cssDocument = this.getCSSDocumentForStyleTag(styleTag, document);
167
- const cssLang = extractLanguage(cssDocument);
168
- const langService = (0, language_service_1.getLanguageService)(cssLang);
169
- const range = langService.prepareRename(cssDocument, cssDocument.getGeneratedPosition(position), cssDocument.stylesheet);
170
- if (!range) {
171
- return null;
172
- }
173
- return (0, documents_1.mapRangeToOriginal)(cssDocument, range);
174
- }
175
- rename(document, position, newName) {
176
- const styleTag = this.getStyleTagForPosition(document, position);
177
- if (!styleTag) {
178
- return null;
179
- }
180
- const cssDocument = this.getCSSDocumentForStyleTag(styleTag, document);
181
- const cssLang = extractLanguage(cssDocument);
182
- const langService = (0, language_service_1.getLanguageService)(cssLang);
183
- const renames = langService.doRename(cssDocument, cssDocument.getGeneratedPosition(position), newName, cssDocument.stylesheet);
184
- if (renames?.changes?.[document.uri]) {
185
- renames.changes[document.uri] = renames?.changes?.[document.uri].map((edit) => (0, documents_1.mapObjWithRangeToOriginal)(cssDocument, edit));
186
- }
187
- return renames;
188
- }
189
- getFoldingRanges(document) {
190
- const allFoldingRanges = this.getCSSDocumentsForDocument(document).flatMap((cssDoc) => {
191
- const cssLang = extractLanguage(cssDoc);
192
- const langService = (0, language_service_1.getLanguageService)(cssLang);
193
- return langService.getFoldingRanges(cssDoc).map((foldingRange) => (0, documents_1.mapFoldingRangeToParent)(cssDoc, foldingRange));
194
- });
195
- return allFoldingRanges;
196
- }
197
- async getDocumentSymbols(document) {
198
- if (!(await this.featureEnabled(document, 'documentSymbols'))) {
199
- return [];
200
- }
201
- const allDocumentSymbols = this.getCSSDocumentsForDocument(document).flatMap((cssDoc) => {
202
- return (0, language_service_1.getLanguageService)(extractLanguage(cssDoc))
203
- .findDocumentSymbols(cssDoc, cssDoc.stylesheet)
204
- .map((symbol) => (0, documents_1.mapSymbolInformationToOriginal)(cssDoc, symbol));
205
- });
206
- return allDocumentSymbols;
207
- }
208
- inStyleAttributeWithoutInterpolation(attrContext, text) {
209
- return (attrContext.name === 'style' &&
210
- !!attrContext.valueRange &&
211
- !text.substring(attrContext.valueRange[0], attrContext.valueRange[1]).includes('{'));
212
- }
213
- /**
214
- * Get the associated CSS Document for a style tag
215
- */
216
- getCSSDocumentForStyleTag(tag, document) {
217
- let cssDoc = this.cssDocuments.get(tag);
218
- if (!cssDoc || cssDoc.version < document.version) {
219
- cssDoc = new CSSDocument_1.CSSDocument(document, tag);
220
- this.cssDocuments.set(tag, cssDoc);
221
- }
222
- return cssDoc;
223
- }
224
- /**
225
- * Get all the CSSDocuments in a document
226
- */
227
- getCSSDocumentsForDocument(document) {
228
- return document.styleTags.map((tag) => this.getCSSDocumentForStyleTag(tag, document));
229
- }
230
- /**
231
- * Get all the stylesheets (Stylesheet type) in a document
232
- */
233
- getStylesheetsForDocument(document) {
234
- return this.getCSSDocumentsForDocument(document).map((cssDoc) => cssDoc.stylesheet);
235
- }
236
- /**
237
- * Get style tag at position for a document
238
- */
239
- getStyleTagForPosition(document, position) {
240
- return document.styleTags.find((styleTag) => {
241
- return (0, documents_1.isInTag)(position, styleTag);
242
- });
243
- }
244
- async featureEnabled(document, feature) {
245
- return ((await this.configManager.isEnabled(document, 'css')) &&
246
- (await this.configManager.isEnabled(document, 'css', feature)));
247
- }
248
- }
249
- exports.CSSPlugin = CSSPlugin;
250
- /**
251
- * Check is a CSSDocument's language is supported by the CSS language service
252
- */
253
- function isSupportedByLangService(language) {
254
- switch (language) {
255
- case 'css':
256
- case 'scss':
257
- case 'less':
258
- return true;
259
- default:
260
- return false;
261
- }
262
- }
263
- function isSASS(document) {
264
- switch (extractLanguage(document)) {
265
- case 'sass':
266
- return true;
267
- default:
268
- return false;
269
- }
270
- }
271
- function extractLanguage(document) {
272
- const lang = document.languageId;
273
- return lang.replace(/^text\//, '');
274
- }
@@ -1,40 +0,0 @@
1
- import type { Stylesheet } from 'vscode-css-languageservice';
2
- import type { Position } from 'vscode-languageserver';
3
- import { AstroDocument, DocumentMapper, ReadableDocument } from '../../core/documents';
4
- export declare class StyleAttributeDocument extends ReadableDocument implements DocumentMapper {
5
- private readonly parent;
6
- private readonly attrStart;
7
- private readonly attrEnd;
8
- readonly version: number;
9
- stylesheet: Stylesheet;
10
- languageId: string;
11
- constructor(parent: AstroDocument, attrStart: number, attrEnd: number);
12
- /**
13
- * Get the fragment position relative to the parent
14
- * @param pos Position in fragment
15
- */
16
- getOriginalPosition(pos: Position): Position;
17
- /**
18
- * Get the position relative to the start of the fragment
19
- * @param pos Position in parent
20
- */
21
- getGeneratedPosition(pos: Position): Position;
22
- /**
23
- * Returns true if the given parent position is inside of this fragment
24
- * @param pos Position in parent
25
- */
26
- isInGenerated(pos: Position): boolean;
27
- /**
28
- * Get the fragment text from the parent
29
- */
30
- getText(): string;
31
- /**
32
- * Returns the length of the fragment as calculated from the start and end position
33
- */
34
- getTextLength(): number;
35
- /**
36
- * Return the parent file path
37
- */
38
- getFilePath(): string | null;
39
- getURL(): string;
40
- }
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StyleAttributeDocument = void 0;
4
- const documents_1 = require("../../core/documents");
5
- const language_service_1 = require("./language-service");
6
- const PREFIX = '__ {';
7
- const SUFFIX = '}';
8
- class StyleAttributeDocument extends documents_1.ReadableDocument {
9
- constructor(parent, attrStart, attrEnd) {
10
- super();
11
- this.parent = parent;
12
- this.attrStart = attrStart;
13
- this.attrEnd = attrEnd;
14
- this.version = this.parent.version;
15
- this.languageId = 'css';
16
- this.stylesheet = (0, language_service_1.getLanguageService)(this.languageId).parseStylesheet(this);
17
- }
18
- /**
19
- * Get the fragment position relative to the parent
20
- * @param pos Position in fragment
21
- */
22
- getOriginalPosition(pos) {
23
- const parentOffset = this.attrStart + this.offsetAt(pos) - PREFIX.length;
24
- return this.parent.positionAt(parentOffset);
25
- }
26
- /**
27
- * Get the position relative to the start of the fragment
28
- * @param pos Position in parent
29
- */
30
- getGeneratedPosition(pos) {
31
- const fragmentOffset = this.parent.offsetAt(pos) - this.attrStart + PREFIX.length;
32
- return this.positionAt(fragmentOffset);
33
- }
34
- /**
35
- * Returns true if the given parent position is inside of this fragment
36
- * @param pos Position in parent
37
- */
38
- isInGenerated(pos) {
39
- const offset = this.parent.offsetAt(pos);
40
- return offset >= this.attrStart && offset <= this.attrEnd;
41
- }
42
- /**
43
- * Get the fragment text from the parent
44
- */
45
- getText() {
46
- return PREFIX + this.parent.getText().slice(this.attrStart, this.attrEnd) + SUFFIX;
47
- }
48
- /**
49
- * Returns the length of the fragment as calculated from the start and end position
50
- */
51
- getTextLength() {
52
- return PREFIX.length + this.attrEnd - this.attrStart + SUFFIX.length;
53
- }
54
- /**
55
- * Return the parent file path
56
- */
57
- getFilePath() {
58
- return this.parent.getFilePath();
59
- }
60
- getURL() {
61
- return this.parent.getURL();
62
- }
63
- }
64
- exports.StyleAttributeDocument = StyleAttributeDocument;
@@ -1,2 +0,0 @@
1
- import type { IPseudoClassData } from 'vscode-css-languageservice';
2
- export declare const pseudoClass: IPseudoClassData[];
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pseudoClass = void 0;
4
- exports.pseudoClass = [
5
- {
6
- name: ':global()',
7
- description: 'Apply styles to a selector globally',
8
- references: [
9
- {
10
- name: 'Astro documentation',
11
- url: 'https://docs.astro.build/en/guides/styling/#global-styles-within-style-tag',
12
- },
13
- ],
14
- },
15
- ];
@@ -1,19 +0,0 @@
1
- import type { Stylesheet } from 'vscode-css-languageservice';
2
- import { CompletionItem, CompletionList } from 'vscode-languageserver';
3
- import type { AttributeContext } from '../../../core/documents/parseHtml';
4
- export declare function getIdClassCompletion(stylesheets: Stylesheet[], attributeContext: AttributeContext): CompletionList | null;
5
- /**
6
- * incomplete see
7
- * https://github.com/microsoft/vscode-css-languageservice/blob/master/src/parser/cssNodes.ts#L14
8
- * The enum is not exported. we have to update this whenever it changes
9
- */
10
- export declare enum NodeType {
11
- ClassSelector = 14,
12
- IdentifierSelector = 15
13
- }
14
- export type CSSNode = {
15
- type: number;
16
- children: CSSNode[] | undefined;
17
- getText(): string;
18
- };
19
- export declare function collectSelectors(stylesheets: CSSNode[], type: number): CompletionItem[];
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectSelectors = exports.NodeType = exports.getIdClassCompletion = void 0;
4
- const vscode_languageserver_1 = require("vscode-languageserver");
5
- function getIdClassCompletion(stylesheets, attributeContext) {
6
- const collectingType = getCollectingType(attributeContext);
7
- if (!collectingType) {
8
- return null;
9
- }
10
- const items = collectSelectors(stylesheets, collectingType);
11
- return vscode_languageserver_1.CompletionList.create(items);
12
- }
13
- exports.getIdClassCompletion = getIdClassCompletion;
14
- function getCollectingType(attributeContext) {
15
- if (attributeContext.inValue) {
16
- if (attributeContext.name === 'class') {
17
- return NodeType.ClassSelector;
18
- }
19
- if (attributeContext.name === 'id') {
20
- return NodeType.IdentifierSelector;
21
- }
22
- }
23
- else if (attributeContext.name.startsWith('class:')) {
24
- return NodeType.ClassSelector;
25
- }
26
- }
27
- /**
28
- * incomplete see
29
- * https://github.com/microsoft/vscode-css-languageservice/blob/master/src/parser/cssNodes.ts#L14
30
- * The enum is not exported. we have to update this whenever it changes
31
- */
32
- var NodeType;
33
- (function (NodeType) {
34
- NodeType[NodeType["ClassSelector"] = 14] = "ClassSelector";
35
- NodeType[NodeType["IdentifierSelector"] = 15] = "IdentifierSelector";
36
- })(NodeType = exports.NodeType || (exports.NodeType = {}));
37
- function collectSelectors(stylesheets, type) {
38
- const result = [];
39
- stylesheets.forEach((stylesheet) => {
40
- walk(stylesheet, (node) => {
41
- if (node.type === type) {
42
- result.push(node);
43
- }
44
- });
45
- });
46
- return result.map((node) => ({
47
- label: node.getText().substring(1),
48
- kind: vscode_languageserver_1.CompletionItemKind.Keyword,
49
- }));
50
- }
51
- exports.collectSelectors = collectSelectors;
52
- function walk(node, callback) {
53
- callback(node);
54
- if (node.children) {
55
- node.children.forEach((childrenNode) => walk(childrenNode, callback));
56
- }
57
- }
@@ -1,3 +0,0 @@
1
- import { LanguageService } from 'vscode-css-languageservice';
2
- export declare function getLanguage(kind?: string): "css" | "less" | "scss";
3
- export declare function getLanguageService(kind?: string): LanguageService;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLanguageService = exports.getLanguage = void 0;
4
- const vscode_css_languageservice_1 = require("vscode-css-languageservice");
5
- const astro_selectors_1 = require("./features/astro-selectors");
6
- const customDataProvider = {
7
- providePseudoClasses() {
8
- return astro_selectors_1.pseudoClass;
9
- },
10
- provideProperties() {
11
- return [];
12
- },
13
- provideAtDirectives() {
14
- return [];
15
- },
16
- providePseudoElements() {
17
- return [];
18
- },
19
- };
20
- const [css, scss, less] = [vscode_css_languageservice_1.getCSSLanguageService, vscode_css_languageservice_1.getSCSSLanguageService, vscode_css_languageservice_1.getLESSLanguageService].map((getService) => getService({
21
- customDataProviders: [customDataProvider],
22
- }));
23
- const langs = {
24
- css,
25
- scss,
26
- less,
27
- };
28
- function getLanguage(kind) {
29
- switch (kind) {
30
- case 'scss':
31
- case 'text/scss':
32
- return 'scss';
33
- case 'less':
34
- case 'text/less':
35
- return 'less';
36
- case 'css':
37
- case 'text/css':
38
- default:
39
- return 'css';
40
- }
41
- }
42
- exports.getLanguage = getLanguage;
43
- function getLanguageService(kind) {
44
- const lang = getLanguage(kind);
45
- return langs[lang];
46
- }
47
- exports.getLanguageService = getLanguageService;
@@ -1,33 +0,0 @@
1
- import { CompletionList, FoldingRange, Hover, LinkedEditingRanges, Position, Range, SymbolInformation, WorkspaceEdit } from 'vscode-languageserver';
2
- import type { ConfigManager } from '../../core/config/ConfigManager';
3
- import type { AstroDocument } from '../../core/documents/AstroDocument';
4
- import type { Plugin } from '../interfaces';
5
- export declare class HTMLPlugin implements Plugin {
6
- __name: string;
7
- private lang;
8
- private attributeOnlyLang;
9
- private componentLang;
10
- private styleScriptTemplate;
11
- private configManager;
12
- constructor(configManager: ConfigManager);
13
- doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
14
- /**
15
- * Get HTML completions
16
- */
17
- getCompletions(document: AstroDocument, position: Position): Promise<CompletionList | null>;
18
- getFoldingRanges(document: AstroDocument): FoldingRange[] | null;
19
- getLinkedEditingRanges(document: AstroDocument, position: Position): LinkedEditingRanges | null;
20
- doTagComplete(document: AstroDocument, position: Position): Promise<string | null>;
21
- prepareRename(document: AstroDocument, position: Position): Range | null;
22
- rename(document: AstroDocument, position: Position, newName: string): WorkspaceEdit | null;
23
- getDocumentSymbols(document: AstroDocument): Promise<SymbolInformation[]>;
24
- /**
25
- * Get lang completions for style tags (ex: `<style lang="scss">`)
26
- */
27
- private getLangCompletions;
28
- /**
29
- * Returns true if rename happens at the tag name, not anywhere inbetween.
30
- */
31
- private isRenameAtTag;
32
- private featureEnabled;
33
- }