Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose JSON worker #3956

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DavidMulder0
Copy link
Contributor

Fix #727

Exposes the JSON worker and the parseDocument function from the JSON Worker.

This is useful when editors want to use the JSON Worker's ability to parse the document, as using a separate parser can result in inconsistencies and does double the work.

(I had a lot of trouble getting this repository to build properly. Best I can tell the instructions in CONTRIBUTING should be significantly updated, and certain things just don't seem to work (the standard playground linked execution seems to never work with the JSON worker)).

@DavidMulder0
Copy link
Contributor Author

@microsoft-github-policy-service agree

@DavidMulder0
Copy link
Contributor Author

Worth noting, this mirrors exactly what the typescript/javascript worker do and how they expose their worker.

@DavidMulder0
Copy link
Contributor Author

And as an example of what this allows

monaco.languages.registerCodeLensProvider('json', {
    provideCodeLenses: async function (model, token) {
      const getWorker = await monaco.languages.json.getWorker();
      const worker = await getWorker(model.uri.toString());
      const schema = await worker.getMatchingSchemas(model.uri.toString());
      return {
        lenses: schema
          .filter((item) => item.schema.format === 'ipv4')
          .map((schemaItem) => {
            const start = model.getPositionAt(schemaItem.node.parent.offset);
            const end = model.getPositionAt(
              schemaItem.node.parent.offset + schemaItem.node.parent.length
            );
            return {
              range: {
                startLineNumber: start.lineNumber,
                startColumn: start.column,
                endLineNumber: end.lineNumber,
                endColumn: end.column,
              },
              id: 'First Line',
              command: {
                id: commandId,
                title: 'Select VM',
              },
            };
          }),
        dispose: () => {},
      };
    },
    resolveCodeLens: function (model, codeLens, token) {
      return codeLens;
    },
});

@hediet
Copy link
Member

hediet commented May 31, 2023

(I had a lot of trouble getting this repository to build properly. Best I can tell the instructions in CONTRIBUTING should be significantly updated, and certain things just don't seem to work (the standard playground linked execution seems to never work with the JSON worker)).

Sorry to hear that. What problems did you run into?
I just noticed, the JSON language features require a bundler. I created #3990 for that

@hediet hediet requested a review from aeschli July 7, 2023 15:40
@DG4ever
Copy link

DG4ever commented Nov 10, 2023

Any news on this pull request? This is exactly what I am looking for.

@@ -4,7 +4,8 @@
*--------------------------------------------------------------------------------------------*/

import * as mode from './jsonMode';
import { Emitter, IEvent, languages } from '../../fillers/monaco-editor-core';
import { Emitter, IEvent, languages, Uri } from '../../fillers/monaco-editor-core';
import type { JSONWorker } from './jsonWorker';
Copy link
Contributor

@aeschli aeschli Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want that all exported types are in monaco.contribution.ts. So also a interface describing the JSONWorker should be defined here.
Can you add a IJSONWorker. I suggest it is limited to the function you want to expose.

@mevisioam mevisioam mentioned this pull request Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose access to JSON worker
4 participants