@astrojs/language-server 0.16.0 → 0.18.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 (47) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/core/config/ConfigManager.d.ts +25 -16
  3. package/dist/core/config/ConfigManager.js +160 -46
  4. package/dist/core/config/interfaces.d.ts +4 -51
  5. package/dist/core/documents/AstroDocument.d.ts +1 -0
  6. package/dist/core/documents/AstroDocument.js +1 -0
  7. package/dist/core/documents/DocumentMapper.d.ts +2 -0
  8. package/dist/core/documents/DocumentMapper.js +7 -5
  9. package/dist/core/documents/utils.d.ts +1 -0
  10. package/dist/core/documents/utils.js +16 -1
  11. package/dist/plugins/PluginHost.d.ts +3 -1
  12. package/dist/plugins/PluginHost.js +8 -0
  13. package/dist/plugins/astro/AstroPlugin.d.ts +1 -6
  14. package/dist/plugins/astro/AstroPlugin.js +10 -85
  15. package/dist/plugins/astro/features/CompletionsProvider.d.ts +4 -5
  16. package/dist/plugins/astro/features/CompletionsProvider.js +53 -58
  17. package/dist/plugins/css/CSSPlugin.d.ts +5 -5
  18. package/dist/plugins/css/CSSPlugin.js +36 -31
  19. package/dist/plugins/html/HTMLPlugin.d.ts +6 -5
  20. package/dist/plugins/html/HTMLPlugin.js +38 -16
  21. package/dist/plugins/html/features/astro-attributes.js +1 -0
  22. package/dist/plugins/interfaces.d.ts +5 -2
  23. package/dist/plugins/typescript/TypeScriptPlugin.d.ts +7 -4
  24. package/dist/plugins/typescript/TypeScriptPlugin.js +34 -110
  25. package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +3 -1
  26. package/dist/plugins/typescript/features/CodeActionsProvider.js +82 -17
  27. package/dist/plugins/typescript/features/CompletionsProvider.d.ts +5 -3
  28. package/dist/plugins/typescript/features/CompletionsProvider.js +112 -56
  29. package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +9 -0
  30. package/dist/plugins/typescript/features/DefinitionsProvider.js +57 -0
  31. package/dist/plugins/typescript/features/DiagnosticsProvider.js +58 -15
  32. package/dist/plugins/typescript/features/FoldingRangesProvider.js +13 -6
  33. package/dist/plugins/typescript/features/FormattingProvider.d.ts +11 -0
  34. package/dist/plugins/typescript/features/FormattingProvider.js +132 -0
  35. package/dist/plugins/typescript/features/HoverProvider.js +14 -1
  36. package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +12 -0
  37. package/dist/plugins/typescript/features/InlayHintsProvider.js +36 -0
  38. package/dist/plugins/typescript/features/SignatureHelpProvider.js +9 -1
  39. package/dist/plugins/typescript/language-service.js +18 -0
  40. package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +22 -2
  41. package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +48 -1
  42. package/dist/plugins/typescript/snapshots/SnapshotManager.js +1 -0
  43. package/dist/plugins/typescript/snapshots/utils.js +3 -2
  44. package/dist/plugins/typescript/utils.d.ts +11 -1
  45. package/dist/plugins/typescript/utils.js +17 -1
  46. package/dist/server.js +27 -15
  47. package/package.json +7 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @astrojs/language-server
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d3c6fd8: Add support for formatting
8
+ - 09e1163: Updated language server to latest version of LSP, added support for Inlay Hints
9
+ - fcaba8e: Add support for completions and type checking for Vue props
10
+
11
+ ### Patch Changes
12
+
13
+ - 4138005: Fix frontmatter folding not working properly when last few lines of frontmatter are empty
14
+ - 76ff46a: Add `?` in the label of completions of optional parameters (including component props)
15
+
16
+ ## 0.17.0
17
+
18
+ ### Minor Changes
19
+
20
+ - 3ad0f65: Add support for TypeScript features inside script tags (completions, diagnostics, hover etc)
21
+
22
+ ### Patch Changes
23
+
24
+ - 2e9da14: Add support for loading props completions from .d.ts files, improve performance of props completions
25
+
26
+ ## 0.16.1
27
+
28
+ ### Patch Changes
29
+
30
+ - ad5a5e5: Fix misc issues with Go To Definition
31
+ - 1bd790d: Updates config management, make sure to respect TypeScript settings when doing completions and quickfixes
32
+
3
33
  ## 0.16.0
4
34
 
5
35
  ### Minor Changes
@@ -1,5 +1,9 @@
1
1
  import { VSCodeEmmetConfig } from '@vscode/emmet-helper';
2
- import { LSConfig } from './interfaces';
2
+ import { LSConfig, LSCSSConfig, LSFormatConfig, LSHTMLConfig, LSTypescriptConfig } from './interfaces';
3
+ import { Connection, FormattingOptions } from 'vscode-languageserver';
4
+ import { TextDocument } from 'vscode-languageserver-textdocument';
5
+ import { FormatCodeSettings, InlayHintsOptions, UserPreferences } from 'typescript';
6
+ export declare const defaultLSConfig: LSConfig;
3
7
  declare type DeepPartial<T> = T extends Record<string, unknown> ? {
4
8
  [P in keyof T]?: DeepPartial<T[P]>;
5
9
  } : T;
@@ -9,25 +13,30 @@ declare type DeepPartial<T> = T extends Record<string, unknown> ? {
9
13
  * For more info on this, see the [internal docs](../../../../../docs/internal/language-server/config.md)
10
14
  */
11
15
  export declare class ConfigManager {
12
- private config;
13
- private emmetConfig;
16
+ private globalConfig;
17
+ private documentSettings;
14
18
  private isTrusted;
15
- updateConfig(config: DeepPartial<LSConfig>): void;
16
- updateEmmetConfig(config: VSCodeEmmetConfig): void;
17
- getEmmetConfig(): VSCodeEmmetConfig;
19
+ private connection;
20
+ constructor(connection?: Connection);
21
+ updateConfig(): void;
22
+ removeDocument(scopeUri: string): void;
23
+ getConfig<T>(section: string, scopeUri: string): Promise<T>;
24
+ getEmmetConfig(document: TextDocument): Promise<VSCodeEmmetConfig>;
25
+ getAstroFormatConfig(document: TextDocument): Promise<LSFormatConfig>;
26
+ getTSFormatConfig(document: TextDocument, vscodeOptions?: FormattingOptions): Promise<FormatCodeSettings>;
27
+ getTSPreferences(document: TextDocument): Promise<UserPreferences>;
28
+ getTSInlayHintsPreferences(document: TextDocument): Promise<InlayHintsOptions>;
18
29
  /**
19
- * Whether or not specified setting is enabled
20
- * @param key a string which is a path. Example: 'astro.diagnostics.enabled'.
30
+ * Return true if a plugin and an optional feature is enabled
21
31
  */
22
- enabled(key: string): boolean;
32
+ isEnabled(document: TextDocument, plugin: keyof LSConfig, feature?: keyof LSTypescriptConfig | keyof LSCSSConfig | keyof LSHTMLConfig): Promise<boolean>;
23
33
  /**
24
- * Get a specific setting value
25
- * @param key a string which is a path. Example: 'astro.diagnostics.enable'.
34
+ * Updating the global config should only be done in cases where the client doesn't support `workspace/configuration`
35
+ * or inside of tests.
36
+ *
37
+ * The `outsideAstro` parameter can be set to true to change configurations in the global scope.
38
+ * For example, to change TypeScript settings
26
39
  */
27
- get<T>(key: string): T;
28
- /**
29
- * Get the entire user configuration
30
- */
31
- getFullConfig(): Readonly<LSConfig>;
40
+ updateGlobalConfig(config: DeepPartial<LSConfig> | any, outsideAstro?: boolean): void;
32
41
  }
33
42
  export {};
@@ -1,43 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConfigManager = void 0;
3
+ exports.ConfigManager = exports.defaultLSConfig = void 0;
4
4
  const lodash_1 = require("lodash");
5
- const defaultLSConfig = {
6
- astro: {
7
- enabled: true,
8
- diagnostics: { enabled: true },
9
- rename: { enabled: true },
10
- format: { enabled: true },
11
- completions: { enabled: true },
12
- hover: { enabled: true },
13
- codeActions: { enabled: true },
14
- selectionRange: { enabled: true },
15
- },
5
+ const typescript_1 = require("typescript");
6
+ exports.defaultLSConfig = {
16
7
  typescript: {
17
8
  enabled: true,
18
9
  diagnostics: { enabled: true },
19
10
  hover: { enabled: true },
20
11
  completions: { enabled: true },
21
12
  definitions: { enabled: true },
22
- findReferences: { enabled: true },
23
13
  documentSymbols: { enabled: true },
24
14
  codeActions: { enabled: true },
25
15
  rename: { enabled: true },
26
- selectionRange: { enabled: true },
27
16
  signatureHelp: { enabled: true },
28
17
  semanticTokens: { enabled: true },
29
- implementation: { enabled: true },
30
- typeDefinition: { enabled: true },
31
18
  },
32
19
  css: {
33
20
  enabled: true,
34
- diagnostics: { enabled: true },
35
21
  hover: { enabled: true },
36
22
  completions: { enabled: true, emmet: true },
37
23
  documentColors: { enabled: true },
38
- colorPresentations: { enabled: true },
39
24
  documentSymbols: { enabled: true },
40
- selectionRange: { enabled: true },
41
25
  },
42
26
  html: {
43
27
  enabled: true,
@@ -45,8 +29,10 @@ const defaultLSConfig = {
45
29
  completions: { enabled: true, emmet: true },
46
30
  tagComplete: { enabled: true },
47
31
  documentSymbols: { enabled: true },
48
- renameTags: { enabled: true },
49
- linkedEditing: { enabled: true },
32
+ },
33
+ format: {
34
+ indentFrontmatter: true,
35
+ newLineAfterFrontmatter: true,
50
36
  },
51
37
  };
52
38
  /**
@@ -55,42 +41,170 @@ const defaultLSConfig = {
55
41
  * For more info on this, see the [internal docs](../../../../../docs/internal/language-server/config.md)
56
42
  */
57
43
  class ConfigManager {
58
- constructor() {
59
- this.config = defaultLSConfig;
60
- this.emmetConfig = {};
44
+ constructor(connection) {
45
+ this.globalConfig = { astro: exports.defaultLSConfig };
46
+ this.documentSettings = {};
61
47
  this.isTrusted = true;
48
+ this.connection = connection;
62
49
  }
63
- updateConfig(config) {
64
- // Ideally we shouldn't need the merge here because all updates should be valid and complete configs.
65
- // But since those configs come from the client they might be out of synch with the valid config:
66
- // We might at some point in the future forget to synch config settings in all packages after updating the config.
67
- this.config = (0, lodash_1.merge)({}, defaultLSConfig, this.config, config);
50
+ updateConfig() {
51
+ // Reset all cached document settings
52
+ this.documentSettings = {};
68
53
  }
69
- updateEmmetConfig(config) {
70
- this.emmetConfig = config || {};
54
+ removeDocument(scopeUri) {
55
+ delete this.documentSettings[scopeUri];
71
56
  }
72
- getEmmetConfig() {
73
- return this.emmetConfig;
57
+ async getConfig(section, scopeUri) {
58
+ if (!this.connection) {
59
+ return this.globalConfig[section];
60
+ }
61
+ if (!this.documentSettings[scopeUri]) {
62
+ this.documentSettings[scopeUri] = {};
63
+ }
64
+ if (!this.documentSettings[scopeUri][section]) {
65
+ this.documentSettings[scopeUri][section] = await this.connection.workspace.getConfiguration({
66
+ scopeUri,
67
+ section,
68
+ });
69
+ }
70
+ return this.documentSettings[scopeUri][section];
74
71
  }
75
- /**
76
- * Whether or not specified setting is enabled
77
- * @param key a string which is a path. Example: 'astro.diagnostics.enabled'.
78
- */
79
- enabled(key) {
80
- return !!this.get(key);
72
+ async getEmmetConfig(document) {
73
+ const emmetConfig = (await this.getConfig('emmet', document.uri)) ?? {};
74
+ return emmetConfig;
75
+ }
76
+ async getAstroFormatConfig(document) {
77
+ const astroFormatConfig = (await this.getConfig('astro.format', document.uri)) ?? {};
78
+ return {
79
+ indentFrontmatter: astroFormatConfig.indentFrontmatter ?? true,
80
+ newLineAfterFrontmatter: astroFormatConfig.newLineAfterFrontmatter ?? true,
81
+ };
82
+ }
83
+ async getTSFormatConfig(document, vscodeOptions) {
84
+ const formatConfig = (await this.getConfig('typescript.format', document.uri)) ?? {};
85
+ return {
86
+ tabSize: vscodeOptions?.tabSize,
87
+ indentSize: vscodeOptions?.tabSize,
88
+ convertTabsToSpaces: vscodeOptions?.insertSpaces,
89
+ // We can use \n here since the editor normalizes later on to its line endings.
90
+ newLineCharacter: '\n',
91
+ insertSpaceAfterCommaDelimiter: formatConfig.insertSpaceAfterCommaDelimiter ?? true,
92
+ insertSpaceAfterConstructor: formatConfig.insertSpaceAfterConstructor ?? false,
93
+ insertSpaceAfterSemicolonInForStatements: formatConfig.insertSpaceAfterSemicolonInForStatements ?? true,
94
+ insertSpaceBeforeAndAfterBinaryOperators: formatConfig.insertSpaceBeforeAndAfterBinaryOperators ?? true,
95
+ insertSpaceAfterKeywordsInControlFlowStatements: formatConfig.insertSpaceAfterKeywordsInControlFlowStatements ?? true,
96
+ insertSpaceAfterFunctionKeywordForAnonymousFunctions: formatConfig.insertSpaceAfterFunctionKeywordForAnonymousFunctions ?? true,
97
+ insertSpaceBeforeFunctionParenthesis: formatConfig.insertSpaceBeforeFunctionParenthesis ?? false,
98
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: formatConfig.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis ?? false,
99
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: formatConfig.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets ?? false,
100
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: formatConfig.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces ?? true,
101
+ insertSpaceAfterOpeningAndBeforeClosingEmptyBraces: formatConfig.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces ?? true,
102
+ insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: formatConfig.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces ?? false,
103
+ insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: formatConfig.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces ?? false,
104
+ insertSpaceAfterTypeAssertion: formatConfig.insertSpaceAfterTypeAssertion ?? false,
105
+ placeOpenBraceOnNewLineForFunctions: formatConfig.placeOpenBraceOnNewLineForFunctions ?? false,
106
+ placeOpenBraceOnNewLineForControlBlocks: formatConfig.placeOpenBraceOnNewLineForControlBlocks ?? false,
107
+ semicolons: formatConfig.semicolons ?? typescript_1.SemicolonPreference.Ignore,
108
+ };
109
+ }
110
+ async getTSPreferences(document) {
111
+ const config = (await this.getConfig('typescript', document.uri)) ?? {};
112
+ const preferences = (await this.getConfig('typescript.preferences', document.uri)) ?? {};
113
+ return {
114
+ quotePreference: getQuoteStylePreference(preferences),
115
+ importModuleSpecifierPreference: getImportModuleSpecifierPreference(preferences),
116
+ importModuleSpecifierEnding: getImportModuleSpecifierEndingPreference(preferences),
117
+ allowTextChangesInNewFiles: document.uri.startsWith('file://'),
118
+ providePrefixAndSuffixTextForRename: (preferences.renameShorthandProperties ?? true) === false ? false : preferences.useAliasesForRenames ?? true,
119
+ includeAutomaticOptionalChainCompletions: config.suggest?.includeAutomaticOptionalChainCompletions ?? true,
120
+ includeCompletionsForImportStatements: config.suggest?.includeCompletionsForImportStatements ?? true,
121
+ includeCompletionsWithSnippetText: config.suggest?.includeCompletionsWithSnippetText ?? true,
122
+ includeCompletionsForModuleExports: config.suggest?.autoImports ?? true,
123
+ allowIncompleteCompletions: true,
124
+ includeCompletionsWithInsertText: true,
125
+ };
126
+ }
127
+ async getTSInlayHintsPreferences(document) {
128
+ const config = (await this.getConfig('typescript', document.uri)) ?? {};
129
+ const tsPreferences = this.getTSPreferences(document);
130
+ return {
131
+ ...tsPreferences,
132
+ includeInlayParameterNameHints: getInlayParameterNameHintsPreference(config),
133
+ includeInlayParameterNameHintsWhenArgumentMatchesName: !(config.inlayHints?.parameterNames?.suppressWhenArgumentMatchesName ?? true),
134
+ includeInlayFunctionParameterTypeHints: config.inlayHints?.parameterTypes?.enabled ?? false,
135
+ includeInlayVariableTypeHints: config.inlayHints?.variableTypes?.enabled ?? false,
136
+ includeInlayPropertyDeclarationTypeHints: config.inlayHints?.propertyDeclarationTypes?.enabled ?? false,
137
+ includeInlayFunctionLikeReturnTypeHints: config.inlayHints?.functionLikeReturnTypes?.enabled ?? false,
138
+ includeInlayEnumMemberValueHints: config.inlayHints?.enumMemberValues?.enabled ?? false,
139
+ };
81
140
  }
82
141
  /**
83
- * Get a specific setting value
84
- * @param key a string which is a path. Example: 'astro.diagnostics.enable'.
142
+ * Return true if a plugin and an optional feature is enabled
85
143
  */
86
- get(key) {
87
- return (0, lodash_1.get)(this.config, key);
144
+ async isEnabled(document, plugin, feature) {
145
+ const config = await this.getConfig('astro', document.uri);
146
+ return feature ? config[plugin].enabled && config[plugin][feature].enabled : config[plugin].enabled;
88
147
  }
89
148
  /**
90
- * Get the entire user configuration
149
+ * Updating the global config should only be done in cases where the client doesn't support `workspace/configuration`
150
+ * or inside of tests.
151
+ *
152
+ * The `outsideAstro` parameter can be set to true to change configurations in the global scope.
153
+ * For example, to change TypeScript settings
91
154
  */
92
- getFullConfig() {
93
- return this.config;
155
+ updateGlobalConfig(config, outsideAstro) {
156
+ if (outsideAstro) {
157
+ this.globalConfig = (0, lodash_1.merge)({}, this.globalConfig, config);
158
+ }
159
+ else {
160
+ this.globalConfig.astro = (0, lodash_1.merge)({}, exports.defaultLSConfig, this.globalConfig.astro, config);
161
+ }
94
162
  }
95
163
  }
96
164
  exports.ConfigManager = ConfigManager;
165
+ function getQuoteStylePreference(config) {
166
+ switch (config.quoteStyle) {
167
+ case 'single':
168
+ return 'single';
169
+ case 'double':
170
+ return 'double';
171
+ default:
172
+ return 'auto';
173
+ }
174
+ }
175
+ function getImportModuleSpecifierPreference(config) {
176
+ switch (config.importModuleSpecifier) {
177
+ case 'project-relative':
178
+ return 'project-relative';
179
+ case 'relative':
180
+ return 'relative';
181
+ case 'non-relative':
182
+ return 'non-relative';
183
+ default:
184
+ return undefined;
185
+ }
186
+ }
187
+ function getImportModuleSpecifierEndingPreference(config) {
188
+ switch (config.importModuleSpecifierEnding) {
189
+ case 'minimal':
190
+ return 'minimal';
191
+ case 'index':
192
+ return 'index';
193
+ case 'js':
194
+ return 'js';
195
+ default:
196
+ return 'auto';
197
+ }
198
+ }
199
+ function getInlayParameterNameHintsPreference(config) {
200
+ switch (config.inlayHints?.parameterNames?.enabled) {
201
+ case 'none':
202
+ return 'none';
203
+ case 'literals':
204
+ return 'literals';
205
+ case 'all':
206
+ return 'all';
207
+ default:
208
+ return undefined;
209
+ }
210
+ }
@@ -3,34 +3,14 @@
3
3
  * Make sure that this is kept in sync with the `package.json` of the VS Code extension
4
4
  */
5
5
  export interface LSConfig {
6
- astro: LSAstroConfig;
7
6
  typescript: LSTypescriptConfig;
8
7
  html: LSHTMLConfig;
9
8
  css: LSCSSConfig;
9
+ format: LSFormatConfig;
10
10
  }
11
- export interface LSAstroConfig {
12
- enabled: boolean;
13
- diagnostics: {
14
- enabled: boolean;
15
- };
16
- format: {
17
- enabled: boolean;
18
- };
19
- rename: {
20
- enabled: boolean;
21
- };
22
- completions: {
23
- enabled: boolean;
24
- };
25
- hover: {
26
- enabled: boolean;
27
- };
28
- codeActions: {
29
- enabled: boolean;
30
- };
31
- selectionRange: {
32
- enabled: boolean;
33
- };
11
+ export interface LSFormatConfig {
12
+ indentFrontmatter: boolean;
13
+ newLineAfterFrontmatter: boolean;
34
14
  }
35
15
  export interface LSTypescriptConfig {
36
16
  enabled: boolean;
@@ -46,9 +26,6 @@ export interface LSTypescriptConfig {
46
26
  completions: {
47
27
  enabled: boolean;
48
28
  };
49
- findReferences: {
50
- enabled: boolean;
51
- };
52
29
  definitions: {
53
30
  enabled: boolean;
54
31
  };
@@ -58,21 +35,12 @@ export interface LSTypescriptConfig {
58
35
  rename: {
59
36
  enabled: boolean;
60
37
  };
61
- selectionRange: {
62
- enabled: boolean;
63
- };
64
38
  signatureHelp: {
65
39
  enabled: boolean;
66
40
  };
67
41
  semanticTokens: {
68
42
  enabled: boolean;
69
43
  };
70
- implementation: {
71
- enabled: boolean;
72
- };
73
- typeDefinition: {
74
- enabled: boolean;
75
- };
76
44
  }
77
45
  export interface LSHTMLConfig {
78
46
  enabled: boolean;
@@ -89,18 +57,9 @@ export interface LSHTMLConfig {
89
57
  documentSymbols: {
90
58
  enabled: boolean;
91
59
  };
92
- renameTags: {
93
- enabled: boolean;
94
- };
95
- linkedEditing: {
96
- enabled: boolean;
97
- };
98
60
  }
99
61
  export interface LSCSSConfig {
100
62
  enabled: boolean;
101
- diagnostics: {
102
- enabled: boolean;
103
- };
104
63
  hover: {
105
64
  enabled: boolean;
106
65
  };
@@ -111,13 +70,7 @@ export interface LSCSSConfig {
111
70
  documentColors: {
112
71
  enabled: boolean;
113
72
  };
114
- colorPresentations: {
115
- enabled: boolean;
116
- };
117
73
  documentSymbols: {
118
74
  enabled: boolean;
119
75
  };
120
- selectionRange: {
121
- enabled: boolean;
122
- };
123
76
  }
@@ -9,6 +9,7 @@ export declare class AstroDocument extends WritableDocument {
9
9
  astroMeta: AstroMetadata;
10
10
  html: HTMLDocument;
11
11
  styleTags: TagInformation[];
12
+ scriptTags: TagInformation[];
12
13
  constructor(url: string, content: string);
13
14
  private updateDocInfo;
14
15
  setText(text: string): void;
@@ -18,6 +18,7 @@ class AstroDocument extends DocumentBase_1.WritableDocument {
18
18
  this.astroMeta = (0, parseAstro_1.parseAstro)(this.content);
19
19
  this.html = (0, parseHtml_1.parseHtml)(this.content);
20
20
  this.styleTags = (0, utils_2.extractStyleTags)(this.content, this.html);
21
+ this.scriptTags = (0, utils_2.extractScriptTags)(this.content, this.html);
21
22
  }
22
23
  setText(text) {
23
24
  this.content = text;
@@ -46,6 +46,8 @@ export declare class FragmentMapper implements DocumentMapper {
46
46
  private originalText;
47
47
  private tagInfo;
48
48
  private url;
49
+ private lineOffsetsOriginal;
50
+ private lineOffsetsGenerated;
49
51
  constructor(originalText: string, tagInfo: TagInformation, url: string);
50
52
  getOriginalPosition(generatedPosition: Position): Position;
51
53
  private offsetInParent;
@@ -45,20 +45,22 @@ class FragmentMapper {
45
45
  this.originalText = originalText;
46
46
  this.tagInfo = tagInfo;
47
47
  this.url = url;
48
+ this.lineOffsetsOriginal = (0, utils_1.getLineOffsets)(this.originalText);
49
+ this.lineOffsetsGenerated = (0, utils_1.getLineOffsets)(this.tagInfo.content);
48
50
  }
49
51
  getOriginalPosition(generatedPosition) {
50
- const parentOffset = this.offsetInParent((0, utils_1.offsetAt)(generatedPosition, this.tagInfo.content));
51
- return (0, utils_1.positionAt)(parentOffset, this.originalText);
52
+ const parentOffset = this.offsetInParent((0, utils_1.offsetAt)(generatedPosition, this.tagInfo.content, this.lineOffsetsGenerated));
53
+ return (0, utils_1.positionAt)(parentOffset, this.originalText, this.lineOffsetsOriginal);
52
54
  }
53
55
  offsetInParent(offset) {
54
56
  return this.tagInfo.start + offset;
55
57
  }
56
58
  getGeneratedPosition(originalPosition) {
57
- const fragmentOffset = (0, utils_1.offsetAt)(originalPosition, this.originalText) - this.tagInfo.start;
58
- return (0, utils_1.positionAt)(fragmentOffset, this.tagInfo.content);
59
+ const fragmentOffset = (0, utils_1.offsetAt)(originalPosition, this.originalText, this.lineOffsetsOriginal) - this.tagInfo.start;
60
+ return (0, utils_1.positionAt)(fragmentOffset, this.tagInfo.content, this.lineOffsetsGenerated);
59
61
  }
60
62
  isInGenerated(pos) {
61
- const offset = (0, utils_1.offsetAt)(pos, this.originalText);
63
+ const offset = (0, utils_1.offsetAt)(pos, this.originalText, this.lineOffsetsOriginal);
62
64
  return offset >= this.tagInfo.start && offset <= this.tagInfo.end;
63
65
  }
64
66
  getURL() {
@@ -15,6 +15,7 @@ export interface TagInformation {
15
15
  }
16
16
  export declare function walk(node: Node): Generator<Node, void, unknown>;
17
17
  export declare function extractStyleTags(source: string, html?: HTMLDocument): TagInformation[];
18
+ export declare function extractScriptTags(source: string, html?: HTMLDocument): TagInformation[];
18
19
  export declare function getLineAtPosition(position: Position, text: string): string;
19
20
  /**
20
21
  * Returns the node if offset is inside a HTML start tag
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFirstNonWhitespaceIndex = exports.getLineOffsets = exports.offsetAt = exports.positionAt = exports.isInsideFrontmatter = exports.isInsideExpression = exports.isInTag = exports.isInComponentStartTag = exports.isComponentTag = exports.getNodeIfIsInHTMLStartTag = exports.getLineAtPosition = exports.extractStyleTags = exports.walk = void 0;
3
+ exports.getFirstNonWhitespaceIndex = exports.getLineOffsets = exports.offsetAt = exports.positionAt = exports.isInsideFrontmatter = exports.isInsideExpression = exports.isInTag = exports.isInComponentStartTag = exports.isComponentTag = exports.getNodeIfIsInHTMLStartTag = exports.getLineAtPosition = exports.extractScriptTags = exports.extractStyleTags = exports.walk = void 0;
4
4
  const vscode_languageserver_1 = require("vscode-languageserver");
5
5
  const utils_1 = require("../../utils");
6
6
  const parseHtml_1 = require("./parseHtml");
@@ -28,6 +28,13 @@ function extractTags(text, tag, html) {
28
28
  }
29
29
  }
30
30
  }
31
+ if (tag === 'script' && !matchedNodes.length && rootNodes.length) {
32
+ for (let child of walk(rootNodes[0])) {
33
+ if (child.tag === 'script') {
34
+ matchedNodes.push(child);
35
+ }
36
+ }
37
+ }
31
38
  return matchedNodes.map(transformToTagInfo);
32
39
  function transformToTagInfo(matchedNode) {
33
40
  const start = matchedNode.startTagEnd ?? matchedNode.start;
@@ -60,6 +67,14 @@ function extractStyleTags(source, html) {
60
67
  return styles;
61
68
  }
62
69
  exports.extractStyleTags = extractStyleTags;
70
+ function extractScriptTags(source, html) {
71
+ const scripts = extractTags(source, 'script', html);
72
+ if (!scripts.length) {
73
+ return [];
74
+ }
75
+ return scripts;
76
+ }
77
+ exports.extractScriptTags = extractScriptTags;
63
78
  function parseAttributes(rawAttrs) {
64
79
  const attrs = {};
65
80
  if (!rawAttrs) {
@@ -1,4 +1,4 @@
1
- import { CancellationToken, Color, ColorInformation, ColorPresentation, CompletionContext, CompletionItem, CompletionList, DefinitionLink, Diagnostic, FoldingRange, Hover, Position, Range, Location, SignatureHelp, SignatureHelpContext, TextDocumentContentChangeEvent, TextDocumentIdentifier, WorkspaceEdit, SymbolInformation, SemanticTokens, CodeActionContext, CodeAction } from 'vscode-languageserver';
1
+ import { CancellationToken, Color, ColorInformation, ColorPresentation, CompletionContext, CompletionItem, CompletionList, DefinitionLink, Diagnostic, FoldingRange, Hover, Position, Range, Location, SignatureHelp, SignatureHelpContext, TextDocumentContentChangeEvent, TextDocumentIdentifier, WorkspaceEdit, SymbolInformation, SemanticTokens, CodeActionContext, CodeAction, InlayHint, FormattingOptions, TextEdit } from 'vscode-languageserver';
2
2
  import type { AppCompletionItem, Plugin } from './interfaces';
3
3
  import { DocumentManager } from '../core/documents/DocumentManager';
4
4
  interface PluginHostConfig {
@@ -16,6 +16,7 @@ export declare class PluginHost {
16
16
  resolveCompletion(textDocument: TextDocumentIdentifier, completionItem: AppCompletionItem): Promise<CompletionItem>;
17
17
  getDiagnostics(textDocument: TextDocumentIdentifier): Promise<Diagnostic[]>;
18
18
  doHover(textDocument: TextDocumentIdentifier, position: Position): Promise<Hover | null>;
19
+ formatDocument(textDocument: TextDocumentIdentifier, options: FormattingOptions): Promise<TextEdit[]>;
19
20
  getCodeActions(textDocument: TextDocumentIdentifier, range: Range, context: CodeActionContext, cancellationToken: CancellationToken): Promise<CodeAction[]>;
20
21
  doTagComplete(textDocument: TextDocumentIdentifier, position: Position): Promise<string | null>;
21
22
  getFoldingRanges(textDocument: TextDocumentIdentifier): Promise<FoldingRange[] | null>;
@@ -24,6 +25,7 @@ export declare class PluginHost {
24
25
  getDefinitions(textDocument: TextDocumentIdentifier, position: Position): Promise<DefinitionLink[] | Location[]>;
25
26
  rename(textDocument: TextDocumentIdentifier, position: Position, newName: string): Promise<WorkspaceEdit | null>;
26
27
  getDocumentColors(textDocument: TextDocumentIdentifier): Promise<ColorInformation[]>;
28
+ getInlayHints(textDocument: TextDocumentIdentifier, range: Range, cancellationToken: CancellationToken): Promise<InlayHint[]>;
27
29
  getColorPresentations(textDocument: TextDocumentIdentifier, range: Range, color: Color): Promise<ColorPresentation[]>;
28
30
  getSignatureHelp(textDocument: TextDocumentIdentifier, position: Position, context: SignatureHelpContext | undefined, cancellationToken: CancellationToken): Promise<SignatureHelp | null>;
29
31
  onWatchFileChanges(onWatchFileChangesParams: any[]): void;
@@ -69,6 +69,10 @@ class PluginHost {
69
69
  const document = this.getDocument(textDocument.uri);
70
70
  return this.execute('doHover', [document, position], ExecuteMode.FirstNonNull);
71
71
  }
72
+ async formatDocument(textDocument, options) {
73
+ const document = this.getDocument(textDocument.uri);
74
+ return (0, lodash_1.flatten)(await this.execute('formatDocument', [document, options], ExecuteMode.Collect));
75
+ }
72
76
  async getCodeActions(textDocument, range, context, cancellationToken) {
73
77
  const document = this.getDocument(textDocument.uri);
74
78
  return (0, lodash_1.flatten)(await this.execute('getCodeActions', [document, range, context, cancellationToken], ExecuteMode.Collect));
@@ -108,6 +112,10 @@ class PluginHost {
108
112
  const document = this.getDocument(textDocument.uri);
109
113
  return (0, lodash_1.flatten)(await this.execute('getDocumentColors', [document], ExecuteMode.Collect));
110
114
  }
115
+ async getInlayHints(textDocument, range, cancellationToken) {
116
+ const document = this.getDocument(textDocument.uri);
117
+ return (0, lodash_1.flatten)(await this.execute('getInlayHints', [document, range], ExecuteMode.FirstNonNull));
118
+ }
111
119
  async getColorPresentations(textDocument, range, color) {
112
120
  const document = this.getDocument(textDocument.uri);
113
121
  return (0, lodash_1.flatten)(await this.execute('getColorPresentations', [document, range, color], ExecuteMode.Collect));
@@ -1,4 +1,4 @@
1
- import { CompletionContext, DefinitionLink, FoldingRange, Position } from 'vscode-languageserver';
1
+ import { CompletionContext, FoldingRange, Position } from 'vscode-languageserver';
2
2
  import { ConfigManager } from '../../core/config';
3
3
  import { AstroDocument, DocumentManager } from '../../core/documents';
4
4
  import { AppCompletionList, Plugin } from '../interfaces';
@@ -10,9 +10,4 @@ export declare class AstroPlugin implements Plugin {
10
10
  constructor(docManager: DocumentManager, configManager: ConfigManager, workspaceUris: string[]);
11
11
  getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList | null>;
12
12
  getFoldingRanges(document: AstroDocument): FoldingRange[];
13
- getDefinitions(document: AstroDocument, position: Position): Promise<DefinitionLink[]>;
14
- private isInsideFrontmatter;
15
- private isComponentTag;
16
- private getDefinitionsForComponentName;
17
- private getImportSpecifierForIdentifier;
18
13
  }