@volar/monaco 1.3.0-alpha.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/LICENSE +21 -0
- package/README.md +97 -0
- package/out/editor.d.ts +5 -0
- package/out/editor.js +95 -0
- package/out/index.d.ts +2 -0
- package/out/index.js +18 -0
- package/out/languages.d.ts +5 -0
- package/out/languages.js +47 -0
- package/out/utils/autoFetchTypes.d.ts +6 -0
- package/out/utils/autoFetchTypes.js +82 -0
- package/out/utils/markers.d.ts +3 -0
- package/out/utils/markers.js +4 -0
- package/out/utils/monaco2protocol.d.ts +7 -0
- package/out/utils/monaco2protocol.js +38 -0
- package/out/utils/protocol2monaco.d.ts +38 -0
- package/out/utils/protocol2monaco.js +490 -0
- package/out/utils/provider.d.ts +3 -0
- package/out/utils/provider.js +341 -0
- package/out/worker.d.ts +15 -0
- package/out/worker.js +179 -0
- package/package.json +25 -0
- package/worker.d.ts +1 -0
- package/worker.js +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Johnson Chu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# @volar/monaco
|
|
2
|
+
|
|
3
|
+
`@volar/monaco` is used to bridge the language capabilities implemented based on Volar.js to Monaco Editor, you can expect:
|
|
4
|
+
|
|
5
|
+
- Support IntelliSense, Diagnosis, Formatting
|
|
6
|
+
- Language behavior is consistent with regular IDEs
|
|
7
|
+
- Optimized Performance
|
|
8
|
+
- Missing package types are automatically fetched from CDN
|
|
9
|
+
|
|
10
|
+
It should be noted that this package does not participate in syntax highlighting support and language configuration.
|
|
11
|
+
|
|
12
|
+
We assume you already know:
|
|
13
|
+
|
|
14
|
+
- How to create a Monaco Editor
|
|
15
|
+
- How to work with Web Worker
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Setup worker
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// my-lang.worker.ts
|
|
23
|
+
import * as worker from 'monaco-editor-core/esm/vs/editor/editor.worker';
|
|
24
|
+
import type * as monaco from 'monaco-editor-core';
|
|
25
|
+
import { createLanguageService } from '@volar/monaco/worker';
|
|
26
|
+
|
|
27
|
+
self.onmessage = () => {
|
|
28
|
+
worker.initialize((ctx: monaco.worker.IWorkerContext) => {
|
|
29
|
+
return createLanguageService({
|
|
30
|
+
workerContext: ctx,
|
|
31
|
+
config: {
|
|
32
|
+
// ...Language Service Config of my-lang language support
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### TypeScript Support
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { createLanguageService } from '@volar/monaco/worker';
|
|
43
|
+
import * as ts from 'typescript';
|
|
44
|
+
|
|
45
|
+
createLanguageService({
|
|
46
|
+
// ...
|
|
47
|
+
typescript: {
|
|
48
|
+
module: ts as any,
|
|
49
|
+
compilerOptions: {
|
|
50
|
+
// ...tsconfig options
|
|
51
|
+
},
|
|
52
|
+
// Enable auto fetch node_modules types
|
|
53
|
+
autoFetchTypes: true,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Add worker loader to global env
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import editorWorker from 'monaco-editor-core/esm/vs/editor/editor.worker?worker';
|
|
62
|
+
import myWorker from './my-lang.worker?worker';
|
|
63
|
+
|
|
64
|
+
(self as any).MonacoEnvironment = {
|
|
65
|
+
getWorker(_: any, label: string) {
|
|
66
|
+
if (label === 'my-lang') {
|
|
67
|
+
return new myWorker();
|
|
68
|
+
}
|
|
69
|
+
return new editorWorker();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Setup Language Features and Diagnostics
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import type { LanguageService } from '@volar/language-service';
|
|
78
|
+
import { editor, languages } from 'monaco-editor-core';
|
|
79
|
+
import * as VolarMonaco from '@volar/monaco';
|
|
80
|
+
|
|
81
|
+
languages.register({ id: 'my-lang', extensions: ['.my-lang'] });
|
|
82
|
+
|
|
83
|
+
languages.onLanguage('my-lang', () => {
|
|
84
|
+
const worker = editor.createWebWorker<LanguageService>({
|
|
85
|
+
moduleId: 'vs/language/my-lang/myLangWorker',
|
|
86
|
+
label: 'my-lang',
|
|
87
|
+
});
|
|
88
|
+
VolarMonaco.editor.activateMarkers(worker, ['my-lang'], 'my-lang-markers-owner', editor);
|
|
89
|
+
VolarMonaco.languages.registerProvides(worker, ['my-lang'], languages)
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
## Samples
|
|
95
|
+
|
|
96
|
+
- Implementation for Vue:\
|
|
97
|
+
https://github.com/Kingwl/monaco-volar
|
package/out/editor.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LanguageService } from '@volar/language-service';
|
|
2
|
+
import type { editor as _editor, IDisposable } from 'monaco-editor-core';
|
|
3
|
+
export declare namespace editor {
|
|
4
|
+
function activateMarkers(worker: _editor.MonacoWebWorker<LanguageService>, languages: string[], markersOwn: string, editor: typeof import('monaco-editor-core').editor): IDisposable;
|
|
5
|
+
}
|
package/out/editor.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.editor = void 0;
|
|
12
|
+
const markers_1 = require("./utils/markers");
|
|
13
|
+
const protocol2monaco = require("./utils/protocol2monaco");
|
|
14
|
+
var editor;
|
|
15
|
+
(function (editor_1) {
|
|
16
|
+
function activateMarkers(worker, languages, markersOwn, editor) {
|
|
17
|
+
const disposables = [];
|
|
18
|
+
const listener = new Map();
|
|
19
|
+
disposables.push(editor.onDidCreateModel((model) => hostingMarkers(model)), editor.onWillDisposeModel(stopHostingMarkers), editor.onDidChangeModelLanguage((event) => {
|
|
20
|
+
stopHostingMarkers(event.model);
|
|
21
|
+
hostingMarkers(event.model);
|
|
22
|
+
}), {
|
|
23
|
+
dispose: () => {
|
|
24
|
+
for (const model of editor.getModels()) {
|
|
25
|
+
stopHostingMarkers(model);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
for (const model of editor.getModels()) {
|
|
30
|
+
hostingMarkers(model);
|
|
31
|
+
}
|
|
32
|
+
return { dispose: () => disposables.forEach((d) => d.dispose()) };
|
|
33
|
+
function stopHostingMarkers(model) {
|
|
34
|
+
var _a;
|
|
35
|
+
editor.setModelMarkers(model, markersOwn, []);
|
|
36
|
+
const key = model.uri.toString();
|
|
37
|
+
if (listener.has(key)) {
|
|
38
|
+
(_a = listener.get(key)) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
39
|
+
listener.delete(key);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function hostingMarkers(model) {
|
|
43
|
+
if (!languages.includes(model.getLanguageId())) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let timer;
|
|
47
|
+
const changeSubscription = model.onDidChangeContent(() => {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
timer = setTimeout(() => doValidation(model), 200);
|
|
50
|
+
});
|
|
51
|
+
const visibleSubscription = model.onDidChangeAttached(() => {
|
|
52
|
+
if (model.isAttachedToEditor()) {
|
|
53
|
+
doValidation(model);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
editor.setModelMarkers(model, markersOwn, []);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
listener.set(model.uri.toString(), {
|
|
60
|
+
dispose: () => {
|
|
61
|
+
changeSubscription.dispose();
|
|
62
|
+
visibleSubscription.dispose();
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
doValidation(model);
|
|
67
|
+
}
|
|
68
|
+
function doValidation(model) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
if (model.isDisposed()) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!model.isAttachedToEditor()) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const languageService = yield getLanguageService(model.uri);
|
|
77
|
+
const diagnostics = yield languageService.doValidation(model.uri.toString());
|
|
78
|
+
const result = diagnostics.map(error => {
|
|
79
|
+
const marker = protocol2monaco.asMarkerData(error);
|
|
80
|
+
markers_1.markers.set(marker, error);
|
|
81
|
+
return marker;
|
|
82
|
+
});
|
|
83
|
+
editor.setModelMarkers(model, markersOwn, result);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function getLanguageService(...uris) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
yield worker.withSyncedResources(uris);
|
|
89
|
+
return worker.getProxy();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
editor_1.activateMarkers = activateMarkers;
|
|
94
|
+
})(editor = exports.editor || (exports.editor = {}));
|
|
95
|
+
//# sourceMappingURL=editor.js.map
|
package/out/index.d.ts
ADDED
package/out/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
13
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
__exportStar(require("./languages"), exports);
|
|
17
|
+
__exportStar(require("./editor"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { editor, languages as _languages, IDisposable } from 'monaco-editor-core';
|
|
2
|
+
import type { LanguageService } from '@volar/language-service';
|
|
3
|
+
export declare namespace languages {
|
|
4
|
+
function registerProvides(worker: editor.MonacoWebWorker<LanguageService>, language: _languages.LanguageSelector, languages: typeof import('monaco-editor-core').languages): Promise<IDisposable>;
|
|
5
|
+
}
|
package/out/languages.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.languages = void 0;
|
|
12
|
+
const provider_1 = require("./utils/provider");
|
|
13
|
+
var languages;
|
|
14
|
+
(function (languages_1) {
|
|
15
|
+
function registerProvides(worker, language, languages) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const provider = yield (0, provider_1.createLanguageFeaturesProvider)(worker);
|
|
18
|
+
const disposables = [
|
|
19
|
+
languages.registerHoverProvider(language, provider),
|
|
20
|
+
languages.registerReferenceProvider(language, provider),
|
|
21
|
+
languages.registerRenameProvider(language, provider),
|
|
22
|
+
languages.registerSignatureHelpProvider(language, provider),
|
|
23
|
+
languages.registerDocumentSymbolProvider(language, provider),
|
|
24
|
+
languages.registerDocumentHighlightProvider(language, provider),
|
|
25
|
+
languages.registerLinkedEditingRangeProvider(language, provider),
|
|
26
|
+
languages.registerDefinitionProvider(language, provider),
|
|
27
|
+
languages.registerImplementationProvider(language, provider),
|
|
28
|
+
languages.registerTypeDefinitionProvider(language, provider),
|
|
29
|
+
languages.registerCodeLensProvider(language, provider),
|
|
30
|
+
languages.registerCodeActionProvider(language, provider),
|
|
31
|
+
languages.registerDocumentFormattingEditProvider(language, provider),
|
|
32
|
+
languages.registerDocumentRangeFormattingEditProvider(language, provider),
|
|
33
|
+
languages.registerOnTypeFormattingEditProvider(language, provider),
|
|
34
|
+
languages.registerLinkProvider(language, provider),
|
|
35
|
+
languages.registerCompletionItemProvider(language, provider),
|
|
36
|
+
languages.registerColorProvider(language, provider),
|
|
37
|
+
languages.registerFoldingRangeProvider(language, provider),
|
|
38
|
+
languages.registerDeclarationProvider(language, provider),
|
|
39
|
+
languages.registerSelectionRangeProvider(language, provider),
|
|
40
|
+
languages.registerInlayHintsProvider(language, provider),
|
|
41
|
+
];
|
|
42
|
+
return { dispose: () => disposables.forEach((d) => d.dispose()) };
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
languages_1.registerProvides = registerProvides;
|
|
46
|
+
})(languages = exports.languages || (exports.languages = {}));
|
|
47
|
+
//# sourceMappingURL=languages.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createAutoTypesFetchingHost = void 0;
|
|
12
|
+
const axios_1 = require("axios");
|
|
13
|
+
function createAutoTypesFetchingHost(cdn) {
|
|
14
|
+
const fetchTasks = [];
|
|
15
|
+
const files = new Map();
|
|
16
|
+
let fetching;
|
|
17
|
+
return {
|
|
18
|
+
fileExists,
|
|
19
|
+
readFile,
|
|
20
|
+
files,
|
|
21
|
+
wait: () => __awaiter(this, void 0, void 0, function* () { return yield fetching; }),
|
|
22
|
+
};
|
|
23
|
+
function fileExists(fileName) {
|
|
24
|
+
return readFile(fileName) !== undefined;
|
|
25
|
+
}
|
|
26
|
+
function readFile(fileName) {
|
|
27
|
+
if (!files.has(fileName)) {
|
|
28
|
+
files.set(fileName, undefined);
|
|
29
|
+
fetch(fileName);
|
|
30
|
+
}
|
|
31
|
+
return files.get(fileName);
|
|
32
|
+
}
|
|
33
|
+
function readFileAsync(fileName) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
if (fileName.startsWith('/node_modules/')) {
|
|
36
|
+
const url = cdn + fileName.slice('/node_modules/'.length);
|
|
37
|
+
const text = yield readWebFile(url);
|
|
38
|
+
files.set(fileName, text);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function readWebFile(uri) {
|
|
43
|
+
var _a;
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
// ignore .js because it's no help for intellisense
|
|
46
|
+
if (uri.endsWith('.d.ts') || uri.endsWith('.json')) {
|
|
47
|
+
try {
|
|
48
|
+
return (_a = (yield axios_1.default.get(uri, {
|
|
49
|
+
transformResponse: (res) => {
|
|
50
|
+
// avoid parse to json object
|
|
51
|
+
return res;
|
|
52
|
+
},
|
|
53
|
+
})).data) !== null && _a !== void 0 ? _a : undefined;
|
|
54
|
+
}
|
|
55
|
+
catch (_b) {
|
|
56
|
+
// ignore
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function fetch(fileName) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
fetchTasks.push([fileName, readFileAsync(fileName)]);
|
|
64
|
+
if (!fetching) {
|
|
65
|
+
fetching = fetchWorker();
|
|
66
|
+
yield fetching;
|
|
67
|
+
fetching = undefined;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function fetchWorker() {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
while (fetchTasks.length) {
|
|
74
|
+
const tasks = fetchTasks.map(([_, task]) => task);
|
|
75
|
+
fetchTasks.length = 0;
|
|
76
|
+
yield Promise.all(tasks);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.createAutoTypesFetchingHost = createAutoTypesFetchingHost;
|
|
82
|
+
//# sourceMappingURL=autoFetchTypes.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IRange, languages, Position } from 'monaco-editor-core';
|
|
2
|
+
import * as protocol from 'vscode-languageserver-protocol';
|
|
3
|
+
export declare function asPosition(position: Position): protocol.Position;
|
|
4
|
+
export declare function asRange(range: IRange): protocol.Range;
|
|
5
|
+
export declare function asCompletionContext(context: languages.CompletionContext): protocol.CompletionContext;
|
|
6
|
+
export declare function asTriggerKind(kind: languages.CompletionTriggerKind): protocol.CompletionTriggerKind;
|
|
7
|
+
export declare function asFormattingOptions(options: languages.FormattingOptions): protocol.FormattingOptions;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.asFormattingOptions = exports.asTriggerKind = exports.asCompletionContext = exports.asRange = exports.asPosition = void 0;
|
|
3
|
+
const monaco_editor_core_1 = require("monaco-editor-core");
|
|
4
|
+
const protocol = require("vscode-languageserver-protocol");
|
|
5
|
+
function asPosition(position) {
|
|
6
|
+
return protocol.Position.create(position.lineNumber - 1, position.column - 1);
|
|
7
|
+
}
|
|
8
|
+
exports.asPosition = asPosition;
|
|
9
|
+
function asRange(range) {
|
|
10
|
+
return protocol.Range.create(range.startLineNumber - 1, range.startColumn - 1, range.endLineNumber - 1, range.endColumn - 1);
|
|
11
|
+
}
|
|
12
|
+
exports.asRange = asRange;
|
|
13
|
+
function asCompletionContext(context) {
|
|
14
|
+
return {
|
|
15
|
+
triggerKind: asTriggerKind(context.triggerKind),
|
|
16
|
+
triggerCharacter: context.triggerCharacter,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.asCompletionContext = asCompletionContext;
|
|
20
|
+
function asTriggerKind(kind) {
|
|
21
|
+
switch (kind) {
|
|
22
|
+
case monaco_editor_core_1.languages.CompletionTriggerKind.Invoke:
|
|
23
|
+
return protocol.CompletionTriggerKind.Invoked;
|
|
24
|
+
case monaco_editor_core_1.languages.CompletionTriggerKind.TriggerCharacter:
|
|
25
|
+
return protocol.CompletionTriggerKind.TriggerCharacter;
|
|
26
|
+
case monaco_editor_core_1.languages.CompletionTriggerKind.TriggerForIncompleteCompletions:
|
|
27
|
+
return protocol.CompletionTriggerKind.TriggerForIncompleteCompletions;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.asTriggerKind = asTriggerKind;
|
|
31
|
+
function asFormattingOptions(options) {
|
|
32
|
+
return {
|
|
33
|
+
tabSize: options.tabSize,
|
|
34
|
+
insertSpaces: options.insertSpaces,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.asFormattingOptions = asFormattingOptions;
|
|
38
|
+
//# sourceMappingURL=monaco2protocol.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { editor, IMarkdownString, IRange, languages, MarkerSeverity, MarkerTag, Position, Uri } from 'monaco-editor-core';
|
|
2
|
+
import * as protocol from 'vscode-languageserver-protocol';
|
|
3
|
+
export declare function asCompletionList(list: protocol.CompletionList, range: protocol.Range): languages.CompletionList;
|
|
4
|
+
export declare function asCompletionItemKind(kind: protocol.CompletionItemKind | undefined): languages.CompletionItemKind;
|
|
5
|
+
export declare function asCompletionItem(item: protocol.CompletionItem, range: protocol.Range): languages.CompletionItem;
|
|
6
|
+
export declare function asCommand(command: protocol.Command): languages.Command;
|
|
7
|
+
export declare function asTextEdit(edit: protocol.TextEdit): languages.TextEdit;
|
|
8
|
+
export declare function asCompletionItemRange(textEdit: NonNullable<protocol.CompletionItem['textEdit']>): languages.CompletionItem['range'];
|
|
9
|
+
export declare function asRange(range: protocol.Range): IRange;
|
|
10
|
+
export declare function asHover(hover: protocol.Hover): languages.Hover;
|
|
11
|
+
export declare function asMarkdownString(markdownString: protocol.Hover['contents']): IMarkdownString[];
|
|
12
|
+
export declare function asLocation(definition: protocol.LocationLink | protocol.Location): languages.Location;
|
|
13
|
+
export declare function asUri(uri: protocol.URI): Uri;
|
|
14
|
+
export declare function asSignatureHelp(signatureHelp: protocol.SignatureHelp): languages.SignatureHelp;
|
|
15
|
+
export declare function asSignatureInformation(signatureInformation: protocol.SignatureInformation): languages.SignatureInformation;
|
|
16
|
+
export declare function asParameterInformation(parameterInformation: protocol.ParameterInformation): languages.ParameterInformation;
|
|
17
|
+
export declare function asMarkerData(diagnostic: protocol.Diagnostic): editor.IMarkerData;
|
|
18
|
+
export declare function asMarkerTag(tag: protocol.DiagnosticTag): MarkerTag;
|
|
19
|
+
export declare function asRelatedInformation(relatedInformation: protocol.DiagnosticRelatedInformation): editor.IRelatedInformation;
|
|
20
|
+
export declare function asMarkerSeverity(severity: protocol.DiagnosticSeverity | undefined): MarkerSeverity;
|
|
21
|
+
export declare function asWorkspaceEdit(workspaceEdit: protocol.WorkspaceEdit): languages.WorkspaceEdit;
|
|
22
|
+
export declare function asDocumentSymbol(symbol: protocol.DocumentSymbol): languages.DocumentSymbol;
|
|
23
|
+
export declare function asSymbolTag(tag: protocol.SymbolTag): languages.SymbolTag;
|
|
24
|
+
export declare function asSymbolKind(kind: protocol.SymbolKind): languages.SymbolKind;
|
|
25
|
+
export declare function asDocumentHighlight(highlight: protocol.DocumentHighlight): languages.DocumentHighlight;
|
|
26
|
+
export declare function asDocumentHighlightKind(kind: protocol.DocumentHighlightKind | undefined): languages.DocumentHighlightKind;
|
|
27
|
+
export declare function asCodeLens(item: protocol.CodeLens): languages.CodeLens;
|
|
28
|
+
export declare function asCodeAction(item: protocol.CodeAction): languages.CodeAction;
|
|
29
|
+
export declare function asLink(item: protocol.DocumentLink): languages.ILink;
|
|
30
|
+
export declare function asColorInformation(item: protocol.ColorInformation): languages.IColorInformation;
|
|
31
|
+
export declare function asColorPresentation(item: protocol.ColorPresentation): languages.IColorPresentation;
|
|
32
|
+
export declare function asFoldingRange(item: protocol.FoldingRange): languages.FoldingRange;
|
|
33
|
+
export declare function asSelectionRange(item: protocol.SelectionRange): languages.SelectionRange;
|
|
34
|
+
export declare function asInlayHint(item: protocol.InlayHint): languages.InlayHint;
|
|
35
|
+
export declare function asInlayHintKind(kind: protocol.InlayHintKind): languages.InlayHintKind;
|
|
36
|
+
export declare function asInlayHintLabel(label: protocol.InlayHint['label']): languages.InlayHint['label'];
|
|
37
|
+
export declare function asInlayHintLabelPart(part: protocol.InlayHintLabelPart): languages.InlayHintLabelPart;
|
|
38
|
+
export declare function asPosition(position: protocol.Position): Position;
|