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