@codingame/monaco-vscode-standalone-html-language-features 23.1.1 → 23.2.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/common/initialize.js +11 -0
- package/common/workers.d.ts +29 -0
- package/common/workers.js +70 -0
- package/language/common/lspLanguageFeatures.js +644 -0
- package/language/html/html.worker.js +8 -0
- package/language/html/htmlMode.js +141 -0
- package/language/html/htmlWorker.js +126 -0
- package/language/html/monaco.contribution.d.ts +162 -0
- package/{index.js → language/html/monaco.contribution.js} +21 -57
- package/language/html/workerManager.js +64 -0
- package/package.json +7 -4
- package/htmlMode.js +0 -2108
- package/worker.js +0 -16161
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { WorkerManager } from './workerManager.js';
|
|
2
|
+
import { HoverAdapter, DocumentHighlightAdapter, DocumentLinkAdapter, FoldingRangeAdapter, DocumentSymbolAdapter, SelectionRangeAdapter, RenameAdapter, DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider, CompletionAdapter } from '../common/lspLanguageFeatures.js';
|
|
3
|
+
export { DefinitionAdapter, DiagnosticsAdapter, DocumentColorAdapter, ReferenceAdapter, fromPosition, fromRange, toRange, toTextEdit } from '../common/lspLanguageFeatures.js';
|
|
4
|
+
import { languages } from 'monaco-editor';
|
|
5
|
+
|
|
6
|
+
class HTMLCompletionAdapter extends CompletionAdapter {
|
|
7
|
+
constructor(worker) {
|
|
8
|
+
super(worker, [".", ":", "<", '"', "=", "/"]);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function setupMode1(defaults) {
|
|
12
|
+
const client = new WorkerManager(defaults);
|
|
13
|
+
const worker = (...uris) => {
|
|
14
|
+
return client.getLanguageServiceWorker(...uris);
|
|
15
|
+
};
|
|
16
|
+
let languageId = defaults.languageId;
|
|
17
|
+
languages.registerCompletionItemProvider(languageId, new HTMLCompletionAdapter(worker));
|
|
18
|
+
languages.registerHoverProvider(languageId, new HoverAdapter(worker));
|
|
19
|
+
languages.registerDocumentHighlightProvider(
|
|
20
|
+
languageId,
|
|
21
|
+
new DocumentHighlightAdapter(worker)
|
|
22
|
+
);
|
|
23
|
+
languages.registerLinkProvider(languageId, new DocumentLinkAdapter(worker));
|
|
24
|
+
languages.registerFoldingRangeProvider(
|
|
25
|
+
languageId,
|
|
26
|
+
new FoldingRangeAdapter(worker)
|
|
27
|
+
);
|
|
28
|
+
languages.registerDocumentSymbolProvider(
|
|
29
|
+
languageId,
|
|
30
|
+
new DocumentSymbolAdapter(worker)
|
|
31
|
+
);
|
|
32
|
+
languages.registerSelectionRangeProvider(
|
|
33
|
+
languageId,
|
|
34
|
+
new SelectionRangeAdapter(worker)
|
|
35
|
+
);
|
|
36
|
+
languages.registerRenameProvider(languageId, new RenameAdapter(worker));
|
|
37
|
+
if (languageId === "html") {
|
|
38
|
+
languages.registerDocumentFormattingEditProvider(
|
|
39
|
+
languageId,
|
|
40
|
+
new DocumentFormattingEditProvider(worker)
|
|
41
|
+
);
|
|
42
|
+
languages.registerDocumentRangeFormattingEditProvider(
|
|
43
|
+
languageId,
|
|
44
|
+
new DocumentRangeFormattingEditProvider(worker)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function setupMode(defaults) {
|
|
49
|
+
const disposables = [];
|
|
50
|
+
const providers = [];
|
|
51
|
+
const client = new WorkerManager(defaults);
|
|
52
|
+
disposables.push(client);
|
|
53
|
+
const worker = (...uris) => {
|
|
54
|
+
return client.getLanguageServiceWorker(...uris);
|
|
55
|
+
};
|
|
56
|
+
function registerProviders() {
|
|
57
|
+
const { languageId, modeConfiguration } = defaults;
|
|
58
|
+
disposeAll(providers);
|
|
59
|
+
if (modeConfiguration.completionItems) {
|
|
60
|
+
providers.push(
|
|
61
|
+
languages.registerCompletionItemProvider(languageId, new HTMLCompletionAdapter(worker))
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
if (modeConfiguration.hovers) {
|
|
65
|
+
providers.push(
|
|
66
|
+
languages.registerHoverProvider(languageId, new HoverAdapter(worker))
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
if (modeConfiguration.documentHighlights) {
|
|
70
|
+
providers.push(
|
|
71
|
+
languages.registerDocumentHighlightProvider(
|
|
72
|
+
languageId,
|
|
73
|
+
new DocumentHighlightAdapter(worker)
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (modeConfiguration.links) {
|
|
78
|
+
providers.push(
|
|
79
|
+
languages.registerLinkProvider(languageId, new DocumentLinkAdapter(worker))
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (modeConfiguration.documentSymbols) {
|
|
83
|
+
providers.push(
|
|
84
|
+
languages.registerDocumentSymbolProvider(
|
|
85
|
+
languageId,
|
|
86
|
+
new DocumentSymbolAdapter(worker)
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
if (modeConfiguration.rename) {
|
|
91
|
+
providers.push(
|
|
92
|
+
languages.registerRenameProvider(languageId, new RenameAdapter(worker))
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (modeConfiguration.foldingRanges) {
|
|
96
|
+
providers.push(
|
|
97
|
+
languages.registerFoldingRangeProvider(
|
|
98
|
+
languageId,
|
|
99
|
+
new FoldingRangeAdapter(worker)
|
|
100
|
+
)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (modeConfiguration.selectionRanges) {
|
|
104
|
+
providers.push(
|
|
105
|
+
languages.registerSelectionRangeProvider(
|
|
106
|
+
languageId,
|
|
107
|
+
new SelectionRangeAdapter(worker)
|
|
108
|
+
)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
if (modeConfiguration.documentFormattingEdits) {
|
|
112
|
+
providers.push(
|
|
113
|
+
languages.registerDocumentFormattingEditProvider(
|
|
114
|
+
languageId,
|
|
115
|
+
new DocumentFormattingEditProvider(worker)
|
|
116
|
+
)
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
if (modeConfiguration.documentRangeFormattingEdits) {
|
|
120
|
+
providers.push(
|
|
121
|
+
languages.registerDocumentRangeFormattingEditProvider(
|
|
122
|
+
languageId,
|
|
123
|
+
new DocumentRangeFormattingEditProvider(worker)
|
|
124
|
+
)
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
registerProviders();
|
|
129
|
+
disposables.push(asDisposable(providers));
|
|
130
|
+
return asDisposable(disposables);
|
|
131
|
+
}
|
|
132
|
+
function asDisposable(disposables) {
|
|
133
|
+
return { dispose: () => disposeAll(disposables) };
|
|
134
|
+
}
|
|
135
|
+
function disposeAll(disposables) {
|
|
136
|
+
while (disposables.length) {
|
|
137
|
+
disposables.pop().dispose();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { CompletionAdapter, DocumentFormattingEditProvider, DocumentHighlightAdapter, DocumentLinkAdapter, DocumentRangeFormattingEditProvider, DocumentSymbolAdapter, FoldingRangeAdapter, HoverAdapter, RenameAdapter, SelectionRangeAdapter, WorkerManager, setupMode, setupMode1 };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { newHTMLDataProvider, getLanguageService } from 'vscode-html-languageservice';
|
|
2
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
+
|
|
4
|
+
class HTMLWorker {
|
|
5
|
+
constructor(ctx, createData) {
|
|
6
|
+
this._ctx = ctx;
|
|
7
|
+
this._languageSettings = createData.languageSettings;
|
|
8
|
+
this._languageId = createData.languageId;
|
|
9
|
+
const data = this._languageSettings.data;
|
|
10
|
+
const useDefaultDataProvider = data?.useDefaultDataProvider;
|
|
11
|
+
const customDataProviders = [];
|
|
12
|
+
if (data?.dataProviders) {
|
|
13
|
+
for (const id in data.dataProviders) {
|
|
14
|
+
customDataProviders.push(newHTMLDataProvider(id, data.dataProviders[id]));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
this._languageService = getLanguageService({
|
|
18
|
+
useDefaultDataProvider,
|
|
19
|
+
customDataProviders
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async doComplete(uri, position) {
|
|
23
|
+
let document = this._getTextDocument(uri);
|
|
24
|
+
if (!document) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
let htmlDocument = this._languageService.parseHTMLDocument(document);
|
|
28
|
+
return Promise.resolve(
|
|
29
|
+
this._languageService.doComplete(
|
|
30
|
+
document,
|
|
31
|
+
position,
|
|
32
|
+
htmlDocument,
|
|
33
|
+
this._languageSettings && this._languageSettings.suggest
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
async format(uri, range, options) {
|
|
38
|
+
let document = this._getTextDocument(uri);
|
|
39
|
+
if (!document) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
let formattingOptions = { ...this._languageSettings.format, ...options };
|
|
43
|
+
let textEdits = this._languageService.format(document, range, formattingOptions);
|
|
44
|
+
return Promise.resolve(textEdits);
|
|
45
|
+
}
|
|
46
|
+
async doHover(uri, position) {
|
|
47
|
+
let document = this._getTextDocument(uri);
|
|
48
|
+
if (!document) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
let htmlDocument = this._languageService.parseHTMLDocument(document);
|
|
52
|
+
let hover = this._languageService.doHover(document, position, htmlDocument);
|
|
53
|
+
return Promise.resolve(hover);
|
|
54
|
+
}
|
|
55
|
+
async findDocumentHighlights(uri, position) {
|
|
56
|
+
let document = this._getTextDocument(uri);
|
|
57
|
+
if (!document) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
let htmlDocument = this._languageService.parseHTMLDocument(document);
|
|
61
|
+
let highlights = this._languageService.findDocumentHighlights(document, position, htmlDocument);
|
|
62
|
+
return Promise.resolve(highlights);
|
|
63
|
+
}
|
|
64
|
+
async findDocumentLinks(uri) {
|
|
65
|
+
let document = this._getTextDocument(uri);
|
|
66
|
+
if (!document) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
let links = this._languageService.findDocumentLinks(
|
|
70
|
+
document,
|
|
71
|
+
null
|
|
72
|
+
/*TODO@aeschli*/
|
|
73
|
+
);
|
|
74
|
+
return Promise.resolve(links);
|
|
75
|
+
}
|
|
76
|
+
async findDocumentSymbols(uri) {
|
|
77
|
+
let document = this._getTextDocument(uri);
|
|
78
|
+
if (!document) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
let htmlDocument = this._languageService.parseHTMLDocument(document);
|
|
82
|
+
let symbols = this._languageService.findDocumentSymbols(document, htmlDocument);
|
|
83
|
+
return Promise.resolve(symbols);
|
|
84
|
+
}
|
|
85
|
+
async getFoldingRanges(uri, context) {
|
|
86
|
+
let document = this._getTextDocument(uri);
|
|
87
|
+
if (!document) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
let ranges = this._languageService.getFoldingRanges(document, context);
|
|
91
|
+
return Promise.resolve(ranges);
|
|
92
|
+
}
|
|
93
|
+
async getSelectionRanges(uri, positions) {
|
|
94
|
+
let document = this._getTextDocument(uri);
|
|
95
|
+
if (!document) {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
let ranges = this._languageService.getSelectionRanges(document, positions);
|
|
99
|
+
return Promise.resolve(ranges);
|
|
100
|
+
}
|
|
101
|
+
async doRename(uri, position, newName) {
|
|
102
|
+
let document = this._getTextDocument(uri);
|
|
103
|
+
if (!document) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
let htmlDocument = this._languageService.parseHTMLDocument(document);
|
|
107
|
+
let renames = this._languageService.doRename(document, position, newName, htmlDocument);
|
|
108
|
+
return Promise.resolve(renames);
|
|
109
|
+
}
|
|
110
|
+
_getTextDocument(uri) {
|
|
111
|
+
let models = this._ctx.getMirrorModels();
|
|
112
|
+
for (let model of models) {
|
|
113
|
+
if (model.uri.toString() === uri) {
|
|
114
|
+
return TextDocument.create(
|
|
115
|
+
uri,
|
|
116
|
+
this._languageId,
|
|
117
|
+
model.version,
|
|
118
|
+
model.getValue()
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export { HTMLWorker };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { IEvent, IDisposable } from "@codingame/monaco-vscode-api/vscode/vs/editor/editor.api.js";
|
|
2
|
+
interface HTMLFormatConfiguration {
|
|
3
|
+
readonly tabSize: number;
|
|
4
|
+
readonly insertSpaces: boolean;
|
|
5
|
+
readonly wrapLineLength: number;
|
|
6
|
+
readonly unformatted: string;
|
|
7
|
+
readonly contentUnformatted: string;
|
|
8
|
+
readonly indentInnerHtml: boolean;
|
|
9
|
+
readonly preserveNewLines: boolean;
|
|
10
|
+
readonly maxPreserveNewLines: number | undefined;
|
|
11
|
+
readonly indentHandlebars: boolean;
|
|
12
|
+
readonly endWithNewline: boolean;
|
|
13
|
+
readonly extraLiners: string;
|
|
14
|
+
readonly wrapAttributes: "auto" | "force" | "force-aligned" | "force-expand-multiline";
|
|
15
|
+
}
|
|
16
|
+
interface CompletionConfiguration {
|
|
17
|
+
readonly [providerId: string]: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface Options {
|
|
20
|
+
/**
|
|
21
|
+
* Settings for the HTML formatter.
|
|
22
|
+
*/
|
|
23
|
+
readonly format?: HTMLFormatConfiguration;
|
|
24
|
+
/**
|
|
25
|
+
* Code completion settings.
|
|
26
|
+
*/
|
|
27
|
+
readonly suggest?: CompletionConfiguration;
|
|
28
|
+
/**
|
|
29
|
+
* Configures the HTML data types known by the HTML langauge service.
|
|
30
|
+
*/
|
|
31
|
+
readonly data?: HTMLDataConfiguration;
|
|
32
|
+
}
|
|
33
|
+
interface ModeConfiguration {
|
|
34
|
+
/**
|
|
35
|
+
* Defines whether the built-in completionItemProvider is enabled.
|
|
36
|
+
*/
|
|
37
|
+
readonly completionItems?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Defines whether the built-in hoverProvider is enabled.
|
|
40
|
+
*/
|
|
41
|
+
readonly hovers?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Defines whether the built-in documentSymbolProvider is enabled.
|
|
44
|
+
*/
|
|
45
|
+
readonly documentSymbols?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Defines whether the built-in definitions provider is enabled.
|
|
48
|
+
*/
|
|
49
|
+
readonly links?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Defines whether the built-in references provider is enabled.
|
|
52
|
+
*/
|
|
53
|
+
readonly documentHighlights?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Defines whether the built-in rename provider is enabled.
|
|
56
|
+
*/
|
|
57
|
+
readonly rename?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Defines whether the built-in color provider is enabled.
|
|
60
|
+
*/
|
|
61
|
+
readonly colors?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Defines whether the built-in foldingRange provider is enabled.
|
|
64
|
+
*/
|
|
65
|
+
readonly foldingRanges?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Defines whether the built-in diagnostic provider is enabled.
|
|
68
|
+
*/
|
|
69
|
+
readonly diagnostics?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Defines whether the built-in selection range provider is enabled.
|
|
72
|
+
*/
|
|
73
|
+
readonly selectionRanges?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Defines whether the built-in documentFormattingEdit provider is enabled.
|
|
76
|
+
*/
|
|
77
|
+
readonly documentFormattingEdits?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Defines whether the built-in documentRangeFormattingEdit provider is enabled.
|
|
80
|
+
*/
|
|
81
|
+
readonly documentRangeFormattingEdits?: boolean;
|
|
82
|
+
}
|
|
83
|
+
interface LanguageServiceDefaults {
|
|
84
|
+
readonly languageId: string;
|
|
85
|
+
readonly modeConfiguration: ModeConfiguration;
|
|
86
|
+
readonly onDidChange: IEvent<LanguageServiceDefaults>;
|
|
87
|
+
readonly options: Options;
|
|
88
|
+
setOptions(options: Options): void;
|
|
89
|
+
setModeConfiguration(modeConfiguration: ModeConfiguration): void;
|
|
90
|
+
}
|
|
91
|
+
declare const htmlLanguageService: LanguageServiceRegistration;
|
|
92
|
+
declare const htmlDefaults: LanguageServiceDefaults;
|
|
93
|
+
declare const handlebarLanguageService: LanguageServiceRegistration;
|
|
94
|
+
declare const handlebarDefaults: LanguageServiceDefaults;
|
|
95
|
+
declare const razorLanguageService: LanguageServiceRegistration;
|
|
96
|
+
declare const razorDefaults: LanguageServiceDefaults;
|
|
97
|
+
interface LanguageServiceRegistration extends IDisposable {
|
|
98
|
+
readonly defaults: LanguageServiceDefaults;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Registers a new HTML language service for the languageId.
|
|
102
|
+
* Note: 'html', 'handlebar' and 'razor' are registered by default.
|
|
103
|
+
*
|
|
104
|
+
* Use this method to register additional language ids with a HTML service.
|
|
105
|
+
* The language server has to be registered before an editor model is opened.
|
|
106
|
+
*/
|
|
107
|
+
declare function registerHTMLLanguageService(languageId: string, options?: Options, modeConfiguration?: ModeConfiguration): LanguageServiceRegistration;
|
|
108
|
+
interface HTMLDataConfiguration {
|
|
109
|
+
/**
|
|
110
|
+
* Defines whether the standard HTML tags and attributes are shown
|
|
111
|
+
*/
|
|
112
|
+
readonly useDefaultDataProvider?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Provides a set of custom data providers.
|
|
115
|
+
*/
|
|
116
|
+
readonly dataProviders?: {
|
|
117
|
+
[providerId: string]: HTMLDataV1;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Custom HTML tags attributes and attribute values
|
|
122
|
+
* https://github.com/microsoft/vscode-html-languageservice/blob/main/docs/customData.md
|
|
123
|
+
*/
|
|
124
|
+
interface HTMLDataV1 {
|
|
125
|
+
readonly version: 1 | 1.1;
|
|
126
|
+
readonly tags?: ITagData[];
|
|
127
|
+
readonly globalAttributes?: IAttributeData[];
|
|
128
|
+
readonly valueSets?: IValueSet[];
|
|
129
|
+
}
|
|
130
|
+
interface IReference {
|
|
131
|
+
readonly name: string;
|
|
132
|
+
readonly url: string;
|
|
133
|
+
}
|
|
134
|
+
interface ITagData {
|
|
135
|
+
readonly name: string;
|
|
136
|
+
readonly description?: string | MarkupContent;
|
|
137
|
+
readonly attributes: IAttributeData[];
|
|
138
|
+
readonly references?: IReference[];
|
|
139
|
+
}
|
|
140
|
+
interface IAttributeData {
|
|
141
|
+
readonly name: string;
|
|
142
|
+
readonly description?: string | MarkupContent;
|
|
143
|
+
readonly valueSet?: string;
|
|
144
|
+
readonly values?: IValueData[];
|
|
145
|
+
readonly references?: IReference[];
|
|
146
|
+
}
|
|
147
|
+
interface IValueData {
|
|
148
|
+
readonly name: string;
|
|
149
|
+
readonly description?: string | MarkupContent;
|
|
150
|
+
readonly references?: IReference[];
|
|
151
|
+
}
|
|
152
|
+
interface IValueSet {
|
|
153
|
+
readonly name: string;
|
|
154
|
+
readonly values: IValueData[];
|
|
155
|
+
}
|
|
156
|
+
interface MarkupContent {
|
|
157
|
+
readonly kind: MarkupKind;
|
|
158
|
+
readonly value: string;
|
|
159
|
+
}
|
|
160
|
+
declare type MarkupKind = "plaintext" | "markdown";
|
|
161
|
+
export { handlebarDefaults, handlebarLanguageService, htmlDefaults, htmlLanguageService, razorDefaults, razorLanguageService, registerHTMLLanguageService };
|
|
162
|
+
export type { CompletionConfiguration, HTMLDataConfiguration, HTMLDataV1, HTMLFormatConfiguration, IAttributeData, IReference, ITagData, IValueData, IValueSet, LanguageServiceDefaults, LanguageServiceRegistration, MarkupContent, MarkupKind, ModeConfiguration, Options };
|
|
@@ -1,34 +1,9 @@
|
|
|
1
|
-
import * as monaco_editor_core_star from 'monaco-editor';
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
|
-
* Version: 0.54.0(undefined)
|
|
6
|
-
* Released under the MIT license
|
|
7
|
-
* https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
|
|
8
|
-
*-----------------------------------------------------------------------------*/
|
|
2
|
+
import { languages, Emitter } from 'monaco-editor';
|
|
9
3
|
|
|
10
|
-
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __copyProps = (to, from, except, desc) => {
|
|
15
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
-
for (let key of __getOwnPropNames(from))
|
|
17
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget);
|
|
23
|
-
|
|
24
|
-
// src/fillers/monaco-editor-core.ts
|
|
25
|
-
var monaco_editor_core_exports = {};
|
|
26
|
-
__reExport(monaco_editor_core_exports, monaco_editor_core_star);
|
|
27
|
-
|
|
28
|
-
// src/language/html/monaco.contribution.ts
|
|
29
|
-
var LanguageServiceDefaultsImpl = class {
|
|
4
|
+
class LanguageServiceDefaultsImpl {
|
|
30
5
|
constructor(languageId, options, modeConfiguration) {
|
|
31
|
-
this._onDidChange = new
|
|
6
|
+
this._onDidChange = new Emitter();
|
|
32
7
|
this._languageId = languageId;
|
|
33
8
|
this.setOptions(options);
|
|
34
9
|
this.setModeConfiguration(modeConfiguration);
|
|
@@ -53,8 +28,8 @@ var LanguageServiceDefaultsImpl = class {
|
|
|
53
28
|
this._modeConfiguration = modeConfiguration || /* @__PURE__ */ Object.create(null);
|
|
54
29
|
this._onDidChange.fire(this);
|
|
55
30
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
31
|
+
}
|
|
32
|
+
const formatDefaults = {
|
|
58
33
|
tabSize: 4,
|
|
59
34
|
insertSpaces: false,
|
|
60
35
|
wrapLineLength: 120,
|
|
@@ -68,7 +43,7 @@ var formatDefaults = {
|
|
|
68
43
|
extraLiners: "head, body, /html",
|
|
69
44
|
wrapAttributes: "auto"
|
|
70
45
|
};
|
|
71
|
-
|
|
46
|
+
const optionsDefault = {
|
|
72
47
|
format: formatDefaults,
|
|
73
48
|
suggest: {},
|
|
74
49
|
data: { useDefaultDataProvider: true }
|
|
@@ -92,53 +67,42 @@ function getConfigurationDefault(languageId) {
|
|
|
92
67
|
// turned off for Razor and Handlebar
|
|
93
68
|
};
|
|
94
69
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
70
|
+
const htmlLanguageId = "html";
|
|
71
|
+
const handlebarsLanguageId = "handlebars";
|
|
72
|
+
const razorLanguageId = "razor";
|
|
73
|
+
const htmlLanguageService = registerHTMLLanguageService(
|
|
99
74
|
htmlLanguageId,
|
|
100
75
|
optionsDefault,
|
|
101
76
|
getConfigurationDefault(htmlLanguageId)
|
|
102
77
|
);
|
|
103
|
-
|
|
104
|
-
|
|
78
|
+
const htmlDefaults = htmlLanguageService.defaults;
|
|
79
|
+
const handlebarLanguageService = registerHTMLLanguageService(
|
|
105
80
|
handlebarsLanguageId,
|
|
106
81
|
optionsDefault,
|
|
107
82
|
getConfigurationDefault(handlebarsLanguageId)
|
|
108
83
|
);
|
|
109
|
-
|
|
110
|
-
|
|
84
|
+
const handlebarDefaults = handlebarLanguageService.defaults;
|
|
85
|
+
const razorLanguageService = registerHTMLLanguageService(
|
|
111
86
|
razorLanguageId,
|
|
112
87
|
optionsDefault,
|
|
113
88
|
getConfigurationDefault(razorLanguageId)
|
|
114
89
|
);
|
|
115
|
-
|
|
116
|
-
monaco_editor_core_exports.languages.html = {
|
|
117
|
-
htmlDefaults,
|
|
118
|
-
razorDefaults,
|
|
119
|
-
handlebarDefaults,
|
|
120
|
-
htmlLanguageService,
|
|
121
|
-
handlebarLanguageService,
|
|
122
|
-
razorLanguageService,
|
|
123
|
-
registerHTMLLanguageService
|
|
124
|
-
};
|
|
90
|
+
const razorDefaults = razorLanguageService.defaults;
|
|
125
91
|
function getMode() {
|
|
126
|
-
|
|
127
|
-
return import('./htmlMode.js');
|
|
128
|
-
}
|
|
92
|
+
return import('./htmlMode.js');
|
|
129
93
|
}
|
|
130
94
|
function registerHTMLLanguageService(languageId, options = optionsDefault, modeConfiguration = getConfigurationDefault(languageId)) {
|
|
131
95
|
const defaults = new LanguageServiceDefaultsImpl(languageId, options, modeConfiguration);
|
|
132
|
-
let
|
|
133
|
-
const onLanguageListener =
|
|
134
|
-
|
|
96
|
+
let mode2;
|
|
97
|
+
const onLanguageListener = languages.onLanguage(languageId, async () => {
|
|
98
|
+
mode2 = (await getMode()).setupMode(defaults);
|
|
135
99
|
});
|
|
136
100
|
return {
|
|
137
101
|
defaults,
|
|
138
102
|
dispose() {
|
|
139
103
|
onLanguageListener.dispose();
|
|
140
|
-
|
|
141
|
-
|
|
104
|
+
mode2?.dispose();
|
|
105
|
+
mode2 = void 0;
|
|
142
106
|
}
|
|
143
107
|
};
|
|
144
108
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createWebWorker } from '../../common/workers.js';
|
|
2
|
+
|
|
3
|
+
const STOP_WHEN_IDLE_FOR = 2 * 60 * 1e3;
|
|
4
|
+
class WorkerManager {
|
|
5
|
+
constructor(defaults) {
|
|
6
|
+
this._defaults = defaults;
|
|
7
|
+
this._worker = null;
|
|
8
|
+
this._client = null;
|
|
9
|
+
this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 30 * 1e3);
|
|
10
|
+
this._lastUsedTime = 0;
|
|
11
|
+
this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
|
|
12
|
+
}
|
|
13
|
+
_stopWorker() {
|
|
14
|
+
if (this._worker) {
|
|
15
|
+
this._worker.dispose();
|
|
16
|
+
this._worker = null;
|
|
17
|
+
}
|
|
18
|
+
this._client = null;
|
|
19
|
+
}
|
|
20
|
+
dispose() {
|
|
21
|
+
clearInterval(this._idleCheckInterval);
|
|
22
|
+
this._configChangeListener.dispose();
|
|
23
|
+
this._stopWorker();
|
|
24
|
+
}
|
|
25
|
+
_checkIfIdle() {
|
|
26
|
+
if (!this._worker) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
|
|
30
|
+
if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
|
|
31
|
+
this._stopWorker();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
_getClient() {
|
|
35
|
+
this._lastUsedTime = Date.now();
|
|
36
|
+
if (!this._client) {
|
|
37
|
+
this._worker = createWebWorker({
|
|
38
|
+
// module that exports the create() method and returns a `HTMLWorker` instance
|
|
39
|
+
moduleId: "vs/language/html/htmlWorker",
|
|
40
|
+
createWorker: () => new Worker('./html.worker.js', { type: "module" }),
|
|
41
|
+
// passed in to the create() method
|
|
42
|
+
createData: {
|
|
43
|
+
languageSettings: this._defaults.options,
|
|
44
|
+
languageId: this._defaults.languageId
|
|
45
|
+
},
|
|
46
|
+
label: this._defaults.languageId
|
|
47
|
+
});
|
|
48
|
+
this._client = this._worker.getProxy();
|
|
49
|
+
}
|
|
50
|
+
return this._client;
|
|
51
|
+
}
|
|
52
|
+
getLanguageServiceWorker(...resources) {
|
|
53
|
+
let _client;
|
|
54
|
+
return this._getClient().then((client) => {
|
|
55
|
+
_client = client;
|
|
56
|
+
}).then((_) => {
|
|
57
|
+
if (this._worker) {
|
|
58
|
+
return this._worker.withSyncedResources(resources);
|
|
59
|
+
}
|
|
60
|
+
}).then((_) => _client);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { WorkerManager };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-vscode-standalone-html-language-features",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.2.1",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "CodinGame",
|
|
@@ -16,15 +16,18 @@
|
|
|
16
16
|
"description": "monaco-editor html language features bundled to work with @codingame/monaco-vscode-api",
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
|
-
"default": "./
|
|
19
|
+
"default": "./language/html/monaco.contribution.js"
|
|
20
20
|
},
|
|
21
21
|
"./worker": {
|
|
22
|
-
"default": "./worker.js"
|
|
22
|
+
"default": "./language/html/html.worker.js"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"main": "index.js",
|
|
26
26
|
"module": "index.js",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@23.
|
|
28
|
+
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@23.2.1",
|
|
29
|
+
"vscode-html-languageservice": "5.2.0",
|
|
30
|
+
"vscode-languageserver-textdocument": "1.0.12",
|
|
31
|
+
"vscode-languageserver-types": "3.17.5"
|
|
29
32
|
}
|
|
30
33
|
}
|