@astrojs/language-server 0.12.1 → 0.13.2
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 +25 -0
- package/dist/core/documents/AstroDocument.d.ts +2 -2
- package/dist/core/documents/AstroDocument.js +6 -1
- package/dist/plugins/PluginHost.d.ts +2 -1
- package/dist/plugins/PluginHost.js +4 -0
- package/dist/plugins/css/CSSPlugin.d.ts +10 -1
- package/dist/plugins/css/CSSPlugin.js +62 -0
- package/dist/plugins/css/features/astro-selectors.js +2 -2
- package/dist/plugins/html/HTMLPlugin.d.ts +4 -1
- package/dist/plugins/html/HTMLPlugin.js +37 -1
- package/dist/plugins/html/features/astro-attributes.d.ts +2 -0
- package/dist/plugins/html/features/astro-attributes.js +126 -0
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +3 -1
- package/dist/plugins/typescript/TypeScriptPlugin.js +15 -0
- package/dist/plugins/typescript/features/CompletionsProvider.js +1 -1
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +8 -29
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +10 -0
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +69 -0
- package/dist/plugins/typescript/language-service.js +11 -3
- package/dist/plugins/typescript/snapshots/utils.js +1 -1
- package/dist/plugins/typescript/utils.d.ts +2 -1
- package/dist/plugins/typescript/utils.js +50 -1
- package/dist/server.js +2 -0
- package/dist/utils.d.ts +4 -8
- package/dist/utils.js +6 -10
- package/package.json +2 -2
- package/types/astro-jsx.d.ts +1077 -0
|
@@ -70,6 +70,14 @@ async function createLanguageService(tsconfigPath, docContext) {
|
|
|
70
70
|
let projectVersion = 0;
|
|
71
71
|
const snapshotManager = new SnapshotManager_1.SnapshotManager(docContext.globalSnapshotManager, files, fullConfig, workspaceRoot || process.cwd());
|
|
72
72
|
const astroModuleLoader = (0, module_loader_1.createAstroModuleLoader)(getScriptSnapshot, compilerOptions);
|
|
73
|
+
let languageServerDirectory;
|
|
74
|
+
try {
|
|
75
|
+
languageServerDirectory = (0, path_1.dirname)(require.resolve('@astrojs/language-server'));
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
languageServerDirectory = __dirname;
|
|
79
|
+
}
|
|
80
|
+
const astroTSXFile = typescript_1.default.sys.resolvePath((0, path_1.resolve)(languageServerDirectory, '../types/astro-jsx.d.ts'));
|
|
73
81
|
const host = {
|
|
74
82
|
getNewLine: () => typescript_1.default.sys.newLine,
|
|
75
83
|
useCaseSensitiveFileNames: () => typescript_1.default.sys.useCaseSensitiveFileNames,
|
|
@@ -82,7 +90,7 @@ async function createLanguageService(tsconfigPath, docContext) {
|
|
|
82
90
|
getCurrentDirectory: () => workspaceRoot,
|
|
83
91
|
getDefaultLibFileName: typescript_1.default.getDefaultLibFilePath,
|
|
84
92
|
getProjectVersion: () => projectVersion.toString(),
|
|
85
|
-
getScriptFileNames: () => Array.from(new Set([...snapshotManager.getProjectFileNames(), ...snapshotManager.getFileNames()])),
|
|
93
|
+
getScriptFileNames: () => Array.from(new Set([...snapshotManager.getProjectFileNames(), ...snapshotManager.getFileNames(), astroTSXFile])),
|
|
86
94
|
getScriptSnapshot,
|
|
87
95
|
getScriptVersion: (fileName) => getScriptSnapshot(fileName).version.toString(),
|
|
88
96
|
};
|
|
@@ -181,13 +189,13 @@ async function createLanguageService(tsconfigPath, docContext) {
|
|
|
181
189
|
(_c = configJson.exclude) !== null && _c !== void 0 ? _c : (configJson.exclude = getDefaultExclude());
|
|
182
190
|
// Everything here will always, unconditionally, be in the resulting config
|
|
183
191
|
const forcedCompilerOptions = {
|
|
184
|
-
// Our TSX is currently not typed, which unfortunately means that we can't support `noImplicitAny`
|
|
185
|
-
noImplicitAny: false,
|
|
186
192
|
noEmit: true,
|
|
187
193
|
declaration: false,
|
|
188
194
|
allowNonTsExtensions: true,
|
|
189
195
|
allowJs: true,
|
|
190
196
|
jsx: typescript_1.default.JsxEmit.Preserve,
|
|
197
|
+
jsxImportSource: undefined,
|
|
198
|
+
jsxFactory: 'astroHTML',
|
|
191
199
|
module: typescript_1.default.ModuleKind.ESNext,
|
|
192
200
|
target: typescript_1.default.ScriptTarget.ESNext,
|
|
193
201
|
moduleResolution: typescript_1.default.ModuleResolutionKind.NodeJs,
|
|
@@ -77,7 +77,7 @@ function createFromFrameworkFilePath(filePath, framework) {
|
|
|
77
77
|
code = (0, svelte_language_integration_1.toTSX)(originalText);
|
|
78
78
|
}
|
|
79
79
|
else {
|
|
80
|
-
code = 'export default function() {}';
|
|
80
|
+
code = 'export default function(props: Record<string, any>): any {<div></div>}';
|
|
81
81
|
}
|
|
82
82
|
return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, code, typescript_1.default.ScriptKind.TSX);
|
|
83
83
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import { CompletionItemKind, DiagnosticSeverity, Position, Range } from 'vscode-languageserver';
|
|
2
|
+
import { CompletionItemKind, DiagnosticSeverity, Position, Range, SymbolKind } from 'vscode-languageserver';
|
|
3
3
|
import { SnapshotFragment } from './snapshots/DocumentSnapshot';
|
|
4
|
+
export declare function symbolKindFromString(kind: string): SymbolKind;
|
|
4
5
|
export declare function scriptElementKindToCompletionItemKind(kind: ts.ScriptElementKind): CompletionItemKind;
|
|
5
6
|
export declare function getCommitCharactersForScriptElement(kind: ts.ScriptElementKind): string[] | undefined;
|
|
6
7
|
export declare function getExtensionFromScriptKind(kind: ts.ScriptKind | undefined): ts.Extension;
|
|
@@ -3,12 +3,61 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ensureRealFilePath = exports.ensureRealAstroFilePath = exports.toRealAstroFilePath = exports.toVirtualFilePath = exports.toVirtualAstroFilePath = exports.isVirtualFilePath = exports.isVirtualSvelteFilePath = exports.isVirtualVueFilePath = exports.isVirtualAstroFilePath = exports.isFrameworkFilePath = exports.isAstroFilePath = exports.isVirtualFrameworkFilePath = exports.getFrameworkFromFilePath = exports.convertToLocationRange = exports.convertRange = exports.mapSeverity = exports.getScriptKindFromFileName = exports.isSubPath = exports.findTsConfigPath = exports.getExtensionFromScriptKind = exports.getCommitCharactersForScriptElement = exports.scriptElementKindToCompletionItemKind = void 0;
|
|
6
|
+
exports.ensureRealFilePath = exports.ensureRealAstroFilePath = exports.toRealAstroFilePath = exports.toVirtualFilePath = exports.toVirtualAstroFilePath = exports.isVirtualFilePath = exports.isVirtualSvelteFilePath = exports.isVirtualVueFilePath = exports.isVirtualAstroFilePath = exports.isFrameworkFilePath = exports.isAstroFilePath = exports.isVirtualFrameworkFilePath = exports.getFrameworkFromFilePath = exports.convertToLocationRange = exports.convertRange = exports.mapSeverity = exports.getScriptKindFromFileName = exports.isSubPath = exports.findTsConfigPath = exports.getExtensionFromScriptKind = exports.getCommitCharactersForScriptElement = exports.scriptElementKindToCompletionItemKind = exports.symbolKindFromString = void 0;
|
|
7
7
|
const typescript_1 = __importDefault(require("typescript"));
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const utils_1 = require("../../utils");
|
|
10
10
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
11
11
|
const documents_1 = require("../../core/documents");
|
|
12
|
+
function symbolKindFromString(kind) {
|
|
13
|
+
switch (kind) {
|
|
14
|
+
case 'module':
|
|
15
|
+
return vscode_languageserver_1.SymbolKind.Module;
|
|
16
|
+
case 'class':
|
|
17
|
+
return vscode_languageserver_1.SymbolKind.Class;
|
|
18
|
+
case 'local class':
|
|
19
|
+
return vscode_languageserver_1.SymbolKind.Class;
|
|
20
|
+
case 'interface':
|
|
21
|
+
return vscode_languageserver_1.SymbolKind.Interface;
|
|
22
|
+
case 'enum':
|
|
23
|
+
return vscode_languageserver_1.SymbolKind.Enum;
|
|
24
|
+
case 'enum member':
|
|
25
|
+
return vscode_languageserver_1.SymbolKind.Constant;
|
|
26
|
+
case 'var':
|
|
27
|
+
return vscode_languageserver_1.SymbolKind.Variable;
|
|
28
|
+
case 'local var':
|
|
29
|
+
return vscode_languageserver_1.SymbolKind.Variable;
|
|
30
|
+
case 'function':
|
|
31
|
+
return vscode_languageserver_1.SymbolKind.Function;
|
|
32
|
+
case 'local function':
|
|
33
|
+
return vscode_languageserver_1.SymbolKind.Function;
|
|
34
|
+
case 'method':
|
|
35
|
+
return vscode_languageserver_1.SymbolKind.Method;
|
|
36
|
+
case 'getter':
|
|
37
|
+
return vscode_languageserver_1.SymbolKind.Method;
|
|
38
|
+
case 'setter':
|
|
39
|
+
return vscode_languageserver_1.SymbolKind.Method;
|
|
40
|
+
case 'property':
|
|
41
|
+
return vscode_languageserver_1.SymbolKind.Property;
|
|
42
|
+
case 'constructor':
|
|
43
|
+
return vscode_languageserver_1.SymbolKind.Constructor;
|
|
44
|
+
case 'parameter':
|
|
45
|
+
return vscode_languageserver_1.SymbolKind.Variable;
|
|
46
|
+
case 'type parameter':
|
|
47
|
+
return vscode_languageserver_1.SymbolKind.Variable;
|
|
48
|
+
case 'alias':
|
|
49
|
+
return vscode_languageserver_1.SymbolKind.Variable;
|
|
50
|
+
case 'let':
|
|
51
|
+
return vscode_languageserver_1.SymbolKind.Variable;
|
|
52
|
+
case 'const':
|
|
53
|
+
return vscode_languageserver_1.SymbolKind.Constant;
|
|
54
|
+
case 'JSX attribute':
|
|
55
|
+
return vscode_languageserver_1.SymbolKind.Property;
|
|
56
|
+
default:
|
|
57
|
+
return vscode_languageserver_1.SymbolKind.Variable;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.symbolKindFromString = symbolKindFromString;
|
|
12
61
|
function scriptElementKindToCompletionItemKind(kind) {
|
|
13
62
|
switch (kind) {
|
|
14
63
|
case typescript_1.default.ScriptElementKind.primitiveType:
|
package/dist/server.js
CHANGED
|
@@ -96,6 +96,7 @@ function startLanguageServer(connection) {
|
|
|
96
96
|
},
|
|
97
97
|
colorProvider: true,
|
|
98
98
|
hoverProvider: true,
|
|
99
|
+
documentSymbolProvider: true,
|
|
99
100
|
signatureHelpProvider: {
|
|
100
101
|
triggerCharacters: ['(', ',', '<'],
|
|
101
102
|
retriggerCharacters: [')'],
|
|
@@ -144,6 +145,7 @@ function startLanguageServer(connection) {
|
|
|
144
145
|
}
|
|
145
146
|
return pluginHost.resolveCompletion(data, completionItem);
|
|
146
147
|
});
|
|
148
|
+
connection.onDocumentSymbol((params, cancellationToken) => pluginHost.getDocumentSymbols(params.textDocument, cancellationToken));
|
|
147
149
|
connection.onDocumentColor((params) => pluginHost.getDocumentColors(params.textDocument));
|
|
148
150
|
connection.onColorPresentation((params) => pluginHost.getColorPresentations(params.textDocument, params.range, params.color));
|
|
149
151
|
connection.onRequest(TagCloseRequest, (evt) => pluginHost.doTagComplete(evt.textDocument, evt.position));
|
package/dist/utils.d.ts
CHANGED
|
@@ -17,17 +17,13 @@ export declare function pathToUrl(path: string): string;
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function getLastPartOfPath(path: string): string;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* hover info for Svelte components like `Option` which have
|
|
23
|
-
* the same name like a html tag.
|
|
20
|
+
* Return true if a specific node could be a component.
|
|
21
|
+
* This is not a 100% sure test as it'll return false for any component that does not match the standard format for a component
|
|
24
22
|
*/
|
|
25
23
|
export declare function isPossibleComponent(node: Node): boolean;
|
|
26
24
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* hover info for Svelte components like `Option` which have
|
|
30
|
-
* the same name like a html tag.
|
|
25
|
+
* Return true if a specific node could be a component with a client directive on it.
|
|
26
|
+
* This is not a 100% sure test as it'll return false for any component that does not match the standard format for a component
|
|
31
27
|
*/
|
|
32
28
|
export declare function isPossibleClientComponent(node: Node): boolean;
|
|
33
29
|
/** Flattens an array */
|
package/dist/utils.js
CHANGED
|
@@ -38,21 +38,17 @@ function getLastPartOfPath(path) {
|
|
|
38
38
|
}
|
|
39
39
|
exports.getLastPartOfPath = getLastPartOfPath;
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* hover info for Svelte components like `Option` which have
|
|
44
|
-
* the same name like a html tag.
|
|
41
|
+
* Return true if a specific node could be a component.
|
|
42
|
+
* This is not a 100% sure test as it'll return false for any component that does not match the standard format for a component
|
|
45
43
|
*/
|
|
46
44
|
function isPossibleComponent(node) {
|
|
47
|
-
var _a;
|
|
48
|
-
return !!((_a = node.tag) === null || _a === void 0 ? void 0 : _a[0].match(/[A-Z]/));
|
|
45
|
+
var _a, _b;
|
|
46
|
+
return !!((_a = node.tag) === null || _a === void 0 ? void 0 : _a[0].match(/[A-Z]/)) || !!((_b = node.tag) === null || _b === void 0 ? void 0 : _b.match(/.+[.][A-Z]/));
|
|
49
47
|
}
|
|
50
48
|
exports.isPossibleComponent = isPossibleComponent;
|
|
51
49
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* hover info for Svelte components like `Option` which have
|
|
55
|
-
* the same name like a html tag.
|
|
50
|
+
* Return true if a specific node could be a component with a client directive on it.
|
|
51
|
+
* This is not a 100% sure test as it'll return false for any component that does not match the standard format for a component
|
|
56
52
|
*/
|
|
57
53
|
function isPossibleClientComponent(node) {
|
|
58
54
|
if (isPossibleComponent(node) && node.attributes) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"test": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --require ts-node/register \"test/**/*.ts\" --exclude \"test/**/*.d.ts\""
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@astrojs/svelte-language-integration": "^0.1.
|
|
22
|
+
"@astrojs/svelte-language-integration": "^0.1.2",
|
|
23
23
|
"@vscode/emmet-helper": "^2.8.4",
|
|
24
24
|
"lodash": "^4.17.21",
|
|
25
25
|
"source-map": "^0.7.3",
|