@astrojs/language-server 0.11.0 → 0.13.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 +23 -0
- package/bin/browserServer.js +3 -0
- package/bin/nodeServer.js +3 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +8 -0
- package/dist/check.js +2 -5
- package/dist/core/DiagnosticsManager.d.ts +3 -3
- package/dist/core/DiagnosticsManager.js +2 -2
- package/dist/core/config/ConfigManager.d.ts +19 -164
- package/dist/core/config/ConfigManager.js +62 -101
- package/dist/core/config/index.d.ts +1 -0
- package/dist/core/config/index.js +1 -0
- package/dist/core/config/interfaces.d.ts +123 -0
- package/dist/core/config/interfaces.js +2 -0
- package/dist/core/documents/AstroDocument.d.ts +18 -0
- package/dist/core/documents/AstroDocument.js +42 -0
- package/dist/core/documents/DocumentBase.d.ts +10 -2
- package/dist/core/documents/DocumentBase.js +15 -50
- package/dist/core/documents/DocumentManager.d.ts +12 -16
- package/dist/core/documents/DocumentManager.js +32 -26
- package/dist/core/documents/DocumentMapper.js +3 -1
- package/dist/core/documents/index.d.ts +1 -1
- package/dist/core/documents/index.js +1 -1
- package/dist/core/documents/parseAstro.d.ts +2 -2
- package/dist/core/documents/parseHtml.d.ts +2 -2
- package/dist/core/documents/parseHtml.js +4 -1
- package/dist/core/documents/utils.d.ts +22 -26
- package/dist/core/documents/utils.js +96 -134
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -3
- package/dist/node.d.ts +1 -0
- package/dist/node.js +29 -0
- package/dist/plugins/PluginHost.d.ts +11 -9
- package/dist/plugins/PluginHost.js +34 -36
- package/dist/plugins/astro/AstroPlugin.d.ts +11 -12
- package/dist/plugins/astro/AstroPlugin.js +17 -42
- package/dist/plugins/astro/features/{CompletionProvider.d.ts → CompletionsProvider.d.ts} +5 -5
- package/dist/plugins/astro/features/{CompletionProvider.js → CompletionsProvider.js} +33 -58
- package/dist/plugins/css/CSSDocument.d.ts +3 -3
- package/dist/plugins/css/CSSDocument.js +7 -16
- package/dist/plugins/css/CSSPlugin.d.ts +31 -12
- package/dist/plugins/css/CSSPlugin.js +174 -41
- package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
- package/dist/plugins/css/StyleAttributeDocument.js +2 -2
- package/dist/plugins/css/features/astro-selectors.d.ts +2 -0
- package/dist/plugins/css/features/astro-selectors.js +16 -0
- package/dist/plugins/css/features/{getIdClassCompletion.d.ts → getIdClassCompletions.d.ts} +3 -3
- package/dist/plugins/css/features/{getIdClassCompletion.js → getIdClassCompletions.js} +10 -9
- package/dist/plugins/css/{service.d.ts → language-service.d.ts} +0 -0
- package/dist/plugins/css/{service.js → language-service.js} +2 -1
- package/dist/plugins/html/HTMLPlugin.d.ts +18 -17
- package/dist/plugins/html/HTMLPlugin.js +69 -41
- package/dist/plugins/html/features/astro-attributes.d.ts +2 -0
- package/dist/plugins/html/features/astro-attributes.js +126 -0
- package/dist/plugins/index.d.ts +2 -2
- package/dist/plugins/index.js +2 -2
- package/dist/plugins/interfaces.d.ts +35 -48
- package/dist/plugins/typescript/LanguageServiceManager.d.ts +33 -14
- package/dist/plugins/typescript/LanguageServiceManager.js +57 -32
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +18 -23
- package/dist/plugins/typescript/TypeScriptPlugin.js +58 -55
- package/dist/plugins/typescript/astro-sys.d.ts +5 -3
- package/dist/plugins/typescript/astro-sys.js +24 -45
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +6 -6
- package/dist/plugins/typescript/features/CompletionsProvider.js +18 -38
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +4 -4
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +27 -87
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +10 -0
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +69 -0
- package/dist/plugins/typescript/features/HoverProvider.d.ts +4 -5
- package/dist/plugins/typescript/features/HoverProvider.js +9 -10
- package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +4 -5
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +15 -11
- package/dist/plugins/typescript/features/utils.d.ts +1 -12
- package/dist/plugins/typescript/features/utils.js +2 -22
- package/dist/plugins/typescript/language-service.d.ts +38 -0
- package/dist/plugins/typescript/language-service.js +230 -0
- package/dist/plugins/typescript/module-loader.d.ts +5 -8
- package/dist/plugins/typescript/module-loader.js +43 -23
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +90 -0
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +135 -0
- package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +42 -0
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +197 -0
- package/dist/plugins/typescript/snapshots/utils.d.ts +28 -0
- package/dist/plugins/typescript/snapshots/utils.js +84 -0
- package/dist/plugins/typescript/utils.d.ts +10 -13
- package/dist/plugins/typescript/utils.js +154 -158
- package/dist/server.d.ts +2 -4
- package/dist/server.js +93 -54
- package/dist/utils.d.ts +20 -16
- package/dist/utils.js +35 -24
- package/package.json +18 -12
- package/types/astro-jsx.d.ts +1077 -0
- package/bin/server.js +0 -7
- package/dist/core/documents/Document.d.ts +0 -51
- package/dist/core/documents/Document.js +0 -135
- package/dist/plugins/typescript/DocumentSnapshot.d.ts +0 -99
- package/dist/plugins/typescript/DocumentSnapshot.js +0 -259
- package/dist/plugins/typescript/SnapshotManager.d.ts +0 -24
- package/dist/plugins/typescript/SnapshotManager.js +0 -103
- package/dist/plugins/typescript/languageService.d.ts +0 -17
- package/dist/plugins/typescript/languageService.js +0 -173
- package/types/index.d.ts +0 -4
|
@@ -1,44 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
6
|
exports.AstroPlugin = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
27
8
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
9
|
+
const documents_1 = require("../../core/documents");
|
|
28
10
|
const utils_1 = require("../../utils");
|
|
29
|
-
const utils_2 = require("../typescript/utils");
|
|
30
|
-
const utils_3 = require("../../core/documents/utils");
|
|
31
|
-
const ts = __importStar(require("typescript"));
|
|
32
11
|
const LanguageServiceManager_1 = require("../typescript/LanguageServiceManager");
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const CompletionProvider_1 = require("./features/CompletionProvider");
|
|
12
|
+
const utils_2 = require("../typescript/utils");
|
|
13
|
+
const CompletionsProvider_1 = require("./features/CompletionsProvider");
|
|
36
14
|
class AstroPlugin {
|
|
37
15
|
constructor(docManager, configManager, workspaceUris) {
|
|
38
|
-
this.
|
|
16
|
+
this.__name = 'astro';
|
|
39
17
|
this.configManager = configManager;
|
|
40
|
-
this.
|
|
41
|
-
this.completionProvider = new
|
|
18
|
+
this.languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(docManager, workspaceUris, configManager);
|
|
19
|
+
this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(docManager, this.languageServiceManager);
|
|
42
20
|
}
|
|
43
21
|
async getCompletions(document, position, completionContext) {
|
|
44
22
|
const completions = this.completionProvider.getCompletions(document, position, completionContext);
|
|
@@ -46,7 +24,7 @@ class AstroPlugin {
|
|
|
46
24
|
}
|
|
47
25
|
async getFoldingRanges(document) {
|
|
48
26
|
const foldingRanges = [];
|
|
49
|
-
const { frontmatter } = document.
|
|
27
|
+
const { frontmatter } = document.astroMeta;
|
|
50
28
|
// Currently editing frontmatter, don't fold
|
|
51
29
|
if (frontmatter.state !== 'closed')
|
|
52
30
|
return foldingRanges;
|
|
@@ -58,7 +36,7 @@ class AstroPlugin {
|
|
|
58
36
|
startCharacter: start.character,
|
|
59
37
|
endLine: end.line,
|
|
60
38
|
endCharacter: end.character,
|
|
61
|
-
kind:
|
|
39
|
+
kind: vscode_languageserver_1.FoldingRangeKind.Imports,
|
|
62
40
|
},
|
|
63
41
|
];
|
|
64
42
|
}
|
|
@@ -73,20 +51,20 @@ class AstroPlugin {
|
|
|
73
51
|
return [];
|
|
74
52
|
}
|
|
75
53
|
const [componentName] = node.tag.split(':');
|
|
76
|
-
const { lang } = await this.
|
|
54
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
77
55
|
const defs = this.getDefinitionsForComponentName(document, lang, componentName);
|
|
78
56
|
if (!defs || !defs.length) {
|
|
79
57
|
return [];
|
|
80
58
|
}
|
|
81
59
|
const startRange = vscode_languageserver_1.Range.create(vscode_languageserver_1.Position.create(0, 0), vscode_languageserver_1.Position.create(0, 0));
|
|
82
60
|
const links = defs.map((def) => {
|
|
83
|
-
const defFilePath = (0,
|
|
61
|
+
const defFilePath = (0, utils_2.ensureRealFilePath)(def.fileName);
|
|
84
62
|
return vscode_languageserver_1.LocationLink.create((0, utils_1.pathToUrl)(defFilePath), startRange, startRange);
|
|
85
63
|
});
|
|
86
64
|
return links;
|
|
87
65
|
}
|
|
88
66
|
isInsideFrontmatter(document, position) {
|
|
89
|
-
return (0,
|
|
67
|
+
return (0, documents_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position));
|
|
90
68
|
}
|
|
91
69
|
isComponentTag(node) {
|
|
92
70
|
if (!node.tag) {
|
|
@@ -115,15 +93,15 @@ class AstroPlugin {
|
|
|
115
93
|
}
|
|
116
94
|
getImportSpecifierForIdentifier(sourceFile, identifier) {
|
|
117
95
|
let importSpecifier = undefined;
|
|
118
|
-
|
|
119
|
-
if (
|
|
96
|
+
typescript_1.default.forEachChild(sourceFile, (tsNode) => {
|
|
97
|
+
if (typescript_1.default.isImportDeclaration(tsNode)) {
|
|
120
98
|
if (tsNode.importClause) {
|
|
121
99
|
const { name, namedBindings } = tsNode.importClause;
|
|
122
100
|
if (name && name.getText() === identifier) {
|
|
123
101
|
importSpecifier = tsNode.moduleSpecifier;
|
|
124
102
|
return true;
|
|
125
103
|
}
|
|
126
|
-
else if (namedBindings && namedBindings.kind ===
|
|
104
|
+
else if (namedBindings && namedBindings.kind === typescript_1.default.SyntaxKind.NamedImports) {
|
|
127
105
|
const elements = namedBindings.elements;
|
|
128
106
|
for (let elem of elements) {
|
|
129
107
|
if (elem.name.getText() === identifier) {
|
|
@@ -139,6 +117,3 @@ class AstroPlugin {
|
|
|
139
117
|
}
|
|
140
118
|
}
|
|
141
119
|
exports.AstroPlugin = AstroPlugin;
|
|
142
|
-
function isNodeExported(node) {
|
|
143
|
-
return (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Export) !== 0 || (!!node.parent && node.parent.kind === ts.SyntaxKind.SourceFile);
|
|
144
|
-
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { AppCompletionList } from '../../interfaces';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AstroDocument, DocumentManager } from '../../../core/documents';
|
|
3
3
|
import { CompletionContext, Position } from 'vscode-languageserver';
|
|
4
4
|
import { LanguageServiceManager as TypeScriptLanguageServiceManager } from '../../typescript/LanguageServiceManager';
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class CompletionsProviderImpl {
|
|
6
6
|
private readonly docManager;
|
|
7
|
-
private readonly
|
|
8
|
-
constructor(docManager: DocumentManager,
|
|
9
|
-
getCompletions(document:
|
|
7
|
+
private readonly languageServiceManager;
|
|
8
|
+
constructor(docManager: DocumentManager, languageServiceManager: TypeScriptLanguageServiceManager);
|
|
9
|
+
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList | null>;
|
|
10
10
|
private getClientHintCompletion;
|
|
11
11
|
private getComponentScriptCompletion;
|
|
12
12
|
private getPropCompletions;
|
|
@@ -1,38 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
6
|
+
exports.CompletionsProviderImpl = void 0;
|
|
27
7
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
28
|
-
const
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
29
9
|
const utils_1 = require("../../../core/documents/utils");
|
|
30
10
|
const utils_2 = require("../../../utils");
|
|
31
11
|
const utils_3 = require("../../typescript/utils");
|
|
32
|
-
class
|
|
33
|
-
constructor(docManager,
|
|
12
|
+
class CompletionsProviderImpl {
|
|
13
|
+
constructor(docManager, languageServiceManager) {
|
|
34
14
|
this.docManager = docManager;
|
|
35
|
-
this.
|
|
15
|
+
this.languageServiceManager = languageServiceManager;
|
|
36
16
|
}
|
|
37
17
|
async getCompletions(document, position, completionContext) {
|
|
38
18
|
const doc = this.docManager.get(document.uri);
|
|
@@ -80,8 +60,8 @@ class CompletionProvider {
|
|
|
80
60
|
{
|
|
81
61
|
label: ':media',
|
|
82
62
|
insertText: 'media',
|
|
83
|
-
commitCharacters: ['m']
|
|
84
|
-
}
|
|
63
|
+
commitCharacters: ['m'],
|
|
64
|
+
},
|
|
85
65
|
];
|
|
86
66
|
}
|
|
87
67
|
getComponentScriptCompletion(document, position, completionContext) {
|
|
@@ -95,18 +75,22 @@ class CompletionProvider {
|
|
|
95
75
|
commitCharacters: ['-'],
|
|
96
76
|
};
|
|
97
77
|
const prefix = document.getLineUntilOffset(document.offsetAt(position));
|
|
98
|
-
if (document.
|
|
78
|
+
if (document.astroMeta.frontmatter.state === null) {
|
|
99
79
|
return {
|
|
100
80
|
...base,
|
|
101
81
|
insertText: '---\n$0\n---',
|
|
102
|
-
textEdit: prefix.match(/^\s*\-+/)
|
|
82
|
+
textEdit: prefix.match(/^\s*\-+/)
|
|
83
|
+
? vscode_languageserver_1.TextEdit.replace({ start: { ...position, character: 0 }, end: position }, '---\n$0\n---')
|
|
84
|
+
: undefined,
|
|
103
85
|
};
|
|
104
86
|
}
|
|
105
|
-
if (document.
|
|
87
|
+
if (document.astroMeta.frontmatter.state === 'open') {
|
|
106
88
|
return {
|
|
107
89
|
...base,
|
|
108
90
|
insertText: '---',
|
|
109
|
-
textEdit: prefix.match(/^\s*\-+/)
|
|
91
|
+
textEdit: prefix.match(/^\s*\-+/)
|
|
92
|
+
? vscode_languageserver_1.TextEdit.replace({ start: { ...position, character: 0 }, end: position }, '---')
|
|
93
|
+
: undefined,
|
|
110
94
|
};
|
|
111
95
|
}
|
|
112
96
|
return null;
|
|
@@ -127,15 +111,17 @@ class CompletionProvider {
|
|
|
127
111
|
return [];
|
|
128
112
|
}
|
|
129
113
|
// If inside of attribute value, skip.
|
|
130
|
-
if (completionContext &&
|
|
114
|
+
if (completionContext &&
|
|
115
|
+
completionContext.triggerKind === vscode_languageserver_1.CompletionTriggerKind.TriggerCharacter &&
|
|
116
|
+
completionContext.triggerCharacter === '"') {
|
|
131
117
|
return [];
|
|
132
118
|
}
|
|
133
119
|
const componentName = node.tag;
|
|
134
|
-
const { lang
|
|
120
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
135
121
|
// Get the source file
|
|
136
122
|
const filePath = (0, utils_2.urlToPath)(document.uri);
|
|
137
123
|
const tsFilePath = (0, utils_3.toVirtualAstroFilePath)(filePath);
|
|
138
|
-
const program =
|
|
124
|
+
const program = lang.getProgram();
|
|
139
125
|
const sourceFile = program === null || program === void 0 ? void 0 : program.getSourceFile(tsFilePath);
|
|
140
126
|
const typeChecker = program === null || program === void 0 ? void 0 : program.getTypeChecker();
|
|
141
127
|
if (!sourceFile || !typeChecker) {
|
|
@@ -156,14 +142,14 @@ class CompletionProvider {
|
|
|
156
142
|
// Add completions for this types props
|
|
157
143
|
for (let baseType of componentType.getBaseTypes() || []) {
|
|
158
144
|
const members = ((_a = baseType.getSymbol()) === null || _a === void 0 ? void 0 : _a.members) || [];
|
|
159
|
-
members.forEach(mem => {
|
|
145
|
+
members.forEach((mem) => {
|
|
160
146
|
let completionItem = this.getCompletionItemForTypeMember(mem, typeChecker);
|
|
161
147
|
completionItems.push(completionItem);
|
|
162
148
|
});
|
|
163
149
|
}
|
|
164
150
|
// Add completions for this types base members
|
|
165
151
|
const members = ((_b = componentType.getSymbol()) === null || _b === void 0 ? void 0 : _b.members) || [];
|
|
166
|
-
members.forEach(mem => {
|
|
152
|
+
members.forEach((mem) => {
|
|
167
153
|
let completionItem = this.getCompletionItemForTypeMember(mem, typeChecker);
|
|
168
154
|
completionItems.push(completionItem);
|
|
169
155
|
});
|
|
@@ -172,19 +158,20 @@ class CompletionProvider {
|
|
|
172
158
|
getImportedSymbol(sourceFile, identifier) {
|
|
173
159
|
for (let list of sourceFile.getChildren()) {
|
|
174
160
|
for (let node of list.getChildren()) {
|
|
175
|
-
if (
|
|
161
|
+
if (typescript_1.default.isImportDeclaration(node)) {
|
|
176
162
|
let clauses = node.importClause;
|
|
177
163
|
if (!clauses)
|
|
178
164
|
return null;
|
|
179
165
|
let namedImport = clauses.getChildAt(0);
|
|
180
|
-
if (
|
|
181
|
-
for (let imp of namedImport.elements) {
|
|
166
|
+
if (typescript_1.default.isNamedImports(namedImport)) {
|
|
167
|
+
for (let imp of namedImport.elements) {
|
|
168
|
+
// Iterate the named imports
|
|
182
169
|
if (imp.name.getText() === identifier) {
|
|
183
170
|
return imp;
|
|
184
171
|
}
|
|
185
172
|
}
|
|
186
173
|
}
|
|
187
|
-
else if (
|
|
174
|
+
else if (typescript_1.default.isIdentifier(namedImport)) {
|
|
188
175
|
if (namedImport.getText() === identifier) {
|
|
189
176
|
return namedImport;
|
|
190
177
|
}
|
|
@@ -200,21 +187,9 @@ class CompletionProvider {
|
|
|
200
187
|
return null;
|
|
201
188
|
}
|
|
202
189
|
for (const decl of (sym === null || sym === void 0 ? void 0 : sym.getDeclarations()) || []) {
|
|
203
|
-
const fileName = decl.getSourceFile().fileName;
|
|
204
|
-
if ((
|
|
205
|
-
if (!
|
|
206
|
-
console.error(`Unexpected: .astro files should export a default function for the component definition.`);
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
const fn = decl;
|
|
210
|
-
if (!fn.parameters.length)
|
|
211
|
-
continue;
|
|
212
|
-
const param1 = fn.parameters[0];
|
|
213
|
-
const type = typeChecker.getTypeAtLocation(param1);
|
|
214
|
-
return type;
|
|
215
|
-
}
|
|
216
|
-
else if (fileName.endsWith('.tsx') || fileName.endsWith('.jsx')) {
|
|
217
|
-
if (!ts.isFunctionDeclaration(decl)) {
|
|
190
|
+
const fileName = (0, utils_3.toVirtualFilePath)(decl.getSourceFile().fileName);
|
|
191
|
+
if (fileName.endsWith('.tsx') || fileName.endsWith('.jsx')) {
|
|
192
|
+
if (!typescript_1.default.isFunctionDeclaration(decl)) {
|
|
218
193
|
console.error(`We only support function components for tsx/jsx at the moment.`);
|
|
219
194
|
continue;
|
|
220
195
|
}
|
|
@@ -259,4 +234,4 @@ class CompletionProvider {
|
|
|
259
234
|
return (0, utils_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position));
|
|
260
235
|
}
|
|
261
236
|
}
|
|
262
|
-
exports.
|
|
237
|
+
exports.CompletionsProviderImpl = CompletionsProviderImpl;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Stylesheet, TextDocument } from 'vscode-css-languageservice';
|
|
2
2
|
import { Position } from 'vscode-languageserver';
|
|
3
|
-
import {
|
|
3
|
+
import { AstroDocument, DocumentMapper, ReadableDocument, TagInformation } from '../../core/documents';
|
|
4
4
|
export interface CSSDocumentBase extends DocumentMapper, TextDocument {
|
|
5
5
|
languageId: string;
|
|
6
6
|
stylesheet: Stylesheet;
|
|
@@ -11,7 +11,7 @@ export declare class CSSDocument extends ReadableDocument implements DocumentMap
|
|
|
11
11
|
readonly version: number;
|
|
12
12
|
stylesheet: Stylesheet;
|
|
13
13
|
languageId: string;
|
|
14
|
-
constructor(parent:
|
|
14
|
+
constructor(parent: AstroDocument, styleInfo: Pick<TagInformation, 'attributes' | 'start' | 'end'>);
|
|
15
15
|
/**
|
|
16
16
|
* Get the fragment position relative to the parent
|
|
17
17
|
* @param pos Position in fragment
|
|
@@ -32,7 +32,7 @@ export declare class CSSDocument extends ReadableDocument implements DocumentMap
|
|
|
32
32
|
*/
|
|
33
33
|
getText(): string;
|
|
34
34
|
/**
|
|
35
|
-
* Returns the length of the fragment as calculated from the start and end
|
|
35
|
+
* Returns the length of the fragment as calculated from the start and end position
|
|
36
36
|
*/
|
|
37
37
|
getTextLength(): number;
|
|
38
38
|
/**
|
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CSSDocument = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
class CSSDocument extends
|
|
7
|
-
constructor(parent) {
|
|
4
|
+
const language_service_1 = require("./language-service");
|
|
5
|
+
const documents_1 = require("../../core/documents");
|
|
6
|
+
class CSSDocument extends documents_1.ReadableDocument {
|
|
7
|
+
constructor(parent, styleInfo) {
|
|
8
8
|
super();
|
|
9
9
|
this.parent = parent;
|
|
10
|
+
this.styleInfo = styleInfo;
|
|
10
11
|
this.version = this.parent.version;
|
|
11
|
-
if (this.parent.styleInfo) {
|
|
12
|
-
this.styleInfo = this.parent.styleInfo;
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
this.styleInfo = {
|
|
16
|
-
attributes: {},
|
|
17
|
-
start: -1,
|
|
18
|
-
end: -1,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
12
|
this.languageId = this.language;
|
|
22
|
-
this.stylesheet = (0,
|
|
13
|
+
this.stylesheet = (0, language_service_1.getLanguageService)(this.language).parseStylesheet(this);
|
|
23
14
|
}
|
|
24
15
|
/**
|
|
25
16
|
* Get the fragment position relative to the parent
|
|
@@ -52,7 +43,7 @@ class CSSDocument extends index_1.ReadableDocument {
|
|
|
52
43
|
return this.parent.getText().slice(this.styleInfo.start, this.styleInfo.end);
|
|
53
44
|
}
|
|
54
45
|
/**
|
|
55
|
-
* Returns the length of the fragment as calculated from the start and end
|
|
46
|
+
* Returns the length of the fragment as calculated from the start and end position
|
|
56
47
|
*/
|
|
57
48
|
getTextLength() {
|
|
58
49
|
return this.styleInfo.end - this.styleInfo.start;
|
|
@@ -1,17 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
export declare class CSSPlugin implements
|
|
6
|
-
|
|
1
|
+
import { Color, ColorInformation, ColorPresentation, CompletionContext, CompletionList, Hover, Position, Range, SymbolInformation } from 'vscode-languageserver';
|
|
2
|
+
import { ConfigManager } from '../../core/config/ConfigManager';
|
|
3
|
+
import { AstroDocument } from '../../core/documents';
|
|
4
|
+
import type { Plugin } from '../interfaces';
|
|
5
|
+
export declare class CSSPlugin implements Plugin {
|
|
6
|
+
__name: string;
|
|
7
7
|
private configManager;
|
|
8
|
-
private
|
|
8
|
+
private cssDocuments;
|
|
9
9
|
private triggerCharacters;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
constructor(configManager: ConfigManager);
|
|
11
|
+
doHover(document: AstroDocument, position: Position): Hover | null;
|
|
12
|
+
private doHoverInternal;
|
|
13
|
+
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): CompletionList | null;
|
|
13
14
|
private getCompletionsInternal;
|
|
15
|
+
getDocumentColors(document: AstroDocument): ColorInformation[];
|
|
16
|
+
getColorPresentations(document: AstroDocument, range: Range, color: Color): ColorPresentation[];
|
|
17
|
+
getDocumentSymbols(document: AstroDocument): SymbolInformation[];
|
|
14
18
|
private inStyleAttributeWithoutInterpolation;
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Get the associated CSS Document for a style tag
|
|
21
|
+
*/
|
|
22
|
+
private getCSSDocumentForStyleTag;
|
|
23
|
+
/**
|
|
24
|
+
* Get all the CSSDocuments in a document
|
|
25
|
+
*/
|
|
26
|
+
private getCSSDocumentsForDocument;
|
|
27
|
+
/**
|
|
28
|
+
* Get all the stylesheets (Stylesheet type) in a document
|
|
29
|
+
*/
|
|
30
|
+
private getStylesheetsForDocument;
|
|
31
|
+
/**
|
|
32
|
+
* Get style tag at position for a document
|
|
33
|
+
*/
|
|
34
|
+
private getStyleTagForPosition;
|
|
35
|
+
private featureEnabled;
|
|
17
36
|
}
|