@astrojs/language-server 0.9.2 → 0.12.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 +22 -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 +6 -1
- 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 +37 -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 +6 -2
- 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 +8 -9
- package/dist/plugins/PluginHost.js +22 -36
- package/dist/plugins/astro/AstroPlugin.d.ts +11 -12
- package/dist/plugins/astro/AstroPlugin.js +17 -38
- package/dist/plugins/astro/features/{CompletionProvider.d.ts → CompletionsProvider.d.ts} +5 -5
- package/dist/plugins/astro/features/{CompletionProvider.js → CompletionsProvider.js} +33 -54
- package/dist/plugins/css/CSSDocument.d.ts +3 -3
- package/dist/plugins/css/CSSDocument.js +7 -16
- package/dist/plugins/css/CSSPlugin.d.ts +19 -11
- package/dist/plugins/css/CSSPlugin.js +63 -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 +15 -17
- package/dist/plugins/html/HTMLPlugin.js +33 -41
- package/dist/plugins/index.d.ts +2 -2
- package/dist/plugins/index.js +7 -3
- 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 +16 -23
- package/dist/plugins/typescript/TypeScriptPlugin.js +48 -56
- package/dist/plugins/typescript/astro-sys.d.ts +5 -3
- package/dist/plugins/typescript/astro-sys.js +24 -41
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +6 -6
- package/dist/plugins/typescript/features/CompletionsProvider.js +17 -33
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +4 -4
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +22 -61
- 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 +227 -0
- package/dist/plugins/typescript/module-loader.d.ts +5 -8
- package/dist/plugins/typescript/module-loader.js +43 -23
- package/dist/plugins/typescript/{DocumentSnapshot.d.ts → snapshots/DocumentSnapshot.d.ts} +45 -42
- 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 -11
- package/dist/plugins/typescript/utils.js +122 -151
- package/dist/server.d.ts +2 -4
- package/dist/server.js +88 -54
- package/dist/utils.d.ts +16 -8
- package/dist/utils.js +29 -14
- package/package.json +19 -13
- 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.js +0 -202
- package/dist/plugins/typescript/SnapshotManager.d.ts +0 -24
- package/dist/plugins/typescript/SnapshotManager.js +0 -97
- package/dist/plugins/typescript/languageService.d.ts +0 -17
- package/dist/plugins/typescript/languageService.js +0 -169
- package/types/index.d.ts +0 -4
|
@@ -1,81 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HTMLPlugin = void 0;
|
|
4
|
+
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
4
5
|
const emmet_helper_1 = require("@vscode/emmet-helper");
|
|
5
6
|
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
6
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
7
7
|
const utils_1 = require("../../core/documents/utils");
|
|
8
8
|
class HTMLPlugin {
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(configManager) {
|
|
10
|
+
this.__name = 'html';
|
|
10
11
|
this.lang = (0, vscode_html_languageservice_1.getLanguageService)();
|
|
11
|
-
this.
|
|
12
|
-
this.styleScriptTemplate = new Set(['template', 'style', 'script']);
|
|
13
|
-
this.pluginName = 'HTML';
|
|
14
|
-
docManager.on('documentChange', (document) => {
|
|
15
|
-
this.documents.set(document, document.html);
|
|
16
|
-
});
|
|
12
|
+
this.styleScriptTemplate = new Set(['style']);
|
|
17
13
|
this.configManager = configManager;
|
|
18
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Get HTML completions
|
|
17
|
+
*/
|
|
19
18
|
getCompletions(document, position) {
|
|
20
|
-
|
|
21
|
-
if (!html) {
|
|
19
|
+
if (!this.featureEnabled('completions')) {
|
|
22
20
|
return null;
|
|
23
21
|
}
|
|
24
|
-
|
|
22
|
+
const html = document.html;
|
|
23
|
+
const offset = document.offsetAt(position);
|
|
24
|
+
if (!html ||
|
|
25
|
+
(0, utils_1.isInsideFrontmatter)(document.getText(), offset) ||
|
|
26
|
+
(0, utils_1.isInsideExpression)(document.getText(), html.findNodeAt(offset).start, offset)) {
|
|
25
27
|
return null;
|
|
26
28
|
}
|
|
29
|
+
// Get Emmet completions
|
|
27
30
|
let emmetResults = {
|
|
28
31
|
isIncomplete: true,
|
|
29
32
|
items: [],
|
|
30
33
|
};
|
|
31
34
|
this.lang.setCompletionParticipants([
|
|
32
35
|
{
|
|
33
|
-
onHtmlContent: () => (emmetResults =
|
|
36
|
+
onHtmlContent: () => (emmetResults =
|
|
37
|
+
(0, emmet_helper_1.doComplete)(document, position, 'html', this.configManager.getEmmetConfig()) || emmetResults),
|
|
34
38
|
},
|
|
35
39
|
]);
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
+
// If we're in a component starting tag, we do not want HTML language completions
|
|
41
|
+
// as HTML attributes are not valid for components
|
|
42
|
+
const results = (0, utils_1.isInComponentStartTag)(html, document.offsetAt(position))
|
|
43
|
+
? vscode_languageserver_1.CompletionList.create([])
|
|
44
|
+
: this.lang.doComplete(document, position, html);
|
|
45
|
+
return vscode_languageserver_1.CompletionList.create([...results.items, ...this.getLangCompletions(results.items), ...emmetResults.items],
|
|
40
46
|
// Emmet completions change on every keystroke, so they are never complete
|
|
41
47
|
emmetResults.items.length > 0);
|
|
42
48
|
}
|
|
43
49
|
getFoldingRanges(document) {
|
|
44
|
-
const html =
|
|
50
|
+
const html = document.html;
|
|
45
51
|
if (!html) {
|
|
46
52
|
return null;
|
|
47
53
|
}
|
|
48
54
|
return this.lang.getFoldingRanges(document);
|
|
49
55
|
}
|
|
50
56
|
doTagComplete(document, position) {
|
|
51
|
-
|
|
52
|
-
if (!html) {
|
|
57
|
+
if (!this.featureEnabled('tagComplete')) {
|
|
53
58
|
return null;
|
|
54
59
|
}
|
|
55
|
-
|
|
60
|
+
const html = document.html;
|
|
61
|
+
const offset = document.offsetAt(position);
|
|
62
|
+
if (!html ||
|
|
63
|
+
(0, utils_1.isInsideFrontmatter)(document.getText(), offset) ||
|
|
64
|
+
(0, utils_1.isInsideExpression)(document.getText(), html.findNodeAt(offset).start, offset)) {
|
|
56
65
|
return null;
|
|
57
66
|
}
|
|
58
67
|
return this.lang.doTagComplete(document, position, html);
|
|
59
68
|
}
|
|
60
69
|
/**
|
|
61
|
-
*
|
|
62
|
-
* without the stable ones. Transform to the stable types.
|
|
70
|
+
* Get lang completions for style tags (ex: `<style lang="scss">`)
|
|
63
71
|
*/
|
|
64
|
-
toCompletionItems(items) {
|
|
65
|
-
return items.map((item) => {
|
|
66
|
-
if (!item.textEdit || vscode_languageserver_1.TextEdit.is(item.textEdit)) {
|
|
67
|
-
return item;
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
...item,
|
|
71
|
-
textEdit: vscode_languageserver_1.TextEdit.replace(item.textEdit.replace, item.textEdit.newText),
|
|
72
|
-
};
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
72
|
getLangCompletions(completions) {
|
|
76
73
|
const styleScriptTemplateCompletions = completions.filter((completion) => completion.kind === vscode_languageserver_1.CompletionItemKind.Property && this.styleScriptTemplate.has(completion.label));
|
|
77
74
|
const langCompletions = [];
|
|
78
|
-
addLangCompletion('style', ['scss', 'sass']);
|
|
75
|
+
addLangCompletion('style', ['scss', 'sass', 'less', 'styl', 'stylus']);
|
|
79
76
|
return langCompletions;
|
|
80
77
|
/** Add language completions */
|
|
81
78
|
function addLangCompletion(tag, languages) {
|
|
@@ -96,13 +93,8 @@ class HTMLPlugin {
|
|
|
96
93
|
}));
|
|
97
94
|
}
|
|
98
95
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const node = html.findNodeAt(offset);
|
|
102
|
-
return (0, utils_1.isInsideExpression)(document.getText(), node.start, offset);
|
|
103
|
-
}
|
|
104
|
-
isInsideFrontmatter(document, position) {
|
|
105
|
-
return (0, utils_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position));
|
|
96
|
+
featureEnabled(feature) {
|
|
97
|
+
return this.configManager.enabled('html.enabled') && this.configManager.enabled(`html.${feature}.enabled`);
|
|
106
98
|
}
|
|
107
99
|
}
|
|
108
100
|
exports.HTMLPlugin = HTMLPlugin;
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './PluginHost';
|
|
2
|
-
export * from './astro/AstroPlugin';
|
|
3
2
|
export * from './html/HTMLPlugin';
|
|
3
|
+
export * from './css/CSSPlugin';
|
|
4
4
|
export * from './typescript/TypeScriptPlugin';
|
|
5
|
+
export * from './astro/AstroPlugin';
|
|
5
6
|
export * from './interfaces';
|
|
6
|
-
export * from './css/CSSPlugin';
|
package/dist/plugins/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -11,8 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
17
|
__exportStar(require("./PluginHost"), exports);
|
|
14
|
-
__exportStar(require("./astro/AstroPlugin"), exports);
|
|
15
18
|
__exportStar(require("./html/HTMLPlugin"), exports);
|
|
19
|
+
__exportStar(require("./css/CSSPlugin"), exports);
|
|
16
20
|
__exportStar(require("./typescript/TypeScriptPlugin"), exports);
|
|
21
|
+
__exportStar(require("./astro/AstroPlugin"), exports);
|
|
17
22
|
__exportStar(require("./interfaces"), exports);
|
|
18
|
-
__exportStar(require("./css/CSSPlugin"), exports);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { CompletionContext, FileChangeType, LinkedEditingRanges, SemanticTokens, SignatureHelpContext, TextDocumentContentChangeEvent } from 'vscode-languageserver';
|
|
2
|
-
import {
|
|
3
|
-
import { Document } from '../core/documents';
|
|
1
|
+
import { CodeAction, CodeActionContext, Color, ColorInformation, ColorPresentation, CompletionContext, CompletionItem, CompletionList, DefinitionLink, Diagnostic, FileChangeType, FoldingRange, FormattingOptions, Hover, LinkedEditingRanges, Position, Range, ReferenceContext, SelectionRange, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, TextDocumentIdentifier, TextEdit, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
3
|
export declare type Resolvable<T> = T | Promise<T>;
|
|
5
4
|
export interface AppCompletionItem<T extends TextDocumentIdentifier = any> extends CompletionItem {
|
|
6
5
|
data?: T;
|
|
@@ -9,42 +8,42 @@ export interface AppCompletionList<T extends TextDocumentIdentifier = any> exten
|
|
|
9
8
|
items: Array<AppCompletionItem<T>>;
|
|
10
9
|
}
|
|
11
10
|
export interface DiagnosticsProvider {
|
|
12
|
-
getDiagnostics(document:
|
|
11
|
+
getDiagnostics(document: TextDocument): Resolvable<Diagnostic[]>;
|
|
13
12
|
}
|
|
14
13
|
export interface HoverProvider {
|
|
15
|
-
doHover(document:
|
|
14
|
+
doHover(document: TextDocument, position: Position): Resolvable<Hover | null>;
|
|
16
15
|
}
|
|
17
16
|
export interface FoldingRangeProvider {
|
|
18
|
-
getFoldingRanges(document:
|
|
17
|
+
getFoldingRanges(document: TextDocument): Resolvable<FoldingRange[] | null>;
|
|
19
18
|
}
|
|
20
19
|
export interface CompletionsProvider<T extends TextDocumentIdentifier = any> {
|
|
21
|
-
getCompletions(document:
|
|
22
|
-
resolveCompletion?(document:
|
|
20
|
+
getCompletions(document: TextDocument, position: Position, completionContext?: CompletionContext): Resolvable<AppCompletionList<T> | null>;
|
|
21
|
+
resolveCompletion?(document: TextDocument, completionItem: AppCompletionItem<T>): Resolvable<AppCompletionItem<T>>;
|
|
23
22
|
}
|
|
24
23
|
export interface FormattingProvider {
|
|
25
|
-
formatDocument(document:
|
|
24
|
+
formatDocument(document: TextDocument, options: FormattingOptions): Resolvable<TextEdit[]>;
|
|
26
25
|
}
|
|
27
26
|
export interface TagCompleteProvider {
|
|
28
|
-
doTagComplete(document:
|
|
27
|
+
doTagComplete(document: TextDocument, position: Position): Resolvable<string | null>;
|
|
29
28
|
}
|
|
30
29
|
export interface DocumentColorsProvider {
|
|
31
|
-
getDocumentColors(document:
|
|
30
|
+
getDocumentColors(document: TextDocument): Resolvable<ColorInformation[]>;
|
|
32
31
|
}
|
|
33
32
|
export interface ColorPresentationsProvider {
|
|
34
|
-
getColorPresentations(document:
|
|
33
|
+
getColorPresentations(document: TextDocument, range: Range, color: Color): Resolvable<ColorPresentation[]>;
|
|
35
34
|
}
|
|
36
35
|
export interface DocumentSymbolsProvider {
|
|
37
|
-
getDocumentSymbols(document:
|
|
36
|
+
getDocumentSymbols(document: TextDocument): Resolvable<SymbolInformation[]>;
|
|
38
37
|
}
|
|
39
38
|
export interface DefinitionsProvider {
|
|
40
|
-
getDefinitions(document:
|
|
39
|
+
getDefinitions(document: TextDocument, position: Position): Resolvable<DefinitionLink[]>;
|
|
41
40
|
}
|
|
42
41
|
export interface BackwardsCompatibleDefinitionsProvider {
|
|
43
|
-
getDefinitions(document:
|
|
42
|
+
getDefinitions(document: TextDocument, position: Position): Resolvable<DefinitionLink[] | Location[]>;
|
|
44
43
|
}
|
|
45
44
|
export interface CodeActionsProvider {
|
|
46
|
-
getCodeActions(document:
|
|
47
|
-
executeCommand?(document:
|
|
45
|
+
getCodeActions(document: TextDocument, range: Range, context: CodeActionContext): Resolvable<CodeAction[]>;
|
|
46
|
+
executeCommand?(document: TextDocument, command: string, args?: any[]): Resolvable<WorkspaceEdit | string | null>;
|
|
48
47
|
}
|
|
49
48
|
export interface FileRename {
|
|
50
49
|
oldUri: string;
|
|
@@ -54,49 +53,37 @@ export interface UpdateImportsProvider {
|
|
|
54
53
|
updateImports(fileRename: FileRename): Resolvable<WorkspaceEdit | null>;
|
|
55
54
|
}
|
|
56
55
|
export interface RenameProvider {
|
|
57
|
-
rename(document:
|
|
58
|
-
prepareRename(document:
|
|
56
|
+
rename(document: TextDocument, position: Position, newName: string): Resolvable<WorkspaceEdit | null>;
|
|
57
|
+
prepareRename(document: TextDocument, position: Position): Resolvable<Range | null>;
|
|
59
58
|
}
|
|
60
59
|
export interface FindReferencesProvider {
|
|
61
|
-
findReferences(document:
|
|
60
|
+
findReferences(document: TextDocument, position: Position, context: ReferenceContext): Promise<Location[] | null>;
|
|
62
61
|
}
|
|
63
62
|
export interface SignatureHelpProvider {
|
|
64
|
-
getSignatureHelp(document:
|
|
63
|
+
getSignatureHelp(document: TextDocument, position: Position, context: SignatureHelpContext | undefined): Resolvable<SignatureHelp | null>;
|
|
65
64
|
}
|
|
66
65
|
export interface SelectionRangeProvider {
|
|
67
|
-
getSelectionRange(document:
|
|
66
|
+
getSelectionRange(document: TextDocument, position: Position): Resolvable<SelectionRange | null>;
|
|
68
67
|
}
|
|
69
68
|
export interface SemanticTokensProvider {
|
|
70
|
-
getSemanticTokens(textDocument:
|
|
69
|
+
getSemanticTokens(textDocument: TextDocument, range?: Range): Resolvable<SemanticTokens | null>;
|
|
71
70
|
}
|
|
72
71
|
export interface LinkedEditingRangesProvider {
|
|
73
|
-
getLinkedEditingRanges(document:
|
|
72
|
+
getLinkedEditingRanges(document: TextDocument, position: Position): Resolvable<LinkedEditingRanges | null>;
|
|
74
73
|
}
|
|
75
|
-
export interface
|
|
74
|
+
export interface OnWatchFileChangesParam {
|
|
76
75
|
fileName: string;
|
|
77
76
|
changeType: FileChangeType;
|
|
78
77
|
}
|
|
79
|
-
export interface
|
|
80
|
-
onWatchFileChanges(
|
|
81
|
-
}
|
|
82
|
-
export interface
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
declare type ProviderBase = DiagnosticsProvider & HoverProvider & CompletionsProvider & FormattingProvider & FoldingRangeProvider & TagCompleteProvider & DocumentColorsProvider & ColorPresentationsProvider & DocumentSymbolsProvider & UpdateImportsProvider & CodeActionsProvider & FindReferencesProvider & RenameProvider & SignatureHelpProvider & SemanticTokensProvider & LinkedEditingRangesProvider;
|
|
86
|
-
export declare type LSProvider = ProviderBase
|
|
87
|
-
export
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
* should be filtered server side.
|
|
91
|
-
*/
|
|
92
|
-
filterIncompleteCompletions: boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Whether or not getDefinitions supports the LocationLink interface.
|
|
95
|
-
*/
|
|
96
|
-
definitionLinkSupport: boolean;
|
|
97
|
-
}
|
|
98
|
-
interface NamedPlugin {
|
|
99
|
-
pluginName: string;
|
|
100
|
-
}
|
|
101
|
-
export declare type Plugin = Partial<NamedPlugin & ProviderBase & DefinitionsProvider & OnWatchFileChanges & SelectionRangeProvider & UpdateTsOrJsFile>;
|
|
78
|
+
export interface OnWatchFileChangesProvider {
|
|
79
|
+
onWatchFileChanges(onWatchFileChangesParams: OnWatchFileChangesParam[]): void;
|
|
80
|
+
}
|
|
81
|
+
export interface UpdateNonAstroFile {
|
|
82
|
+
updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): void;
|
|
83
|
+
}
|
|
84
|
+
declare type ProviderBase = DiagnosticsProvider & HoverProvider & CompletionsProvider & DefinitionsProvider & FormattingProvider & FoldingRangeProvider & TagCompleteProvider & DocumentColorsProvider & ColorPresentationsProvider & DocumentSymbolsProvider & UpdateImportsProvider & CodeActionsProvider & FindReferencesProvider & RenameProvider & SignatureHelpProvider & SemanticTokensProvider & SelectionRangeProvider & OnWatchFileChangesProvider & LinkedEditingRangesProvider & UpdateNonAstroFile;
|
|
85
|
+
export declare type LSProvider = ProviderBase;
|
|
86
|
+
export declare type Plugin = Partial<ProviderBase> & {
|
|
87
|
+
__name: string;
|
|
88
|
+
};
|
|
102
89
|
export {};
|
|
@@ -1,23 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { TextDocumentContentChangeEvent } from 'vscode-languageserver';
|
|
3
|
+
import { ConfigManager } from '../../core/config';
|
|
4
|
+
import { AstroDocument, DocumentManager } from '../../core/documents';
|
|
5
|
+
import { LanguageServiceContainer } from './language-service';
|
|
6
|
+
import { DocumentSnapshot } from './snapshots/DocumentSnapshot';
|
|
6
7
|
export declare class LanguageServiceManager {
|
|
7
8
|
private readonly docManager;
|
|
8
|
-
private readonly configManager;
|
|
9
9
|
private readonly workspaceUris;
|
|
10
|
+
private readonly configManager;
|
|
10
11
|
private docContext;
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
private globalSnapshotManager;
|
|
13
|
+
constructor(docManager: DocumentManager, workspaceUris: string[], configManager: ConfigManager);
|
|
14
|
+
/**
|
|
15
|
+
* Create an AstroDocument (only for astro files)
|
|
16
|
+
*/
|
|
13
17
|
private createDocument;
|
|
14
|
-
getSnapshot(document:
|
|
15
|
-
getSnapshot(pathOrDoc: string |
|
|
16
|
-
|
|
18
|
+
getSnapshot(document: AstroDocument): Promise<DocumentSnapshot>;
|
|
19
|
+
getSnapshot(pathOrDoc: string | AstroDocument): Promise<DocumentSnapshot>;
|
|
20
|
+
/**
|
|
21
|
+
* Updates snapshot path in all existing ts services and retrieves snapshot
|
|
22
|
+
*/
|
|
23
|
+
updateSnapshotPath(oldPath: string, newPath: string): Promise<DocumentSnapshot>;
|
|
24
|
+
/**
|
|
25
|
+
* Deletes snapshot in all existing ts services
|
|
26
|
+
*/
|
|
27
|
+
deleteSnapshot(filePath: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Updates project files in all existing ts services
|
|
30
|
+
*/
|
|
31
|
+
updateProjectFiles(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Updates file in all ts services where it exists
|
|
34
|
+
*/
|
|
35
|
+
updateExistingNonAstroFile(path: string, changes?: TextDocumentContentChangeEvent[]): Promise<void>;
|
|
36
|
+
getLSAndTSDoc(document: AstroDocument): Promise<{
|
|
17
37
|
tsDoc: DocumentSnapshot;
|
|
18
38
|
lang: ts.LanguageService;
|
|
19
39
|
}>;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
private getTypeScriptLanguageService;
|
|
40
|
+
getLSForPath(path: string): Promise<ts.LanguageService>;
|
|
41
|
+
getTypeScriptLanguageService(filePath: string): Promise<LanguageServiceContainer>;
|
|
23
42
|
}
|
|
@@ -2,62 +2,87 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LanguageServiceManager = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
|
-
const
|
|
5
|
+
const language_service_1 = require("./language-service");
|
|
6
|
+
const SnapshotManager_1 = require("./snapshots/SnapshotManager");
|
|
6
7
|
class LanguageServiceManager {
|
|
7
|
-
constructor(docManager,
|
|
8
|
-
this.
|
|
8
|
+
constructor(docManager, workspaceUris, configManager) {
|
|
9
|
+
this.docManager = docManager;
|
|
10
|
+
this.workspaceUris = workspaceUris;
|
|
11
|
+
this.configManager = configManager;
|
|
12
|
+
this.globalSnapshotManager = new SnapshotManager_1.GlobalSnapshotManager();
|
|
13
|
+
/**
|
|
14
|
+
* Create an AstroDocument (only for astro files)
|
|
15
|
+
*/
|
|
16
|
+
this.createDocument = (fileName, content) => {
|
|
9
17
|
const uri = (0, utils_1.pathToUrl)(fileName);
|
|
10
18
|
const document = this.docManager.openDocument({
|
|
11
|
-
languageId: 'astro',
|
|
12
|
-
version: 0,
|
|
13
19
|
text: content,
|
|
14
20
|
uri,
|
|
15
|
-
overrideText,
|
|
16
21
|
});
|
|
22
|
+
this.docManager.lockDocument(uri);
|
|
17
23
|
return document;
|
|
18
24
|
};
|
|
19
|
-
this.docManager = docManager;
|
|
20
|
-
this.configManager = configManager;
|
|
21
|
-
this.workspaceUris = workspaceUris;
|
|
22
25
|
this.docContext = {
|
|
23
|
-
getWorkspaceRoot: (fileName) => this.getWorkspaceRoot(fileName),
|
|
24
26
|
createDocument: this.createDocument,
|
|
27
|
+
globalSnapshotManager: this.globalSnapshotManager,
|
|
25
28
|
};
|
|
26
29
|
const handleDocumentChange = (document) => {
|
|
27
|
-
|
|
28
|
-
this.getTypeScriptDoc(document);
|
|
30
|
+
this.getSnapshot(document);
|
|
29
31
|
};
|
|
30
32
|
docManager.on('documentChange', (0, utils_1.debounceSameArg)(handleDocumentChange, (newDoc, prevDoc) => newDoc.uri === (prevDoc === null || prevDoc === void 0 ? void 0 : prevDoc.uri), 1000));
|
|
31
33
|
docManager.on('documentOpen', handleDocumentChange);
|
|
32
34
|
}
|
|
33
|
-
getWorkspaceRoot(fileName) {
|
|
34
|
-
if (this.workspaceUris.length === 1)
|
|
35
|
-
return (0, utils_1.urlToPath)(this.workspaceUris[0]);
|
|
36
|
-
return this.workspaceUris.reduce((found, curr) => {
|
|
37
|
-
const url = (0, utils_1.urlToPath)(curr);
|
|
38
|
-
if (fileName.startsWith(url) && curr.length < url.length)
|
|
39
|
-
return url;
|
|
40
|
-
return found;
|
|
41
|
-
}, '');
|
|
42
|
-
}
|
|
43
35
|
async getSnapshot(pathOrDoc) {
|
|
44
36
|
const filePath = typeof pathOrDoc === 'string' ? pathOrDoc : pathOrDoc.getFilePath() || '';
|
|
45
37
|
const tsService = await this.getTypeScriptLanguageService(filePath);
|
|
46
|
-
return tsService.
|
|
38
|
+
return tsService.updateSnapshot(pathOrDoc);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Updates snapshot path in all existing ts services and retrieves snapshot
|
|
42
|
+
*/
|
|
43
|
+
async updateSnapshotPath(oldPath, newPath) {
|
|
44
|
+
await this.deleteSnapshot(oldPath);
|
|
45
|
+
return this.getSnapshot(newPath);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Deletes snapshot in all existing ts services
|
|
49
|
+
*/
|
|
50
|
+
async deleteSnapshot(filePath) {
|
|
51
|
+
await (0, language_service_1.forAllLanguageServices)((service) => service.deleteSnapshot(filePath));
|
|
52
|
+
this.docManager.releaseDocument((0, utils_1.pathToUrl)(filePath));
|
|
47
53
|
}
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Updates project files in all existing ts services
|
|
56
|
+
*/
|
|
57
|
+
async updateProjectFiles() {
|
|
58
|
+
await (0, language_service_1.forAllLanguageServices)((service) => service.updateProjectFiles());
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Updates file in all ts services where it exists
|
|
62
|
+
*/
|
|
63
|
+
async updateExistingNonAstroFile(path, changes) {
|
|
64
|
+
path = (0, utils_1.normalizePath)(path);
|
|
65
|
+
// Only update once because all snapshots are shared between
|
|
66
|
+
// services. Since we don't have a current version of TS/JS
|
|
67
|
+
// files, the operation wouldn't be idempotent.
|
|
68
|
+
let didUpdate = false;
|
|
69
|
+
await (0, language_service_1.forAllLanguageServices)((service) => {
|
|
70
|
+
if (service.hasFile(path) && !didUpdate) {
|
|
71
|
+
didUpdate = true;
|
|
72
|
+
service.updateNonAstroFile(path, changes);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async getLSAndTSDoc(document) {
|
|
77
|
+
const lang = await this.getLSForPath(document.getFilePath() || '');
|
|
50
78
|
const tsDoc = await this.getSnapshot(document);
|
|
51
79
|
return { tsDoc, lang };
|
|
52
80
|
}
|
|
53
|
-
async
|
|
54
|
-
return (
|
|
55
|
-
}
|
|
56
|
-
async getSnapshotManager(filePath) {
|
|
57
|
-
return (await this.getTypeScriptLanguageService(filePath)).snapshotManager;
|
|
81
|
+
async getLSForPath(path) {
|
|
82
|
+
return (await this.getTypeScriptLanguageService(path)).getService();
|
|
58
83
|
}
|
|
59
|
-
getTypeScriptLanguageService(filePath) {
|
|
60
|
-
return (0,
|
|
84
|
+
async getTypeScriptLanguageService(filePath) {
|
|
85
|
+
return (0, language_service_1.getLanguageService)(filePath, this.workspaceUris, this.docContext);
|
|
61
86
|
}
|
|
62
87
|
}
|
|
63
88
|
exports.LanguageServiceManager = LanguageServiceManager;
|
|
@@ -1,33 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { CompletionContext, DefinitionLink, Position } from 'vscode-languageserver';
|
|
6
|
-
import { SnapshotManager } from './SnapshotManager';
|
|
1
|
+
import { CancellationToken, CompletionContext, DefinitionLink, Diagnostic, Hover, Position, SignatureHelp, SignatureHelpContext, TextDocumentContentChangeEvent, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
|
+
import { ConfigManager } from '../../core/config';
|
|
3
|
+
import { AstroDocument, DocumentManager } from '../../core/documents';
|
|
4
|
+
import { AppCompletionItem, AppCompletionList, OnWatchFileChangesParam, Plugin } from '../interfaces';
|
|
7
5
|
import { CompletionEntryWithIdentifer } from './features/CompletionsProvider';
|
|
8
|
-
export declare class TypeScriptPlugin implements
|
|
9
|
-
|
|
10
|
-
private
|
|
6
|
+
export declare class TypeScriptPlugin implements Plugin {
|
|
7
|
+
__name: string;
|
|
8
|
+
private configManager;
|
|
11
9
|
private readonly languageServiceManager;
|
|
12
|
-
pluginName: string;
|
|
13
10
|
private readonly completionProvider;
|
|
14
11
|
private readonly hoverProvider;
|
|
15
12
|
private readonly signatureHelpProvider;
|
|
16
13
|
private readonly diagnosticsProvider;
|
|
17
14
|
constructor(docManager: DocumentManager, configManager: ConfigManager, workspaceUris: string[]);
|
|
18
|
-
doHover(document:
|
|
19
|
-
rename(document:
|
|
20
|
-
getCompletions(document:
|
|
21
|
-
resolveCompletion(document:
|
|
22
|
-
getDefinitions(document:
|
|
23
|
-
getDiagnostics(document:
|
|
24
|
-
onWatchFileChanges(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
getSnapshotManager(fileName: string): Promise<SnapshotManager>;
|
|
15
|
+
doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
|
|
16
|
+
rename(document: AstroDocument, position: Position, newName: string): Promise<WorkspaceEdit | null>;
|
|
17
|
+
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList<CompletionEntryWithIdentifer> | null>;
|
|
18
|
+
resolveCompletion(document: AstroDocument, completionItem: AppCompletionItem<CompletionEntryWithIdentifer>): Promise<AppCompletionItem<CompletionEntryWithIdentifer>>;
|
|
19
|
+
getDefinitions(document: AstroDocument, position: Position): Promise<DefinitionLink[]>;
|
|
20
|
+
getDiagnostics(document: AstroDocument, cancellationToken?: CancellationToken): Promise<Diagnostic[]>;
|
|
21
|
+
onWatchFileChanges(onWatchFileChangesParas: OnWatchFileChangesParam[]): Promise<void>;
|
|
22
|
+
updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): Promise<void>;
|
|
23
|
+
getSignatureHelp(document: AstroDocument, position: Position, context: SignatureHelpContext | undefined, cancellationToken?: CancellationToken): Promise<SignatureHelp | null>;
|
|
31
24
|
private goToDefinitionFoundOnlyAlias;
|
|
32
25
|
private getGoToDefinitionRefsForImportSpecifier;
|
|
33
26
|
private featureEnabled;
|