@astrojs/language-server 0.23.2 → 0.24.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 +23 -0
- package/dist/browser.js +8 -1
- package/dist/check.d.ts +2 -1
- package/dist/check.js +8 -2
- package/dist/core/DiagnosticsManager.d.ts +2 -2
- package/dist/core/config/ConfigManager.d.ts +5 -6
- package/dist/core/config/ConfigManager.js +2 -9
- package/dist/core/documents/AstroDocument.d.ts +1 -1
- package/dist/core/documents/AstroDocument.js +1 -1
- package/dist/core/documents/DocumentBase.d.ts +2 -2
- package/dist/core/documents/DocumentManager.d.ts +1 -1
- package/dist/core/documents/DocumentManager.js +1 -1
- package/dist/core/documents/DocumentMapper.d.ts +2 -2
- package/dist/core/documents/parseHtml.d.ts +3 -2
- package/dist/core/documents/parseHtml.js +12 -5
- package/dist/core/documents/utils.d.ts +3 -3
- package/dist/core/documents/utils.js +1 -2
- package/dist/node.js +15 -1
- package/dist/plugins/PluginHost.d.ts +2 -2
- package/dist/plugins/PluginHost.js +1 -1
- package/dist/plugins/astro/AstroPlugin.d.ts +6 -5
- package/dist/plugins/astro/AstroPlugin.js +1 -0
- package/dist/plugins/astro/features/CompletionsProvider.d.ts +4 -3
- package/dist/plugins/astro/features/CompletionsProvider.js +12 -15
- package/dist/plugins/css/CSSDocument.d.ts +2 -2
- package/dist/plugins/css/CSSDocument.js +1 -1
- package/dist/plugins/css/CSSPlugin.d.ts +1 -1
- package/dist/plugins/css/CSSPlugin.js +3 -3
- package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
- package/dist/plugins/css/StyleAttributeDocument.js +1 -1
- package/dist/plugins/css/features/astro-selectors.d.ts +1 -1
- package/dist/plugins/css/features/getIdClassCompletions.d.ts +2 -2
- package/dist/plugins/html/HTMLPlugin.d.ts +3 -3
- package/dist/plugins/html/HTMLPlugin.js +1 -1
- package/dist/plugins/html/utils.d.ts +1 -1
- package/dist/plugins/index.d.ts +4 -4
- package/dist/plugins/index.js +4 -4
- package/dist/plugins/interfaces.d.ts +2 -2
- package/dist/plugins/typescript/LanguageServiceManager.d.ts +8 -9
- package/dist/plugins/typescript/LanguageServiceManager.js +5 -3
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +7 -6
- package/dist/plugins/typescript/TypeScriptPlugin.js +15 -15
- package/dist/plugins/typescript/astro-sys.d.ts +2 -3
- package/dist/plugins/typescript/astro-sys.js +7 -11
- package/dist/plugins/typescript/astro2tsx.js +3 -4
- package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +5 -4
- package/dist/plugins/typescript/features/CodeActionsProvider.js +6 -9
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +9 -7
- package/dist/plugins/typescript/features/CompletionsProvider.js +56 -80
- package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +4 -4
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +6 -4
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +29 -19
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +3 -2
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +3 -4
- package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +7 -4
- package/dist/plugins/typescript/features/FoldingRangesProvider.js +12 -15
- package/dist/plugins/typescript/features/HoverProvider.d.ts +5 -4
- package/dist/plugins/typescript/features/HoverProvider.js +3 -6
- package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +5 -4
- package/dist/plugins/typescript/features/InlayHintsProvider.js +5 -8
- package/dist/plugins/typescript/features/SemanticTokenProvider.d.ts +3 -2
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +4 -7
- package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +5 -4
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +7 -10
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +3 -3
- package/dist/plugins/typescript/features/utils.d.ts +3 -3
- package/dist/plugins/typescript/language-service.d.ts +7 -6
- package/dist/plugins/typescript/language-service.js +29 -30
- package/dist/plugins/typescript/module-loader.d.ts +2 -2
- package/dist/plugins/typescript/module-loader.js +12 -16
- package/dist/plugins/typescript/previewer.d.ts +3 -7
- package/dist/plugins/typescript/previewer.js +13 -17
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +4 -5
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +2 -7
- package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +5 -2
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +15 -17
- package/dist/plugins/typescript/snapshots/utils.d.ts +7 -7
- package/dist/plugins/typescript/snapshots/utils.js +28 -29
- package/dist/plugins/typescript/utils.d.ts +8 -10
- package/dist/plugins/typescript/utils.js +90 -107
- package/dist/server.d.ts +5 -1
- package/dist/server.js +27 -17
- package/dist/utils.d.ts +1 -1
- package/package.json +5 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CodeAction, CodeActionContext, Color,
|
|
2
|
-
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
1
|
+
import type { CodeAction, CodeActionContext, Color, ColorInformation, ColorPresentation, CompletionContext, CompletionItem, CompletionList, DefinitionLink, Diagnostic, FileChangeType, FoldingRange, FormattingOptions, Hover, InlayHint, LinkedEditingRanges, Location, Position, Range, ReferenceContext, SelectionRange, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, TextDocumentIdentifier, TextEdit, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
3
|
export declare type Resolvable<T> = T | Promise<T>;
|
|
4
4
|
export interface AppCompletionItem<T extends TextDocumentIdentifier = any> extends CompletionItem {
|
|
5
5
|
data?: T;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { DocumentSnapshot } from './snapshots/DocumentSnapshot';
|
|
1
|
+
import type { TextDocumentContentChangeEvent } from 'vscode-languageserver';
|
|
2
|
+
import type { ConfigManager } from '../../core/config';
|
|
3
|
+
import type { AstroDocument, DocumentManager } from '../../core/documents';
|
|
4
|
+
import { LanguageServiceContainer, LanguageServiceDocumentContext } from './language-service';
|
|
5
|
+
import type { DocumentSnapshot } from './snapshots/DocumentSnapshot';
|
|
7
6
|
export declare class LanguageServiceManager {
|
|
8
7
|
private readonly docManager;
|
|
9
8
|
private readonly workspaceUris;
|
|
10
9
|
private readonly configManager;
|
|
11
|
-
|
|
10
|
+
docContext: LanguageServiceDocumentContext;
|
|
12
11
|
private globalSnapshotManager;
|
|
13
|
-
constructor(docManager: DocumentManager, workspaceUris: string[], configManager: ConfigManager);
|
|
12
|
+
constructor(docManager: DocumentManager, workspaceUris: string[], configManager: ConfigManager, ts: typeof import('typescript/lib/tsserverlibrary'), tsLocalized?: Record<string, string> | undefined);
|
|
14
13
|
/**
|
|
15
14
|
* Create an AstroDocument (only for astro files)
|
|
16
15
|
*/
|
|
@@ -37,6 +36,6 @@ export declare class LanguageServiceManager {
|
|
|
37
36
|
tsDoc: DocumentSnapshot;
|
|
38
37
|
lang: ts.LanguageService;
|
|
39
38
|
}>;
|
|
40
|
-
getLSForPath(path: string): Promise<
|
|
39
|
+
getLSForPath(path: string): Promise<import("typescript/lib/tsserverlibrary").LanguageService>;
|
|
41
40
|
getTypeScriptLanguageService(filePath: string): Promise<LanguageServiceContainer>;
|
|
42
41
|
}
|
|
@@ -5,11 +5,10 @@ const utils_1 = require("../../utils");
|
|
|
5
5
|
const language_service_1 = require("./language-service");
|
|
6
6
|
const SnapshotManager_1 = require("./snapshots/SnapshotManager");
|
|
7
7
|
class LanguageServiceManager {
|
|
8
|
-
constructor(docManager, workspaceUris, configManager) {
|
|
8
|
+
constructor(docManager, workspaceUris, configManager, ts, tsLocalized) {
|
|
9
9
|
this.docManager = docManager;
|
|
10
10
|
this.workspaceUris = workspaceUris;
|
|
11
11
|
this.configManager = configManager;
|
|
12
|
-
this.globalSnapshotManager = new SnapshotManager_1.GlobalSnapshotManager();
|
|
13
12
|
/**
|
|
14
13
|
* Create an AstroDocument (only for astro files)
|
|
15
14
|
*/
|
|
@@ -22,10 +21,13 @@ class LanguageServiceManager {
|
|
|
22
21
|
this.docManager.lockDocument(uri);
|
|
23
22
|
return document;
|
|
24
23
|
};
|
|
24
|
+
this.globalSnapshotManager = new SnapshotManager_1.GlobalSnapshotManager(ts);
|
|
25
25
|
this.docContext = {
|
|
26
26
|
createDocument: this.createDocument,
|
|
27
27
|
globalSnapshotManager: this.globalSnapshotManager,
|
|
28
28
|
configManager: this.configManager,
|
|
29
|
+
ts,
|
|
30
|
+
tsLocalized: tsLocalized,
|
|
29
31
|
};
|
|
30
32
|
const handleDocumentChange = (document) => {
|
|
31
33
|
this.getSnapshot(document);
|
|
@@ -36,7 +38,7 @@ class LanguageServiceManager {
|
|
|
36
38
|
async getSnapshot(pathOrDoc) {
|
|
37
39
|
const filePath = typeof pathOrDoc === 'string' ? pathOrDoc : pathOrDoc.getFilePath() || '';
|
|
38
40
|
const tsService = await this.getTypeScriptLanguageService(filePath);
|
|
39
|
-
return tsService.updateSnapshot(pathOrDoc);
|
|
41
|
+
return tsService.updateSnapshot(pathOrDoc, this.docContext.ts);
|
|
40
42
|
}
|
|
41
43
|
/**
|
|
42
44
|
* Updates snapshot path in all existing ts services and retrieves snapshot
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CancellationToken, CodeAction, CodeActionContext, CompletionContext, DefinitionLink,
|
|
2
|
-
import { ConfigManager } from '../../core/config';
|
|
3
|
-
import { AstroDocument } from '../../core/documents';
|
|
4
|
-
import { AppCompletionItem, AppCompletionList, OnWatchFileChangesParam, Plugin } from '../interfaces';
|
|
5
|
-
import { CompletionItemData } from './features/CompletionsProvider';
|
|
6
|
-
import { LanguageServiceManager } from './LanguageServiceManager';
|
|
1
|
+
import { CancellationToken, CodeAction, CodeActionContext, CompletionContext, DefinitionLink, Diagnostic, FoldingRange, Hover, InlayHint, Location, Position, Range, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
|
+
import type { ConfigManager } from '../../core/config';
|
|
3
|
+
import type { AstroDocument } from '../../core/documents';
|
|
4
|
+
import type { AppCompletionItem, AppCompletionList, OnWatchFileChangesParam, Plugin } from '../interfaces';
|
|
7
5
|
import { Astro2TSXResult } from './astro2tsx';
|
|
6
|
+
import { CompletionItemData } from './features/CompletionsProvider';
|
|
7
|
+
import type { LanguageServiceManager } from './LanguageServiceManager';
|
|
8
8
|
export declare class TypeScriptPlugin implements Plugin {
|
|
9
9
|
__name: string;
|
|
10
10
|
private configManager;
|
|
@@ -20,6 +20,7 @@ export declare class TypeScriptPlugin implements Plugin {
|
|
|
20
20
|
private readonly inlayHintsProvider;
|
|
21
21
|
private readonly semanticTokensProvider;
|
|
22
22
|
private readonly foldingRangesProvider;
|
|
23
|
+
private readonly ts;
|
|
23
24
|
constructor(configManager: ConfigManager, languageServiceManager: LanguageServiceManager);
|
|
24
25
|
doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
|
|
25
26
|
rename(document: AstroDocument, position: Position, newName: string): Promise<WorkspaceEdit | null>;
|
|
@@ -4,27 +4,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TypeScriptPlugin = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
8
7
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
8
|
+
const astro2tsx_1 = __importDefault(require("./astro2tsx"));
|
|
9
|
+
const CodeActionsProvider_1 = require("./features/CodeActionsProvider");
|
|
9
10
|
const CompletionsProvider_1 = require("./features/CompletionsProvider");
|
|
11
|
+
const DefinitionsProvider_1 = require("./features/DefinitionsProvider");
|
|
10
12
|
const DiagnosticsProvider_1 = require("./features/DiagnosticsProvider");
|
|
11
|
-
const HoverProvider_1 = require("./features/HoverProvider");
|
|
12
|
-
const SignatureHelpProvider_1 = require("./features/SignatureHelpProvider");
|
|
13
|
-
const utils_1 = require("./utils");
|
|
14
13
|
const DocumentSymbolsProvider_1 = require("./features/DocumentSymbolsProvider");
|
|
15
|
-
const SemanticTokenProvider_1 = require("./features/SemanticTokenProvider");
|
|
16
14
|
const FoldingRangesProvider_1 = require("./features/FoldingRangesProvider");
|
|
17
|
-
const
|
|
18
|
-
const DefinitionsProvider_1 = require("./features/DefinitionsProvider");
|
|
15
|
+
const HoverProvider_1 = require("./features/HoverProvider");
|
|
19
16
|
const InlayHintsProvider_1 = require("./features/InlayHintsProvider");
|
|
20
|
-
const
|
|
21
|
-
const
|
|
17
|
+
const SemanticTokenProvider_1 = require("./features/SemanticTokenProvider");
|
|
18
|
+
const SignatureHelpProvider_1 = require("./features/SignatureHelpProvider");
|
|
22
19
|
const TypeDefinitionsProvider_1 = require("./features/TypeDefinitionsProvider");
|
|
20
|
+
const utils_1 = require("./snapshots/utils");
|
|
21
|
+
const utils_2 = require("./utils");
|
|
23
22
|
class TypeScriptPlugin {
|
|
24
23
|
constructor(configManager, languageServiceManager) {
|
|
25
24
|
this.__name = 'typescript';
|
|
26
25
|
this.configManager = configManager;
|
|
27
26
|
this.languageServiceManager = languageServiceManager;
|
|
27
|
+
this.ts = languageServiceManager.docContext.ts;
|
|
28
28
|
this.codeActionsProvider = new CodeActionsProvider_1.CodeActionsProviderImpl(this.languageServiceManager, this.configManager);
|
|
29
29
|
this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(this.languageServiceManager, this.configManager);
|
|
30
30
|
this.hoverProvider = new HoverProvider_1.HoverProviderImpl(this.languageServiceManager);
|
|
@@ -47,7 +47,7 @@ class TypeScriptPlugin {
|
|
|
47
47
|
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
48
48
|
const fragment = await tsDoc.createFragment();
|
|
49
49
|
const offset = fragment.offsetAt(fragment.getGeneratedPosition(position));
|
|
50
|
-
let renames = lang.findRenameLocations((0,
|
|
50
|
+
let renames = lang.findRenameLocations((0, utils_2.toVirtualAstroFilePath)(tsDoc.filePath), offset, false, false, true);
|
|
51
51
|
if (!renames) {
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
@@ -55,13 +55,13 @@ class TypeScriptPlugin {
|
|
|
55
55
|
changes: {},
|
|
56
56
|
};
|
|
57
57
|
renames.forEach((rename) => {
|
|
58
|
-
const filePath = (0,
|
|
58
|
+
const filePath = (0, utils_2.ensureRealFilePath)(rename.fileName);
|
|
59
59
|
if (!(filePath in edit.changes)) {
|
|
60
60
|
edit.changes[filePath] = [];
|
|
61
61
|
}
|
|
62
62
|
edit.changes[filePath].push({
|
|
63
63
|
newText: newName,
|
|
64
|
-
range: (0,
|
|
64
|
+
range: (0, utils_2.convertToLocationRange)(fragment, rename.textSpan),
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
67
|
return edit;
|
|
@@ -116,8 +116,8 @@ class TypeScriptPlugin {
|
|
|
116
116
|
async onWatchFileChanges(onWatchFileChangesParas) {
|
|
117
117
|
let doneUpdateProjectFiles = false;
|
|
118
118
|
for (const { fileName, changeType } of onWatchFileChangesParas) {
|
|
119
|
-
const scriptKind = (0,
|
|
120
|
-
if (scriptKind ===
|
|
119
|
+
const scriptKind = (0, utils_2.getScriptKindFromFileName)(fileName, this.ts);
|
|
120
|
+
if (scriptKind === this.ts.ScriptKind.Unknown) {
|
|
121
121
|
continue;
|
|
122
122
|
}
|
|
123
123
|
if (changeType === vscode_languageserver_1.FileChangeType.Created && !doneUpdateProjectFiles) {
|
|
@@ -139,7 +139,7 @@ class TypeScriptPlugin {
|
|
|
139
139
|
return this.signatureHelpProvider.getSignatureHelp(document, position, context, cancellationToken);
|
|
140
140
|
}
|
|
141
141
|
getTSXForDocument(document) {
|
|
142
|
-
return (0, astro2tsx_1.default)(document.getText(), (0,
|
|
142
|
+
return (0, astro2tsx_1.default)(document.getText(), (0, utils_1.classNameFromFilename)(document.getURL()));
|
|
143
143
|
}
|
|
144
144
|
async featureEnabled(document, feature) {
|
|
145
145
|
return ((await this.configManager.isEnabled(document, 'typescript')) &&
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DocumentSnapshot } from './snapshots/DocumentSnapshot';
|
|
1
|
+
import type { DocumentSnapshot } from './snapshots/DocumentSnapshot';
|
|
3
2
|
/**
|
|
4
3
|
* This should only be accessed by TS Astro module resolution.
|
|
5
4
|
*/
|
|
6
|
-
export declare function createAstroSys(getSnapshot: (fileName: string) => DocumentSnapshot):
|
|
5
|
+
export declare function createAstroSys(getSnapshot: (fileName: string) => DocumentSnapshot, ts: typeof import('typescript/lib/tsserverlibrary')): import("typescript/lib/tsserverlibrary").System & {
|
|
7
6
|
deleteFromCache: (path: string) => void;
|
|
8
7
|
};
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.createAstroSys = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
8
4
|
const utils_1 = require("./utils");
|
|
9
5
|
/**
|
|
10
6
|
* This should only be accessed by TS Astro module resolution.
|
|
11
7
|
*/
|
|
12
|
-
function createAstroSys(getSnapshot) {
|
|
8
|
+
function createAstroSys(getSnapshot, ts) {
|
|
13
9
|
const fileExistsCache = new Map();
|
|
14
10
|
const AstroSys = {
|
|
15
|
-
...
|
|
11
|
+
...ts.sys,
|
|
16
12
|
fileExists(path) {
|
|
17
13
|
path = (0, utils_1.ensureRealFilePath)(path);
|
|
18
|
-
const exists = fileExistsCache.get(path) ??
|
|
14
|
+
const exists = fileExistsCache.get(path) ?? ts.sys.fileExists(path);
|
|
19
15
|
fileExistsCache.set(path, exists);
|
|
20
16
|
return exists;
|
|
21
17
|
},
|
|
@@ -25,19 +21,19 @@ function createAstroSys(getSnapshot) {
|
|
|
25
21
|
},
|
|
26
22
|
readDirectory(path, extensions, exclude, include, depth) {
|
|
27
23
|
const extensionsWithAstro = (extensions ?? []).concat(...['.astro', '.svelte', '.vue']);
|
|
28
|
-
const result =
|
|
24
|
+
const result = ts.sys.readDirectory(path, extensionsWithAstro, exclude, include, depth);
|
|
29
25
|
return result;
|
|
30
26
|
},
|
|
31
27
|
deleteFile(path) {
|
|
32
28
|
fileExistsCache.delete((0, utils_1.ensureRealFilePath)(path));
|
|
33
|
-
return
|
|
29
|
+
return ts.sys.deleteFile?.(path);
|
|
34
30
|
},
|
|
35
31
|
deleteFromCache(path) {
|
|
36
32
|
fileExistsCache.delete((0, utils_1.ensureRealFilePath)(path));
|
|
37
33
|
},
|
|
38
34
|
};
|
|
39
|
-
if (
|
|
40
|
-
const realpath =
|
|
35
|
+
if (ts.sys.realpath) {
|
|
36
|
+
const realpath = ts.sys.realpath;
|
|
41
37
|
AstroSys.realpath = function (path) {
|
|
42
38
|
if ((0, utils_1.isVirtualFilePath)(path)) {
|
|
43
39
|
return realpath((0, utils_1.ensureRealFilePath)(path)) + '.tsx';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const os_1 = require("os");
|
|
4
3
|
const parseAstro_1 = require("../../core/documents/parseAstro");
|
|
5
4
|
function addProps(content, className) {
|
|
6
5
|
let defaultExportType = 'Record<string, any>';
|
|
@@ -19,8 +18,8 @@ function addProps(content, className) {
|
|
|
19
18
|
shouldAddGlobal = true;
|
|
20
19
|
astroGlobal += ' & { props: Props }';
|
|
21
20
|
}
|
|
22
|
-
return (
|
|
23
|
-
(shouldAddGlobal ? astroGlobal +
|
|
21
|
+
return ('\n' +
|
|
22
|
+
(shouldAddGlobal ? astroGlobal + '\n' + astroGlobalConstDef : '') +
|
|
24
23
|
`export default function ${className}__AstroComponent_(_props: ${defaultExportType}): any {}`);
|
|
25
24
|
}
|
|
26
25
|
function escapeTemplateLiteralContent(content) {
|
|
@@ -88,7 +87,7 @@ function default_1(content, className) {
|
|
|
88
87
|
result.code =
|
|
89
88
|
frontMatterRaw +
|
|
90
89
|
htmlRaw +
|
|
91
|
-
|
|
90
|
+
'\n' +
|
|
92
91
|
// Add TypeScript definitions
|
|
93
92
|
addProps(frontMatterRaw, className);
|
|
94
93
|
return result;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { CancellationToken } from 'vscode-languageserver';
|
|
1
|
+
import type { CancellationToken } from 'vscode-languageserver';
|
|
2
2
|
import { CodeAction, CodeActionContext, Range } from 'vscode-languageserver-types';
|
|
3
|
-
import { ConfigManager } from '../../../core/config';
|
|
3
|
+
import type { ConfigManager } from '../../../core/config';
|
|
4
4
|
import { AstroDocument } from '../../../core/documents';
|
|
5
|
-
import { CodeActionsProvider } from '../../interfaces';
|
|
6
|
-
import { LanguageServiceManager } from '../LanguageServiceManager';
|
|
5
|
+
import type { CodeActionsProvider } from '../../interfaces';
|
|
6
|
+
import type { LanguageServiceManager } from '../LanguageServiceManager';
|
|
7
7
|
export declare const sortImportKind: string;
|
|
8
8
|
export declare class CodeActionsProviderImpl implements CodeActionsProvider {
|
|
9
9
|
private languageServiceManager;
|
|
10
10
|
private configManager;
|
|
11
|
+
private ts;
|
|
11
12
|
constructor(languageServiceManager: LanguageServiceManager, configManager: ConfigManager);
|
|
12
13
|
getCodeActions(document: AstroDocument, range: Range, context: CodeActionContext, cancellationToken?: CancellationToken): Promise<CodeAction[]>;
|
|
13
14
|
private getComponentQuickFix;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.CodeActionsProviderImpl = exports.sortImportKind = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
8
4
|
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
9
5
|
const documents_1 = require("../../../core/documents");
|
|
10
6
|
const utils_1 = require("../../../utils");
|
|
@@ -17,6 +13,7 @@ class CodeActionsProviderImpl {
|
|
|
17
13
|
constructor(languageServiceManager, configManager) {
|
|
18
14
|
this.languageServiceManager = languageServiceManager;
|
|
19
15
|
this.configManager = configManager;
|
|
16
|
+
this.ts = languageServiceManager.docContext.ts;
|
|
20
17
|
}
|
|
21
18
|
async getCodeActions(document, range, context, cancellationToken) {
|
|
22
19
|
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
@@ -71,11 +68,11 @@ class CodeActionsProviderImpl {
|
|
|
71
68
|
codeFixes =
|
|
72
69
|
codeFixes ?? lang.getCodeFixesAtPosition(filePath, start, end, errorCodes, formatOptions, tsPreferences);
|
|
73
70
|
}
|
|
74
|
-
const codeActions = codeFixes.map((fix) => codeFixToCodeAction(fix, context.diagnostics, context.only ? vscode_languageserver_types_1.CodeActionKind.QuickFix : vscode_languageserver_types_1.CodeActionKind.Empty, isInsideScript));
|
|
71
|
+
const codeActions = codeFixes.map((fix) => codeFixToCodeAction(fix, context.diagnostics, context.only ? vscode_languageserver_types_1.CodeActionKind.QuickFix : vscode_languageserver_types_1.CodeActionKind.Empty, isInsideScript, this.ts));
|
|
75
72
|
result.push(...codeActions);
|
|
76
73
|
}
|
|
77
74
|
return result;
|
|
78
|
-
function codeFixToCodeAction(codeFix, diagnostics, kind, isInsideScript) {
|
|
75
|
+
function codeFixToCodeAction(codeFix, diagnostics, kind, isInsideScript, ts) {
|
|
79
76
|
const documentChanges = codeFix.changes.map((change) => {
|
|
80
77
|
return vscode_languageserver_types_1.TextDocumentEdit.create(vscode_languageserver_types_1.OptionalVersionedTextDocumentIdentifier.create(document.getURL(), null), change.textChanges.map((edit) => {
|
|
81
78
|
let originalRange = (0, documents_1.mapRangeToOriginal)(fragment, (0, utils_2.convertRange)(fragment, edit.span));
|
|
@@ -83,7 +80,7 @@ class CodeActionsProviderImpl {
|
|
|
83
80
|
// restricted to the area of the script tag by default
|
|
84
81
|
if (!isInsideScript) {
|
|
85
82
|
if (codeFix.fixName === 'import') {
|
|
86
|
-
return (0, CompletionsProvider_1.codeActionChangeToTextEdit)(document, fragment, false, edit);
|
|
83
|
+
return (0, CompletionsProvider_1.codeActionChangeToTextEdit)(document, fragment, false, edit, ts);
|
|
87
84
|
}
|
|
88
85
|
if (codeFix.fixName === 'fixMissingFunctionDeclaration') {
|
|
89
86
|
originalRange = (0, utils_2.checkEndOfFileCodeInsert)(originalRange, document);
|
|
@@ -95,7 +92,7 @@ class CodeActionsProviderImpl {
|
|
|
95
92
|
const existingLine = (0, documents_1.getLineAtPosition)(document.positionAt(edit.span.start), document.getText());
|
|
96
93
|
const isNewImport = !existingLine.trim().startsWith('import');
|
|
97
94
|
if (!(edit.newText.startsWith('\n') || edit.newText.startsWith('\r\n')) && isNewImport) {
|
|
98
|
-
edit.newText =
|
|
95
|
+
edit.newText = ts.sys.newLine + edit.newText;
|
|
99
96
|
}
|
|
100
97
|
}
|
|
101
98
|
}
|
|
@@ -126,7 +123,7 @@ class CodeActionsProviderImpl {
|
|
|
126
123
|
const node = (0, utils_3.findContainingNode)(sourceFile, {
|
|
127
124
|
start,
|
|
128
125
|
length: end - start,
|
|
129
|
-
}, (n) =>
|
|
126
|
+
}, (n) => this.ts.isJsxClosingElement(n) || this.ts.isJsxOpeningLikeElement(n));
|
|
130
127
|
if (!node) {
|
|
131
128
|
return;
|
|
132
129
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import { CancellationToken, CompletionContext, Position, TextDocumentIdentifier, TextEdit } from 'vscode-languageserver';
|
|
3
|
+
import type { ConfigManager } from '../../../core/config';
|
|
3
4
|
import { AstroDocument } from '../../../core/documents';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { AstroSnapshotFragment } from '../snapshots/DocumentSnapshot';
|
|
7
|
-
import { ConfigManager } from '../../../core/config';
|
|
5
|
+
import type { AppCompletionItem, AppCompletionList, CompletionsProvider } from '../../interfaces';
|
|
6
|
+
import type { LanguageServiceManager } from '../LanguageServiceManager';
|
|
7
|
+
import type { AstroSnapshotFragment } from '../snapshots/DocumentSnapshot';
|
|
8
8
|
export interface CompletionItemData extends TextDocumentIdentifier {
|
|
9
9
|
filePath: string;
|
|
10
10
|
offset: number;
|
|
@@ -14,6 +14,7 @@ export interface CompletionItemData extends TextDocumentIdentifier {
|
|
|
14
14
|
export declare class CompletionsProviderImpl implements CompletionsProvider<CompletionItemData> {
|
|
15
15
|
private languageServiceManager;
|
|
16
16
|
private configManager;
|
|
17
|
+
private ts;
|
|
17
18
|
constructor(languageServiceManager: LanguageServiceManager, configManager: ConfigManager);
|
|
18
19
|
private readonly validTriggerCharacters;
|
|
19
20
|
private isValidTriggerCharacter;
|
|
@@ -31,5 +32,6 @@ export declare class CompletionsProviderImpl implements CompletionsProvider<Comp
|
|
|
31
32
|
private canReuseLastCompletion;
|
|
32
33
|
private getExistingImports;
|
|
33
34
|
private isAstroComponentImport;
|
|
35
|
+
private isValidCompletion;
|
|
34
36
|
}
|
|
35
|
-
export declare function codeActionChangeToTextEdit(document: AstroDocument, fragment: AstroSnapshotFragment, isInsideScriptTag: boolean, change: ts.TextChange): TextEdit;
|
|
37
|
+
export declare function codeActionChangeToTextEdit(document: AstroDocument, fragment: AstroSnapshotFragment, isInsideScriptTag: boolean, change: ts.TextChange, ts: typeof import('typescript/lib/tsserverlibrary')): TextEdit;
|