@typespec/playground 0.3.0-dev.9 → 0.4.0-dev.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/dist/.storybook/main.d.ts +5 -0
- package/dist/.storybook/main.d.ts.map +1 -0
- package/dist/.storybook/preview.d.ts +5 -0
- package/dist/.storybook/preview.d.ts.map +1 -0
- package/dist/index.js +31 -34
- package/dist/react/index.js +1430 -783
- package/dist/react/viewers/index.js +8 -7
- package/dist/react-wrapper-CT3xxCSW.js +20 -0
- package/dist/src/browser-host.d.ts +3 -2
- package/dist/src/browser-host.d.ts.map +1 -1
- package/dist/src/core.d.ts +1 -1
- package/dist/src/core.d.ts.map +1 -1
- package/dist/src/editor-command-bar/editor-command-bar.d.ts +4 -3
- package/dist/src/editor-command-bar/editor-command-bar.d.ts.map +1 -1
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/lsp/monaco-to-lsp.d.ts +1 -1
- package/dist/src/manifest.d.ts +2 -4
- package/dist/src/manifest.d.ts.map +1 -1
- package/dist/src/react/context/index.d.ts +1 -1
- package/dist/src/react/context/index.d.ts.map +1 -1
- package/dist/src/react/context/playground-context.d.ts +4 -4
- package/dist/src/react/context/playground-context.d.ts.map +1 -1
- package/dist/src/react/default-footer.d.ts +2 -1
- package/dist/src/react/default-footer.d.ts.map +1 -1
- package/dist/src/react/diagnostic-list/diagnostic-list.d.ts +3 -2
- package/dist/src/react/diagnostic-list/diagnostic-list.d.ts.map +1 -1
- package/dist/src/react/editor.d.ts +3 -2
- package/dist/src/react/editor.d.ts.map +1 -1
- package/dist/src/react/emitter-dropdown.d.ts +2 -1
- package/dist/src/react/emitter-dropdown.d.ts.map +1 -1
- package/dist/src/react/file-output/file-output.d.ts +6 -5
- package/dist/src/react/file-output/file-output.d.ts.map +1 -1
- package/dist/src/react/footer/footer-item.d.ts +2 -1
- package/dist/src/react/footer/footer-item.d.ts.map +1 -1
- package/dist/src/react/footer/footer-version-item.d.ts +1 -1
- package/dist/src/react/footer/footer.d.ts +2 -1
- package/dist/src/react/footer/footer.d.ts.map +1 -1
- package/dist/src/react/footer/index.d.ts +3 -3
- package/dist/src/react/footer/index.d.ts.map +1 -1
- package/dist/src/react/index.d.ts +6 -6
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/output-tabs/output-tabs.d.ts +3 -7
- package/dist/src/react/output-tabs/output-tabs.d.ts.map +1 -1
- package/dist/src/react/output-view/file-viewer.d.ts +4 -0
- package/dist/src/react/output-view/file-viewer.d.ts.map +1 -0
- package/dist/src/react/output-view/output-view.d.ts +9 -4
- package/dist/src/react/output-view/output-view.d.ts.map +1 -1
- package/dist/src/react/output-view/type-graph-viewer.d.ts +4 -0
- package/dist/src/react/output-view/type-graph-viewer.d.ts.map +1 -0
- package/dist/src/react/playground.d.ts +8 -5
- package/dist/src/react/playground.d.ts.map +1 -1
- package/dist/src/react/problem-pane/header.d.ts +4 -3
- package/dist/src/react/problem-pane/header.d.ts.map +1 -1
- package/dist/src/react/problem-pane/index.d.ts +1 -1
- package/dist/src/react/problem-pane/problem-pane.d.ts +4 -3
- package/dist/src/react/problem-pane/problem-pane.d.ts.map +1 -1
- package/dist/src/react/samples-dropdown.d.ts +3 -2
- package/dist/src/react/samples-dropdown.d.ts.map +1 -1
- package/dist/src/react/settings/compiler-settings-dialog-button.d.ts +2 -1
- package/dist/src/react/settings/compiler-settings.d.ts +4 -3
- package/dist/src/react/settings/compiler-settings.d.ts.map +1 -1
- package/dist/src/react/settings/emitter-options-form.d.ts +4 -3
- package/dist/src/react/settings/emitter-options-form.d.ts.map +1 -1
- package/dist/src/react/settings/linter-form.d.ts +4 -3
- package/dist/src/react/settings/linter-form.d.ts.map +1 -1
- package/dist/src/react/split-pane/index.d.ts +1 -1
- package/dist/src/react/split-pane/index.d.ts.map +1 -1
- package/dist/src/react/split-pane/pane.d.ts +2 -1
- package/dist/src/react/split-pane/pane.d.ts.map +1 -1
- package/dist/src/react/split-pane/sash-content.d.ts +2 -1
- package/dist/src/react/split-pane/sash-content.d.ts.map +1 -1
- package/dist/src/react/split-pane/sash.d.ts +2 -1
- package/dist/src/react/split-pane/sash.d.ts.map +1 -1
- package/dist/src/react/split-pane/split-pane.d.ts +2 -1
- package/dist/src/react/split-pane/split-pane.d.ts.map +1 -1
- package/dist/src/react/standalone.d.ts +5 -4
- package/dist/src/react/standalone.d.ts.map +1 -1
- package/dist/src/react/types.d.ts +20 -8
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/typespec-editor.d.ts +5 -4
- package/dist/src/react/typespec-editor.d.ts.map +1 -1
- package/dist/src/react/viewers/index.d.ts +2 -1
- package/dist/src/react/viewers/index.d.ts.map +1 -1
- package/dist/src/react/viewers/swagger-ui.d.ts +2 -2
- package/dist/src/react/viewers/swagger-ui.d.ts.map +1 -1
- package/dist/src/services.d.ts +3 -2
- package/dist/src/services.d.ts.map +1 -1
- package/dist/src/tooling/index.d.ts +2 -1
- package/dist/src/tooling/index.d.ts.map +1 -1
- package/dist/src/tooling/types.d.ts +2 -1
- package/dist/src/tooling/types.d.ts.map +1 -1
- package/dist/src/types.d.ts +2 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/vite/index.d.ts +3 -2
- package/dist/src/vite/index.d.ts.map +1 -1
- package/dist/src/vite/types.d.ts +4 -3
- package/dist/src/vite/types.d.ts.map +1 -1
- package/dist/state-storage-BjOULkS3.js +654 -0
- package/dist/stories/footer/footer-item.stories.d.ts +9 -0
- package/dist/stories/footer/footer-item.stories.d.ts.map +1 -0
- package/dist/stories/footer/footer-version-item.stories.d.ts +9 -0
- package/dist/stories/footer/footer-version-item.stories.d.ts.map +1 -0
- package/dist/stories/footer/footer.stories.d.ts +9 -0
- package/dist/stories/footer/footer.stories.d.ts.map +1 -0
- package/dist/stories/playground.stories.d.ts +9 -0
- package/dist/stories/playground.stories.d.ts.map +1 -0
- package/dist/{index.css → style.css} +168 -161
- package/dist/tooling/index.js +18 -23
- package/dist/vite/index.js +74 -76
- package/dist/vite.config.d.ts +3 -0
- package/dist/vite.config.d.ts.map +1 -0
- package/package.json +38 -36
- package/dist/index.js.map +0 -1
- package/dist/react/index.js.map +0 -1
- package/dist/react/viewers/index.js.map +0 -1
- package/dist/react-wrapper-uSmRU7Jg.js +0 -21
- package/dist/react-wrapper-uSmRU7Jg.js.map +0 -1
- package/dist/state-storage-CObxFEXn.js +0 -657
- package/dist/state-storage-CObxFEXn.js.map +0 -1
- package/dist/tooling/index.js.map +0 -1
- package/dist/vite/index.js.map +0 -1
|
@@ -1,657 +0,0 @@
|
|
|
1
|
-
import { resolvePath, createSourceFile, getSourceFileKindFromExt, TypeSpecLanguageConfiguration } from '@typespec/compiler';
|
|
2
|
-
import * as monaco from 'monaco-editor';
|
|
3
|
-
import * as lsp from 'vscode-languageserver';
|
|
4
|
-
import { DiagnosticSeverity, FormattingOptions, DocumentHighlightKind } from 'vscode-languageserver';
|
|
5
|
-
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
6
|
-
import lzutf8 from 'lzutf8';
|
|
7
|
-
|
|
8
|
-
async function importTypeSpecCompiler(config) {
|
|
9
|
-
return (await importLibrary("@typespec/compiler", config));
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* @param name Import name.
|
|
13
|
-
* @returns Promise with the loaded module.
|
|
14
|
-
*/
|
|
15
|
-
async function importLibrary(name, config) {
|
|
16
|
-
return config.useShim
|
|
17
|
-
? importShim(name)
|
|
18
|
-
: import(/* @vite-ignore */ /* webpackIgnore: true */ name);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Loading external import map doesn't work yet
|
|
22
|
-
*
|
|
23
|
-
* https://github.com/WICG/import-maps/issues/235
|
|
24
|
-
*
|
|
25
|
-
* A polyfill for importmap is loaded but required calling importShim instead of the native import https://github.com/guybedford/es-module-shims
|
|
26
|
-
* @param name Import name.
|
|
27
|
-
* @returns Promise with the loaded module.
|
|
28
|
-
*/
|
|
29
|
-
async function importShim(name) {
|
|
30
|
-
return window.importShim(name);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function resolveVirtualPath(path, ...paths) {
|
|
34
|
-
return resolvePath("/test", path, ...paths);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Create the browser host from the list of libraries.
|
|
38
|
-
* @param libsToLoad List of libraries to load. Those must be set in the webpage importmap.
|
|
39
|
-
* @param importOptions Import configuration.
|
|
40
|
-
* @returns
|
|
41
|
-
*/
|
|
42
|
-
async function createBrowserHost(libsToLoad, importOptions = {}) {
|
|
43
|
-
const virtualFs = new Map();
|
|
44
|
-
const jsImports = new Map();
|
|
45
|
-
const libraries = {};
|
|
46
|
-
for (const libName of libsToLoad) {
|
|
47
|
-
const { _TypeSpecLibrary_, $lib, $linter } = (await importLibrary(libName, importOptions));
|
|
48
|
-
libraries[libName] = {
|
|
49
|
-
name: libName,
|
|
50
|
-
isEmitter: $lib?.emitter,
|
|
51
|
-
definition: $lib,
|
|
52
|
-
packageJson: JSON.parse(_TypeSpecLibrary_.typespecSourceFiles["package.json"]),
|
|
53
|
-
linter: $linter,
|
|
54
|
-
};
|
|
55
|
-
for (const [key, value] of Object.entries(_TypeSpecLibrary_.typespecSourceFiles)) {
|
|
56
|
-
virtualFs.set(`/test/node_modules/${libName}/${key}`, value);
|
|
57
|
-
}
|
|
58
|
-
for (const [key, value] of Object.entries(_TypeSpecLibrary_.jsSourceFiles)) {
|
|
59
|
-
addJsImport(`/test/node_modules/${libName}/${key}`, value);
|
|
60
|
-
}
|
|
61
|
-
virtualFs.set(`/test/package.json`, JSON.stringify({
|
|
62
|
-
name: "playground-pkg",
|
|
63
|
-
dependencies: Object.fromEntries(Object.values(libraries).map((x) => [x.name, x.packageJson.version])),
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
function addJsImport(path, value) {
|
|
67
|
-
virtualFs.set(path, "");
|
|
68
|
-
jsImports.set(path, value);
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
compiler: await importTypeSpecCompiler(importOptions),
|
|
72
|
-
libraries,
|
|
73
|
-
async readUrl(url) {
|
|
74
|
-
const contents = virtualFs.get(url);
|
|
75
|
-
if (contents === undefined) {
|
|
76
|
-
const e = new Error(`File ${url} not found.`);
|
|
77
|
-
e.code = "ENOENT";
|
|
78
|
-
throw e;
|
|
79
|
-
}
|
|
80
|
-
return createSourceFile(contents, url);
|
|
81
|
-
},
|
|
82
|
-
async readFile(path) {
|
|
83
|
-
path = resolveVirtualPath(path);
|
|
84
|
-
const contents = virtualFs.get(path);
|
|
85
|
-
if (contents === undefined) {
|
|
86
|
-
const e = new Error(`File ${path} not found.`);
|
|
87
|
-
e.code = "ENOENT";
|
|
88
|
-
throw e;
|
|
89
|
-
}
|
|
90
|
-
return createSourceFile(contents, path);
|
|
91
|
-
},
|
|
92
|
-
async writeFile(path, content) {
|
|
93
|
-
path = resolveVirtualPath(path);
|
|
94
|
-
virtualFs.set(path, content);
|
|
95
|
-
},
|
|
96
|
-
async readDir(path) {
|
|
97
|
-
path = resolveVirtualPath(path);
|
|
98
|
-
const fileFolder = [...virtualFs.keys()]
|
|
99
|
-
.filter((x) => x.startsWith(`${path}/`))
|
|
100
|
-
.map((x) => x.replace(`${path}/`, ""))
|
|
101
|
-
.map((x) => {
|
|
102
|
-
const index = x.indexOf("/");
|
|
103
|
-
return index !== -1 ? x.substring(0, index) : x;
|
|
104
|
-
});
|
|
105
|
-
return [...new Set(fileFolder)];
|
|
106
|
-
},
|
|
107
|
-
async rm(path) {
|
|
108
|
-
path = resolveVirtualPath(path);
|
|
109
|
-
for (const key of virtualFs.keys()) {
|
|
110
|
-
if (key === path || key.startsWith(`${path}/`)) {
|
|
111
|
-
virtualFs.delete(key);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
getLibDirs() {
|
|
116
|
-
if (virtualFs.has(resolveVirtualPath("/test/node_modules/@typespec/compiler/lib/std/main.tsp"))) {
|
|
117
|
-
return [resolveVirtualPath("/test/node_modules/@typespec/compiler/lib/std")];
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
// To load older version of the compiler < 0.55.0
|
|
121
|
-
return [resolveVirtualPath("/test/node_modules/@typespec/compiler/lib")];
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
getExecutionRoot() {
|
|
125
|
-
return resolveVirtualPath("/test/node_modules/@typespec/compiler");
|
|
126
|
-
},
|
|
127
|
-
async getJsImport(path) {
|
|
128
|
-
path = resolveVirtualPath(path);
|
|
129
|
-
const module = await jsImports.get(path);
|
|
130
|
-
if (module === undefined) {
|
|
131
|
-
const e = new Error(`Module ${path} not found`);
|
|
132
|
-
e.code = "MODULE_NOT_FOUND";
|
|
133
|
-
throw e;
|
|
134
|
-
}
|
|
135
|
-
return module;
|
|
136
|
-
},
|
|
137
|
-
async stat(path) {
|
|
138
|
-
path = resolveVirtualPath(path);
|
|
139
|
-
if (virtualFs.has(path)) {
|
|
140
|
-
return {
|
|
141
|
-
isDirectory() {
|
|
142
|
-
return false;
|
|
143
|
-
},
|
|
144
|
-
isFile() {
|
|
145
|
-
return true;
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
for (const fsPath of virtualFs.keys()) {
|
|
150
|
-
if (fsPath.startsWith(path) && fsPath !== path) {
|
|
151
|
-
return {
|
|
152
|
-
isDirectory() {
|
|
153
|
-
return true;
|
|
154
|
-
},
|
|
155
|
-
isFile() {
|
|
156
|
-
return false;
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const e = new Error(`File ${path} not found.`);
|
|
162
|
-
e.code = "ENOENT";
|
|
163
|
-
throw e;
|
|
164
|
-
},
|
|
165
|
-
// symlinks not supported in test-host
|
|
166
|
-
async realpath(path) {
|
|
167
|
-
return path;
|
|
168
|
-
},
|
|
169
|
-
getSourceFileKind: getSourceFileKindFromExt,
|
|
170
|
-
logSink: console,
|
|
171
|
-
mkdirp: async (path) => path,
|
|
172
|
-
fileURLToPath(path) {
|
|
173
|
-
return path.replace("inmemory:/", "");
|
|
174
|
-
},
|
|
175
|
-
pathToFileURL(path) {
|
|
176
|
-
return "inmemory:/" + resolveVirtualPath(path);
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function range(range) {
|
|
182
|
-
return {
|
|
183
|
-
startColumn: range.start.character + 1,
|
|
184
|
-
startLineNumber: range.start.line + 1,
|
|
185
|
-
endColumn: range.end.character + 1,
|
|
186
|
-
endLineNumber: range.end.line + 1,
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
function foldingRange(range) {
|
|
190
|
-
return {
|
|
191
|
-
start: range.startLine + 1,
|
|
192
|
-
end: range.endLine + 1,
|
|
193
|
-
kind: range.kind ? new monaco.languages.FoldingRangeKind(range.kind) : undefined,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
function textEdits(edit) {
|
|
197
|
-
return edit.map(textEdit);
|
|
198
|
-
}
|
|
199
|
-
function textEdit(edit) {
|
|
200
|
-
return {
|
|
201
|
-
range: range(edit.range),
|
|
202
|
-
text: edit.newText,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
function signatureHelp(help) {
|
|
206
|
-
return {
|
|
207
|
-
signatures: help?.signatures.map((x) => ({
|
|
208
|
-
...x,
|
|
209
|
-
parameters: x.parameters ?? [],
|
|
210
|
-
})) ?? [],
|
|
211
|
-
activeSignature: help?.activeSignature ?? 0,
|
|
212
|
-
activeParameter: help?.activeParameter ?? 0,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
function command(command) {
|
|
216
|
-
return {
|
|
217
|
-
id: command.command,
|
|
218
|
-
title: command.title,
|
|
219
|
-
arguments: command.arguments,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
function severity(severity) {
|
|
223
|
-
switch (severity) {
|
|
224
|
-
case DiagnosticSeverity.Error:
|
|
225
|
-
return monaco.MarkerSeverity.Error;
|
|
226
|
-
case DiagnosticSeverity.Warning:
|
|
227
|
-
return monaco.MarkerSeverity.Warning;
|
|
228
|
-
case DiagnosticSeverity.Hint:
|
|
229
|
-
return monaco.MarkerSeverity.Hint;
|
|
230
|
-
case DiagnosticSeverity.Information:
|
|
231
|
-
return monaco.MarkerSeverity.Info;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
function diagnostic(diagnostic) {
|
|
235
|
-
return {
|
|
236
|
-
severity: diagnostic.severity ? severity(diagnostic.severity) : monaco.MarkerSeverity.Error,
|
|
237
|
-
message: diagnostic.message,
|
|
238
|
-
code: diagnostic.code?.toString(),
|
|
239
|
-
source: diagnostic.source,
|
|
240
|
-
startLineNumber: diagnostic.range.start.line + 1,
|
|
241
|
-
startColumn: diagnostic.range.start.character + 1,
|
|
242
|
-
endLineNumber: diagnostic.range.end.line + 1,
|
|
243
|
-
endColumn: diagnostic.range.end.character + 1,
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
function codeAction(action) {
|
|
247
|
-
return {
|
|
248
|
-
title: action.title,
|
|
249
|
-
kind: action.kind,
|
|
250
|
-
diagnostics: action.diagnostics?.map(diagnostic),
|
|
251
|
-
command: action.command && command(action.command),
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
const LspToMonaco = {
|
|
255
|
-
range,
|
|
256
|
-
foldingRange,
|
|
257
|
-
textEdits,
|
|
258
|
-
textEdit,
|
|
259
|
-
signatureHelp,
|
|
260
|
-
codeAction,
|
|
261
|
-
command,
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
function getIndentAction(value) {
|
|
265
|
-
switch (value) {
|
|
266
|
-
case "none":
|
|
267
|
-
return monaco.languages.IndentAction.None;
|
|
268
|
-
case "indent":
|
|
269
|
-
return monaco.languages.IndentAction.Indent;
|
|
270
|
-
case "indentOutdent":
|
|
271
|
-
return monaco.languages.IndentAction.IndentOutdent;
|
|
272
|
-
case "outdent":
|
|
273
|
-
return monaco.languages.IndentAction.Outdent;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
function getTypeSpecLanguageConfiguration() {
|
|
277
|
-
return {
|
|
278
|
-
...TypeSpecLanguageConfiguration,
|
|
279
|
-
onEnterRules: TypeSpecLanguageConfiguration.onEnterRules.map((rule) => {
|
|
280
|
-
return {
|
|
281
|
-
beforeText: new RegExp(rule.beforeText.pattern),
|
|
282
|
-
previousLineText: "previousLineText" in rule ? new RegExp(rule.previousLineText.pattern) : undefined,
|
|
283
|
-
action: {
|
|
284
|
-
indentAction: getIndentAction(rule.action.indent),
|
|
285
|
-
appendText: "appendText" in rule.action ? rule.action.appendText : undefined,
|
|
286
|
-
removeText: "removeText" in rule.action ? rule.action.removeText : undefined,
|
|
287
|
-
},
|
|
288
|
-
};
|
|
289
|
-
}),
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
async function registerMonacoLanguage(host) {
|
|
293
|
-
monaco.languages.register({ id: "typespec", extensions: [".tsp"] });
|
|
294
|
-
monaco.languages.setLanguageConfiguration("typespec", getTypeSpecLanguageConfiguration());
|
|
295
|
-
const serverHost = {
|
|
296
|
-
compilerHost: host,
|
|
297
|
-
getOpenDocumentByURL(url) {
|
|
298
|
-
const model = monaco.editor.getModel(monaco.Uri.parse(url));
|
|
299
|
-
return model ? textDocumentForModel(model) : undefined;
|
|
300
|
-
},
|
|
301
|
-
sendDiagnostics() { },
|
|
302
|
-
// eslint-disable-next-line no-console
|
|
303
|
-
log: console.log,
|
|
304
|
-
applyEdit(param) {
|
|
305
|
-
return Promise.resolve({ applied: false });
|
|
306
|
-
},
|
|
307
|
-
};
|
|
308
|
-
const { createServer } = host.compiler;
|
|
309
|
-
const serverLib = createServer(serverHost);
|
|
310
|
-
const lsConfig = await serverLib.initialize({
|
|
311
|
-
capabilities: {},
|
|
312
|
-
processId: 1,
|
|
313
|
-
workspaceFolders: [],
|
|
314
|
-
rootUri: "inmemory://",
|
|
315
|
-
});
|
|
316
|
-
serverLib.initialized({});
|
|
317
|
-
function textDocumentForModel(model) {
|
|
318
|
-
return TextDocument.create(model.uri.toString(), "typespec", model.getVersionId(), model.getValue());
|
|
319
|
-
}
|
|
320
|
-
function lspDocumentArgs(model) {
|
|
321
|
-
return {
|
|
322
|
-
textDocument: textDocumentForModel(model),
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
function lspArgs(model, pos) {
|
|
326
|
-
return {
|
|
327
|
-
...lspDocumentArgs(model),
|
|
328
|
-
position: lspPosition(pos),
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
function lspPosition(pos) {
|
|
332
|
-
return {
|
|
333
|
-
line: pos.lineNumber - 1,
|
|
334
|
-
character: pos.column - 1,
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
function lspFormattingOptions(options) {
|
|
338
|
-
return FormattingOptions.create(options.tabSize, options.insertSpaces);
|
|
339
|
-
}
|
|
340
|
-
function monacoLocation(loc) {
|
|
341
|
-
return {
|
|
342
|
-
uri: monaco.Uri.parse(loc.uri),
|
|
343
|
-
range: LspToMonaco.range(loc.range),
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
function monacoDocumentHighlight(highlight) {
|
|
347
|
-
return {
|
|
348
|
-
range: LspToMonaco.range(highlight.range),
|
|
349
|
-
kind: monacoDocumentHighlightKind(highlight.kind),
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
function monacoDocumentHighlightKind(kind) {
|
|
353
|
-
switch (kind) {
|
|
354
|
-
case DocumentHighlightKind.Text:
|
|
355
|
-
return monaco.languages.DocumentHighlightKind.Text;
|
|
356
|
-
case DocumentHighlightKind.Read:
|
|
357
|
-
return monaco.languages.DocumentHighlightKind.Read;
|
|
358
|
-
case DocumentHighlightKind.Write:
|
|
359
|
-
return monaco.languages.DocumentHighlightKind.Write;
|
|
360
|
-
default:
|
|
361
|
-
return undefined;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
function monacoHoverContents(contents) {
|
|
365
|
-
return [{ value: contents.value }];
|
|
366
|
-
}
|
|
367
|
-
function monacoHover(hover) {
|
|
368
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
369
|
-
if (Array.isArray(hover.contents) || lsp.MarkedString.is(hover.contents)) {
|
|
370
|
-
throw new Error("MarkedString (deprecated) not supported.");
|
|
371
|
-
}
|
|
372
|
-
return {
|
|
373
|
-
contents: monacoHoverContents(hover.contents),
|
|
374
|
-
range: hover.range ? LspToMonaco.range(hover.range) : undefined,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
function monacoWorkspaceEdit(edit) {
|
|
378
|
-
const edits = [];
|
|
379
|
-
for (const [uri, changes] of Object.entries(edit.changes ?? {})) {
|
|
380
|
-
const resource = monaco.Uri.parse(uri);
|
|
381
|
-
for (const change of changes) {
|
|
382
|
-
edits.push({ resource, textEdit: LspToMonaco.textEdit(change), versionId: undefined });
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return { edits };
|
|
386
|
-
}
|
|
387
|
-
monaco.languages.registerDefinitionProvider("typespec", {
|
|
388
|
-
async provideDefinition(model, position) {
|
|
389
|
-
const results = await serverLib.gotoDefinition(lspArgs(model, position));
|
|
390
|
-
return results.map(monacoLocation);
|
|
391
|
-
},
|
|
392
|
-
});
|
|
393
|
-
monaco.languages.registerReferenceProvider("typespec", {
|
|
394
|
-
async provideReferences(model, position, context) {
|
|
395
|
-
const results = await serverLib.findReferences({ ...lspArgs(model, position), context });
|
|
396
|
-
return results.map(monacoLocation);
|
|
397
|
-
},
|
|
398
|
-
});
|
|
399
|
-
monaco.languages.registerRenameProvider("typespec", {
|
|
400
|
-
async resolveRenameLocation(model, position) {
|
|
401
|
-
const result = await serverLib.prepareRename(lspArgs(model, position));
|
|
402
|
-
if (!result) {
|
|
403
|
-
throw new Error("This element can't be renamed.");
|
|
404
|
-
}
|
|
405
|
-
const text = model.getWordAtPosition(position)?.word;
|
|
406
|
-
if (!text) {
|
|
407
|
-
throw new Error("Failed to obtain word at position.");
|
|
408
|
-
}
|
|
409
|
-
return { text, range: LspToMonaco.range(result) };
|
|
410
|
-
},
|
|
411
|
-
async provideRenameEdits(model, position, newName) {
|
|
412
|
-
const result = await serverLib.rename({ ...lspArgs(model, position), newName });
|
|
413
|
-
return monacoWorkspaceEdit(result);
|
|
414
|
-
},
|
|
415
|
-
});
|
|
416
|
-
monaco.languages.registerFoldingRangeProvider("typespec", {
|
|
417
|
-
async provideFoldingRanges(model) {
|
|
418
|
-
const ranges = await serverLib.getFoldingRanges(lspDocumentArgs(model));
|
|
419
|
-
const output = ranges.map(LspToMonaco.foldingRange);
|
|
420
|
-
return output;
|
|
421
|
-
},
|
|
422
|
-
});
|
|
423
|
-
monaco.languages.registerHoverProvider("typespec", {
|
|
424
|
-
async provideHover(model, position) {
|
|
425
|
-
const hover = await serverLib.getHover(lspArgs(model, position));
|
|
426
|
-
return monacoHover(hover);
|
|
427
|
-
},
|
|
428
|
-
});
|
|
429
|
-
monaco.languages.registerSignatureHelpProvider("typespec", {
|
|
430
|
-
signatureHelpTriggerCharacters: ["(", ",", "<"],
|
|
431
|
-
signatureHelpRetriggerCharacters: [")"],
|
|
432
|
-
async provideSignatureHelp(model, position) {
|
|
433
|
-
const help = await serverLib.getSignatureHelp(lspArgs(model, position));
|
|
434
|
-
return { value: LspToMonaco.signatureHelp(help), dispose: () => { } };
|
|
435
|
-
},
|
|
436
|
-
});
|
|
437
|
-
monaco.languages.registerDocumentFormattingEditProvider("typespec", {
|
|
438
|
-
async provideDocumentFormattingEdits(model, options, token) {
|
|
439
|
-
const edits = await serverLib.formatDocument({
|
|
440
|
-
...lspDocumentArgs(model),
|
|
441
|
-
options: lspFormattingOptions(options),
|
|
442
|
-
});
|
|
443
|
-
return LspToMonaco.textEdits(edits);
|
|
444
|
-
},
|
|
445
|
-
});
|
|
446
|
-
monaco.languages.registerDocumentHighlightProvider("typespec", {
|
|
447
|
-
async provideDocumentHighlights(model, position) {
|
|
448
|
-
const highlights = await serverLib.findDocumentHighlight(lspArgs(model, position));
|
|
449
|
-
return highlights.map(monacoDocumentHighlight);
|
|
450
|
-
},
|
|
451
|
-
});
|
|
452
|
-
monaco.languages.registerCompletionItemProvider("typespec", {
|
|
453
|
-
triggerCharacters: lsConfig.capabilities.completionProvider.triggerCharacters,
|
|
454
|
-
async provideCompletionItems(model, position) {
|
|
455
|
-
const result = await serverLib.complete(lspArgs(model, position));
|
|
456
|
-
const word = model.getWordUntilPosition(position);
|
|
457
|
-
const range = {
|
|
458
|
-
startLineNumber: position.lineNumber,
|
|
459
|
-
endLineNumber: position.lineNumber,
|
|
460
|
-
startColumn: word.startColumn,
|
|
461
|
-
endColumn: word.endColumn,
|
|
462
|
-
};
|
|
463
|
-
const suggestions = [];
|
|
464
|
-
for (const item of result.items) {
|
|
465
|
-
let itemRange = range;
|
|
466
|
-
let insertText = item.insertText ?? item.label;
|
|
467
|
-
if (item.textEdit && "range" in item.textEdit) {
|
|
468
|
-
itemRange = LspToMonaco.range(item.textEdit.range);
|
|
469
|
-
insertText = item.textEdit.newText;
|
|
470
|
-
}
|
|
471
|
-
suggestions.push({
|
|
472
|
-
label: item.label,
|
|
473
|
-
kind: item.kind,
|
|
474
|
-
documentation: item.documentation,
|
|
475
|
-
insertText,
|
|
476
|
-
range: itemRange,
|
|
477
|
-
commitCharacters: item.commitCharacters ?? lsConfig.capabilities.completionProvider.allCommitCharacters,
|
|
478
|
-
tags: item.tags,
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
return { suggestions };
|
|
482
|
-
},
|
|
483
|
-
});
|
|
484
|
-
// This doesn't actually work because the lsp is not aware of the diagnostics here as we make our own compilation in the playground.
|
|
485
|
-
// monaco.languages.registerCodeActionProvider("typespec", {
|
|
486
|
-
// async provideCodeActions(model, range, context, token) {
|
|
487
|
-
// const result = await serverLib.getCodeActions({
|
|
488
|
-
// range: MonacoToLsp.range(range),
|
|
489
|
-
// context: MonacoToLsp.codeActionContext(context),
|
|
490
|
-
// textDocument: textDocumentForModel(model),
|
|
491
|
-
// });
|
|
492
|
-
// return { actions: result.map(LspToMonaco.codeAction), dispose: () => {} };
|
|
493
|
-
// },
|
|
494
|
-
// });
|
|
495
|
-
monaco.editor.defineTheme("typespec", {
|
|
496
|
-
base: "vs",
|
|
497
|
-
inherit: true,
|
|
498
|
-
colors: {},
|
|
499
|
-
rules: [
|
|
500
|
-
{ token: "macro", foreground: "#800000" },
|
|
501
|
-
{ token: "function", foreground: "#795E26" },
|
|
502
|
-
],
|
|
503
|
-
});
|
|
504
|
-
monaco.editor.defineTheme("typespec-dark", {
|
|
505
|
-
base: "vs-dark",
|
|
506
|
-
inherit: true,
|
|
507
|
-
colors: {},
|
|
508
|
-
rules: [
|
|
509
|
-
{ token: "macro", foreground: "#E06C75" },
|
|
510
|
-
{ token: "function", foreground: "#E06C75" },
|
|
511
|
-
],
|
|
512
|
-
});
|
|
513
|
-
monaco.editor.setTheme("typespec");
|
|
514
|
-
monaco.languages.registerDocumentSemanticTokensProvider("typespec", {
|
|
515
|
-
getLegend() {
|
|
516
|
-
const legend = lsConfig.capabilities.semanticTokensProvider.legend;
|
|
517
|
-
return {
|
|
518
|
-
tokenModifiers: legend.tokenModifiers,
|
|
519
|
-
tokenTypes: legend.tokenTypes.map((entry) => {
|
|
520
|
-
switch (entry) {
|
|
521
|
-
case "namespace":
|
|
522
|
-
case "class":
|
|
523
|
-
case "enum":
|
|
524
|
-
case "typeParameter":
|
|
525
|
-
case "struct":
|
|
526
|
-
case "interface":
|
|
527
|
-
return "type";
|
|
528
|
-
case "property":
|
|
529
|
-
case "enumMember":
|
|
530
|
-
return "variable";
|
|
531
|
-
case "docCommentTag":
|
|
532
|
-
return "keyword";
|
|
533
|
-
default:
|
|
534
|
-
return entry;
|
|
535
|
-
}
|
|
536
|
-
}),
|
|
537
|
-
};
|
|
538
|
-
},
|
|
539
|
-
async provideDocumentSemanticTokens(model) {
|
|
540
|
-
const result = await serverLib.buildSemanticTokens(lspDocumentArgs(model));
|
|
541
|
-
return {
|
|
542
|
-
resultId: result.resultId,
|
|
543
|
-
data: new Uint32Array(result.data),
|
|
544
|
-
};
|
|
545
|
-
},
|
|
546
|
-
releaseDocumentSemanticTokens() { },
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
function getMonacoRange(typespecCompiler, target) {
|
|
550
|
-
const loc = typespecCompiler.getSourceLocation(target);
|
|
551
|
-
if (loc === undefined || loc.file.path !== "/test/main.tsp") {
|
|
552
|
-
return {
|
|
553
|
-
startLineNumber: 1,
|
|
554
|
-
startColumn: 1,
|
|
555
|
-
endLineNumber: 1,
|
|
556
|
-
endColumn: 1,
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
const start = loc.file.getLineAndCharacterOfPosition(loc.pos);
|
|
560
|
-
const end = loc.file.getLineAndCharacterOfPosition(loc.end);
|
|
561
|
-
return {
|
|
562
|
-
startLineNumber: start.line + 1,
|
|
563
|
-
startColumn: start.character + 1,
|
|
564
|
-
endLineNumber: end.line + 1,
|
|
565
|
-
endColumn: end.character + 1,
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
/**
|
|
570
|
-
* Generic storage mechanism for data in the playground.
|
|
571
|
-
* @param schema Schema of the data to be serialized in the query
|
|
572
|
-
* @returns
|
|
573
|
-
*/
|
|
574
|
-
function createUrlStateStorage(schema) {
|
|
575
|
-
return { load, save, resolveSearchParams };
|
|
576
|
-
function load() {
|
|
577
|
-
const result = {};
|
|
578
|
-
const parsed = new URLSearchParams(window.location.search);
|
|
579
|
-
for (const [key, item] of Object.entries(schema)) {
|
|
580
|
-
const value = parsed.get(item.queryParam);
|
|
581
|
-
const decompressed = value && decompress(item, value);
|
|
582
|
-
const deserialized = decompressed && deserialize(item, decompressed);
|
|
583
|
-
if (deserialized) {
|
|
584
|
-
result[key] = deserialized;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
return result;
|
|
588
|
-
}
|
|
589
|
-
function decompress(item, value) {
|
|
590
|
-
if (item.compress) {
|
|
591
|
-
try {
|
|
592
|
-
return lzutf8.decompress(value, { inputEncoding: "Base64" });
|
|
593
|
-
}
|
|
594
|
-
catch (e) {
|
|
595
|
-
// eslint-disable-next-line no-console
|
|
596
|
-
console.error(`Error decompressing query parameter ${item.queryParam} with content:`, value);
|
|
597
|
-
return undefined;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
else {
|
|
601
|
-
return value;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
function deserialize(item, value) {
|
|
605
|
-
if (item.type === "object") {
|
|
606
|
-
try {
|
|
607
|
-
return JSON.parse(value);
|
|
608
|
-
}
|
|
609
|
-
catch (e) {
|
|
610
|
-
// eslint-disable-next-line no-console
|
|
611
|
-
console.error(`Error decompressing query parameter ${item.queryParam} with content:`, value);
|
|
612
|
-
return undefined;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
else {
|
|
616
|
-
return value;
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
function save(data) {
|
|
620
|
-
const params = resolveSearchParams(data, true);
|
|
621
|
-
history.pushState(null, "", window.location.pathname + "?" + params.toString());
|
|
622
|
-
}
|
|
623
|
-
function resolveSearchParams(data, mergeWithExisting = false) {
|
|
624
|
-
const params = new URLSearchParams(mergeWithExisting ? location.search : undefined);
|
|
625
|
-
for (const [key, item] of Object.entries(schema)) {
|
|
626
|
-
const value = data[key];
|
|
627
|
-
if (value) {
|
|
628
|
-
const serialized = serialize(item, value);
|
|
629
|
-
const compressed = compress(item, serialized);
|
|
630
|
-
params.set(item.queryParam, compressed);
|
|
631
|
-
}
|
|
632
|
-
else {
|
|
633
|
-
params.delete(item.queryParam);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
return params;
|
|
637
|
-
}
|
|
638
|
-
function compress(item, value) {
|
|
639
|
-
if (item.compress) {
|
|
640
|
-
return lzutf8.compress(value, { outputEncoding: "Base64" });
|
|
641
|
-
}
|
|
642
|
-
else {
|
|
643
|
-
return value;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
function serialize(item, value) {
|
|
647
|
-
if (item.type === "object") {
|
|
648
|
-
return JSON.stringify(value);
|
|
649
|
-
}
|
|
650
|
-
else {
|
|
651
|
-
return value;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
export { createUrlStateStorage as a, createBrowserHost as c, getMonacoRange as g, registerMonacoLanguage as r };
|
|
657
|
-
//# sourceMappingURL=state-storage-CObxFEXn.js.map
|