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 access to JSON worker #727

Closed
TedDriggs opened this issue Feb 20, 2018 · 9 comments · Fixed by #4299 · May be fixed by #3956
Closed

Expose access to JSON worker #727

TedDriggs opened this issue Feb 20, 2018 · 9 comments · Fixed by #4299 · May be fixed by #3956
Assignees
Labels
feature-request Request for new features or functionality json
Milestone

Comments

@TedDriggs
Copy link

monaco.languages.typescript has methods for getting the JS and TS workers, but there is no analogous method for JSON. This seems to imply that getting access to the diagnostic messages requires mining the decorator information or running a second language server.

@rcjsuen
Copy link
Contributor

rcjsuen commented Feb 20, 2018

I think you need to open an issue in the Microsoft/monaco-json repository instead.

@TedDriggs
Copy link
Author

@rcjsuen that repo doesn't accept issues; it says to file them here.

@rcjsuen
Copy link
Contributor

rcjsuen commented Feb 20, 2018

@TedDriggs Oh, you are right! Don't I feel stupid. Sorry... (><)

@aeschli
Copy link
Contributor

aeschli commented Mar 2, 2018

@TedDriggs Please describe what you are trying to achieve.

There's monaco.languages.json that let you configure the JSON worker, e.g. if you want validation or not.

To get access to the diagnostic messages, use monaco.editor.getModelMarkers:

You can try this on the Monaco playground:
https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-configure-json-defaults

monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
    validate: true,
    schemas: [{
        uri: "http://myserver/foo-schema.json",
        schema: {
            type: "object",
            properties: {
                q1: {
                    type: "string"
                }
            },
            required: [ 'q1']
        }
    }]
});


var jsonCode = [
    '{',
    '    "$schema": "http://myserver/foo-schema.json"',
    "}"
].join('\n');

monaco.editor.create(document.getElementById("container"), {
    value: jsonCode,
    language: "json"
});

setInterval(() => {
    console.log(monaco.editor.getModelMarkers({}).map(m => m.message).join(', '));
}, 2000);

Check the dev tools console for the output.

@TedDriggs
Copy link
Author

TedDriggs commented Mar 7, 2018

@aeschli I'm trying that, but it's always a character behind, and I'm not sure how to mitigate that without adding a timeout and hoping for the best. That's made more complicated because I don't have a good way of checking if the markers are in sync with the model value.

If I could get a Promise or callback when the markers change then I might be able to make this work, but otherwise I'm not able to use the model markers.

@aeschli
Copy link
Contributor

aeschli commented Mar 7, 2018

Oh, I see. Can you describe what you need the markers for?
A marker change event makes sense. An API on the JSON worker to compute markers would not be hard to add, but it's not something we have at other places.

@TedDriggs
Copy link
Author

It's easiest to explain with a picture:

schema editor

The error that you currently see is a semantic error I've implemented on my own worker thread. I'd like to show schema and syntax errors alongside my semantic errors. Since the other non-Monaco form fields can also have errors, I'm keeping the source-of-truth diagnostics list in the redux store.

(As an aside, I'm planning to figure out the character ranges for those and add my own model markers, but I've run into microsoft/node-jsonc-parser#7 which has stymied that ambition for now.)

@pcasa
Copy link

pcasa commented Sep 28, 2018

Any progress with this? Going through the same goal of trying to validate JSON via the worker vs getModelMarkers.

@pcasa
Copy link

pcasa commented Sep 28, 2018

This provided a workaround #30 (comment)

@alexdima alexdima added the feature-request Request for new features or functionality label Dec 12, 2019
@alexdima alexdima added this to the Backlog milestone Dec 12, 2019
DavidMulder0 added a commit to DavidMulder0/monaco-editor that referenced this issue May 11, 2023
DavidMulder0 added a commit to DavidMulder0/monaco-editor that referenced this issue May 11, 2023
mevisioam added a commit to mevisioam/monaco-editor that referenced this issue Dec 13, 2023
mevisioam pushed a commit to mevisioam/monaco-editor that referenced this issue Dec 13, 2023
mevisioam added a commit to mevisioam/monaco-editor that referenced this issue Dec 13, 2023
mevisioam added a commit to mevisioam/monaco-editor that referenced this issue Dec 15, 2023
mevisioam pushed a commit to mevisioam/monaco-editor that referenced this issue Dec 15, 2023
mevisioam added a commit to mevisioam/monaco-editor that referenced this issue Dec 15, 2023
mevisioam added a commit to mevisioam/monaco-editor that referenced this issue Dec 15, 2023
mevisioam pushed a commit to mevisioam/monaco-editor that referenced this issue Dec 20, 2023
mevisioam added a commit to mevisioam/monaco-editor that referenced this issue Dec 20, 2023
mevisioam added a commit to mevisioam/monaco-editor that referenced this issue Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality json
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants