@typespec/playground 0.13.0-dev.0 → 0.13.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { c as createBrowserHost, r as registerMonacoLanguage } from './services-BTSPLy3C.js';
1
+ export { c as createBrowserHost, r as registerMonacoLanguage } from './services-CzxNzZLi.js';
2
2
  export { createUrlStateStorage } from './state-storage.js';
3
3
 
4
4
  function registerMonacoDefaultWorkersForVite() {
@@ -7,7 +7,7 @@ import { $ } from '@typespec/compiler/typekit';
7
7
  import { DocumentBulletList24Regular, Dismiss24Regular, Settings24Regular, Save16Regular, Broom16Filled, Bug16Regular, FolderListRegular, DataLineRegular, ErrorCircle16Filled, Warning16Filled, ChevronDown16Regular } from '@fluentui/react-icons';
8
8
  import debounce from 'debounce';
9
9
  import { CompletionItemTag } from 'vscode-languageserver';
10
- import { a as resolveVirtualPath, p as printDebugInfo, d as debugGlobals, g as getMonacoRange, c as createBrowserHost, r as registerMonacoLanguage } from '../services-BTSPLy3C.js';
10
+ import { a as resolveVirtualPath, p as printDebugInfo, d as debugGlobals, g as getMonacoRange, u as updateDiagnosticsForCodeFixes, c as createBrowserHost, r as registerMonacoLanguage } from '../services-CzxNzZLi.js';
11
11
  import { ErrorBoundary } from 'react-error-boundary';
12
12
  import { TypeGraph } from '@typespec/html-program-viewer/react';
13
13
  import '@typespec/html-program-viewer/style.css';
@@ -2073,10 +2073,12 @@ const Playground = (props) => {
2073
2073
  severity: diag.severity === "error" ? MarkerSeverity.Error : MarkerSeverity.Warning,
2074
2074
  tags: diag.code === "deprecated" ? [CompletionItemTag.Deprecated] : void 0
2075
2075
  }));
2076
+ updateDiagnosticsForCodeFixes(typespecCompiler, state2.program.diagnostics);
2076
2077
  debugGlobals().program = state2.program;
2077
2078
  debugGlobals().$$ = $(state2.program);
2078
2079
  editor.setModelMarkers(typespecModel, "owner", markers ?? []);
2079
2080
  } else {
2081
+ updateDiagnosticsForCodeFixes(typespecCompiler, []);
2080
2082
  editor.setModelMarkers(typespecModel, "owner", []);
2081
2083
  }
2082
2084
  }, [host, selectedEmitter, compilerOptions, typespecModel]);
@@ -341,6 +341,12 @@ const MonacoToLsp = {
341
341
  codeActionContext
342
342
  };
343
343
 
344
+ let _currentDiagnostics = [];
345
+ let _currentCompiler;
346
+ function updateDiagnosticsForCodeFixes(compiler, diagnostics) {
347
+ _currentDiagnostics = diagnostics;
348
+ _currentCompiler = compiler;
349
+ }
344
350
  function getIndentAction(value) {
345
351
  switch (value) {
346
352
  case "none":
@@ -588,6 +594,66 @@ async function registerMonacoLanguage(host) {
588
594
  return { suggestions };
589
595
  }
590
596
  });
597
+ monaco.languages.registerCodeActionProvider("typespec", {
598
+ async provideCodeActions(model, range) {
599
+ const compiler = _currentCompiler;
600
+ if (!compiler) return { actions: [], dispose: () => {
601
+ } };
602
+ const actions = [];
603
+ for (const diag of _currentDiagnostics) {
604
+ if (!diag.codefixes?.length) continue;
605
+ const loc = compiler.getSourceLocation(diag.target, { locateId: true });
606
+ if (!loc || loc.file.path !== "/test/main.tsp") continue;
607
+ const monacoRange = getMonacoRange(compiler, diag.target);
608
+ if (!monacoRangesOverlap(monacoRange, range)) continue;
609
+ for (const fix of diag.codefixes) {
610
+ const edits = await compiler.resolveCodeFix(fix);
611
+ const workspaceEdits = edits.filter((edit) => edit.file.path === "/test/main.tsp").map((edit) => {
612
+ const start = edit.file.getLineAndCharacterOfPosition(edit.pos);
613
+ if (edit.kind === "insert-text") {
614
+ return {
615
+ resource: model.uri,
616
+ textEdit: {
617
+ range: {
618
+ startLineNumber: start.line + 1,
619
+ startColumn: start.character + 1,
620
+ endLineNumber: start.line + 1,
621
+ endColumn: start.character + 1
622
+ },
623
+ text: edit.text
624
+ },
625
+ versionId: void 0
626
+ };
627
+ } else {
628
+ const end = edit.file.getLineAndCharacterOfPosition(edit.end);
629
+ return {
630
+ resource: model.uri,
631
+ textEdit: {
632
+ range: {
633
+ startLineNumber: start.line + 1,
634
+ startColumn: start.character + 1,
635
+ endLineNumber: end.line + 1,
636
+ endColumn: end.character + 1
637
+ },
638
+ text: edit.text
639
+ },
640
+ versionId: void 0
641
+ };
642
+ }
643
+ });
644
+ if (workspaceEdits.length > 0) {
645
+ actions.push({
646
+ title: fix.label,
647
+ kind: "quickfix",
648
+ edit: { edits: workspaceEdits }
649
+ });
650
+ }
651
+ }
652
+ }
653
+ return { actions, dispose: () => {
654
+ } };
655
+ }
656
+ });
591
657
  monaco.editor.defineTheme("typespec", {
592
658
  base: "vs",
593
659
  inherit: true,
@@ -661,5 +727,17 @@ function getMonacoRange(typespecCompiler, target) {
661
727
  endColumn: end.character + 1
662
728
  };
663
729
  }
730
+ function monacoRangesOverlap(a, b) {
731
+ if (a.endLineNumber < b.startLineNumber || b.endLineNumber < a.startLineNumber) {
732
+ return false;
733
+ }
734
+ if (a.endLineNumber === b.startLineNumber && a.endColumn < b.startColumn) {
735
+ return false;
736
+ }
737
+ if (b.endLineNumber === a.startLineNumber && b.endColumn < a.startColumn) {
738
+ return false;
739
+ }
740
+ return true;
741
+ }
664
742
 
665
- export { resolveVirtualPath as a, createBrowserHost as c, debugGlobals as d, getMonacoRange as g, printDebugInfo as p, registerMonacoLanguage as r };
743
+ export { resolveVirtualPath as a, createBrowserHost as c, debugGlobals as d, getMonacoRange as g, printDebugInfo as p, registerMonacoLanguage as r, updateDiagnosticsForCodeFixes as u };
@@ -1 +1 @@
1
- {"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../../../src/react/playground.tsx"],"names":[],"mappings":"AAGA,OAAO,sCAAsC,CAAC;AAG9C,OAAO,EAML,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAKf,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAQjE,OAAO,KAAK,EAAoB,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;A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AAE,SAAS,CAAC;IAE9B,uBAAuB;IACvB,KAAK,CAAC,EAAE,eAAe,CAAC;IAExB,kDAAkD;IAClD,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAE1B,4FAA4F;IAC5F,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAEpD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAE7C,aAAa,CAAC,EAAE,wBAAwB,CAAC;IAEzC;;OAEG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAEhB,oBAAoB;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,4BAA4B;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,UAAU,EAAE,iBAAiB,CAAC,eAAe,CAqPzD,CAAC"}
@@ -1,6 +1,12 @@
1
- import { DiagnosticTarget, NoTarget } from '@typespec/compiler';
1
+ import { Diagnostic, DiagnosticTarget, NoTarget } from '@typespec/compiler';
2
2
  import { BrowserHost } from './types.js';
3
3
  import * as monaco from "monaco-editor";
4
+ /**
5
+ * Update the current diagnostics so the Monaco code action provider can
6
+ * surface codefixes for the playground's own compilation results.
7
+ * Call this after every compilation.
8
+ */
9
+ export declare function updateDiagnosticsForCodeFixes(compiler: typeof import("@typespec/compiler"), diagnostics: readonly Diagnostic[]): void;
4
10
  export declare function registerMonacoLanguage(host: BrowserHost): Promise<void>;
5
11
  export declare function getMonacoRange(typespecCompiler: typeof import("@typespec/compiler"), target: DiagnosticTarget | typeof NoTarget): monaco.IRange;
6
12
  //# sourceMappingURL=services.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../src/services.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EAEd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAMxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAmC9C,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,WAAW,iBAsU7D;AAED,wBAAgB,cAAc,CAC5B,gBAAgB,EAAE,cAAc,oBAAoB,CAAC,EACrD,MAAM,EAAE,gBAAgB,GAAG,OAAO,QAAQ,GACzC,MAAM,CAAC,MAAM,CAkBf"}
1
+ {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../src/services.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EAEd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAMxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAO9C;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,cAAc,oBAAoB,CAAC,EAC7C,WAAW,EAAE,SAAS,UAAU,EAAE,QAInC;AAmCD,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,WAAW,iBA4X7D;AAED,wBAAgB,cAAc,CAC5B,gBAAgB,EAAE,cAAc,oBAAoB,CAAC,EACrD,MAAM,EAAE,gBAAgB,GAAG,OAAO,QAAQ,GACzC,MAAM,CAAC,MAAM,CAkBf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/playground",
3
- "version": "0.13.0-dev.0",
3
+ "version": "0.13.0-dev.1",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec playground UI components.",
6
6
  "homepage": "https://typespec.io",
@@ -64,7 +64,7 @@
64
64
  "@typespec/bundler": "^0.5.0 || >=0.6.0-dev <0.6.0",
65
65
  "@typespec/compiler": "^1.9.0",
66
66
  "@typespec/html-program-viewer": "^0.79.0 || >=0.80.0-dev <0.80.0",
67
- "@typespec/http": "^1.9.0",
67
+ "@typespec/http": "^1.9.1",
68
68
  "@typespec/openapi": "^1.9.0",
69
69
  "@typespec/openapi3": "^1.9.0",
70
70
  "@typespec/protobuf": "^0.79.0 || >=0.80.0-dev <0.80.0",