@astrojs/language-server 0.14.0 → 0.16.1
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 +39 -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/DocumentMapper.js +2 -4
- package/dist/core/documents/parseAstro.js +1 -1
- package/dist/core/documents/utils.d.ts +5 -0
- package/dist/core/documents/utils.js +18 -5
- package/dist/plugins/PluginHost.d.ts +3 -2
- package/dist/plugins/PluginHost.js +37 -10
- package/dist/plugins/astro/AstroPlugin.d.ts +1 -6
- package/dist/plugins/astro/AstroPlugin.js +0 -82
- package/dist/plugins/astro/features/CompletionsProvider.js +30 -15
- 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/interfaces.d.ts +2 -2
- package/dist/plugins/typescript/LanguageServiceManager.js +1 -1
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +10 -7
- package/dist/plugins/typescript/TypeScriptPlugin.js +39 -112
- package/dist/plugins/typescript/astro-sys.js +3 -5
- package/dist/plugins/typescript/astro2tsx.d.ts +1 -1
- package/dist/plugins/typescript/astro2tsx.js +7 -7
- package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +16 -0
- package/dist/plugins/typescript/features/CodeActionsProvider.js +147 -0
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +26 -7
- package/dist/plugins/typescript/features/CompletionsProvider.js +260 -56
- package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +9 -0
- package/dist/plugins/typescript/features/DefinitionsProvider.js +36 -0
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +2 -3
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +5 -6
- package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +9 -0
- package/dist/plugins/typescript/features/FoldingRangesProvider.js +64 -0
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +2 -2
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +2 -2
- package/dist/plugins/typescript/features/utils.d.ts +4 -0
- package/dist/plugins/typescript/features/utils.js +25 -3
- package/dist/plugins/typescript/language-service.js +5 -6
- package/dist/plugins/typescript/module-loader.js +1 -1
- package/dist/plugins/typescript/previewer.js +1 -1
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +1 -1
- package/dist/plugins/typescript/snapshots/utils.js +27 -9
- package/dist/plugins/typescript/utils.d.ts +4 -0
- package/dist/plugins/typescript/utils.js +29 -1
- package/dist/server.js +43 -14
- package/dist/utils.d.ts +12 -0
- package/dist/utils.js +39 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @astrojs/language-server
|
|
2
2
|
|
|
3
|
+
## 0.16.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ad5a5e5: Fix misc issues with Go To Definition
|
|
8
|
+
- 1bd790d: Updates config management, make sure to respect TypeScript settings when doing completions and quickfixes
|
|
9
|
+
|
|
10
|
+
## 0.16.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 9abff62: Add support for code actions
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- b485acd: Fixed bug where nonexistent server settings would result in a crash
|
|
19
|
+
- 1cff04c: Fix Emmet settings not being loaded, add support for Emmet in CSS
|
|
20
|
+
- 1bcae45: Remove support for Node 12 (VS Code versions under 1.56)
|
|
21
|
+
- c8d81a1: Update directives tooltips, add missing `is:raw`
|
|
22
|
+
- Updated dependencies [1bcae45]
|
|
23
|
+
- @astrojs/svelte-language-integration@0.1.4
|
|
24
|
+
|
|
25
|
+
## 0.15.0
|
|
26
|
+
|
|
27
|
+
### Minor Changes
|
|
28
|
+
|
|
29
|
+
- 6bb45cb: Overhaul TypeScript completions
|
|
30
|
+
|
|
31
|
+
- Add support for completions inside expressions
|
|
32
|
+
- Add support for auto imports on completion
|
|
33
|
+
- Fix misc issues in completions (missing description, deprecated stuff not showing as deprecated)
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- 7978de1: Add support for folding JavaScript
|
|
38
|
+
- 3ac74bc: Improve props completions on components
|
|
39
|
+
- Updated dependencies [6bb45cb]
|
|
40
|
+
- @astrojs/svelte-language-integration@0.1.3
|
|
41
|
+
|
|
3
42
|
## 0.14.0
|
|
4
43
|
|
|
5
44
|
### 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
|
}
|
|
@@ -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;
|
|
@@ -130,8 +129,7 @@ class SourceMapDocumentMapper {
|
|
|
130
129
|
* Needs to be called when source mapper is no longer needed in order to prevent memory leaks.
|
|
131
130
|
*/
|
|
132
131
|
destroy() {
|
|
133
|
-
|
|
134
|
-
(_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
132
|
+
this.parent?.destroy?.();
|
|
135
133
|
this.consumer.destroy();
|
|
136
134
|
}
|
|
137
135
|
}
|
|
@@ -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,11 @@ 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 getLineAtPosition(position: Position, text: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the node if offset is inside a HTML start tag
|
|
21
|
+
*/
|
|
22
|
+
export declare function getNodeIfIsInHTMLStartTag(html: HTMLDocument, offset: number): Node | undefined;
|
|
18
23
|
/**
|
|
19
24
|
* Return if a Node is a Component
|
|
20
25
|
*/
|
|
@@ -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.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.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])) {
|
|
@@ -30,9 +30,8 @@ function extractTags(text, tag, html) {
|
|
|
30
30
|
}
|
|
31
31
|
return matchedNodes.map(transformToTagInfo);
|
|
32
32
|
function transformToTagInfo(matchedNode) {
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const end = (_b = matchedNode.endTagStart) !== null && _b !== void 0 ? _b : matchedNode.end;
|
|
33
|
+
const start = matchedNode.startTagEnd ?? matchedNode.start;
|
|
34
|
+
const end = matchedNode.endTagStart ?? matchedNode.end;
|
|
36
35
|
const startPos = positionAt(start, text);
|
|
37
36
|
const endPos = positionAt(end, text);
|
|
38
37
|
const container = {
|
|
@@ -79,6 +78,20 @@ function parseAttributes(rawAttrs) {
|
|
|
79
78
|
return attrValue;
|
|
80
79
|
}
|
|
81
80
|
}
|
|
81
|
+
function getLineAtPosition(position, text) {
|
|
82
|
+
return text.substring(offsetAt({ line: position.line, character: 0 }, text), offsetAt({ line: position.line, character: Number.MAX_VALUE }, text));
|
|
83
|
+
}
|
|
84
|
+
exports.getLineAtPosition = getLineAtPosition;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the node if offset is inside a HTML start tag
|
|
87
|
+
*/
|
|
88
|
+
function getNodeIfIsInHTMLStartTag(html, offset) {
|
|
89
|
+
const node = html.findNodeAt(offset);
|
|
90
|
+
if (!!node.tag && node.tag[0] === node.tag[0].toLowerCase() && (!node.startTagEnd || offset < node.startTagEnd)) {
|
|
91
|
+
return node;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.getNodeIfIsInHTMLStartTag = getNodeIfIsInHTMLStartTag;
|
|
82
95
|
/**
|
|
83
96
|
* Return if a Node is a Component
|
|
84
97
|
*/
|
|
@@ -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 {
|
|
@@ -12,10 +12,11 @@ export declare class PluginHost {
|
|
|
12
12
|
constructor(docManager: DocumentManager);
|
|
13
13
|
initialize(pluginHostConfig: PluginHostConfig): void;
|
|
14
14
|
registerPlugin(plugin: Plugin): void;
|
|
15
|
-
getCompletions(textDocument: TextDocumentIdentifier, position: Position, completionContext?: CompletionContext): Promise<CompletionList>;
|
|
15
|
+
getCompletions(textDocument: TextDocumentIdentifier, position: Position, completionContext?: CompletionContext, cancellationToken?: CancellationToken): Promise<CompletionList>;
|
|
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[]>;
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PluginHost = void 0;
|
|
4
4
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
5
5
|
const lodash_1 = require("lodash");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const documents_1 = require("../core/documents");
|
|
6
8
|
var ExecuteMode;
|
|
7
9
|
(function (ExecuteMode) {
|
|
8
10
|
ExecuteMode[ExecuteMode["None"] = 0] = "None";
|
|
@@ -24,17 +26,40 @@ class PluginHost {
|
|
|
24
26
|
registerPlugin(plugin) {
|
|
25
27
|
this.plugins.push(plugin);
|
|
26
28
|
}
|
|
27
|
-
async getCompletions(textDocument, position, completionContext) {
|
|
29
|
+
async getCompletions(textDocument, position, completionContext, cancellationToken) {
|
|
28
30
|
const document = this.getDocument(textDocument.uri);
|
|
29
|
-
const completions =
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
const completions = await Promise.all(this.plugins.map(async (plugin) => {
|
|
32
|
+
const result = await this.tryExecutePlugin(plugin, 'getCompletions', [document, position, completionContext, cancellationToken], null);
|
|
33
|
+
if (result) {
|
|
34
|
+
return { result: result, plugin: plugin.__name };
|
|
35
|
+
}
|
|
36
|
+
})).then((fullCompletions) => fullCompletions.filter(utils_1.isNotNullOrUndefined));
|
|
37
|
+
const html = completions.find((completion) => completion.plugin === 'html');
|
|
38
|
+
const ts = completions.find((completion) => completion.plugin === 'typescript');
|
|
39
|
+
const astro = completions.find((completion) => completion.plugin === 'astro');
|
|
40
|
+
if (html && ts) {
|
|
41
|
+
if ((0, documents_1.getNodeIfIsInHTMLStartTag)(document.html, document.offsetAt(position))) {
|
|
42
|
+
ts.result.items = [];
|
|
43
|
+
}
|
|
44
|
+
// If the Astro plugin has completions for us, don't show TypeScript's as they're most likely duplicates
|
|
45
|
+
if (astro && astro.result.items.length > 0 && (0, documents_1.isInComponentStartTag)(document.html, document.offsetAt(position))) {
|
|
46
|
+
ts.result.items = [];
|
|
47
|
+
}
|
|
48
|
+
ts.result.items = ts.result.items.map((item) => {
|
|
49
|
+
if (item.sortText != '-1') {
|
|
50
|
+
item.sortText = 'Z' + (item.sortText || '');
|
|
51
|
+
}
|
|
52
|
+
return item;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
let flattenedCompletions = (0, lodash_1.flatten)(completions.map((completion) => completion.result.items));
|
|
56
|
+
const isIncomplete = completions.reduce((incomplete, completion) => incomplete || completion.result.isIncomplete, false);
|
|
32
57
|
return vscode_languageserver_1.CompletionList.create(flattenedCompletions, isIncomplete);
|
|
33
58
|
}
|
|
34
59
|
async resolveCompletion(textDocument, completionItem) {
|
|
35
60
|
const document = this.getDocument(textDocument.uri);
|
|
36
61
|
const result = await this.execute('resolveCompletion', [document, completionItem], ExecuteMode.FirstNonNull);
|
|
37
|
-
return result
|
|
62
|
+
return result ?? completionItem;
|
|
38
63
|
}
|
|
39
64
|
async getDiagnostics(textDocument) {
|
|
40
65
|
const document = this.getDocument(textDocument.uri);
|
|
@@ -44,13 +69,17 @@ class PluginHost {
|
|
|
44
69
|
const document = this.getDocument(textDocument.uri);
|
|
45
70
|
return this.execute('doHover', [document, position], ExecuteMode.FirstNonNull);
|
|
46
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
|
+
}
|
|
47
76
|
async doTagComplete(textDocument, position) {
|
|
48
77
|
const document = this.getDocument(textDocument.uri);
|
|
49
78
|
return this.execute('doTagComplete', [document, position], ExecuteMode.FirstNonNull);
|
|
50
79
|
}
|
|
51
80
|
async getFoldingRanges(textDocument) {
|
|
52
81
|
const document = this.getDocument(textDocument.uri);
|
|
53
|
-
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));
|
|
54
83
|
return foldingRanges;
|
|
55
84
|
}
|
|
56
85
|
async getDocumentSymbols(textDocument, cancellationToken) {
|
|
@@ -91,15 +120,13 @@ class PluginHost {
|
|
|
91
120
|
return await this.execute('getSignatureHelp', [document, position, context, cancellationToken], ExecuteMode.FirstNonNull);
|
|
92
121
|
}
|
|
93
122
|
onWatchFileChanges(onWatchFileChangesParams) {
|
|
94
|
-
var _a;
|
|
95
123
|
for (const support of this.plugins) {
|
|
96
|
-
|
|
124
|
+
support.onWatchFileChanges?.(onWatchFileChangesParams);
|
|
97
125
|
}
|
|
98
126
|
}
|
|
99
127
|
updateNonAstroFile(fileName, changes) {
|
|
100
|
-
var _a;
|
|
101
128
|
for (const support of this.plugins) {
|
|
102
|
-
|
|
129
|
+
support.updateNonAstroFile?.(fileName, changes);
|
|
103
130
|
}
|
|
104
131
|
}
|
|
105
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
|
}
|