Skip to content

Commit 9fc0c87

Browse files
committed
refactor(top-bar): use apidom worker for dereferencing actions
1 parent 10db8c6 commit 9fc0c87

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

src/plugins/top-bar/actions/dereference-content.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ShortUniqueId from 'short-unique-id';
2-
import { TextDocument } from 'vscode-languageserver-textdocument';
3-
import { getLanguageService } from '@swagger-api/apidom-ls';
2+
import * as monaco from 'monaco-editor';
43

54
/**
65
* Action types.
@@ -49,19 +48,19 @@ export const dereferenceContentFailure = ({ error, content, baseURI, requestId }
4948
* Async thunks.
5049
*/
5150

52-
export const dereferenceContent = ({ content, baseURI, fileExtension }) => {
51+
export const dereferenceContent = ({ content, baseURI }) => {
5352
const uid = new ShortUniqueId({ length: 10 });
5453

5554
return async (system) => {
56-
const { editorActions } = system;
55+
const { editorActions, fn } = system;
5756
const requestId = uid();
5857

5958
editorActions.dereferenceContentStarted({ content, baseURI, requestId });
6059

61-
const languageService = getLanguageService({});
6260
try {
63-
const document = TextDocument.create(`file://filename${fileExtension}`, 'apidom', 0, content);
64-
const contentDereferenced = await languageService.doDeref(document, {
61+
const model = monaco.editor.getModels().find((m) => m.getValue() === content);
62+
const worker = await fn.getApiDOMWorker()(model.uri);
63+
const contentDereferenced = await worker.doDeref(model.uri.toString(), {
6564
baseURI: baseURI ?? globalThis.location.href,
6665
});
6766

@@ -73,8 +72,6 @@ export const dereferenceContent = ({ content, baseURI, fileExtension }) => {
7372
});
7473
} catch (error) {
7574
return editorActions.dereferenceContentFailure({ error, content, baseURI, requestId });
76-
} finally {
77-
languageService.terminate();
7875
}
7976
};
8077
};

src/plugins/top-bar/components/FileMenu/items/DownloadResolvedJSONMenuItemHandler.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const DownloadResolvedJSONMenuItemHandler = forwardRef(
1919
const fileExtension = '.json';
2020
const fileNameWithExtension = `${fileName}${fileExtension}`;
2121

22-
const dereferenceFSA = await editorActions.dereferenceContent({ content, fileExtension });
22+
const dereferenceFSA = await editorActions.dereferenceContent({ content });
2323
if (dereferenceFSA.error) {
2424
alertDialogMessage.current = dereferenceFSA.meta.errorMessage;
2525
setIsAlertDialogOpen(true);

src/plugins/top-bar/components/FileMenu/items/DownloadResolvedYAMLMenuItemHandler.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const DownloadResolvedYAMLMenuItemHandler = forwardRef(
1919
const fileExtension = '.yaml';
2020
const fileNameWithExtension = `${fileName}${fileExtension}`;
2121

22-
const dereferenceFSA = await editorActions.dereferenceContent({ content, fileExtension });
22+
const dereferenceFSA = await editorActions.dereferenceContent({ content });
2323
if (dereferenceFSA.error) {
2424
alertDialogMessage.current = dereferenceFSA.meta.errorMessage;
2525
setIsAlertDialogOpen(true);

0 commit comments

Comments
 (0)