@astrojs/language-server 0.21.0 → 0.21.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 +7 -0
- package/README.md +1 -2
- package/dist/check.js +4 -1
- package/dist/importPackage.d.ts +1 -1
- package/dist/importPackage.js +11 -8
- package/dist/plugins/astro/AstroPlugin.d.ts +3 -2
- package/dist/plugins/astro/AstroPlugin.js +2 -3
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +3 -2
- package/dist/plugins/typescript/TypeScriptPlugin.js +2 -3
- package/dist/plugins/typescript/language-service.js +9 -11
- package/dist/server.js +6 -4
- package/dist/utils.d.ts +9 -7
- package/dist/utils.js +25 -16
- package/package.json +1 -1
- package/types/README.md +5 -0
- package/types/astro-jsx.d.ts +854 -477
- package/types/env.d.ts +22 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @astrojs/language-server
|
|
2
2
|
|
|
3
|
+
## 0.21.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0e9d7d0: Improve error handling in cases where we can't load types from the user's project and when the project isn't at the root of the folder
|
|
8
|
+
- 3f79dbf: Fix `tsconfig.json` not loading properly in certain contexts on Windows
|
|
9
|
+
|
|
3
10
|
## 0.21.0
|
|
4
11
|
|
|
5
12
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -11,6 +11,5 @@ The Astro language server, implement the [language server protocol](https://micr
|
|
|
11
11
|
│ ├── core # Core code such as .astro file parsing, configuration manager, document definition etc
|
|
12
12
|
│ └── plugins # Modules for the different languages supported in .astro files
|
|
13
13
|
├── test # Tests
|
|
14
|
-
|
|
15
|
-
└── astro.d.ts # Types injected into .astro files by the language server
|
|
14
|
+
└── types # Types injected into Astro files by the language server under certain conditions
|
|
16
15
|
```
|
package/dist/check.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.AstroCheck = exports.DiagnosticSeverity = void 0;
|
|
|
4
4
|
const config_1 = require("./core/config");
|
|
5
5
|
const documents_1 = require("./core/documents");
|
|
6
6
|
const plugins_1 = require("./plugins");
|
|
7
|
+
const LanguageServiceManager_1 = require("./plugins/typescript/LanguageServiceManager");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
7
9
|
var vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
8
10
|
Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return vscode_languageserver_types_1.DiagnosticSeverity; } });
|
|
9
11
|
class AstroCheck {
|
|
@@ -37,7 +39,8 @@ class AstroCheck {
|
|
|
37
39
|
}));
|
|
38
40
|
}
|
|
39
41
|
initialize(workspacePath) {
|
|
40
|
-
|
|
42
|
+
const languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(this.docManager, [(0, utils_1.normalizeUri)(workspacePath)], this.configManager);
|
|
43
|
+
this.pluginHost.registerPlugin(new plugins_1.TypeScriptPlugin(this.configManager, languageServiceManager));
|
|
41
44
|
}
|
|
42
45
|
async getDiagnosticsForFile(uri) {
|
|
43
46
|
const diagnostics = await this.pluginHost.getDiagnostics({ uri });
|
package/dist/importPackage.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as svelte from '@astrojs/svelte/dist/editor.cjs';
|
|
2
2
|
import type * as vue from '@astrojs/svelte/dist/editor.cjs';
|
|
3
3
|
export declare function setIsTrusted(_isTrusted: boolean): void;
|
|
4
|
-
export declare function getPackagePath(packageName: string, fromPath: string): string | undefined;
|
|
4
|
+
export declare function getPackagePath(packageName: string, fromPath: string[]): string | undefined;
|
|
5
5
|
export declare function importSvelteIntegration(fromPath: string): typeof svelte | undefined;
|
|
6
6
|
export declare function importVueIntegration(fromPath: string): typeof vue | undefined;
|
package/dist/importPackage.js
CHANGED
|
@@ -10,13 +10,10 @@ exports.setIsTrusted = setIsTrusted;
|
|
|
10
10
|
function getPackagePath(packageName, fromPath) {
|
|
11
11
|
const paths = [];
|
|
12
12
|
if (isTrusted) {
|
|
13
|
-
paths.unshift(fromPath);
|
|
13
|
+
paths.unshift(...fromPath);
|
|
14
14
|
}
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
paths,
|
|
18
|
-
});
|
|
19
|
-
return (0, path_1.dirname)(packageJSONPath);
|
|
16
|
+
return (0, path_1.dirname)(require.resolve(packageName + '/package.json', { paths }));
|
|
20
17
|
}
|
|
21
18
|
catch (e) {
|
|
22
19
|
return undefined;
|
|
@@ -24,10 +21,16 @@ function getPackagePath(packageName, fromPath) {
|
|
|
24
21
|
}
|
|
25
22
|
exports.getPackagePath = getPackagePath;
|
|
26
23
|
function importEditorIntegration(packageName, fromPath) {
|
|
27
|
-
const pkgPath = getPackagePath(packageName, fromPath);
|
|
24
|
+
const pkgPath = getPackagePath(packageName, [fromPath]);
|
|
28
25
|
if (pkgPath) {
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
try {
|
|
27
|
+
const main = (0, path_1.resolve)(pkgPath, 'dist', 'editor.cjs');
|
|
28
|
+
return require(main);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.error(`Couldn't load editor module from ${pkgPath}. Make sure you're using at least version v0.2.1 of the corresponding integration`);
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
31
34
|
}
|
|
32
35
|
return undefined;
|
|
33
36
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { CompletionContext, FoldingRange, Position } from 'vscode-languageserver';
|
|
2
2
|
import { ConfigManager } from '../../core/config';
|
|
3
|
-
import { AstroDocument
|
|
3
|
+
import { AstroDocument } from '../../core/documents';
|
|
4
4
|
import { AppCompletionList, Plugin } from '../interfaces';
|
|
5
|
+
import { LanguageServiceManager } from '../typescript/LanguageServiceManager';
|
|
5
6
|
export declare class AstroPlugin implements Plugin {
|
|
6
7
|
__name: string;
|
|
7
8
|
private configManager;
|
|
8
9
|
private readonly languageServiceManager;
|
|
9
10
|
private readonly completionProvider;
|
|
10
|
-
constructor(
|
|
11
|
+
constructor(configManager: ConfigManager, languageServiceManager: LanguageServiceManager);
|
|
11
12
|
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList | null>;
|
|
12
13
|
getFoldingRanges(document: AstroDocument): FoldingRange[];
|
|
13
14
|
}
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AstroPlugin = void 0;
|
|
4
4
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
5
|
-
const LanguageServiceManager_1 = require("../typescript/LanguageServiceManager");
|
|
6
5
|
const CompletionsProvider_1 = require("./features/CompletionsProvider");
|
|
7
6
|
class AstroPlugin {
|
|
8
|
-
constructor(
|
|
7
|
+
constructor(configManager, languageServiceManager) {
|
|
9
8
|
this.__name = 'astro';
|
|
10
9
|
this.configManager = configManager;
|
|
11
|
-
this.languageServiceManager =
|
|
10
|
+
this.languageServiceManager = languageServiceManager;
|
|
12
11
|
this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(this.languageServiceManager);
|
|
13
12
|
}
|
|
14
13
|
async getCompletions(document, position, completionContext) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CancellationToken, CodeAction, CodeActionContext, CompletionContext, DefinitionLink, Diagnostic, FoldingRange, FormattingOptions, Hover, InlayHint, Position, Range, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, TextEdit, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
2
|
import { ConfigManager } from '../../core/config';
|
|
3
|
-
import { AstroDocument
|
|
3
|
+
import { AstroDocument } from '../../core/documents';
|
|
4
4
|
import { AppCompletionItem, AppCompletionList, OnWatchFileChangesParam, Plugin } from '../interfaces';
|
|
5
5
|
import { CompletionItemData } from './features/CompletionsProvider';
|
|
6
|
+
import { LanguageServiceManager } from './LanguageServiceManager';
|
|
6
7
|
import { Astro2TSXResult } from './astro2tsx';
|
|
7
8
|
export declare class TypeScriptPlugin implements Plugin {
|
|
8
9
|
__name: string;
|
|
@@ -19,7 +20,7 @@ export declare class TypeScriptPlugin implements Plugin {
|
|
|
19
20
|
private readonly semanticTokensProvider;
|
|
20
21
|
private readonly foldingRangesProvider;
|
|
21
22
|
private readonly formattingProvider;
|
|
22
|
-
constructor(
|
|
23
|
+
constructor(configManager: ConfigManager, languageServiceManager: LanguageServiceManager);
|
|
23
24
|
doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
|
|
24
25
|
rename(document: AstroDocument, position: Position, newName: string): Promise<WorkspaceEdit | null>;
|
|
25
26
|
formatDocument(document: AstroDocument, options: FormattingOptions): Promise<TextEdit[]>;
|
|
@@ -10,7 +10,6 @@ const CompletionsProvider_1 = require("./features/CompletionsProvider");
|
|
|
10
10
|
const DiagnosticsProvider_1 = require("./features/DiagnosticsProvider");
|
|
11
11
|
const HoverProvider_1 = require("./features/HoverProvider");
|
|
12
12
|
const SignatureHelpProvider_1 = require("./features/SignatureHelpProvider");
|
|
13
|
-
const LanguageServiceManager_1 = require("./LanguageServiceManager");
|
|
14
13
|
const utils_1 = require("./utils");
|
|
15
14
|
const DocumentSymbolsProvider_1 = require("./features/DocumentSymbolsProvider");
|
|
16
15
|
const SemanticTokenProvider_1 = require("./features/SemanticTokenProvider");
|
|
@@ -22,10 +21,10 @@ const FormattingProvider_1 = require("./features/FormattingProvider");
|
|
|
22
21
|
const astro2tsx_1 = __importDefault(require("./astro2tsx"));
|
|
23
22
|
const utils_2 = require("./snapshots/utils");
|
|
24
23
|
class TypeScriptPlugin {
|
|
25
|
-
constructor(
|
|
24
|
+
constructor(configManager, languageServiceManager) {
|
|
26
25
|
this.__name = 'typescript';
|
|
27
26
|
this.configManager = configManager;
|
|
28
|
-
this.languageServiceManager =
|
|
27
|
+
this.languageServiceManager = languageServiceManager;
|
|
29
28
|
this.codeActionsProvider = new CodeActionsProvider_1.CodeActionsProviderImpl(this.languageServiceManager, this.configManager);
|
|
30
29
|
this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(this.languageServiceManager, this.configManager);
|
|
31
30
|
this.hoverProvider = new HoverProvider_1.HoverProviderImpl(this.languageServiceManager);
|
|
@@ -72,7 +72,7 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
|
|
|
72
72
|
const tsconfigRoot = tsconfigPath ? (0, path_1.dirname)(tsconfigPath) : process.cwd();
|
|
73
73
|
const workspacePaths = workspaceUris.map((uri) => (0, utils_1.urlToPath)(uri));
|
|
74
74
|
const workspacePath = workspacePaths.find((uri) => tsconfigRoot.startsWith(uri)) || workspacePaths[0];
|
|
75
|
-
const
|
|
75
|
+
const astroInstall = (0, utils_1.getAstroInstall)([tsconfigRoot, workspacePath]);
|
|
76
76
|
const config = (await docContext.configManager.getConfig('astro.typescript', workspacePath)) ?? {};
|
|
77
77
|
const allowArbitraryAttrs = config.allowArbitraryAttributes ?? false;
|
|
78
78
|
// `raw` here represent the tsconfig merged with any extended config
|
|
@@ -81,9 +81,8 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
|
|
|
81
81
|
const snapshotManager = new SnapshotManager_1.SnapshotManager(docContext.globalSnapshotManager, files, fullConfig, tsconfigRoot || process.cwd());
|
|
82
82
|
const astroModuleLoader = (0, module_loader_1.createAstroModuleLoader)(getScriptSnapshot, compilerOptions);
|
|
83
83
|
const scriptFileNames = [];
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
scriptFileNames.push(...['./env.d.ts', './astro-jsx.d.ts'].map((f) => typescript_1.default.sys.resolvePath((0, path_1.resolve)(astroDir, f))));
|
|
84
|
+
if (astroInstall) {
|
|
85
|
+
scriptFileNames.push(...['./env.d.ts', './astro-jsx.d.ts'].map((f) => typescript_1.default.sys.resolvePath((0, path_1.resolve)(astroInstall.path, f))));
|
|
87
86
|
}
|
|
88
87
|
let languageServerDirectory;
|
|
89
88
|
try {
|
|
@@ -92,14 +91,13 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
|
|
|
92
91
|
catch (e) {
|
|
93
92
|
languageServerDirectory = __dirname;
|
|
94
93
|
}
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
// Fallback to internal types when Astro is not installed or the Astro version is too old
|
|
95
|
+
if (!astroInstall ||
|
|
96
|
+
((astroInstall.version.major === 0 || astroInstall.version.full === '1.0.0-beta.0') &&
|
|
97
|
+
!astroInstall.version.full.startsWith('0.0.0-rc-')) // 1.0.0's RC is considered to be 0.0.0, so we have to check for it
|
|
99
98
|
) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
console.warn("Version lower than 1.0 detected, using internal types instead of Astro's");
|
|
99
|
+
scriptFileNames.push(...['../types/astro-jsx.d.ts', '../types/env.d.ts'].map((f) => typescript_1.default.sys.resolvePath((0, path_1.resolve)(languageServerDirectory, f))));
|
|
100
|
+
console.warn("Couldn't load types from Astro, using internal types instead");
|
|
103
101
|
}
|
|
104
102
|
if (allowArbitraryAttrs) {
|
|
105
103
|
const arbitraryAttrsDTS = typescript_1.default.sys.resolvePath((0, path_1.resolve)(languageServerDirectory, '../types/arbitrary-attrs.d.ts'));
|
package/dist/server.js
CHANGED
|
@@ -37,6 +37,7 @@ const plugins_1 = require("./plugins");
|
|
|
37
37
|
const utils_1 = require("./utils");
|
|
38
38
|
const utils_2 = require("./plugins/typescript/utils");
|
|
39
39
|
const CodeActionsProvider_1 = require("./plugins/typescript/features/CodeActionsProvider");
|
|
40
|
+
const LanguageServiceManager_1 = require("./plugins/typescript/LanguageServiceManager");
|
|
40
41
|
const TagCloseRequest = new vscode.RequestType('html/tag');
|
|
41
42
|
// Start the language server
|
|
42
43
|
function startLanguageServer(connection) {
|
|
@@ -55,8 +56,8 @@ function startLanguageServer(connection) {
|
|
|
55
56
|
if (!(0, utils_1.isAstroWorkspace)(uri) && uri !== '/' && uri !== '') {
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
59
|
+
const astroInstall = (0, utils_1.getAstroInstall)([uri]);
|
|
60
|
+
if (!astroInstall) {
|
|
60
61
|
connection.sendNotification(vscode_languageserver_1.ShowMessageNotification.type, {
|
|
61
62
|
message: `Couldn't find Astro in workspace "${uri}". Experience might be degraded. For the best experience, please make sure Astro is installed and then restart the language server`,
|
|
62
63
|
type: vscode_languageserver_1.MessageType.Warning,
|
|
@@ -73,8 +74,9 @@ function startLanguageServer(connection) {
|
|
|
73
74
|
pluginHost.registerPlugin(new CSSPlugin_1.CSSPlugin(configManager));
|
|
74
75
|
// We don't currently support running the TypeScript and Astro plugin in the browser
|
|
75
76
|
if (params.initializationOptions.environment !== 'browser') {
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
const languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(documentManager, workspaceUris.map(utils_1.normalizeUri), configManager);
|
|
78
|
+
typescriptPlugin = new plugins_1.TypeScriptPlugin(configManager, languageServiceManager);
|
|
79
|
+
pluginHost.registerPlugin(new AstroPlugin_1.AstroPlugin(configManager, languageServiceManager));
|
|
78
80
|
pluginHost.registerPlugin(typescriptPlugin);
|
|
79
81
|
}
|
|
80
82
|
return {
|
package/dist/utils.d.ts
CHANGED
|
@@ -69,11 +69,13 @@ export declare function debounceThrottle<T extends (...args: any) => void>(fn: T
|
|
|
69
69
|
* Try to determine if a workspace could be an Astro project based on the content of `package.json`
|
|
70
70
|
*/
|
|
71
71
|
export declare function isAstroWorkspace(workspacePath: string): boolean;
|
|
72
|
-
export interface
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
export interface AstroInstall {
|
|
73
|
+
path: string;
|
|
74
|
+
version: {
|
|
75
|
+
full: string;
|
|
76
|
+
major: number;
|
|
77
|
+
minor: number;
|
|
78
|
+
patch: number;
|
|
79
|
+
};
|
|
78
80
|
}
|
|
79
|
-
export declare function
|
|
81
|
+
export declare function getAstroInstall(basePaths: string[]): AstroInstall | undefined;
|
package/dist/utils.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getAstroInstall = exports.isAstroWorkspace = exports.debounceThrottle = exports.debounceSameArg = exports.getRegExpMatches = exports.regexLastIndexOf = exports.isBeforeOrEqualToPosition = exports.isInRange = exports.isNotNullOrUndefined = exports.clamp = exports.modifyLines = exports.toPascalCase = exports.mergeDeep = exports.get = exports.getLastPartOfPath = exports.pathToUrl = exports.urlToPath = exports.normalizePath = exports.normalizeUri = void 0;
|
|
4
4
|
const vscode_uri_1 = require("vscode-uri");
|
|
5
|
+
const importPackage_1 = require("./importPackage");
|
|
5
6
|
/** Normalizes a document URI */
|
|
6
7
|
function normalizeUri(uri) {
|
|
7
8
|
return vscode_uri_1.URI.parse(uri).toString();
|
|
@@ -214,23 +215,29 @@ function isAstroWorkspace(workspacePath) {
|
|
|
214
215
|
return false;
|
|
215
216
|
}
|
|
216
217
|
exports.isAstroWorkspace = isAstroWorkspace;
|
|
217
|
-
function
|
|
218
|
-
let
|
|
219
|
-
let
|
|
218
|
+
function getAstroInstall(basePaths) {
|
|
219
|
+
let path;
|
|
220
|
+
let version;
|
|
220
221
|
try {
|
|
221
|
-
|
|
222
|
-
|
|
222
|
+
path = (0, importPackage_1.getPackagePath)('astro', basePaths);
|
|
223
|
+
if (!path) {
|
|
224
|
+
throw Error;
|
|
225
|
+
}
|
|
226
|
+
version = require(path + '/package.json').version;
|
|
223
227
|
}
|
|
224
228
|
catch {
|
|
225
229
|
// If we couldn't find it inside the workspace's node_modules, it might means we're in the monorepo
|
|
226
230
|
try {
|
|
227
|
-
|
|
228
|
-
|
|
231
|
+
path = (0, importPackage_1.getPackagePath)('./packages/astro', basePaths);
|
|
232
|
+
if (!path) {
|
|
233
|
+
throw Error;
|
|
234
|
+
}
|
|
235
|
+
version = require(path + '/package.json').version;
|
|
229
236
|
}
|
|
230
237
|
catch (e) {
|
|
231
238
|
// If we still couldn't find it, it probably just doesn't exist
|
|
232
|
-
|
|
233
|
-
|
|
239
|
+
console.error(`${basePaths[0]} seems to be an Astro project, but we couldn't find Astro or Astro is not installed`);
|
|
240
|
+
return undefined;
|
|
234
241
|
}
|
|
235
242
|
}
|
|
236
243
|
let [major, minor, patch] = version.split('.');
|
|
@@ -239,11 +246,13 @@ function getUserAstroVersion(basePath) {
|
|
|
239
246
|
patch = patchParts[0];
|
|
240
247
|
}
|
|
241
248
|
return {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
249
|
+
path,
|
|
250
|
+
version: {
|
|
251
|
+
full: version,
|
|
252
|
+
major: Number(major),
|
|
253
|
+
minor: Number(minor),
|
|
254
|
+
patch: Number(patch),
|
|
255
|
+
},
|
|
247
256
|
};
|
|
248
257
|
}
|
|
249
|
-
exports.
|
|
258
|
+
exports.getAstroInstall = getAstroInstall;
|
package/package.json
CHANGED
package/types/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Types
|
|
2
|
+
|
|
3
|
+
**Heads up!** `env.d.ts` and `astro-jsx.d.ts` in this folder are only used as fallback by the language server whenever we're not able to load the real types from the user's project. The types here should be in line with the types from Astro, but only loosely as not being able to load the real types from the user's project is an uncommon situation and some things are not necessarily possible without relying on Astro's internals
|
|
4
|
+
|
|
5
|
+
As such, if you're making a PR to fix/improve something related to types, you should probably make a PR to [Astro itself](https://github.com/withastro/astro), not this project!
|