@astrojs/language-server 0.15.0 → 0.17.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/CHANGELOG.md +32 -0
- package/dist/check.js +1 -2
- package/dist/core/config/ConfigManager.d.ts +20 -16
- package/dist/core/config/ConfigManager.js +112 -46
- package/dist/core/config/interfaces.d.ts +0 -52
- package/dist/core/documents/AstroDocument.d.ts +1 -0
- package/dist/core/documents/AstroDocument.js +1 -0
- package/dist/core/documents/DocumentMapper.d.ts +2 -0
- package/dist/core/documents/DocumentMapper.js +9 -9
- package/dist/core/documents/parseAstro.js +1 -1
- package/dist/core/documents/utils.d.ts +1 -0
- package/dist/core/documents/utils.js +19 -5
- package/dist/plugins/PluginHost.d.ts +2 -1
- package/dist/plugins/PluginHost.js +8 -6
- package/dist/plugins/astro/AstroPlugin.d.ts +1 -6
- package/dist/plugins/astro/AstroPlugin.js +1 -83
- package/dist/plugins/astro/features/CompletionsProvider.d.ts +4 -5
- package/dist/plugins/astro/features/CompletionsProvider.js +49 -59
- package/dist/plugins/css/CSSPlugin.d.ts +5 -5
- package/dist/plugins/css/CSSPlugin.js +41 -20
- package/dist/plugins/html/HTMLPlugin.d.ts +4 -4
- package/dist/plugins/html/HTMLPlugin.js +20 -16
- package/dist/plugins/html/features/astro-attributes.js +44 -27
- package/dist/plugins/typescript/LanguageServiceManager.js +1 -1
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +5 -4
- package/dist/plugins/typescript/TypeScriptPlugin.js +30 -108
- package/dist/plugins/typescript/astro-sys.js +3 -5
- package/dist/plugins/typescript/astro2tsx.js +1 -2
- package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +16 -0
- package/dist/plugins/typescript/features/CodeActionsProvider.js +206 -0
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +5 -2
- package/dist/plugins/typescript/features/CompletionsProvider.js +116 -68
- package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +9 -0
- package/dist/plugins/typescript/features/DefinitionsProvider.js +57 -0
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +60 -18
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +3 -4
- package/dist/plugins/typescript/features/FoldingRangesProvider.js +13 -6
- package/dist/plugins/typescript/features/HoverProvider.js +14 -1
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +1 -1
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +11 -3
- package/dist/plugins/typescript/features/utils.d.ts +2 -0
- package/dist/plugins/typescript/features/utils.js +19 -3
- package/dist/plugins/typescript/language-service.js +23 -6
- package/dist/plugins/typescript/module-loader.js +1 -1
- package/dist/plugins/typescript/previewer.js +1 -1
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +22 -2
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +48 -1
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +2 -1
- package/dist/plugins/typescript/snapshots/utils.js +3 -6
- package/dist/plugins/typescript/utils.d.ts +12 -1
- package/dist/plugins/typescript/utils.js +29 -1
- package/dist/server.js +43 -14
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +16 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @astrojs/language-server
|
|
2
2
|
|
|
3
|
+
## 0.17.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3ad0f65: Add support for TypeScript features inside script tags (completions, diagnostics, hover etc)
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 2e9da14: Add support for loading props completions from .d.ts files, improve performance of props completions
|
|
12
|
+
|
|
13
|
+
## 0.16.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- ad5a5e5: Fix misc issues with Go To Definition
|
|
18
|
+
- 1bd790d: Updates config management, make sure to respect TypeScript settings when doing completions and quickfixes
|
|
19
|
+
|
|
20
|
+
## 0.16.0
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- 9abff62: Add support for code actions
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- b485acd: Fixed bug where nonexistent server settings would result in a crash
|
|
29
|
+
- 1cff04c: Fix Emmet settings not being loaded, add support for Emmet in CSS
|
|
30
|
+
- 1bcae45: Remove support for Node 12 (VS Code versions under 1.56)
|
|
31
|
+
- c8d81a1: Update directives tooltips, add missing `is:raw`
|
|
32
|
+
- Updated dependencies [1bcae45]
|
|
33
|
+
- @astrojs/svelte-language-integration@0.1.4
|
|
34
|
+
|
|
3
35
|
## 0.15.0
|
|
4
36
|
|
|
5
37
|
### Minor Changes
|
package/dist/check.js
CHANGED
|
@@ -37,11 +37,10 @@ class AstroCheck {
|
|
|
37
37
|
this.pluginHost.registerPlugin(new plugins_1.TypeScriptPlugin(this.docManager, this.configManager, [workspacePath]));
|
|
38
38
|
}
|
|
39
39
|
async getDiagnosticsForFile(uri) {
|
|
40
|
-
var _a;
|
|
41
40
|
const diagnostics = await this.pluginHost.getDiagnostics({ uri });
|
|
42
41
|
return {
|
|
43
42
|
filePath: new URL(uri).pathname || '',
|
|
44
|
-
text:
|
|
43
|
+
text: this.docManager.get(uri)?.getText() || '',
|
|
45
44
|
diagnostics,
|
|
46
45
|
};
|
|
47
46
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { VSCodeEmmetConfig } from '@vscode/emmet-helper';
|
|
2
|
-
import { LSConfig } from './interfaces';
|
|
2
|
+
import { LSConfig, LSCSSConfig, LSHTMLConfig, LSTypescriptConfig } from './interfaces';
|
|
3
|
+
import { Connection } from 'vscode-languageserver';
|
|
4
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
5
|
+
import { FormatCodeSettings, 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,25 @@ 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
|
|
13
|
-
private
|
|
16
|
+
private globalConfig;
|
|
17
|
+
private documentSettings;
|
|
14
18
|
private isTrusted;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
getTSFormatConfig(document: TextDocument): Promise<FormatCodeSettings>;
|
|
26
|
+
getTSPreferences(document: TextDocument): Promise<UserPreferences>;
|
|
18
27
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @param key a string which is a path. Example: 'astro.diagnostics.enabled'.
|
|
28
|
+
* Return true if a plugin and an optional feature is enabled
|
|
21
29
|
*/
|
|
22
|
-
|
|
30
|
+
isEnabled(document: TextDocument, plugin: keyof LSConfig, feature?: keyof LSTypescriptConfig | keyof LSCSSConfig | keyof LSHTMLConfig): Promise<boolean>;
|
|
23
31
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
32
|
+
* Updating the global config should only be done in cases where the client doesn't support `workspace/configuration`
|
|
33
|
+
* or inside of tests
|
|
26
34
|
*/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Get the entire user configuration
|
|
30
|
-
*/
|
|
31
|
-
getFullConfig(): Readonly<LSConfig>;
|
|
35
|
+
updateGlobalConfig(config: DeepPartial<LSConfig>): void;
|
|
32
36
|
}
|
|
33
37
|
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
|
|
6
|
-
|
|
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,6 @@ 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 },
|
|
50
32
|
},
|
|
51
33
|
};
|
|
52
34
|
/**
|
|
@@ -55,42 +37,126 @@ const defaultLSConfig = {
|
|
|
55
37
|
* For more info on this, see the [internal docs](../../../../../docs/internal/language-server/config.md)
|
|
56
38
|
*/
|
|
57
39
|
class ConfigManager {
|
|
58
|
-
constructor() {
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
40
|
+
constructor(connection) {
|
|
41
|
+
this.globalConfig = { astro: exports.defaultLSConfig };
|
|
42
|
+
this.documentSettings = {};
|
|
61
43
|
this.isTrusted = true;
|
|
44
|
+
this.connection = connection;
|
|
62
45
|
}
|
|
63
|
-
updateConfig(
|
|
64
|
-
//
|
|
65
|
-
|
|
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);
|
|
46
|
+
updateConfig() {
|
|
47
|
+
// Reset all cached document settings
|
|
48
|
+
this.documentSettings = {};
|
|
68
49
|
}
|
|
69
|
-
|
|
70
|
-
this.
|
|
50
|
+
removeDocument(scopeUri) {
|
|
51
|
+
delete this.documentSettings[scopeUri];
|
|
71
52
|
}
|
|
72
|
-
|
|
73
|
-
|
|
53
|
+
async getConfig(section, scopeUri) {
|
|
54
|
+
if (!this.connection) {
|
|
55
|
+
return this.globalConfig[section];
|
|
56
|
+
}
|
|
57
|
+
if (!this.documentSettings[scopeUri]) {
|
|
58
|
+
this.documentSettings[scopeUri] = {};
|
|
59
|
+
}
|
|
60
|
+
if (!this.documentSettings[scopeUri][section]) {
|
|
61
|
+
this.documentSettings[scopeUri][section] = await this.connection.workspace.getConfiguration({
|
|
62
|
+
scopeUri,
|
|
63
|
+
section,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return this.documentSettings[scopeUri][section];
|
|
74
67
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
async getEmmetConfig(document) {
|
|
69
|
+
const emmetConfig = (await this.getConfig('emmet', document.uri)) ?? {};
|
|
70
|
+
return emmetConfig;
|
|
71
|
+
}
|
|
72
|
+
async getTSFormatConfig(document) {
|
|
73
|
+
const formatConfig = (await this.getConfig('typescript.format', document.uri)) ?? {};
|
|
74
|
+
return {
|
|
75
|
+
// We can use \n here since the editor normalizes later on to its line endings.
|
|
76
|
+
newLineCharacter: '\n',
|
|
77
|
+
insertSpaceAfterCommaDelimiter: formatConfig.insertSpaceAfterCommaDelimiter ?? true,
|
|
78
|
+
insertSpaceAfterConstructor: formatConfig.insertSpaceAfterConstructor ?? false,
|
|
79
|
+
insertSpaceAfterSemicolonInForStatements: formatConfig.insertSpaceAfterSemicolonInForStatements ?? true,
|
|
80
|
+
insertSpaceBeforeAndAfterBinaryOperators: formatConfig.insertSpaceBeforeAndAfterBinaryOperators ?? true,
|
|
81
|
+
insertSpaceAfterKeywordsInControlFlowStatements: formatConfig.insertSpaceAfterKeywordsInControlFlowStatements ?? true,
|
|
82
|
+
insertSpaceAfterFunctionKeywordForAnonymousFunctions: formatConfig.insertSpaceAfterFunctionKeywordForAnonymousFunctions ?? true,
|
|
83
|
+
insertSpaceBeforeFunctionParenthesis: formatConfig.insertSpaceBeforeFunctionParenthesis ?? false,
|
|
84
|
+
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: formatConfig.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis ?? false,
|
|
85
|
+
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: formatConfig.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets ?? false,
|
|
86
|
+
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: formatConfig.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces ?? true,
|
|
87
|
+
insertSpaceAfterOpeningAndBeforeClosingEmptyBraces: formatConfig.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces ?? true,
|
|
88
|
+
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: formatConfig.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces ?? false,
|
|
89
|
+
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: formatConfig.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces ?? false,
|
|
90
|
+
insertSpaceAfterTypeAssertion: formatConfig.insertSpaceAfterTypeAssertion ?? false,
|
|
91
|
+
placeOpenBraceOnNewLineForFunctions: formatConfig.placeOpenBraceOnNewLineForFunctions ?? false,
|
|
92
|
+
placeOpenBraceOnNewLineForControlBlocks: formatConfig.placeOpenBraceOnNewLineForControlBlocks ?? false,
|
|
93
|
+
semicolons: formatConfig.semicolons ?? typescript_1.SemicolonPreference.Ignore,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async getTSPreferences(document) {
|
|
97
|
+
const config = (await this.getConfig('typescript', document.uri)) ?? {};
|
|
98
|
+
const preferences = (await this.getConfig('typescript.preferences', document.uri)) ?? {};
|
|
99
|
+
return {
|
|
100
|
+
quotePreference: getQuoteStylePreference(preferences),
|
|
101
|
+
importModuleSpecifierPreference: getImportModuleSpecifierPreference(preferences),
|
|
102
|
+
importModuleSpecifierEnding: getImportModuleSpecifierEndingPreference(preferences),
|
|
103
|
+
allowTextChangesInNewFiles: document.uri.startsWith('file://'),
|
|
104
|
+
providePrefixAndSuffixTextForRename: (preferences.renameShorthandProperties ?? true) === false ? false : preferences.useAliasesForRenames ?? true,
|
|
105
|
+
includeAutomaticOptionalChainCompletions: config.suggest?.includeAutomaticOptionalChainCompletions ?? true,
|
|
106
|
+
includeCompletionsForImportStatements: config.suggest?.includeCompletionsForImportStatements ?? true,
|
|
107
|
+
includeCompletionsWithSnippetText: config.suggest?.includeCompletionsWithSnippetText ?? true,
|
|
108
|
+
includeCompletionsForModuleExports: config.suggest?.autoImports ?? true,
|
|
109
|
+
allowIncompleteCompletions: true,
|
|
110
|
+
includeCompletionsWithInsertText: true,
|
|
111
|
+
};
|
|
81
112
|
}
|
|
82
113
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @param key a string which is a path. Example: 'astro.diagnostics.enable'.
|
|
114
|
+
* Return true if a plugin and an optional feature is enabled
|
|
85
115
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
116
|
+
async isEnabled(document, plugin, feature) {
|
|
117
|
+
const config = await this.getConfig('astro', document.uri);
|
|
118
|
+
return feature ? config[plugin].enabled && config[plugin][feature].enabled : config[plugin].enabled;
|
|
88
119
|
}
|
|
89
120
|
/**
|
|
90
|
-
*
|
|
121
|
+
* Updating the global config should only be done in cases where the client doesn't support `workspace/configuration`
|
|
122
|
+
* or inside of tests
|
|
91
123
|
*/
|
|
92
|
-
|
|
93
|
-
|
|
124
|
+
updateGlobalConfig(config) {
|
|
125
|
+
this.globalConfig.astro = (0, lodash_1.merge)({}, exports.defaultLSConfig, this.globalConfig.astro, config);
|
|
94
126
|
}
|
|
95
127
|
}
|
|
96
128
|
exports.ConfigManager = ConfigManager;
|
|
129
|
+
function getQuoteStylePreference(config) {
|
|
130
|
+
switch (config.quoteStyle) {
|
|
131
|
+
case 'single':
|
|
132
|
+
return 'single';
|
|
133
|
+
case 'double':
|
|
134
|
+
return 'double';
|
|
135
|
+
default:
|
|
136
|
+
return 'auto';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function getImportModuleSpecifierPreference(config) {
|
|
140
|
+
switch (config.importModuleSpecifier) {
|
|
141
|
+
case 'project-relative':
|
|
142
|
+
return 'project-relative';
|
|
143
|
+
case 'relative':
|
|
144
|
+
return 'relative';
|
|
145
|
+
case 'non-relative':
|
|
146
|
+
return 'non-relative';
|
|
147
|
+
default:
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function getImportModuleSpecifierEndingPreference(config) {
|
|
152
|
+
switch (config.importModuleSpecifierEnding) {
|
|
153
|
+
case 'minimal':
|
|
154
|
+
return 'minimal';
|
|
155
|
+
case 'index':
|
|
156
|
+
return 'index';
|
|
157
|
+
case 'js':
|
|
158
|
+
return 'js';
|
|
159
|
+
default:
|
|
160
|
+
return 'auto';
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -3,35 +3,10 @@
|
|
|
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;
|
|
10
9
|
}
|
|
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
|
-
};
|
|
34
|
-
}
|
|
35
10
|
export interface LSTypescriptConfig {
|
|
36
11
|
enabled: boolean;
|
|
37
12
|
diagnostics: {
|
|
@@ -46,9 +21,6 @@ export interface LSTypescriptConfig {
|
|
|
46
21
|
completions: {
|
|
47
22
|
enabled: boolean;
|
|
48
23
|
};
|
|
49
|
-
findReferences: {
|
|
50
|
-
enabled: boolean;
|
|
51
|
-
};
|
|
52
24
|
definitions: {
|
|
53
25
|
enabled: boolean;
|
|
54
26
|
};
|
|
@@ -58,21 +30,12 @@ export interface LSTypescriptConfig {
|
|
|
58
30
|
rename: {
|
|
59
31
|
enabled: boolean;
|
|
60
32
|
};
|
|
61
|
-
selectionRange: {
|
|
62
|
-
enabled: boolean;
|
|
63
|
-
};
|
|
64
33
|
signatureHelp: {
|
|
65
34
|
enabled: boolean;
|
|
66
35
|
};
|
|
67
36
|
semanticTokens: {
|
|
68
37
|
enabled: boolean;
|
|
69
38
|
};
|
|
70
|
-
implementation: {
|
|
71
|
-
enabled: boolean;
|
|
72
|
-
};
|
|
73
|
-
typeDefinition: {
|
|
74
|
-
enabled: boolean;
|
|
75
|
-
};
|
|
76
39
|
}
|
|
77
40
|
export interface LSHTMLConfig {
|
|
78
41
|
enabled: boolean;
|
|
@@ -89,18 +52,9 @@ export interface LSHTMLConfig {
|
|
|
89
52
|
documentSymbols: {
|
|
90
53
|
enabled: boolean;
|
|
91
54
|
};
|
|
92
|
-
renameTags: {
|
|
93
|
-
enabled: boolean;
|
|
94
|
-
};
|
|
95
|
-
linkedEditing: {
|
|
96
|
-
enabled: boolean;
|
|
97
|
-
};
|
|
98
55
|
}
|
|
99
56
|
export interface LSCSSConfig {
|
|
100
57
|
enabled: boolean;
|
|
101
|
-
diagnostics: {
|
|
102
|
-
enabled: boolean;
|
|
103
|
-
};
|
|
104
58
|
hover: {
|
|
105
59
|
enabled: boolean;
|
|
106
60
|
};
|
|
@@ -111,13 +65,7 @@ export interface LSCSSConfig {
|
|
|
111
65
|
documentColors: {
|
|
112
66
|
enabled: boolean;
|
|
113
67
|
};
|
|
114
|
-
colorPresentations: {
|
|
115
|
-
enabled: boolean;
|
|
116
|
-
};
|
|
117
68
|
documentSymbols: {
|
|
118
69
|
enabled: boolean;
|
|
119
70
|
};
|
|
120
|
-
selectionRange: {
|
|
121
|
-
enabled: boolean;
|
|
122
|
-
};
|
|
123
71
|
}
|
|
@@ -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;
|
|
@@ -33,8 +33,7 @@ class IdentityMapper {
|
|
|
33
33
|
return this.url;
|
|
34
34
|
}
|
|
35
35
|
destroy() {
|
|
36
|
-
|
|
37
|
-
(_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
36
|
+
this.parent?.destroy?.();
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
exports.IdentityMapper = IdentityMapper;
|
|
@@ -46,20 +45,22 @@ class FragmentMapper {
|
|
|
46
45
|
this.originalText = originalText;
|
|
47
46
|
this.tagInfo = tagInfo;
|
|
48
47
|
this.url = url;
|
|
48
|
+
this.lineOffsetsOriginal = (0, utils_1.getLineOffsets)(this.originalText);
|
|
49
|
+
this.lineOffsetsGenerated = (0, utils_1.getLineOffsets)(this.tagInfo.content);
|
|
49
50
|
}
|
|
50
51
|
getOriginalPosition(generatedPosition) {
|
|
51
|
-
const parentOffset = this.offsetInParent((0, utils_1.offsetAt)(generatedPosition, this.tagInfo.content));
|
|
52
|
-
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);
|
|
53
54
|
}
|
|
54
55
|
offsetInParent(offset) {
|
|
55
56
|
return this.tagInfo.start + offset;
|
|
56
57
|
}
|
|
57
58
|
getGeneratedPosition(originalPosition) {
|
|
58
|
-
const fragmentOffset = (0, utils_1.offsetAt)(originalPosition, this.originalText) - this.tagInfo.start;
|
|
59
|
-
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);
|
|
60
61
|
}
|
|
61
62
|
isInGenerated(pos) {
|
|
62
|
-
const offset = (0, utils_1.offsetAt)(pos, this.originalText);
|
|
63
|
+
const offset = (0, utils_1.offsetAt)(pos, this.originalText, this.lineOffsetsOriginal);
|
|
63
64
|
return offset >= this.tagInfo.start && offset <= this.tagInfo.end;
|
|
64
65
|
}
|
|
65
66
|
getURL() {
|
|
@@ -130,8 +131,7 @@ class SourceMapDocumentMapper {
|
|
|
130
131
|
* Needs to be called when source mapper is no longer needed in order to prevent memory leaks.
|
|
131
132
|
*/
|
|
132
133
|
destroy() {
|
|
133
|
-
|
|
134
|
-
(_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
134
|
+
this.parent?.destroy?.();
|
|
135
135
|
this.consumer.destroy();
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -55,7 +55,7 @@ function getContent(content, frontmatter) {
|
|
|
55
55
|
}
|
|
56
56
|
case 'closed': {
|
|
57
57
|
const { endOffset } = frontmatter;
|
|
58
|
-
const end = (endOffset
|
|
58
|
+
const end = (endOffset ?? 0) + 3;
|
|
59
59
|
const offset = (0, utils_1.getFirstNonWhitespaceIndex)(content.slice(end));
|
|
60
60
|
return { firstNonWhitespaceOffset: end + offset };
|
|
61
61
|
}
|
|
@@ -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");
|
|
@@ -19,7 +19,7 @@ exports.walk = walk;
|
|
|
19
19
|
* @param tag the tag to extract
|
|
20
20
|
*/
|
|
21
21
|
function extractTags(text, tag, html) {
|
|
22
|
-
const rootNodes =
|
|
22
|
+
const rootNodes = html?.roots || (0, parseHtml_1.parseHtml)(text).roots;
|
|
23
23
|
const matchedNodes = rootNodes.filter((node) => node.tag === tag);
|
|
24
24
|
if (tag === 'style' && !matchedNodes.length && rootNodes.length) {
|
|
25
25
|
for (let child of walk(rootNodes[0])) {
|
|
@@ -28,11 +28,17 @@ 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
|
-
|
|
34
|
-
const
|
|
35
|
-
const end = (_b = matchedNode.endTagStart) !== null && _b !== void 0 ? _b : matchedNode.end;
|
|
40
|
+
const start = matchedNode.startTagEnd ?? matchedNode.start;
|
|
41
|
+
const end = matchedNode.endTagStart ?? matchedNode.end;
|
|
36
42
|
const startPos = positionAt(start, text);
|
|
37
43
|
const endPos = positionAt(end, text);
|
|
38
44
|
const container = {
|
|
@@ -61,6 +67,14 @@ function extractStyleTags(source, html) {
|
|
|
61
67
|
return styles;
|
|
62
68
|
}
|
|
63
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;
|
|
64
78
|
function parseAttributes(rawAttrs) {
|
|
65
79
|
const attrs = {};
|
|
66
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 } 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 } 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
|
+
getCodeActions(textDocument: TextDocumentIdentifier, range: Range, context: CodeActionContext, cancellationToken: CancellationToken): Promise<CodeAction[]>;
|
|
19
20
|
doTagComplete(textDocument: TextDocumentIdentifier, position: Position): Promise<string | null>;
|
|
20
21
|
getFoldingRanges(textDocument: TextDocumentIdentifier): Promise<FoldingRange[] | null>;
|
|
21
22
|
getDocumentSymbols(textDocument: TextDocumentIdentifier, cancellationToken: CancellationToken): Promise<SymbolInformation[]>;
|
|
@@ -59,7 +59,7 @@ class PluginHost {
|
|
|
59
59
|
async resolveCompletion(textDocument, completionItem) {
|
|
60
60
|
const document = this.getDocument(textDocument.uri);
|
|
61
61
|
const result = await this.execute('resolveCompletion', [document, completionItem], ExecuteMode.FirstNonNull);
|
|
62
|
-
return result
|
|
62
|
+
return result ?? completionItem;
|
|
63
63
|
}
|
|
64
64
|
async getDiagnostics(textDocument) {
|
|
65
65
|
const document = this.getDocument(textDocument.uri);
|
|
@@ -69,13 +69,17 @@ class PluginHost {
|
|
|
69
69
|
const document = this.getDocument(textDocument.uri);
|
|
70
70
|
return this.execute('doHover', [document, position], ExecuteMode.FirstNonNull);
|
|
71
71
|
}
|
|
72
|
+
async getCodeActions(textDocument, range, context, cancellationToken) {
|
|
73
|
+
const document = this.getDocument(textDocument.uri);
|
|
74
|
+
return (0, lodash_1.flatten)(await this.execute('getCodeActions', [document, range, context, cancellationToken], ExecuteMode.Collect));
|
|
75
|
+
}
|
|
72
76
|
async doTagComplete(textDocument, position) {
|
|
73
77
|
const document = this.getDocument(textDocument.uri);
|
|
74
78
|
return this.execute('doTagComplete', [document, position], ExecuteMode.FirstNonNull);
|
|
75
79
|
}
|
|
76
80
|
async getFoldingRanges(textDocument) {
|
|
77
81
|
const document = this.getDocument(textDocument.uri);
|
|
78
|
-
const foldingRanges = (0, lodash_1.flatten)(await this.execute('getFoldingRanges', [document], ExecuteMode.Collect))
|
|
82
|
+
const foldingRanges = (0, lodash_1.flatten)(await this.execute('getFoldingRanges', [document], ExecuteMode.Collect));
|
|
79
83
|
return foldingRanges;
|
|
80
84
|
}
|
|
81
85
|
async getDocumentSymbols(textDocument, cancellationToken) {
|
|
@@ -116,15 +120,13 @@ class PluginHost {
|
|
|
116
120
|
return await this.execute('getSignatureHelp', [document, position, context, cancellationToken], ExecuteMode.FirstNonNull);
|
|
117
121
|
}
|
|
118
122
|
onWatchFileChanges(onWatchFileChangesParams) {
|
|
119
|
-
var _a;
|
|
120
123
|
for (const support of this.plugins) {
|
|
121
|
-
|
|
124
|
+
support.onWatchFileChanges?.(onWatchFileChangesParams);
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
127
|
updateNonAstroFile(fileName, changes) {
|
|
125
|
-
var _a;
|
|
126
128
|
for (const support of this.plugins) {
|
|
127
|
-
|
|
129
|
+
support.updateNonAstroFile?.(fileName, changes);
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
getDocument(uri) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CompletionContext,
|
|
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
|
}
|